forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTSettings.cs
More file actions
131 lines (119 loc) · 4.65 KB
/
Copy pathRTSettings.cs
File metadata and controls
131 lines (119 loc) · 4.65 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using UnityEngine;
namespace RemoteTech
{
public class RTSettings
{
private static Settings mInstance;
public static Settings Instance
{
get
{
return mInstance = mInstance ?? Settings.Load();
}
}
}
public class Settings
{
public Dictionary<String, Rect> savedWindowPositions = new Dictionary<String, Rect>();
[Persistent] public float ConsumptionMultiplier = 1.0f;
[Persistent] public float RangeMultiplier = 1.0f;
[Persistent] public String ActiveVesselGuid = "35b89a0d664c43c6bec8d0840afc97b2";
[Persistent] public float SpeedOfLight = 3e8f;
[Persistent] public MapFilter MapFilter = MapFilter.Path | MapFilter.Omni | MapFilter.Dish;
[Persistent] public bool EnableSignalDelay = true;
[Persistent] public RangeModel.RangeModel RangeModelType = RangeModel.RangeModel.Standard;
[Persistent] public double MultipleAntennaMultiplier = 0.0;
[Persistent] public bool ThrottleTimeWarp = true;
[Persistent] public bool HideGroundStationsBehindBody = false;
[Persistent] public Color DishConnectionColor = XKCDColors.Amber;
[Persistent] public Color OmniConnectionColor = XKCDColors.BrownGrey;
[Persistent] public Color ActiveConnectionColor = XKCDColors.ElectricLime;
[Persistent(collectionIndex="STATION")]
public MissionControlSatellite[] GroundStations = new MissionControlSatellite[] { new MissionControlSatellite() };
/// <summary>
/// Backup config node
/// </summary>
private ConfigNode backupNode;
private static String File
{
get { return KSPUtil.ApplicationRootPath + "/GameData/RemoteTech/RemoteTech_Settings.cfg"; }
}
/// <summary>
/// Saves the current RTSettings object to the RemoteTech_Settings.cfg
/// </summary>
public void Save()
{
try
{
ConfigNode details = new ConfigNode("RemoteTechSettings");
ConfigNode.CreateConfigFromObject(this, 0, details);
ConfigNode save = new ConfigNode();
save.AddNode(details);
save.Save(File);
}
catch (Exception e) { RTLog.Notify("An error occurred while attempting to save: " + e.Message); }
}
/// <summary>
/// Stores the MapFilter Value for overriding with third party settings
/// </summary>
public void backupFields()
{
backupNode = new ConfigNode();
backupNode.AddValue("MapFilter", MapFilter);
backupNode.AddValue("ActiveVesselGuid", ActiveVesselGuid);
}
/// <summary>
/// Restores the backuped values
/// </summary>
public void restoreBackups()
{
if (backupNode != null)
{
// restore backups
ConfigNode.LoadObjectFromConfig(this, backupNode);
}
}
public static Settings Load()
{
// Create a new settings object
Settings settings = new Settings();
// try to load from the base settings.cfg
ConfigNode load = ConfigNode.Load(File);
if (load == null)
{
// write new base file to the rt folder
settings.Save();
}
else
{
// old or new format?
if (load.HasNode("RemoteTechSettings"))
{
load = load.GetNode("RemoteTechSettings");
}
RTLog.Notify("Load base settings into object with {0}", load);
// load basic file
ConfigNode.LoadObjectFromConfig(settings, load);
}
// Prefer to load from GameDatabase, to allow easier user customization
UrlDir.UrlConfig[] configList = GameDatabase.Instance.GetConfigs("RemoteTechSettings");
foreach (UrlDir.UrlConfig curSet in configList)
{
// only third party files
if (!curSet.url.Equals("RemoteTech/RemoteTech_Settings/RemoteTechSettings"))
{
RTLog.Notify("Override RTSettings with configs from {0}", curSet.url);
settings.backupFields();
ConfigNode.LoadObjectFromConfig(settings, curSet.config);
settings.restoreBackups();
}
}
return settings;
}
}
}