Skip to content

Commit

Permalink
Reload MFSSettings via ModuleManagerPostLoad
Browse files Browse the repository at this point in the history
Fixes #99
Reloading the database in various scenes might not be a well-handled idea.
  • Loading branch information
DRVeyl committed Mar 24, 2022
1 parent bcdef30 commit 8161c7e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Source/Engines/RFSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public static string GetVersion()
return version;
}

public void ModuleManagerPostLoad() => Init();

private void Init()
{
ConfigNode node = GameDatabase.Instance.GetConfigNodes("RFSETTINGS").Last();
Expand Down
23 changes: 14 additions & 9 deletions Source/Tanks/MFSSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ public static void TryInitialize()
if (!Initialized) Initialize();
}

public static void Initialize ()
public static void ModuleManagerPostLoad() => Initialize();

public static void Initialize()
{
resourceVsps.Clear();
resourceConductivities.Clear();
resourceGasses.Clear();

// fill vsps & conductivities
foreach (ConfigNode n in GameDatabase.Instance.GetConfigNodes("RESOURCE_DEFINITION"))
{
Expand All @@ -96,7 +102,7 @@ public static void Initialize ()
ConfigNode node = GameDatabase.Instance.GetConfigNodes("MFSSETTINGS").LastOrDefault();
Debug.Log ("[MFS] Loading global settings");

if (node != null) {
if (node != null) {
node.TryGetValue("useRealisticMass", ref useRealisticMass);
node.TryGetValue("tankMassMultiplier", ref tankMassMultiplier);
node.TryGetValue("baseCostPV", ref baseCostPV);
Expand All @@ -106,21 +112,20 @@ public static void Initialize ()
node.TryGetValue("basemassUseTotalVolume", ref basemassUseTotalVolume);
node.TryGetValue("radiatorMinTempMult", ref radiatorMinTempMult);

ConfigNode ignoreNode = node.GetNode("IgnoreFuelsForFill");
if (ignoreNode != null) {
foreach (ConfigNode.Value v in ignoreNode.values) {
ignoreFuelsForFill.Clear();
if (node.GetNode("IgnoreFuelsForFill") is ConfigNode ignoreNode)
foreach (ConfigNode.Value v in ignoreNode.values)
ignoreFuelsForFill.Add(v.name);
}
}
}
}

tankDefinitions.Clear();
foreach (ConfigNode defNode in GameDatabase.Instance.GetConfigNodes("TANK_DEFINITION")) {
if (tankDefinitions.ContainsKey(defNode.GetValue("name"))) {
Debug.LogWarning ("[MFS] Ignored duplicate definition of tank type " + defNode.GetValue ("name"));
} else {
var def = new Tanks.TankDefinition(defNode);
tankDefinitions.Add(def.name, def);
}
}
}
Initialized = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Tanks/ModuleFuelTanks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public override void OnAwake()

if (HighLogic.LoadedScene == GameScenes.LOADING)
unmanagedResources = new Dictionary<string, UnmanagedResource>();
else
else if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor)
{
var mft = part.partInfo.partPrefab.FindModuleImplementing<ModuleFuelTanks>();
unmanagedResources = mft.unmanagedResources;
Expand Down

0 comments on commit 8161c7e

Please sign in to comment.