-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonExporter.cs
73 lines (67 loc) · 3.15 KB
/
JsonExporter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
//using System.Net.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Windows;
namespace WpfApplication1
{
class JsonExporter
{
public static string jsonFileFromCombatTable(CombatTable combatants)
{
return JsonConvert.SerializeObject(combatants, Formatting.Indented);
}
public static string jsonFileFromCombatant(Combatant combatant)
{
return JsonConvert.SerializeObject(combatant, Formatting.Indented);
}
public static void combatTableFromJsonFile(CombatTable paramAdventure, string jsonFile)
{
JArray adventureJson = JArray.Parse(jsonFile);
//Every Combatant
foreach (JObject combatantJson in adventureJson.Children())
{
CommAddCombatant commAdd = new CommAddCombatant(paramAdventure, combatantFromJsonObject(combatantJson));
commAdd.Execute();
}
}
private static Combatant combatantFromJsonObject(JObject combatantJson)
{
Combatant combatant = new Combatant((string)combatantJson["CName"], true);
combatant.AB = (float)combatantJson["AB"];
combatant.AbilityCHA = (int)combatantJson["AbilityCHA"];
combatant.AbilityCON = (int)combatantJson["AbilityCON"];
combatant.AbilityDEX = (int)combatantJson["AbilityDEX"];
combatant.AbilityINT = (int)combatantJson["AbilityINT"];
combatant.AbilitySTR = (int)combatantJson["AbilitySTR"];
combatant.AbilityWIS = (int)combatantJson["AbilityWIS"];
combatant.AC = (float)combatantJson["AC"];
combatant.Fort = (float)combatantJson["Fort"];
combatant.Gold = (float)combatantJson["Gold"];
combatant.HP = (float)combatantJson["HP"];
combatant.Initiative = (float)combatantJson["Initiative"];
combatant.InitMod = (float)combatantJson["InitMod"];
combatant.IsNPC = (bool)combatantJson["IsNPC"];
combatant.MaxHP = (float)combatantJson["MaxHP"];
combatant.Notes = (string)combatantJson["Notes"];
combatant.PName = (string)combatantJson["PName"];
combatant.Refl = (float)combatantJson["Refl"];
combatant.Will = (float)combatantJson["Will"];
combatant.XP = (float)combatantJson["XP"];
combatant.Feats = JsonConvert.DeserializeObject<ObservableCollection<string>>(combatantJson["Feats"].ToString());
combatant.Items = JsonConvert.DeserializeObject<ObservableCollection<Item>>(combatantJson["Items"].ToString());
JArray skillsJson = (JArray)combatantJson["Skills"];
for (int i = 0; i < (int)eSkills.Use_Rope + 1; i++)
{
Skill skill = JsonConvert.DeserializeObject<Skill>(skillsJson[i].ToString());
combatant.setSkillRank((eSkills)i, skill.SkillRank);
}
return combatant;
}
}
}