forked from Stridemann/PoE_PassiveSkillTreePlanter
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTreeConfig.cs
More file actions
55 lines (47 loc) · 1.78 KB
/
TreeConfig.cs
File metadata and controls
55 lines (47 loc) · 1.78 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
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using static PassiveSkillTreePlanter.PassiveSkillTreePlanter;
namespace PassiveSkillTreePlanter
{
public class TreeConfig
{
public static List<string> GetBuilds()
{
var dirInfo = new DirectoryInfo(Core.SkillTreeUrlFilesDir);
var files = dirInfo.GetFiles("*.json").Select(x => Path.GetFileNameWithoutExtension(x.Name)).ToList();
return files;
}
public static SkillTreeData LoadBuild(string buildName)
{
var buildFile = $"{Core.SkillTreeUrlFilesDir}\\{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 int Level { get; set; } = 0;
public string Tag { get; set; } = "";
public string SkillTreeUrl { get; set; } = "";
}
public class SkillTreeData
{
public string Notes { get; set; } = "";
public List<Tree> Trees { get; set; } = new List<Tree>();
public string BuildLink { get; set; } = "";
public int SelectedIndex { get; set; } = 0;
}
}
}