Skip to content

Commit

Permalink
New functionality of ground stations in settings file (Issue #15)
Browse files Browse the repository at this point in the history
  • Loading branch information
KSP-TaxiService committed Dec 1, 2019
1 parent 46cc58a commit df2fd68
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
13 changes: 13 additions & 0 deletions GameData/CommNetConstellation/cnc_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,17 @@ CommNetConstellationSettings
color = 0.65, 0.65, 0.65, 1
}
}
GroundStations
{
GroundStation
{
ID = Kerbin: KSC
Color = 1,0,0,1
OptionalName = Kerbal Space Center
Frequencies
{
Frequency = 0
}
}
}
}
17 changes: 15 additions & 2 deletions src/CommNetConstellation/CNCSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using CommNetConstellation.CommNetLayer;
using System.Collections.Generic;
using UnityEngine;

namespace CommNetConstellation
Expand Down Expand Up @@ -44,7 +45,8 @@ public class Settings
[Persistent] public string DefaultPublicName;
[Persistent] public Color DefaultPublicColor;
[Persistent] public float DistanceToHideGroundStations;
[Persistent(collectionIndex = "Constellations")] public List<Constellation> Constellations;
[Persistent(collectionIndex = "Constellation")] public List<Constellation> Constellations;
[Persistent(collectionIndex = "GroundStation")] public List<CNCCommNetHome> GroundStations;
//-----

public static Settings Load()
Expand Down Expand Up @@ -74,6 +76,17 @@ public static Settings Load()
if (cfgs[i].url.Equals(startingSettingCFGUrl))
{
defaultSuccess = ConfigNode.LoadObjectFromConfig(settings, cfgs[i].config);

//Workaround due to LoadObjectFromConfig not auto-populating ground stations for unknown reason
settings.GroundStations = new List<CNCCommNetHome>();
ConfigNode[] stationNodes = cfgs[i].config.GetNode("GroundStations").GetNodes();
for (int j = 0; j < stationNodes.Length; j++)
{
CNCCommNetHome dummyGroundStation = new CNCCommNetHome();
ConfigNode.LoadObjectFromConfig(dummyGroundStation, stationNodes[j]);
settings.GroundStations.Add(dummyGroundStation);
}

CNCLog.Verbose("Load starting settings into object with {0}: LOADED {1}", cfgs[i].config, defaultSuccess ? "OK" : "FAIL");
break;
}
Expand Down
10 changes: 9 additions & 1 deletion src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public class CNCCommNetHome : CommNetHome, IComparable<CNCCommNetHome>
[Persistent] public string ID;
[Persistent] public Color Color = Color.red;
[Persistent] protected string OptionalName = "";
[Persistent(collectionIndex = "Frequency")] protected List<short> Frequencies = new List<short>(new short[] { CNCSettings.Instance.PublicRadioFrequency });
[Persistent(collectionIndex = "Frequency")] protected List<short> Frequencies =
(HighLogic.LoadedScene != GameScenes.LOADING && HighLogic.LoadedScene != GameScenes.LOADINGBUFFER) ?
new List<short>() { CNCSettings.Instance.PublicRadioFrequency } :
new List<short>();

//for low-gc operations
protected short[] sorted_frequency_array;
Expand All @@ -35,6 +38,11 @@ public string stationName
set { this.OptionalName = value; }
}

/// <summary>
/// Empty constructor for ConfigNode.LoadObjectFromConfig()
/// </summary>
public CNCCommNetHome() { }

public void copyOf(CommNetHome stockHome)
{
CNCLog.Verbose("CommNet Home '{0}' added", stockHome.nodeName);
Expand Down
4 changes: 2 additions & 2 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public override void OnLoad(ConfigNode gameNode)
if (stationNodes.Length < 1) // missing ground-station list
{
CNCLog.Error("The 'GroundStations' node is malformed! Reverted to the default list of ground stations.");
//do nothing since KSP provides this default list
persistentGroundStations = CNCSettings.Instance.GroundStations;
}
else
{
Expand All @@ -244,7 +244,7 @@ public override void OnLoad(ConfigNode gameNode)
else
{
CNCLog.Verbose("The 'GroundStations' node is not found. The default list of ground stations is loaded from KSP's data.");
//do nothing since KSP provides this default list
persistentGroundStations = CNCSettings.Instance.GroundStations;
}
}
catch (Exception e)
Expand Down

0 comments on commit df2fd68

Please sign in to comment.