-
Notifications
You must be signed in to change notification settings - Fork 32
/
SettingsManager.cs
55 lines (47 loc) · 1.27 KB
/
SettingsManager.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
using UnityEngine;
namespace Kethane
{
[KSPAddon(KSPAddon.Startup.Instantly, true)]
internal class SettingsManager : MonoBehaviour
{
private static ConfigNode node;
public static string GetValue(string key)
{
load();
return node.GetValue(key);
}
public static void SetValue(string key, object value)
{
load();
if (node.HasValue(key))
{
node.RemoveValue(key);
}
node.AddValue(key, value);
}
public static void Save()
{
load();
Debug.LogWarning("[Kethane] Saving settings");
node.Save(settingsFile);
}
private static void load()
{
if (node != null) { return; }
Debug.LogWarning("[Kethane] Loading settings");
node = ConfigNode.Load(settingsFile) ?? new ConfigNode();
}
private static string settingsFile
{
get { return KSPUtil.ApplicationRootPath + "GameData/Kethane/settings.cfg"; }
}
public void Awake()
{
MonoBehaviour.DontDestroyOnLoad(this);
}
public void Destroy()
{
Save();
}
}
}