Skip to content

Commit

Permalink
Fix #122: search for internal modules in the internal if there isn't …
Browse files Browse the repository at this point in the history
…one on the prop
  • Loading branch information
JonnyOThan committed Dec 3, 2023
1 parent a32148f commit 240ee4d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
44 changes: 29 additions & 15 deletions RasterPropMonitor/Core/UtilityFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Expansions.Missions;
using KSP.UI.Screens.Flight;
using UnityEngine;
using UnityEngine.Profiling;
Expand Down Expand Up @@ -1449,6 +1450,19 @@ public static double MassageToDouble(this object thatValue)
return double.NaN;
}

internal static InternalModule FindInternalModuleByName(InternalProp prop, string className)
{
foreach (InternalModule potentialModule in prop.internalModules)
{
if (potentialModule.ClassName == className)
{
return potentialModule;
}
}

return null;
}

internal static Delegate GetMethod(string packedMethod, InternalProp internalProp, Type delegateType)
{
string moduleName, stateMethod;
Expand All @@ -1461,26 +1475,26 @@ internal static Delegate GetMethod(string packedMethod, InternalProp internalPro
moduleName = tokens[0];
stateMethod = tokens[1];

InternalModule thatModule = null;
foreach (InternalModule potentialModule in internalProp.internalModules)
// First look on the prop
InternalModule thatModule = FindInternalModuleByName(internalProp, moduleName);

// then on the internal as a whole
if (thatModule == null)
{
if (potentialModule.ClassName == moduleName)
foreach (var prop in internalProp.internalModel.props)
{
thatModule = potentialModule;
break;
// this really means "was this a MODULE placed directly in the INTERNAL"
if (!prop.hasModel)
{
thatModule = FindInternalModuleByName(prop, moduleName);
if (thatModule != null)
{
break;
}
}
}
}

if (thatModule == null)
{
// The module hasn't been instantiated on this part, so let's do so now.
// MOARdV TODO: This actually causes an exception, because
// it's added during InternalProp.OnUpdate. One thing I could
// do is add the internal modules when I instantiate RPMC.
var handlerConfiguration = new ConfigNode("MODULE");
handlerConfiguration.SetValue("name", moduleName, true);
thatModule = internalProp.AddModule(handlerConfiguration);
}
if (thatModule == null)
{
JUtil.LogErrorMessage(internalProp, "Failed finding module {0} for method {1}", moduleName, stateMethod);
Expand Down
2 changes: 1 addition & 1 deletion SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
// Revision number is altered automatically.
[assembly: AssemblyVersion("0.31.13.3")]
[assembly: AssemblyVersion("0.31.13.5")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down

0 comments on commit 240ee4d

Please sign in to comment.