Skip to content

Commit d84b134

Browse files
committed
Merge branch 'release/0.4.0'
2 parents 9b30b5c + b9c2593 commit d84b134

File tree

11 files changed

+151
-20
lines changed

11 files changed

+151
-20
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.4.0
2+
##### New
3+
- Configuration settings are now persisted on scene change.
4+
15
## v0.3.0
26
##### New
37
- Skin temperature added as a new metric.

Configuration/HotSpot.cfg

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,19 @@ HOT_SPOT
313313
+SCHEME[ThermalRateTemplate]
314314
{
315315
@name = ThermalRateVesselCurrent
316-
316+
317317
@GRADIENT[Negative]
318318
{
319319
%min = VesselCurrentMinimum
320320
}
321-
321+
322322
@GRADIENT[Positive]
323323
{
324324
%max = VesselCurrentMaximum
325325
}
326326
}
327327
}
328-
328+
329329
+METRIC[ThermalRateTemplate]
330330
{
331331
@name = ThermalRateConductive
@@ -334,19 +334,19 @@ HOT_SPOT
334334
+SCHEME[ThermalRateTemplate]
335335
{
336336
@name = ThermalRateVesselCurrent
337-
337+
338338
@GRADIENT[Negative]
339339
{
340340
%min = VesselCurrentMinimum
341341
}
342-
342+
343343
@GRADIENT[Positive]
344344
{
345345
%max = VesselCurrentMaximum
346346
}
347347
}
348348
}
349-
349+
350350
+METRIC[ThermalRateTemplate]
351351
{
352352
@name = ThermalRateConvective
@@ -355,19 +355,19 @@ HOT_SPOT
355355
+SCHEME[ThermalRateTemplate]
356356
{
357357
@name = ThermalRateVesselCurrent
358-
358+
359359
@GRADIENT[Negative]
360360
{
361361
%min = VesselCurrentMinimum
362362
}
363-
363+
364364
@GRADIENT[Positive]
365365
{
366366
%max = VesselCurrentMaximum
367367
}
368368
}
369369
}
370-
370+
371371
+METRIC[ThermalRateTemplate]
372372
{
373373
@name = ThermalRateRadiative
@@ -376,12 +376,12 @@ HOT_SPOT
376376
+SCHEME[ThermalRateTemplate]
377377
{
378378
@name = ThermalRateVesselCurrent
379-
379+
380380
@GRADIENT[Negative]
381381
{
382382
%min = VesselCurrentMinimum
383383
}
384-
384+
385385
@GRADIENT[Positive]
386386
{
387387
%max = VesselCurrentMaximum

Source/HotSpot/Config.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
4+
using System.Text;
35
using HotSpot.Configuration;
46

57
namespace HotSpot
@@ -46,6 +48,8 @@ private static void OnInitialLoad(ConfigNode node)
4648
$"Exploded Configuration:{Environment.NewLine}{node}" :
4749
"No configuration found."
4850
);
51+
52+
GameEvents.onGameSceneSwitchRequested.Add(e => Instance.Save());
4953
}
5054

5155
#endregion
@@ -71,6 +75,43 @@ private Config(GuiNode gui, ContextMenuNode contextMenu, OverlayNode overlay, Di
7175
Diagnostics = diagnostics;
7276
}
7377

78+
public void Save()
79+
{
80+
// It appears the top-most node cannot use an edit-or-create operation (%) so use an edit operation (@)
81+
var node = new ConfigNode("@HOT_SPOT:AFTER[HotSpot]");
82+
83+
var guiNode = new ConfigNode("%GUI");
84+
var contextMenuNode = new ConfigNode("%CONTEXT_MENU");
85+
var overlayNode = new ConfigNode("%OVERLAY");
86+
var diagnosticsNode = new ConfigNode("%DIAGNOSTICS");
87+
88+
if (Gui.Save(guiNode))
89+
{
90+
node.AddNode(guiNode);
91+
}
92+
93+
if (ContextMenu.Save(contextMenuNode))
94+
{
95+
node.AddNode(contextMenuNode);
96+
}
97+
98+
if (Overlay.Save(overlayNode))
99+
{
100+
node.AddNode(overlayNode);
101+
}
102+
103+
if (Diagnostics.Save(diagnosticsNode))
104+
{
105+
node.AddNode(diagnosticsNode);
106+
}
107+
108+
File.WriteAllText(
109+
$"{KSPUtil.ApplicationRootPath}/GameData/HotSpot/Configuration/HotSpotPlayer.cfg",
110+
node.ToString(),
111+
new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)
112+
);
113+
}
114+
74115
public static Config TryParse(ConfigNode node)
75116
{
76117
if (node != null)

Source/HotSpot/Configuration/ContextMenu/MetricNode.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,42 @@ namespace HotSpot.Configuration.ContextMenu
55
{
66
internal sealed class MetricNode
77
{
8+
private readonly bool _origEnable;
9+
private readonly Unit _origUnit;
10+
811
public Metric Name { get; }
912
public bool Enable { get; set; }
10-
public Unit Unit { get; set; }
13+
public Unit Unit { get; set; }
1114

1215
private MetricNode(Metric name, bool enable, Unit unit)
1316
{
17+
_origEnable = enable;
18+
_origUnit = unit;
19+
1420
Name = name;
1521
Enable = enable;
1622
Unit = unit;
1723
}
1824

25+
public bool Save(ConfigNode node)
26+
{
27+
var save = false;
28+
29+
if (_origEnable != Enable)
30+
{
31+
node.AddValue("%enable", Enable);
32+
save = true;
33+
}
34+
35+
if (_origUnit != Unit)
36+
{
37+
node.AddValue("%unit", Unit);
38+
save = true;
39+
}
40+
41+
return save;
42+
}
43+
1944
public static MetricNode TryParse(ConfigNode node)
2045
{
2146
if (node != null)

Source/HotSpot/Configuration/ContextMenuNode.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ public MetricNode GetMetric(Metric metric)
2222
return _metricsDictionary[metric.Name];
2323
}
2424

25+
public bool Save(ConfigNode node)
26+
{
27+
var save = false;
28+
29+
foreach (var metric in Metrics)
30+
{
31+
var metricNode = new ConfigNode($"%METRIC[{metric.Name.Name}]");
32+
33+
if (metric.Save(metricNode))
34+
{
35+
node.AddNode(metricNode);
36+
save = true;
37+
}
38+
}
39+
40+
return save;
41+
}
42+
2543
public static ContextMenuNode GetDefault()
2644
{
2745
return new ContextMenuNode(new MetricNode[] { });

Source/HotSpot/Configuration/DiagnosticsNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public static DiagnosticsNode GetDefault()
1414
return new DiagnosticsNode(LogLevel.Info);
1515
}
1616

17+
public bool Save(ConfigNode node) => false;
18+
1719
public static DiagnosticsNode TryParse(ConfigNode node)
1820
{
1921
if (node != null)

Source/HotSpot/Configuration/GuiNode.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ private GuiNode(string buttonTexture)
99
ButtonTexture = buttonTexture;
1010
}
1111

12-
public static GuiNode GetDefault()
13-
{
14-
return new GuiNode(buttonTexture: null);
15-
}
12+
public bool Save(ConfigNode node) => false;
13+
14+
public static GuiNode GetDefault() => new GuiNode(buttonTexture: null);
1615

1716
public static GuiNode TryParse(ConfigNode node)
1817
{

Source/HotSpot/Configuration/Overlay/MetricNode.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace HotSpot.Configuration.Overlay
77
{
88
internal sealed class MetricNode
99
{
10+
private readonly string _origScheme;
11+
1012
private readonly Dictionary<string, SchemeNode> _schemesDictionary;
1113

1214
public Metric Name { get; }
@@ -15,6 +17,8 @@ internal sealed class MetricNode
1517

1618
private MetricNode(Metric name, string scheme, SchemeNode[] schemes)
1719
{
20+
_origScheme = scheme;
21+
1822
Name = name;
1923
Scheme = scheme;
2024
Schemes = schemes;
@@ -26,6 +30,19 @@ public SchemeNode GetActiveScheme()
2630
return _schemesDictionary[Scheme];
2731
}
2832

33+
public bool Save(ConfigNode node)
34+
{
35+
var save = false;
36+
37+
if (_origScheme != Scheme)
38+
{
39+
node.AddValue("%scheme", Scheme);
40+
save = true;
41+
}
42+
43+
return save;
44+
}
45+
2946
public static MetricNode TryParse(ConfigNode node)
3047
{
3148
if (node != null)

Source/HotSpot/Configuration/OverlayNode.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ internal sealed class OverlayNode
1010
{
1111
private readonly Dictionary<string, MetricNode> _metricsDictionary;
1212

13+
private readonly string _origMetric;
14+
1315
public bool Enable { get; }
1416
public bool EnableScreenMessage { get; }
1517
public Metric Metric { get; set; }
1618
public MetricNode[] Metrics { get; }
1719

1820
private OverlayNode(bool enable, bool enableScreenMessage, Metric metric, MetricNode[] metrics)
1921
{
22+
_origMetric = metric.Name;
23+
2024
Enable = enable;
2125
EnableScreenMessage = enableScreenMessage;
2226
Metric = metric;
@@ -29,6 +33,30 @@ public MetricNode GetActiveMetric()
2933
return _metricsDictionary[Metric.Name];
3034
}
3135

36+
public bool Save(ConfigNode node)
37+
{
38+
var save = false;
39+
40+
if (_origMetric != Metric.Name)
41+
{
42+
node.AddValue("%metric", Metric.Name);
43+
save = true;
44+
}
45+
46+
foreach (var metric in Metrics)
47+
{
48+
var metricNode = new ConfigNode($"%METRIC[{metric.Name.Name}]");
49+
50+
if (metric.Save(metricNode))
51+
{
52+
node.AddNode(metricNode);
53+
save = true;
54+
}
55+
}
56+
57+
return save;
58+
}
59+
3260
public static OverlayNode GetDefault()
3361
{
3462
return new OverlayNode(false, true, Metric.TemperatureInternal, new MetricNode[] { });

Source/HotSpot/HotSpot.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@
7777
<Compile Include="Reflection\FlightOverlaysExtensions.cs" />
7878
<Compile Include="Reflection\PartExtensions.cs" />
7979
</ItemGroup>
80-
<ItemGroup>
81-
<Folder Include="Configuration\LoadTime\" />
82-
</ItemGroup>
80+
<ItemGroup />
8381
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8482
</Project>

0 commit comments

Comments
 (0)