-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLocalProgressionManager.Config.cs
More file actions
68 lines (56 loc) · 2.2 KB
/
LocalProgressionManager.Config.cs
File metadata and controls
68 lines (56 loc) · 2.2 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
63
64
65
66
67
68
using System.IO;
using LocalProgression.Data;
using MTFO.API;
namespace LocalProgression
{
public partial class LocalProgressionManager
{
public string LP_CONFIG_DIR => Path.Combine(MTFOPathAPI.CustomPath, "LocalProgressionConfig");
public const string CONFIG_FILE_NAME = "ProgressionConfig.json";
public string CONFIG_PATH => Path.Combine(LP_CONFIG_DIR, CONFIG_FILE_NAME);
public RundownProgressonConfig RundownProgressonConfig { get; private set; } = new();
private void InitConfig()
{
if(!Directory.Exists(LP_CONFIG_DIR))
{
Directory.CreateDirectory(LP_CONFIG_DIR);
}
if(!File.Exists(CONFIG_PATH))
{
var file = File.CreateText(CONFIG_PATH);
file.WriteLine(JSON.Serialize(new RundownProgressonConfig()));
file.Flush();
file.Close();
RundownProgressonConfig = new();
}
ReloadConfig();
RundownManager.OnRundownProgressionUpdated += new System.Action(ReloadConfig);
}
private void ReloadConfig()
{
try
{
RundownProgressonConfig = JSON.Deserialize<RundownProgressonConfig>(File.ReadAllText(CONFIG_PATH));
}
catch
{
LPLogger.Error("Cannot reload RundownProgressonConfig, probably the file is invalid");
RundownProgressonConfig = new();
}
}
public bool TryGetRundownConfig(uint RundownID, out RundownConfig rundownConf)
{
rundownConf = RundownProgressonConfig.Configs.Find(rundownConf => rundownConf.RundownID == RundownID);
return rundownConf != null;
}
public bool TryGetExpeditionConfig(uint RundownID, eRundownTier tier, int expIndex, out ExpeditionProgressionConfig expConf)
{
expConf = null;
if(TryGetRundownConfig(RundownID, out var rundownConf))
{
expConf = rundownConf.Expeditions.Find(e => e.Tier == tier && e.ExpeditionIndex == expIndex);
}
return expConf != null;
}
}
}