-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathHullBreachConfig.cs
84 lines (65 loc) · 2.75 KB
/
HullBreachConfig.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using KSP.UI.Screens;
using UnityEngine;
namespace HullBreach
{
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class config : MonoBehaviour
{
public static string SettingsConfigUrl = "GameData/HullBreach/settings.cfg";
public static double flowRate { get; set; }
public static double critFlowRate { get; set; }
public static double breachTemp { get; set; }
public static double critBreachTemp { get; set; }
public static bool ecDrain { get; set; }
public static bool isHullBreachEnabled { get; set; }
public ModuleHullBreach vesselHullBreach = null;
public static config Instance;
void Awake()
{
LoadConfig();
Instance = this;
}
public static void LoadConfig()
{
try
{
Debug.Log("[HullBreach]: Loading settings.cfg ");
ConfigNode fileNode = ConfigNode.Load(SettingsConfigUrl);
if (!fileNode.HasNode("HullBreachSettings")) return;
ConfigNode settings = fileNode.GetNode("HullBreachSettings");
flowRate = double.Parse(settings.GetValue("flowRate"));
critFlowRate = double.Parse(settings.GetValue("critFlowRate"));
breachTemp = double.Parse(settings.GetValue("breachTemp"));
critBreachTemp = double.Parse(settings.GetValue("critBreachTemp"));
ecDrain = bool.Parse(settings.GetValue("ecDrain"));
isHullBreachEnabled = bool.Parse(settings.GetValue("isHullBreachEnabled"));
}
catch (Exception ex)
{
Debug.Log("[HullBreach]: Failed to load settings config:" + ex.Message);
}
}
public static void SaveConfig()
{
try
{
Debug.Log("[HullBreach]: Saving settings.cfg ==");
ConfigNode fileNode = ConfigNode.Load(SettingsConfigUrl);
if (!fileNode.HasNode("HullBreachSettings")) return;
ConfigNode settings = fileNode.GetNode("HullBreachSettings");
settings.SetValue("flowRate", flowRate);
settings.SetValue("critFlowRate", critBreachTemp);
settings.SetValue("breachTemp", breachTemp);
settings.SetValue("critBreachTemp", critBreachTemp);
settings.SetValue("ecDrain", ecDrain);
settings.SetValue("isHullBreachEnabled", isHullBreachEnabled);
fileNode.Save(SettingsConfigUrl);
}
catch (Exception ex)
{
Debug.Log("[HullBreach]: Failed to save settings config:" + ex.Message); throw;
}
}
}
}