Added player load, added basic world load, v1.3.0

This commit is contained in:
Nicola Sovic 2022-06-10 21:28:04 +02:00
parent 086910c7ca
commit 267dd1c626
2 changed files with 65 additions and 0 deletions

View File

@ -6,6 +6,8 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Assets.Scripts namespace Assets.Scripts
{ {
@ -37,6 +39,9 @@ namespace Assets.Scripts
{ {
jsonString = jsonString + line.Replace("\r\n", ""); jsonString = jsonString + line.Replace("\r\n", "");
} }
JArray json = JsonConvert.DeserializeObject<JArray>(jsonString);
player.loadPlayer(json["player"]);
worldGenerator.loadWorld(json["world"]);
} }
} }

View File

@ -7,6 +7,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Assets.Scripts.Classes; using Assets.Scripts.Classes;
using Assets.Scripts.Races; using Assets.Scripts.Races;
using Newtonsoft.Json.Linq;
namespace Assets.Scripts namespace Assets.Scripts
{ {
@ -580,5 +581,64 @@ namespace Assets.Scripts
result = result + FileHandler.generateJSON("difficulty", difficulty); result = result + FileHandler.generateJSON("difficulty", difficulty);
return result; return result;
} }
public void loadPlayer(JToken json)
{
playername = json["playername"].ToString();
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"];
maxExperience = (int)json["maxExperience"];
loadRole(json["role"].ToString());
loadRace(json["race"].ToString());
points = (int)json["points"];
isDodging = bool.Parse(json["isDodging"].ToString());
killcount = (int)json["killcount"];
difficulty = (int)json["difficulty"];
}
private void loadRole(string name)
{
switch (name)
{
case "Warrior":
role = new WarriorClass();
break;
case "Mage":
role = new MageClass();
break;
case "Thief":
role = new ThiefClass();
break;
}
}
private void loadRace(string name)
{
switch (name)
{
case "Human":
race = new HumanRace();
break;
case "Dwarf":
race = new DwarvenRace();
break;
case "Elf":
race = new ElvenRace();
break;
case "Giant":
race = new GiantRace();
break;
case "Goblin":
race = new GoblinRace();
break;
}
}
} }
} }