Skip to content

Commit

Permalink
Move custom color loading to OnLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed May 4, 2023
1 parent 08f74a8 commit 90354b8
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions RasterPropMonitor/Core/RasterPropMonitorComputer.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ private VariableOrNumber AddVariable(string variableName)
public override void OnLoad(ConfigNode node) public override void OnLoad(ConfigNode node)
{ {
m_persistentVariables.Load(node); m_persistentVariables.Load(node);

foreach (var overrideColorSetup in node.GetNodes("RPM_COLOROVERRIDE"))
{
foreach (var colorConfig in overrideColorSetup.GetNodes("COLORDEFINITION"))
{
string name = colorConfig.GetValue("name");
Color32 color = default(Color);

if (name != null && colorConfig.TryGetValue("color", ref color))
{
name = "COLOR_" + name.Trim();

overrideColors[name] = color;
}
}
}
} }


public override void OnSave(ConfigNode node) public override void OnSave(ConfigNode node)
Expand Down Expand Up @@ -396,35 +412,6 @@ public void Start()
} }
} }


ConfigNode[] moduleConfigs = part.partInfo.partConfig.GetNodes("MODULE");
for (int moduleId = 0; moduleId < moduleConfigs.Length; ++moduleId)
{
if (moduleConfigs[moduleId].GetValue("name") == moduleName)
{
ConfigNode[] overrideColorSetup = moduleConfigs[moduleId].GetNodes("RPM_COLOROVERRIDE");
for (int colorGrp = 0; colorGrp < overrideColorSetup.Length; ++colorGrp)
{
ConfigNode[] colorConfig = overrideColorSetup[colorGrp].GetNodes("COLORDEFINITION");
for (int defIdx = 0; defIdx < colorConfig.Length; ++defIdx)
{
if (colorConfig[defIdx].HasValue("name") && colorConfig[defIdx].HasValue("color"))
{
string name = "COLOR_" + (colorConfig[defIdx].GetValue("name").Trim());
Color32 color = ConfigNode.ParseColor32(colorConfig[defIdx].GetValue("color").Trim());
if (overrideColors.ContainsKey(name))
{
overrideColors[name] = color;
}
else
{
overrideColors.Add(name, color);
}
}
}
}
}
}

UpdateLocalCrew(); UpdateLocalCrew();
UpdateLocalVars(); UpdateLocalVars();
} }
Expand Down

0 comments on commit 90354b8

Please sign in to comment.