Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dbent committed May 29, 2016
2 parents e059591 + 4d7849c commit de61203
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 122 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v0.7.0
##### Changed
- *Incompatible:* "Dynamic" settings (anything changeable in the GUI) are now stored in
`HotSpot/PluginData/HotSpot.cfg` instead of `HotSpot/Configuration/HotSpotPlayer.cfg` and override any values in
"static" settings (anything loaded via the `GameDatabase`). This allows ModuleManager to ignore these settings for
caching purposes.

## v0.6.0
##### Added
- Added core temperature as a new metric for applicable parts.
Expand Down
2 changes: 2 additions & 0 deletions HotSpot.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArgumentsStyleLiteral/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=AutoPropertyCanBeMadeGetOnly_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassNeverInstantiated_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=EnumUnderlyingTypeIsInt/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=Html_002EPathError/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InvertIf/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBePrivate_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBePrivate_002ELocal/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=NotAccessedField_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ after_build:
$env:BUILD_VERSION = (cat .build/meta/VERSION)
$env:BUILD_PRERELEASE = (cat .build/meta/PRERELEASE)
$changeLog = (cat .build/meta/CHANGELOG)
if ($chaneLog -eq $null) {
if ($changeLog -eq $null) {
$env:BUILD_CHANGELOG = ""
} else {
$env:BUILD_CHANGELOG = [System.String]::Join("\n", $changeLog)
Expand Down
125 changes: 83 additions & 42 deletions src/HotSpot/Config.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using HotSpot.Configuration;

namespace HotSpot
Expand All @@ -23,15 +22,22 @@ public static Config Instance
{
if (_instance == null)
{

var node = GameDatabase
.Instance
.GetConfigNodes("HOT_SPOT")
.SingleOrDefault();
Config staticConfig = null;
Config dynamicConfig = null;

_instance = TryParse(node) ?? new Config();
var staticConfigNode = GetStaticConfigNode();
if (staticConfigNode != null)
staticConfig = TryParse(staticConfigNode);

OnInitialLoad(node);
var dynamicConfigNode = GetDynamicConfigNode();
if (dynamicConfigNode != null)
dynamicConfig = TryParse(dynamicConfigNode);

var defaultConfig = new Config();

_instance = Merge(dynamicConfig ?? defaultConfig, staticConfig ?? defaultConfig);

OnInitialLoad(staticConfigNode, dynamicConfigNode);
}
}
}
Expand All @@ -40,13 +46,18 @@ public static Config Instance
}
}

private static void OnInitialLoad(ConfigNode node)
private static void OnInitialLoad(ConfigNode staticNode, ConfigNode dynamicNode)
{
Log.Level = Instance.Diagnostics.LogLevel;

Log.Debug(node != null ?
$"Exploded Configuration:{Environment.NewLine}{node}" :
"No configuration found."
Log.Debug(staticNode != null ?
$"Static Configuration:{Environment.NewLine}{staticNode}" :
"No static configuration found."
);

Log.Debug(staticNode != null ?
$"Dynamic Configuration:{Environment.NewLine}{dynamicNode}" :
"No dynamic configuration found."
);

GameEvents.onGameSceneSwitchRequested.Add(e => Instance.Save());
Expand Down Expand Up @@ -77,39 +88,19 @@ private Config(GuiNode gui, ContextMenuNode contextMenu, OverlayNode overlay, Di

public void Save()
{
// It appears the top-most node cannot use an edit-or-create operation (%) so use an edit operation (@)
var node = new ConfigNode("@HOT_SPOT:AFTER[HotSpot]");
var node = new ConfigNode("HOT_SPOT");

var guiNode = new ConfigNode("%GUI");
var contextMenuNode = new ConfigNode("%CONTEXT_MENU");
var overlayNode = new ConfigNode("%OVERLAY");
var diagnosticsNode = new ConfigNode("%DIAGNOSTICS");
var contextMenuNode = new ConfigNode("CONTEXT_MENU");
var overlayNode = new ConfigNode("OVERLAY");

if (Gui.Save(guiNode))
{
node.AddNode(guiNode);
}
ContextMenu.Save(contextMenuNode);
node.AddNode(contextMenuNode);

if (ContextMenu.Save(contextMenuNode))
{
node.AddNode(contextMenuNode);
}
Overlay.Save(overlayNode);
node.AddNode(overlayNode);

if (Overlay.Save(overlayNode))
{
node.AddNode(overlayNode);
}

if (Diagnostics.Save(diagnosticsNode))
{
node.AddNode(diagnosticsNode);
}

File.WriteAllText(
$"{KSPUtil.ApplicationRootPath}/GameData/HotSpot/Configuration/HotSpotPlayer.cfg",
node.ToString(),
new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)
);
FileSystem.WriteDynamicConfiguration(node);
FileSystem.EnsureLegacyPlayerConfigFileDoesNotExist();
}

public static Config TryParse(ConfigNode node)
Expand All @@ -131,8 +122,58 @@ public static Config TryParse(ConfigNode node)
return new Config(gui, contextMenu, overlay, diagnostics);
}

Log.Warning("Could not parse missing HOT_SPOT node");
Log.Debug("Could not parse missing HOT_SPOT node");
return null;
}

