Skip to content

Commit

Permalink
Switch ModuleInfoUpdater to use index loops, maybe solve #328
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanKell authored Aug 2, 2023
1 parent 9cce0bc commit 33dc05c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions Source/Engines/ConfigFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ModuleInfoUpdater : MonoBehaviour

private void Update()
{
if(hasRun)
if (hasRun)
{
GameObject.Destroy(this);
return;
Expand All @@ -22,18 +22,27 @@ private void Update()
Debug.Log("[RealFuelsFilters] Updating info boxes");
foreach (AvailablePart ap in PartLoader.LoadedPartsList)
{
// workaround for FindModulesImplementing nullrefs when called on the strange kerbalEVA_RD_Exp prefab
// due to the (private) cachedModuleLists being null on it
if (ap.partPrefab.Modules.Count == 0)
continue;
if (ap.partPrefab.FindModulesImplementing<ModuleEngineConfigsBase>() is List<ModuleEngineConfigsBase> mecs)
// We need to keep the modules and the moduleInfos in sync
// so we store the last info outside the loop
int i = 0;

// Loop has two termination conditions, in case there aren't enough infos for the modules.
for (int m = 0; m < ap.partPrefab.Modules.Count && i < ap.moduleInfos.Count; ++m)
{
int i = 0;
foreach (AvailablePart.ModuleInfo x in ap.moduleInfos)
if (ap.partPrefab.Modules[m] is ModuleEngineConfigsBase mec)
{
if (x.moduleName.Equals("Engine Configs"))
for(; i < ap.moduleInfos.Count; ++i)
{
x.info = mecs[i++].GetInfo();
var mInfo = ap.moduleInfos[i];
if (mInfo == null)
continue;

if (mInfo.moduleName.Equals("Engine Configs"))
{
mInfo.info = mec.GetInfo();
++i; // advance to next info box
break;
}
}
}
}
Expand Down

0 comments on commit 33dc05c

Please sign in to comment.