mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00

This fixes VS messages regarding namespaces, removes some redundant usings and SDK parameters, and adds XAML design data contexts.
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using TRX_ConfigToolLib.Utils.Json;
|
|
|
|
namespace TRX_ConfigToolLib.Models.Specification;
|
|
|
|
public class Specification
|
|
{
|
|
public Dictionary<string, List<EnumOption>> Enums { get; private set; }
|
|
public List<Category> CategorisedProperties { get; private set; }
|
|
public List<BaseProperty> Properties { get; private set; }
|
|
|
|
public Specification(string sourceData)
|
|
{
|
|
JObject data = JObject.Parse(sourceData);
|
|
JObject enumData = data.ContainsKey(nameof(Enums))
|
|
? data[nameof(Enums)].ToObject<JObject>()
|
|
: new();
|
|
Enums = new();
|
|
|
|
foreach (var (key, value) in enumData)
|
|
{
|
|
List<string> enumValues = value.ToObject<List<string>>();
|
|
Enums[key] = enumValues.Select(val => new EnumOption
|
|
{
|
|
EnumName = key,
|
|
ID = val
|
|
}).ToList();
|
|
}
|
|
|
|
string categoryData = data[nameof(CategorisedProperties)].ToString();
|
|
PropertyConverter converter = new();
|
|
CategorisedProperties = JsonConvert.DeserializeObject<List<Category>>(categoryData, converter);
|
|
Properties = new();
|
|
|
|
foreach (BaseProperty property in CategorisedProperties.SelectMany(c => c.Properties))
|
|
{
|
|
property.Initialise(this);
|
|
Properties.Add(property);
|
|
}
|
|
}
|
|
}
|