public static ConfigNode GetStaticConfigNode()
{
return GameDatabase.Instance.GetConfigNodes("HOT_SPOT").SingleOrDefault();
}

public static ConfigNode GetDynamicConfigNode()
{
if (File.Exists(FileSystem.DynamicConfigFilePath))
{
var hotSpotNode = ConfigNode.Load(FileSystem.DynamicConfigFilePath).GetNode("HOT_SPOT");
if (hotSpotNode != null)
return hotSpotNode;
}

return null;
}

public static Config Merge(Config source, Config target)
{
// CONTEXT_MENU

var targetContextMenuMetrics = target.ContextMenu.Metrics.ToDictionary(i => i.Name.Name);
foreach (var sourceMetric in source.ContextMenu.Metrics)
{
Configuration.ContextMenu.MetricNode targetMetric;
if (targetContextMenuMetrics.TryGetValue(sourceMetric.Name.Name, out targetMetric))
{
targetMetric.Enable = sourceMetric.Enable;
targetMetric.Prefix = sourceMetric.Prefix;
targetMetric.Unit = sourceMetric.Unit;
}
}

// OVERLAY

target.Overlay.Metric = source.Overlay.Metric;

var targetOverlayMetrics = target.Overlay.Metrics.ToDictionary(i => i.Name.Name);
foreach (var sourceMetric in source.Overlay.Metrics)
{
Configuration.Overlay.MetricNode targetMetric;
if (targetOverlayMetrics.TryGetValue(sourceMetric.Name.Name, out targetMetric))
{
targetMetric.Scheme = sourceMetric.Scheme;
}
}

return target;
}
}
}
17 changes: 8 additions & 9 deletions src/HotSpot/Configuration/ContextMenu/MetricNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ private MetricNode(Metric name, bool enable, Unit unit, Prefix? prefix)
{
Name = name;
Enable = enable;
// TODO: Legacy : Remove Kilowatt
// TODO: LEGACY: Remove Kilowatt
Unit = unit == Unit.Kilowatt ? Unit.Watt : unit;
Prefix = prefix;
}

public bool Save(ConfigNode node)
public void Save(ConfigNode node)
{
node.AddValue("%enable", Enable);
node.AddValue("%unit", Unit);
node.AddValue("name", Name.Name);
node.AddValue("enable", Enable);
node.AddValue("unit", Unit);
if (Prefix != null)
node.AddValue("%prefix", Prefix.Value);
node.AddValue("prefix", Prefix.Value);
else
node.AddValue("%prefix", "auto");

return true;
node.AddValue("prefix", "auto");
}

public static MetricNode TryParse(ConfigNode node)
Expand All @@ -52,7 +51,7 @@ public static MetricNode TryParse(ConfigNode node)
}
}

Log.Warning($"Could not parse config node:{Environment.NewLine}{node}");
Log.Debug($"Could not parse config node:{Environment.NewLine}{node}");
return null;
}
}
Expand Down
17 changes: 5 additions & 12 deletions src/HotSpot/Configuration/ContextMenuNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,16 @@ public MetricNode GetMetric(Metric metric)
return _metricsDictionary[metric.Name];
}

