Finished load and save mechanic, v1.3.0
This commit is contained in:
parent
267dd1c626
commit
8fcc58ee6b
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@
|
|||||||
/[Ll]ogs/
|
/[Ll]ogs/
|
||||||
/[Mm]emoryCaptures/
|
/[Mm]emoryCaptures/
|
||||||
/[Pp]ackages/
|
/[Pp]ackages/
|
||||||
|
/[Ss]ave/
|
||||||
|
|
||||||
# Asset meta data should only be ignored when the corresponding asset is also ignored
|
# Asset meta data should only be ignored when the corresponding asset is also ignored
|
||||||
!/[Aa]ssets/**/*.meta
|
!/[Aa]ssets/**/*.meta
|
||||||
|
|||||||
@ -117,6 +117,7 @@ namespace Assets.Scripts
|
|||||||
public void saveGame()
|
public void saveGame()
|
||||||
{
|
{
|
||||||
audioHandler.playButtonClick();
|
audioHandler.playButtonClick();
|
||||||
|
FileHandler.generateDirectory();
|
||||||
string saveString = "{\r\n\"player\": {\r\n" + player.saveGame();
|
string saveString = "{\r\n\"player\": {\r\n" + player.saveGame();
|
||||||
saveString = saveString + "\r\n},\r\n\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n}\r\n}";
|
saveString = saveString + "\r\n},\r\n\"world\": {\r\n" + worldGenerator.saveGame() + "\r\n}\r\n}";
|
||||||
FileHandler.saveGame(saveString, "./save.json");
|
FileHandler.saveGame(saveString, "./save.json");
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -154,4 +155,80 @@ public class ContentGenerator : MonoBehaviour
|
|||||||
return boss;
|
return boss;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameObject loadObject(JToken json)
|
||||||
|
{
|
||||||
|
GameObject result = gameObject;
|
||||||
|
string name = json["objectname"].ToString().Replace("(Clone)", "");
|
||||||
|
if (name.ToLower().Contains("stone"))
|
||||||
|
{
|
||||||
|
foreach (GameObject stone in stones)
|
||||||
|
{
|
||||||
|
if (stone.name == name)
|
||||||
|
{
|
||||||
|
result = stone;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (GameObject tree in trees)
|
||||||
|
{
|
||||||
|
if (tree.name == name)
|
||||||
|
{
|
||||||
|
result = tree;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameObject loadEnemy(JToken json)
|
||||||
|
{
|
||||||
|
GameObject result = gameObject;
|
||||||
|
string name = json["enemyname"].ToString().Replace("(Clone)", "");
|
||||||
|
if (name.Split(' ').Length > 1)
|
||||||
|
{
|
||||||
|
name = name.Split(' ')[1];
|
||||||
|
}
|
||||||
|
if (name == "(Boss)")
|
||||||
|
{
|
||||||
|
result = boss;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "(Metal)":
|
||||||
|
name = "SlimeMetalIdle";
|
||||||
|
break;
|
||||||
|
case "(MiniBoss)":
|
||||||
|
name = "SlimeMiniBossIdle";
|
||||||
|
break;
|
||||||
|
case "(Water)":
|
||||||
|
name = "SlimeWaterIdle";
|
||||||
|
break;
|
||||||
|
case "(Mage)":
|
||||||
|
name = "SlimeMageIdle";
|
||||||
|
break;
|
||||||
|
case "(Warrior)":
|
||||||
|
name = "SlimeWarriorIdle";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
name = "SlimeBaseIdle";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
foreach (GameObject enemy in enemies)
|
||||||
|
{
|
||||||
|
if (enemy.name == name)
|
||||||
|
{
|
||||||
|
result = enemy;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using Assets.Scripts;
|
using Assets.Scripts;
|
||||||
using Assets.Scripts.Slimes;
|
using Assets.Scripts.Slimes;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -130,5 +131,10 @@ namespace Assets.Scripts
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadEnemy(JToken json)
|
||||||
|
{
|
||||||
|
slime = new BasicSlime(json);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -15,15 +15,8 @@ namespace Assets.Scripts
|
|||||||
{
|
{
|
||||||
static StreamWriter sw;
|
static StreamWriter sw;
|
||||||
public static void saveGame(string data, string path)
|
public static void saveGame(string data, string path)
|
||||||
{
|
|
||||||
if (!File.Exists(path))
|
|
||||||
{
|
|
||||||
sw = File.CreateText(path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
sw = new StreamWriter(path);
|
sw = new StreamWriter(path);
|
||||||
}
|
|
||||||
sw.Write(data);
|
sw.Write(data);
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
sw.Close();
|
sw.Close();
|
||||||
@ -39,22 +32,15 @@ namespace Assets.Scripts
|
|||||||
{
|
{
|
||||||
jsonString = jsonString + line.Replace("\r\n", "");
|
jsonString = jsonString + line.Replace("\r\n", "");
|
||||||
}
|
}
|
||||||
JArray json = JsonConvert.DeserializeObject<JArray>(jsonString);
|
JObject json = JsonConvert.DeserializeObject<JObject>(jsonString);
|
||||||
player.loadPlayer(json["player"]);
|
player.loadPlayer(json["player"]);
|
||||||
worldGenerator.loadWorld(json["world"]);
|
worldGenerator.loadWorld(json["world"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveAudio(string path, float music, float effects)
|
public static void saveAudio(string path, float music, float effects)
|
||||||
{
|
|
||||||
if (!File.Exists(path))
|
|
||||||
{
|
|
||||||
sw = File.CreateText(path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
sw = new StreamWriter(path);
|
sw = new StreamWriter(path);
|
||||||
}
|
|
||||||
sw.WriteLine("Music:" + music);
|
sw.WriteLine("Music:" + music);
|
||||||
sw.WriteLine("Effects:" + effects);
|
sw.WriteLine("Effects:" + effects);
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
@ -86,5 +72,44 @@ namespace Assets.Scripts
|
|||||||
{
|
{
|
||||||
return File.Exists("./save.json");
|
return File.Exists("./save.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void saveTile(string content, string path)
|
||||||
|
{
|
||||||
|
sw = new StreamWriter(path);
|
||||||
|
sw.Write(content);
|
||||||
|
sw.Flush();
|
||||||
|
sw.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveNoise(string content, string path)
|
||||||
|
{
|
||||||
|
sw = new StreamWriter(path, true);
|
||||||
|
sw.Write(content);
|
||||||
|
sw.Flush();
|
||||||
|
sw.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void generateDirectory()
|
||||||
|
{
|
||||||
|
if (!Directory.Exists("./save/"))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory("./save/");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Directory.Delete("./save/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string loadTile(string path)
|
||||||
|
{
|
||||||
|
string result = "";
|
||||||
|
string[] lines = File.ReadAllLines(path);
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
result = result + line.Replace("\r\n", "");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,8 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
public class NoiseGenerator
|
public class NoiseGenerator
|
||||||
{
|
{
|
||||||
@ -230,7 +232,7 @@ public class NoiseGenerator
|
|||||||
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
|
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string saveTile(GameObject tile)
|
public void saveTile(GameObject tile, string path)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
Vector3[] vertices = tile.GetComponent<MeshFilter>().mesh.vertices;
|
Vector3[] vertices = tile.GetComponent<MeshFilter>().mesh.vertices;
|
||||||
@ -247,13 +249,38 @@ public class NoiseGenerator
|
|||||||
result = result + "\r\n},\"colors\": {\r\n";
|
result = result + "\r\n},\"colors\": {\r\n";
|
||||||
for (int i = 0; i < colors.Length; i++)
|
for (int i = 0; i < colors.Length; i++)
|
||||||
{
|
{
|
||||||
result = result + FileHandler.generateJSON("color" + i, "\"" + colors[i].r + "/" + colors[i].g + "/" + colors[i].b + "\"");
|
result = result + FileHandler.generateJSON("color" + i, "\"" + colors[i].r + "/" + colors[i].g + "/" + colors[i].b + "/" + colors[i].a + "\"");
|
||||||
if (i < colors.Length - 1)
|
if (i < colors.Length - 1)
|
||||||
{
|
{
|
||||||
result = result + ",\r\n";
|
result = result + ",\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = result + "\r\n}";
|
result = result + "\r\n}\r\n}";
|
||||||
return result;
|
FileHandler.saveNoise(result, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadTile(GameObject tile, JToken jsonVertices, JToken jsonColors)
|
||||||
|
{
|
||||||
|
var jsonData = JObject.Parse(jsonColors.ToString()).Children();
|
||||||
|
List<JToken> colorTokens = jsonData.Children().ToList();
|
||||||
|
jsonData = JObject.Parse(jsonVertices.ToString()).Children();
|
||||||
|
List<JToken> verticeTokens = jsonData.Children().ToList();
|
||||||
|
Color32[] colors = new Color32[colorTokens.Count];
|
||||||
|
Vector3[] vertices = new Vector3[verticeTokens.Count];
|
||||||
|
JToken current;
|
||||||
|
string[] parts;
|
||||||
|
for(int i = 0; i < colorTokens.Count;i++)
|
||||||
|
{
|
||||||
|
current = colorTokens[i];
|
||||||
|
parts = current.Value<string>().Split('/');
|
||||||
|
colors[i] = new Color32(byte.Parse(parts[0]), byte.Parse(parts[1]), byte.Parse(parts[2]), byte.Parse(parts[3]));
|
||||||
|
}
|
||||||
|
for (int i = 0; i < verticeTokens.Count; i++)
|
||||||
|
{
|
||||||
|
current = verticeTokens[i];
|
||||||
|
parts = current.Value<string>().Split('/');
|
||||||
|
vertices[i] = new Vector3(float.Parse(parts[0]), float.Parse(parts[1]), float.Parse(parts[2]));
|
||||||
|
}
|
||||||
|
applyMesh(tile, vertices, tile.GetComponent<MeshFilter>().mesh, colors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -601,6 +601,7 @@ namespace Assets.Scripts
|
|||||||
isDodging = bool.Parse(json["isDodging"].ToString());
|
isDodging = bool.Parse(json["isDodging"].ToString());
|
||||||
killcount = (int)json["killcount"];
|
killcount = (int)json["killcount"];
|
||||||
difficulty = (int)json["difficulty"];
|
difficulty = (int)json["difficulty"];
|
||||||
|
generateSkills();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadRole(string name)
|
private void loadRole(string name)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -33,6 +34,19 @@ namespace Assets.Scripts.Slimes
|
|||||||
level = playerStats[7];
|
level = playerStats[7];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BasicSlime(JToken json)
|
||||||
|
{
|
||||||
|
maxHealth = (int)json["maxHealth"];
|
||||||
|
maxSecondary = (int)json["maxSecondary"];
|
||||||
|
secondary = (int)json["secondary"];
|
||||||
|
health = (int)json["health"];
|
||||||
|
strength = (int)json["strength"];
|
||||||
|
dexterity = (int)json["dexterity"];
|
||||||
|
intelligence = (int)json["intelligence"];
|
||||||
|
level = (int)json["level"];
|
||||||
|
experience = (int)json["experience"];
|
||||||
|
}
|
||||||
|
|
||||||
public int[] getStats()
|
public int[] getStats()
|
||||||
{
|
{
|
||||||
int[] result = { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
|
int[] result = { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
using Assets.Scripts;
|
using Assets.Scripts;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Tile : MonoBehaviour
|
public class Tile : MonoBehaviour
|
||||||
@ -215,9 +217,9 @@ public class Tile : MonoBehaviour
|
|||||||
return tiletype;
|
return tiletype;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string saveTile()
|
public void saveTile(string path)
|
||||||
{
|
{
|
||||||
string result = "";
|
string result = "{\r\n";
|
||||||
GameObject obj;
|
GameObject obj;
|
||||||
result = result + FileHandler.generateJSON("tiletype", "\"" + tiletype + "\"") + ",\r\n";
|
result = result + FileHandler.generateJSON("tiletype", "\"" + tiletype + "\"") + ",\r\n";
|
||||||
result = result + FileHandler.generateJSON("position", "\"" + position.x + "/" + position.y + "/" + position.z + "\"") + ",\r\n";
|
result = result + FileHandler.generateJSON("position", "\"" + position.x + "/" + position.y + "/" + position.z + "\"") + ",\r\n";
|
||||||
@ -240,8 +242,8 @@ public class Tile : MonoBehaviour
|
|||||||
result = result + ",\r\n";
|
result = result + ",\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = result + "\r\n}";
|
result = result + "\r\n},";
|
||||||
return result;
|
FileHandler.saveTile(result, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string saveCurrent()
|
public string saveCurrent()
|
||||||
@ -250,4 +252,48 @@ public class Tile : MonoBehaviour
|
|||||||
result = result + "\"" + position.x + "/" + position.y + "/" + position.z + "\"";
|
result = result + "\"" + position.x + "/" + position.y + "/" + position.z + "\"";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadTile(JToken json, Vector3 pos)
|
||||||
|
{
|
||||||
|
var jsonData = JObject.Parse(json["objects"].ToString()).Children();
|
||||||
|
List<JToken> tokens = jsonData.Children().ToList();
|
||||||
|
contentGenerator = GameObject.Find("ContentGenerator");
|
||||||
|
GameObject spawnedObject;
|
||||||
|
Vector3 position;
|
||||||
|
foreach (JToken obj in tokens)
|
||||||
|
{
|
||||||
|
if (obj["objectname"] != null)
|
||||||
|
{
|
||||||
|
if (obj["objectname"].ToString() != "pnlWater")
|
||||||
|
{
|
||||||
|
spawnedObject = contentGenerator.GetComponent<ContentGenerator>().loadObject(obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spawnedObject = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spawnedObject = contentGenerator.GetComponent<ContentGenerator>().loadEnemy(obj);
|
||||||
|
}
|
||||||
|
if (spawnedObject != null)
|
||||||
|
{
|
||||||
|
position = new Vector3(float.Parse(obj["position"].ToString().Split('/')[0]), float.Parse(obj["position"].ToString().Split('/')[1]), float.Parse(obj["position"].ToString().Split('/')[2]));
|
||||||
|
spawnedObject = Instantiate(spawnedObject, position, Quaternion.identity);
|
||||||
|
spawnedObject.transform.parent = gameObject.transform;
|
||||||
|
if (spawnedObject.tag.Contains("Enemy"))
|
||||||
|
{
|
||||||
|
aliveEnemies.Add(spawnedObject);
|
||||||
|
if (obj["health"] != null)
|
||||||
|
{
|
||||||
|
spawnedObject.GetComponent<Enemy>().loadEnemy(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tiletype = json["tiletype"].ToString();
|
||||||
|
setPosition(pos);
|
||||||
|
setBorders();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
using Assets.Scripts;
|
using Assets.Scripts;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@ -21,9 +24,14 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
tiles = new Dictionary<Vector3, GameObject>();
|
tiles = new Dictionary<Vector3, GameObject>();
|
||||||
tiles.Add(new Vector3(0,0,0), GameObject.Find("Spawn"));
|
tiles.Add(new Vector3(0, 0, 0), GameObject.Find("Spawn"));
|
||||||
renderedTiles = new List<GameObject>();
|
renderedTiles = new List<GameObject>();
|
||||||
currentTile = GameObject.Find("Spawn");
|
currentTile = GameObject.Find("Spawn");
|
||||||
currentTile.GetComponent<Tile>().setPosition(new Vector3(0, 0, 0));
|
currentTile.GetComponent<Tile>().setPosition(new Vector3(0, 0, 0));
|
||||||
@ -53,7 +61,7 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
}
|
}
|
||||||
player.transform.position = new Vector3(0,1.5f,0);
|
player.transform.position = new Vector3(0,1.5f,0);
|
||||||
player.transform.rotation = Quaternion.identity;
|
player.transform.rotation = Quaternion.identity;
|
||||||
Start();
|
OnEnable();
|
||||||
currentTile.GetComponent<Tile>().resetSpawn();
|
currentTile.GetComponent<Tile>().resetSpawn();
|
||||||
this.cityAmount = cityAmount;
|
this.cityAmount = cityAmount;
|
||||||
maxCityAmount = cityAmount;
|
maxCityAmount = cityAmount;
|
||||||
@ -184,6 +192,7 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
{
|
{
|
||||||
string result = "";
|
string result = "";
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
string savePath = "";
|
||||||
result = result + FileHandler.generateJSON("cityAmount", cityAmount) + ",\r\n";
|
result = result + FileHandler.generateJSON("cityAmount", cityAmount) + ",\r\n";
|
||||||
result = result + FileHandler.generateJSON("maxCityAmount", maxCityAmount) + ",\r\n";
|
result = result + FileHandler.generateJSON("maxCityAmount", maxCityAmount) + ",\r\n";
|
||||||
result = result + "\"currentTile\": " + currentTile.GetComponent<Tile>().saveCurrent() + ",\r\n";
|
result = result + "\"currentTile\": " + currentTile.GetComponent<Tile>().saveCurrent() + ",\r\n";
|
||||||
@ -192,10 +201,18 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (tile.name != "Spawn")
|
if (tile.name != "Spawn")
|
||||||
{
|
{
|
||||||
result = result + "\"tile" + counter + "\": {\r\n";
|
savePath = "./save/tile" + counter + ".json";
|
||||||
result = result + tile.GetComponent<Tile>().saveTile() + ",\r\n";
|
result = result + "\"tile" + counter + "\": \"" + savePath + "\"";
|
||||||
result = result + noise.saveTile(tile) + "\r\n}";
|
tile.GetComponent<Tile>().saveTile(savePath);
|
||||||
if (counter < tiles.Count - 1)
|
if (tile.GetComponent<Tile>().getTileType() == "CityTile")
|
||||||
|
{
|
||||||
|
FileHandler.saveNoise("\r\n}", savePath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
noise.saveTile(tile, savePath);
|
||||||
|
}
|
||||||
|
if (counter < tiles.Count - 2)
|
||||||
{
|
{
|
||||||
result = result + ",\r\n";
|
result = result + ",\r\n";
|
||||||
}
|
}
|
||||||
@ -205,4 +222,39 @@ public class WorldGenerator : MonoBehaviour
|
|||||||
result = result + "\r\n}";
|
result = result + "\r\n}";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadWorld(JToken json)
|
||||||
|
{
|
||||||
|
resetGame(0);
|
||||||
|
cityAmount = (int)json["cityAmount"];
|
||||||
|
maxCityAmount = (int)json["maxCityAmount"];
|
||||||
|
string[] vectorParts = json["currentTile"].ToString().Split('/');
|
||||||
|
Vector3 current = new Vector3(float.Parse(vectorParts[0]), float.Parse(vectorParts[1]), float.Parse(vectorParts[2]));
|
||||||
|
GameObject loadedTile;
|
||||||
|
Vector3 mapPos;
|
||||||
|
Vector3 pos;
|
||||||
|
foreach (JProperty tilePath in json["map"])
|
||||||
|
{
|
||||||
|
JToken jsonData = JObject.Parse(FileHandler.loadTile(tilePath.Value.ToString()));
|
||||||
|
vectorParts = jsonData["position"].ToString().Split('/');
|
||||||
|
pos = new Vector3(float.Parse(vectorParts[0]), float.Parse(vectorParts[1]), float.Parse(vectorParts[2]));
|
||||||
|
mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
|
||||||
|
if (jsonData["tiletype"].ToString() == "CityTile")
|
||||||
|
{
|
||||||
|
loadedTile = Instantiate(city, mapPos, Quaternion.identity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loadedTile = Instantiate(tile, mapPos, Quaternion.identity);
|
||||||
|
loadedTile.GetComponent<Tile>().loadTile(jsonData, pos);
|
||||||
|
noise.loadTile(loadedTile, jsonData["vertices"], jsonData["colors"]);
|
||||||
|
}
|
||||||
|
tiles.Add(pos, loadedTile);
|
||||||
|
renderedTiles.Add(loadedTile);
|
||||||
|
}
|
||||||
|
currentTile = tiles[current];
|
||||||
|
updateRenderedTiles();
|
||||||
|
Vector3 position = new Vector3(currentTile.transform.position.x, 5, currentTile.transform.position.z);
|
||||||
|
player.transform.SetPositionAndRotation(position, player.transform.rotation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
378
save.json
378
save.json
@ -1,352 +1,30 @@
|
|||||||
{
|
{
|
||||||
"player": {
|
"player": {
|
||||||
"playername": "",
|
"playername": "",
|
||||||
"maxHealth": 110,
|
"maxHealth": 110,
|
||||||
"maxSecondary": 10,
|
"maxSecondary": 10,
|
||||||
"secondary": 10,
|
"secondary": 10,
|
||||||
"health": 110,
|
"health": 110,
|
||||||
"strength": 7,
|
"strength": 7,
|
||||||
"dexterity": 5,
|
"dexterity": 5,
|
||||||
"intelligence": 3,
|
"intelligence": 3,
|
||||||
"level": 0,
|
"level": 0,
|
||||||
"experience": 0,
|
"experience": 0,
|
||||||
"maxExperience": 10,
|
"maxExperience": 10,
|
||||||
"race": "Human",
|
"race": "Human",
|
||||||
"role": "Warrior",
|
"role": "Warrior",
|
||||||
"points": 0,
|
"points": 0,
|
||||||
"isDodging": "False",
|
"isDodging": "False",
|
||||||
"killcount": 0,
|
"killcount": 0,
|
||||||
"difficulty": 0
|
"difficulty": 0
|
||||||
},
|
},
|
||||||
"world": {
|
"world": {
|
||||||
"cityAmount": 10,
|
"cityAmount": 5,
|
||||||
"maxCityAmount": 10,
|
"maxCityAmount": 5,
|
||||||
"currentTile": "-1/0/0",
|
"currentTile": "0/0/-1",
|
||||||
"map": {
|
"map": {
|
||||||
"tile0": {
|
"tile0": "./save/tile0.json",
|
||||||
"tiletype": "Plane",
|
"tile1": "./save/tile1.json"
|
||||||
"position": "-1/0/0",
|
}
|
||||||
"objects": {
|
}
|
||||||
"object0": {
|
|
||||||
"position": "-100/-0.5/0",
|
|
||||||
"objectname": "pnlWater"
|
|
||||||
},
|
|
||||||
"object1": {
|
|
||||||
"position": "-100/3.901497/36",
|
|
||||||
"objectname": "PineTree(Clone)"
|
|
||||||
},
|
|
||||||
"object2": {
|
|
||||||
"position": "-78/4.525089/40",
|
|
||||||
"objectname": "PineTree(Clone)"
|
|
||||||
},
|
|
||||||
"object3": {
|
|
||||||
"position": "-62/1.825109/40",
|
|
||||||
"enemyname": "Slime"
|
|
||||||
},
|
|
||||||
"object4": {
|
|
||||||
"position": "-134/5.226842/29",
|
|
||||||
"objectname": "OakTree(Clone)"
|
|
||||||
},
|
|
||||||
"object5": {
|
|
||||||
"position": "-111/4.363989/33",
|
|
||||||
"objectname": "PineTree(Clone)"
|
|
||||||
},
|
|
||||||
"object6": {
|
|
||||||
"position": "-98/4.430823/27",
|
|
||||||
"objectname": "OakTree(Clone)"
|
|
||||||
},
|
|
||||||
"object7": {
|
|
||||||
"position": "-129/2.661985/22",
|
|
||||||
"objectname": "StoneBasic(Clone)"
|
|
||||||
},
|
|
||||||
"object8": {
|
|
||||||
"position": "-111/1.722374/21",
|
|
||||||
"objectname": "StoneBasic(Clone)"
|
|
||||||
},
|
|
||||||
"object9": {
|
|
||||||
"position": "-93/1.801105/18",
|
|
||||||
"objectname": "StoneBasic(Clone)"
|
|
||||||
},
|
|
||||||
"object10": {
|
|
||||||
"position": "-64/5.297513/19",
|
|
||||||
"objectname": "OakTree(Clone)"
|
|
||||||
},
|
|
||||||
"object11": {
|
|
||||||
"position": "-138/2.517758/9",
|
|
||||||
"objectname": "StoneBasic2(Clone)"
|
|
||||||
},
|
|
||||||
"object12": {
|
|
||||||
"position": "-120/1.416847/7",
|
|
||||||
"enemyname": "Slime (Water)"
|
|
||||||
},
|
|
||||||
"object13": {
|
|
||||||
"position": "-68/5.504285/12",
|
|
||||||
"objectname": "OakTree(Clone)"
|
|
||||||
},
|
|
||||||
"object14": {
|
|
||||||
"position": "-58/5.000051/10",
|
|
||||||
"objectname": "OakTree(Clone)"
|
|
||||||
},
|
|
||||||
"object15": {
|
|
||||||
"position": "-142/4.742146/-21",
|
|
||||||
"objectname": "OakTree(Clone)"
|
|
||||||
},
|
|
||||||
"object16": {
|
|
||||||
"position": "-144/1.74514/-44",
|
|
||||||
"objectname": "StoneBasic2(Clone)"
|
|
||||||
},
|
|
||||||
"object17": {
|
|
||||||
"position": "-111/1.408948/-39",
|
|
||||||
"enemyname": "Slime (Water)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"vertices": {
|
|
||||||
"vertice0": "5/0/5",
|
|
||||||
"vertice1": "4/0/5",
|
|
||||||
"vertice2": "3/0/5",
|
|
||||||
"vertice3": "2/0/5",
|
|
||||||
"vertice4": "0.9999999/0/5",
|
|
||||||
"vertice5": "0/0/5",
|
|
||||||
"vertice6": "-1/0/5",
|
|
||||||
"vertice7": "-2/0/5",
|
|
||||||
"vertice8": "-3/0/5",
|
|
||||||
"vertice9": "-4/0/5",
|
|
||||||
"vertice10": "-5/0/5",
|
|
||||||
"vertice11": "5/0/4",
|
|
||||||
"vertice12": "4/0.76252/4",
|
|
||||||
"vertice13": "3/1.109103/4",
|
|
||||||
"vertice14": "2/0.478129/4",
|
|
||||||
"vertice15": "0.9999999/0.371061/4",
|
|
||||||
"vertice16": "0/-0.08722392/4",
|
|
||||||
"vertice17": "-1/-0.228939/4",
|
|
||||||
"vertice18": "-2/1.378129/4",
|
|
||||||
"vertice19": "-3/0.8091032/4",
|
|
||||||
"vertice20": "-4/1.06252/4",
|
|
||||||
"vertice21": "-5/0/4",
|
|
||||||
"vertice22": "5/0/3",
|
|
||||||
"vertice23": "4/-0.01149016/3",
|
|
||||||
"vertice24": "3/0.935093/3",
|
|
||||||
"vertice25": "2/0.3041188/3",
|
|
||||||
"vertice26": "0.9999999/0.4970509/3",
|
|
||||||
"vertice27": "0/0.03876588/3",
|
|
||||||
"vertice28": "-1/0.797051/3",
|
|
||||||
"vertice29": "-2/0.9041188/3",
|
|
||||||
"vertice30": "-3/1.535093/3",
|
|
||||||
"vertice31": "-4/0.5885098/3",
|
|
||||||
"vertice32": "-5/0/3",
|
|
||||||
"vertice33": "5/0/2",
|
|
||||||
"vertice34": "4/1.585729/2",
|
|
||||||
"vertice35": "3/0.7323117/2",
|
|
||||||
"vertice36": "2/0.7013376/2",
|
|
||||||
"vertice37": "0.9999999/-0.005730294/2",
|
|
||||||
"vertice38": "0/1.335985/2",
|
|
||||||
"vertice39": "-1/0.2942697/2",
|
|
||||||
"vertice40": "-2/0.7013376/2",
|
|
||||||
"vertice41": "-3/1.332312/2",
|
|
||||||
"vertice42": "-4/1.585729/2",
|
|
||||||
"vertice43": "-5/0/2",
|
|
||||||
"vertice44": "5/0/0.9999999",
|
|
||||||
"vertice45": "4/1.636129/0.9999999",
|
|
||||||
"vertice46": "3/1.682712/0.9999999",
|
|
||||||
"vertice47": "2/0.4517377/0.9999999",
|
|
||||||
"vertice48": "0.9999999/0.6446697/0.9999999",
|
|
||||||
"vertice49": "0/1.086385/0.9999999",
|
|
||||||
"vertice50": "-1/0.04466984/0.9999999",
|
|
||||||
"vertice51": "-2/0.4517377/0.9999999",
|
|
||||||
"vertice52": "-3/1.082712/0.9999999",
|
|
||||||
"vertice53": "-4/1.336129/0.9999999",
|
|
||||||
"vertice54": "-5/0/0.9999999",
|
|
||||||
"vertice55": "5/0/0",
|
|
||||||
"vertice56": "4/0.1455633/0",
|
|
||||||
"vertice57": "3/1.092146/0",
|
|
||||||
"vertice58": "2/0.1611723/0",
|
|
||||||
"vertice59": "0.9999999/0.05410425/0",
|
|
||||||
"vertice60": "0/-0.1041808/0",
|
|
||||||
"vertice61": "-1/1.554104/0",
|
|
||||||
"vertice62": "-2/0.1611723/0",
|
|
||||||
"vertice63": "-3/1.092146/0",
|
|
||||||
"vertice64": "-4/0.4455633/0",
|
|
||||||
"vertice65": "-5/0/0",
|
|
||||||
"vertice66": "5/0/-1",
|
|
||||||
"vertice67": "4/1.036129/-1",
|
|
||||||
"vertice68": "3/0.1827119/-1",
|
|
||||||
"vertice69": "2/0.1517377/-1",
|
|
||||||
"vertice70": "0.9999999/1.24467/-1",
|
|
||||||
"vertice71": "0/1.386385/-1",
|
|
||||||
"vertice72": "-1/1.24467/-1",
|
|
||||||
"vertice73": "-2/0.4517377/-1",
|
|
||||||
"vertice74": "-3/1.682712/-1",
|
|
||||||
"vertice75": "-4/0.4361287/-1",
|
|
||||||
"vertice76": "-5/0/-1",
|
|
||||||
"vertice77": "5/0/-2",
|
|
||||||
"vertice78": "4/0.6857287/-2",
|
|
||||||
"vertice79": "3/0.7323117/-2",
|
|
||||||
"vertice80": "2/1.601338/-2",
|
|
||||||
"vertice81": "0.9999999/-0.005730294/-2",
|
|
||||||
"vertice82": "0/1.335985/-2",
|
|
||||||
"vertice83": "-1/0.5942697/-2",
|
|
||||||
"vertice84": "-2/0.1013376/-2",
|
|
||||||
"vertice85": "-3/1.632312/-2",
|
|
||||||
"vertice86": "-4/0.9857288/-2",
|
|
||||||
"vertice87": "-5/0/-2",
|
|
||||||
"vertice88": "5/0/-3",
|
|
||||||
"vertice89": "4/0.8885098/-3",
|
|
||||||
"vertice90": "3/0.935093/-3",
|
|
||||||
"vertice91": "2/1.504119/-3",
|
|
||||||
"vertice92": "0.9999999/0.1970509/-3",
|
|
||||||
"vertice93": "0/-0.2612341/-3",
|
|
||||||
"vertice94": "-1/1.097051/-3",
|
|
||||||
"vertice95": "-2/1.204119/-3",
|
|
||||||
"vertice96": "-3/0.6350929/-3",
|
|
||||||
"vertice97": "-4/0.2885098/-3",
|
|
||||||
"vertice98": "-5/0/-3",
|
|
||||||
"vertice99": "5/0/-4",
|
|
||||||
"vertice100": "4/0.4625199/-4",
|
|
||||||
"vertice101": "3/1.109103/-4",
|
|
||||||
"vertice102": "2/0.178129/-4",
|
|
||||||
"vertice103": "0.9999999/0.671061/-4",
|
|
||||||
"vertice104": "0/1.112776/-4",
|
|
||||||
"vertice105": "-1/0.371061/-4",
|
|
||||||
"vertice106": "-2/-0.121871/-4",
|
|
||||||
"vertice107": "-3/1.409103/-4",
|
|
||||||
"vertice108": "-4/0.76252/-4",
|
|
||||||
"vertice109": "-5/0/-4",
|
|
||||||
"vertice110": "5/0/-5",
|
|
||||||
"vertice111": "4/0/-5",
|
|
||||||
"vertice112": "3/0/-5",
|
|
||||||
"vertice113": "2/0/-5",
|
|
||||||
"vertice114": "0.9999999/0/-5",
|
|
||||||
"vertice115": "0/0/-5",
|
|
||||||
"vertice116": "-1/0/-5",
|
|
||||||
"vertice117": "-2/0/-5",
|
|
||||||
"vertice118": "-3/0/-5",
|
|
||||||
"vertice119": "-4/0/-5",
|
|
||||||
"vertice120": "-5/0/-5"
|
|
||||||
},
|
|
||||||
"colors": {
|
|
||||||
"color0": "0/154/0",
|
|
||||||
"color1": "0/154/0",
|
|
||||||
"color2": "0/154/0",
|
|
||||||
"color3": "0/154/0",
|
|
||||||
"color4": "0/154/0",
|
|
||||||
"color5": "0/154/0",
|
|
||||||
"color6": "0/154/0",
|
|
||||||
"color7": "0/154/0",
|
|
||||||
"color8": "0/154/0",
|
|
||||||
"color9": "0/154/0",
|
|
||||||
"color10": "0/154/0",
|
|
||||||
"color11": "0/154/0",
|
|
||||||
"color12": "0/168/0",
|
|
||||||
"color13": "0/174/0",
|
|
||||||
"color14": "0/163/0",
|
|
||||||
"color15": "0/161/0",
|
|
||||||
"color16": "0/153/0",
|
|
||||||
"color17": "0/150/0",
|
|
||||||
"color18": "0/179/0",
|
|
||||||
"color19": "0/169/0",
|
|
||||||
"color20": "0/173/0",
|
|
||||||
"color21": "0/154/0",
|
|
||||||
"color22": "0/154/0",
|
|
||||||
"color23": "0/154/0",
|
|
||||||
"color24": "0/171/0",
|
|
||||||
"color25": "0/160/0",
|
|
||||||
"color26": "0/163/0",
|
|
||||||
"color27": "0/155/0",
|
|
||||||
"color28": "0/169/0",
|
|
||||||
"color29": "0/170/0",
|
|
||||||
"color30": "0/182/0",
|
|
||||||
"color31": "0/165/0",
|
|
||||||
"color32": "0/154/0",
|
|
||||||
"color33": "0/154/0",
|
|
||||||
"color34": "0/183/0",
|
|
||||||
"color35": "0/167/0",
|
|
||||||
"color36": "0/167/0",
|
|
||||||
"color37": "0/154/0",
|
|
||||||
"color38": "0/178/0",
|
|
||||||
"color39": "0/160/0",
|
|
||||||
"color40": "0/167/0",
|
|
||||||
"color41": "0/178/0",
|
|
||||||
"color42": "0/183/0",
|
|
||||||
"color43": "0/154/0",
|
|
||||||
"color44": "0/154/0",
|
|
||||||
"color45": "0/184/0",
|
|
||||||
"color46": "0/185/0",
|
|
||||||
"color47": "0/162/0",
|
|
||||||
"color48": "0/166/0",
|
|
||||||
"color49": "0/174/0",
|
|
||||||
"color50": "0/155/0",
|
|
||||||
"color51": "0/162/0",
|
|
||||||
"color52": "0/174/0",
|
|
||||||
"color53": "0/178/0",
|
|
||||||
"color54": "0/154/0",
|
|
||||||
"color55": "0/154/0",
|
|
||||||
"color56": "0/157/0",
|
|
||||||
"color57": "0/174/0",
|
|
||||||
"color58": "0/157/0",
|
|
||||||
"color59": "0/155/0",
|
|
||||||
"color60": "0/152/0",
|
|
||||||
"color61": "0/182/0",
|
|
||||||
"color62": "0/157/0",
|
|
||||||
"color63": "0/174/0",
|
|
||||||
"color64": "0/162/0",
|
|
||||||
"color65": "0/154/0",
|
|
||||||
"color66": "0/154/0",
|
|
||||||
"color67": "0/173/0",
|
|
||||||
"color68": "0/157/0",
|
|
||||||
"color69": "0/157/0",
|
|
||||||
"color70": "0/177/0",
|
|
||||||
"color71": "0/179/0",
|
|
||||||
"color72": "0/177/0",
|
|
||||||
"color73": "0/162/0",
|
|
||||||
"color74": "0/185/0",
|
|
||||||
"color75": "0/162/0",
|
|
||||||
"color76": "0/154/0",
|
|
||||||
"color77": "0/154/0",
|
|
||||||
"color78": "0/167/0",
|
|
||||||
"color79": "0/167/0",
|
|
||||||
"color80": "0/183/0",
|
|
||||||
"color81": "0/154/0",
|
|
||||||
"color82": "0/178/0",
|
|
||||||
"color83": "0/165/0",
|
|
||||||
"color84": "0/156/0",
|
|
||||||
"color85": "0/184/0",
|
|
||||||
"color86": "0/172/0",
|
|
||||||
"color87": "0/154/0",
|
|
||||||
"color88": "0/154/0",
|
|
||||||
"color89": "0/170/0",
|
|
||||||
"color90": "0/171/0",
|
|
||||||
"color91": "0/181/0",
|
|
||||||
"color92": "0/158/0",
|
|
||||||
"color93": "0/150/0",
|
|
||||||
"color94": "0/174/0",
|
|
||||||
"color95": "0/176/0",
|
|
||||||
"color96": "0/166/0",
|
|
||||||
"color97": "0/159/0",
|
|
||||||
"color98": "0/154/0",
|
|
||||||
"color99": "0/154/0",
|
|
||||||
"color100": "0/163/0",
|
|
||||||
"color101": "0/174/0",
|
|
||||||
"color102": "0/157/0",
|
|
||||||
"color103": "0/166/0",
|
|
||||||
"color104": "0/174/0",
|
|
||||||
"color105": "0/161/0",
|
|
||||||
"color106": "0/152/0",
|
|
||||||
"color107": "0/180/0",
|
|
||||||
"color108": "0/168/0",
|
|
||||||
"color109": "0/154/0",
|
|
||||||
"color110": "0/154/0",
|
|
||||||
"color111": "0/154/0",
|
|
||||||
"color112": "0/154/0",
|
|
||||||
"color113": "0/154/0",
|
|
||||||
"color114": "0/154/0",
|
|
||||||
"color115": "0/154/0",
|
|
||||||
"color116": "0/154/0",
|
|
||||||
"color117": "0/154/0",
|
|
||||||
"color118": "0/154/0",
|
|
||||||
"color119": "0/154/0",
|
|
||||||
"color120": "0/154/0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user