diff --git a/GameData/CommNetConstellation/cnc_settings.cfg b/GameData/CommNetConstellation/cnc_settings.cfg index 35e2860..caedac9 100644 --- a/GameData/CommNetConstellation/cnc_settings.cfg +++ b/GameData/CommNetConstellation/cnc_settings.cfg @@ -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 + } + } + } } \ No newline at end of file diff --git a/src/CommNetConstellation/CNCSettings.cs b/src/CommNetConstellation/CNCSettings.cs index bb6f156..4359973 100644 --- a/src/CommNetConstellation/CNCSettings.cs +++ b/src/CommNetConstellation/CNCSettings.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using CommNetConstellation.CommNetLayer; +using System.Collections.Generic; using UnityEngine; namespace CommNetConstellation @@ -44,7 +45,8 @@ public class Settings [Persistent] public string DefaultPublicName; [Persistent] public Color DefaultPublicColor; [Persistent] public float DistanceToHideGroundStations; - [Persistent(collectionIndex = "Constellations")] public List Constellations; + [Persistent(collectionIndex = "Constellation")] public List Constellations; + [Persistent(collectionIndex = "GroundStation")] public List GroundStations; //----- public static Settings Load() @@ -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(); + 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; } diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs index 5462c66..77cf788 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs @@ -20,7 +20,10 @@ public class CNCCommNetHome : CommNetHome, IComparable [Persistent] public string ID; [Persistent] public Color Color = Color.red; [Persistent] protected string OptionalName = ""; - [Persistent(collectionIndex = "Frequency")] protected List Frequencies = new List(new short[] { CNCSettings.Instance.PublicRadioFrequency }); + [Persistent(collectionIndex = "Frequency")] protected List Frequencies = + (HighLogic.LoadedScene != GameScenes.LOADING && HighLogic.LoadedScene != GameScenes.LOADINGBUFFER) ? + new List() { CNCSettings.Instance.PublicRadioFrequency } : + new List(); //for low-gc operations protected short[] sorted_frequency_array; @@ -35,6 +38,11 @@ public string stationName set { this.OptionalName = value; } } + /// + /// Empty constructor for ConfigNode.LoadObjectFromConfig() + /// + public CNCCommNetHome() { } + public void copyOf(CommNetHome stockHome) { CNCLog.Verbose("CommNet Home '{0}' added", stockHome.nodeName); diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs index 6e586d3..958df5d 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs @@ -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 { @@ -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)