public bool Save(ConfigNode node)
public void Save(ConfigNode node)
{
var save = false;

foreach (var metric in Metrics)
{
var metricNode = new ConfigNode($"%METRIC[{metric.Name.Name}]");
var metricNode = new ConfigNode("METRIC");

if (metric.Save(metricNode))
{
node.AddNode(metricNode);
save = true;
}
}
metric.Save(metricNode);

return save;
node.AddNode(metricNode);
}
}

public static ContextMenuNode GetDefault()
Expand All @@ -59,7 +53,6 @@ public static ContextMenuNode TryParse(ConfigNode node)
return new ContextMenuNode(metrics);
}

Log.Warning("Could not parse missing CONTEXT_MENU node");
return null;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/HotSpot/Configuration/DiagnosticsNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public static DiagnosticsNode GetDefault()
return new DiagnosticsNode(LogLevel.Info);
}

public bool Save(ConfigNode node) => false;

public static DiagnosticsNode TryParse(ConfigNode node)
{
if (node != null)
Expand All @@ -25,7 +23,6 @@ public static DiagnosticsNode TryParse(ConfigNode node)
return new DiagnosticsNode(logLevel);
}

Log.Warning("Could not parse missing DIAGNOSTICS node");
return null;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/HotSpot/Configuration/Gui/AppLauncherNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static AppLauncherNode TryParse(ConfigNode node)
return new AppLauncherNode(enable, texture);
}

Log.Warning("Could not parse missing APPLAUNCHER node");
return null;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/HotSpot/Configuration/Gui/ContextMenuNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static ContextMenuNode TryParse(ConfigNode node)
return new ContextMenuNode(disableStockCoreTemp);
}

Log.Warning("Could not parse missing CONTEXT_MENU node");
return null;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/HotSpot/Configuration/Gui/ToolbarNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public static ToolbarNode TryParse(ConfigNode node)
return new ToolbarNode(enable, texture);
}

Log.Warning("Could not parse missing TOOLBAR node");
return null;
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/HotSpot/Configuration/GuiNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ private GuiNode(AppLauncherNode appLauncher, ToolbarNode toolbar, Gui.ContextMen
ContextMenu = contextMenu;
}

public bool Save(ConfigNode node)
=> false;

public static GuiNode GetDefault()
=> new GuiNode(AppLauncherNode.GetDefault(), ToolbarNode.GetDefault(), Gui.ContextMenuNode.GetDefault());

Expand All @@ -35,7 +32,6 @@ public static GuiNode TryParse(ConfigNode node)
return new GuiNode(appLauncher, toolbar, contextMenu);
}

Log.Warning("Could not parse missing GUI node");
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/HotSpot/Configuration/Overlay/GradientNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static GradientNode TryParse(ConfigNode node)
}
}

Log.Warning($"Could not parse config node:{Environment.NewLine}{node}");
Log.Debug($"Could not parse config node:{Environment.NewLine}{node}");
return null;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/HotSpot/Configuration/Overlay/MetricNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ public SchemeNode GetActiveScheme()
return _schemesDictionary[Scheme];
}

public bool Save(ConfigNode node)
public void Save(ConfigNode node)
{
node.AddValue("%scheme", Scheme);

return true;
node.AddValue("name", Name.Name);
node.AddValue("scheme", Scheme);
}

public static MetricNode TryParse(ConfigNode node)
Expand Down
2 changes: 1 addition & 1 deletion src/HotSpot/Configuration/Overlay/SchemeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static SchemeNode TryParse(ConfigNode node)
}
}

Log.Warning($"Could not parse config node:{Environment.NewLine}{node}");
Log.Debug($"Could not parse config node:{Environment.NewLine}{node}");
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/HotSpot/Configuration/Overlay/StopNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static StopNode TryParse(ConfigNode node)
}
}

Log.Warning($"Could not parse config node:{Environment.NewLine}{node}");
Log.Debug($"Could not parse config node:{Environment.NewLine}{node}");
return null;
}

Expand All @@ -63,7 +63,7 @@ public static StopNode TryParse(ConfigNode node)
return TryConvertColor(match.Groups["color"].Value);
}

Log.Warning($"Could not parse `color` property: {str}");
Log.Debug($"Could not parse `color` property: {str}");
return null;
}

Expand Down
Loading

0 comments on commit de61203

Please sign in to comment.