forked from TehCheat/PassiveSkillTreePlanter
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTreeConfig.cs
More file actions
62 lines (51 loc) · 1.82 KB
/
TreeConfig.cs
File metadata and controls
62 lines (51 loc) · 1.82 KB
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
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
namespace PassiveSkillTreePlanter;
public class TreeConfig
{
public static List<string> GetBuilds(string buildDirectory)
{
var dirInfo = new DirectoryInfo(buildDirectory);
var files = dirInfo.GetFiles("*.json").Select(x => Path.GetFileNameWithoutExtension(x.Name)).ToList();
return files;
}
public static SkillTreeData LoadBuild(string buildDirectory, string buildName)
{
var buildFile = Path.Join(buildDirectory, $"{buildName}.json");
return LoadSettingFile<SkillTreeData>(buildFile);
}
public static TSettingType LoadSettingFile<TSettingType>(string fileName)
{
if (!File.Exists(fileName))
return default(TSettingType);
return JsonConvert.DeserializeObject<TSettingType>(File.ReadAllText(fileName));
}
public static void SaveSettingFile<TSettingType>(string fileName, TSettingType setting)
{
var buildFile = $"{fileName}.json";
var serialized = JsonConvert.SerializeObject(setting, Formatting.Indented);
File.WriteAllText(buildFile, serialized);
}
public class Tree
{
public string Tag = "";
public string SkillTreeUrl = "";
private ESkillTreeType? _type;
[JsonIgnore]
public ESkillTreeType Type => _type ??= TreeEncoder.DecodeUrl(SkillTreeUrl) switch
{
(not null, var type) => type,
_ => ESkillTreeType.Unknown
};
public void ResetType() => _type = null;
}
public class SkillTreeData
{
public string Notes { get; set; } = "";
public List<Tree> Trees { get; set; } = new List<Tree>();
public string BuildLink { get; set; } = "";
internal bool Modified { get; set; }
}
}