Skip to content

Commit 62313ef

Browse files
committed
Refactor and rename RasterPropMonitorComputer.Instantiate so that it can only find the computer module, not add one (because adding modules dynamically is a real bad idea)
1 parent 29531d8 commit 62313ef

22 files changed

+61
-89
lines changed

RasterPropMonitor/Auxiliary modules/JSIActionGroupSwitch.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void Start()
194194

195195
try
196196
{
197-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
197+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
198198

199199
if (!groupList.ContainsKey(actionName) && !customGroupList.ContainsKey(actionName))
200200
{
@@ -626,8 +626,8 @@ public void Start()
626626
{
627627
// Set up the color shift.
628628
Renderer colorShiftRenderer = internalProp.FindModelComponent<Renderer>(coloredObject);
629-
disabledColorValue = JUtil.ParseColor32(disabledColor, part, ref rpmComp);
630-
enabledColorValue = JUtil.ParseColor32(enabledColor, part, ref rpmComp);
629+
disabledColorValue = JUtil.ParseColor32(disabledColor, rpmComp);
630+
enabledColorValue = JUtil.ParseColor32(enabledColor, rpmComp);
631631
colorShiftMaterial = colorShiftRenderer.material;
632632
colorNameId = Shader.PropertyToID(colorName);
633633
colorShiftMaterial.SetColor(colorNameId, (currentState ^ reverse ? enabledColorValue : disabledColorValue));

RasterPropMonitor/Auxiliary modules/JSICallbackAnimator.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Start()
5454

5555
try
5656
{
57-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
57+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
5858

5959
ConfigNode moduleConfig = null;
6060
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP"))
@@ -246,7 +246,7 @@ public CallbackAnimationSet(ConfigNode node, string variableName, InternalProp t
246246
throw new ArgumentException("Could not parse 'scale' parameter.");
247247
}
248248

249-
RasterPropMonitorComputer rpmComp = RasterPropMonitorComputer.Instantiate(thisProp, true);
249+
RasterPropMonitorComputer rpmComp = RasterPropMonitorComputer.FindFromProp(thisProp);
250250
variable = new VariableOrNumberRange(rpmComp, variableName, tokens[0], tokens[1]);
251251

252252
// That takes care of the scale, now what to do about that scale:
@@ -383,13 +383,13 @@ public CallbackAnimationSet(ConfigNode node, string variableName, InternalProp t
383383

384384
if (reverse)
385385
{
386-
activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp);
387-
passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp);
386+
activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), rpmComp);
387+
passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), rpmComp);
388388
}
389389
else
390390
{
391-
passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp);
392-
activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp);
391+
passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), rpmComp);
392+
activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), rpmComp);
393393
}
394394
Renderer colorShiftRenderer = thisProp.FindModelComponent<Renderer>(node.GetValue("coloredObject"));
395395
affectedMaterial = colorShiftRenderer.material;

RasterPropMonitor/Auxiliary modules/JSIInternalBackgroundNoise.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Start()
2626
return;
2727
}
2828

29-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
29+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
3030
if (string.IsNullOrEmpty(soundURL))
3131
{
3232
JUtil.LogMessage(this, "JSIInternalBackgroundNoise called with no soundURL");

RasterPropMonitor/Auxiliary modules/JSILabel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void Start()
118118

119119
try
120120
{
121-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
121+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
122122

123123
Transform textObjTransform = JUtil.FindPropTransform(internalProp, transformName);
124124
Vector3 localScale = internalProp.transform.localScale;
@@ -273,16 +273,16 @@ public void Start()
273273

274274
if (!string.IsNullOrEmpty(zeroColor))
275275
{
276-
zeroColorValue = JUtil.ParseColor32(zeroColor, part, ref rpmComp);
276+
zeroColorValue = JUtil.ParseColor32(zeroColor, rpmComp);
277277
textObj.color = zeroColorValue;
278278
}
279279

280280
bool usesMultiColor = false;
281281
if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor)))
282282
{
283283
usesMultiColor = true;
284-
positiveColorValue = JUtil.ParseColor32(positiveColor, part, ref rpmComp);
285-
negativeColorValue = JUtil.ParseColor32(negativeColor, part, ref rpmComp);
284+
positiveColorValue = JUtil.ParseColor32(positiveColor, rpmComp);
285+
negativeColorValue = JUtil.ParseColor32(negativeColor, rpmComp);
286286
del = (Action<float>)Delegate.CreateDelegate(typeof(Action<float>), this, "OnCallback");
287287
rpmComp.RegisterVariableCallback(variableName, del);
288288
registeredVessel = vessel.id;

RasterPropMonitor/Auxiliary modules/JSINavBall.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void Start()
5555
return;
5656
}
5757

58-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
58+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
5959

6060
lastOrientation = navBall.rotation;
6161

RasterPropMonitor/Auxiliary modules/JSINumericInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void Start()
6666

6767
try
6868
{
69-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
69+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
7070

7171
if (string.IsNullOrEmpty(perPodPersistenceName))
7272
{

RasterPropMonitor/Auxiliary modules/JSISwitchableVariableLabel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void Start()
7070

7171
try
7272
{
73-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
73+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
7474

7575
textObjTransform = JUtil.FindPropTransform(internalProp, labelTransform);
7676
textObj = InternalComponents.Instance.CreateText(fontName, fontSize * 15.5f, textObjTransform, "", Color.green, false, alignment);
@@ -105,7 +105,7 @@ public void Start()
105105
{
106106
try
107107
{
108-
labelsEx.Add(new VariableLabelSet(variableNodes[i], part));
108+
labelsEx.Add(new VariableLabelSet(variableNodes[i], internalProp));
109109
}
110110
catch (ArgumentException e)
111111
{
@@ -121,7 +121,7 @@ public void Start()
121121
{
122122
try
123123
{
124-
labelsEx.Add(new VariableLabelSet(moduleConfig, part));
124+
labelsEx.Add(new VariableLabelSet(moduleConfig, internalProp));
125125
}
126126
catch (ArgumentException e)
127127
{
@@ -265,14 +265,14 @@ public class VariableLabelSet
265265
public readonly Color color;
266266
public readonly bool hasColor;
267267

268-
public VariableLabelSet(ConfigNode node, Part part)
268+
public VariableLabelSet(ConfigNode node, InternalProp prop)
269269
{
270270
RasterPropMonitorComputer rpmComp = null;
271271
if (node.HasValue("labelText"))
272272
{
273273
string labelText = node.GetValue("labelText").Trim().UnMangleConfigText();
274274
hasText = true;
275-
rpmComp = RasterPropMonitorComputer.Instantiate(part, true);
275+
rpmComp = RasterPropMonitorComputer.FindFromProp(prop);
276276
label = new StringProcessorFormatter(labelText, rpmComp);
277277
oneShot = label.IsConstant;
278278
}
@@ -284,7 +284,7 @@ public VariableLabelSet(ConfigNode node, Part part)
284284

285285
if (node.HasValue("color"))
286286
{
287-
color = JUtil.ParseColor32(node.GetValue("color").Trim(), part, ref rpmComp);
287+
color = JUtil.ParseColor32(node.GetValue("color").Trim(), rpmComp);
288288
hasColor = true;
289289
}
290290
else

RasterPropMonitor/Auxiliary modules/JSIVariableAnimator.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void Start()
5757

5858
try
5959
{
60-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
60+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
6161
useNewMode = RPMGlobals.useNewVariableAnimator;
6262

6363
ConfigNode moduleConfig = null;
@@ -387,13 +387,13 @@ public VariableAnimationSet(ConfigNode node, InternalProp thisProp, RasterPropMo
387387

388388
if (reverse)
389389
{
390-
activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp);
391-
passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp);
390+
activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), rpmComp);
391+
passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), rpmComp);
392392
}
393393
else
394394
{
395-
passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp);
396-
activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp);
395+
passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), rpmComp);
396+
activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), rpmComp);
397397
}
398398
Renderer colorShiftRenderer = thisProp.FindModelComponent<Renderer>(node.GetValue("coloredObject"));
399399
affectedMaterial = colorShiftRenderer.material;
@@ -1072,13 +1072,13 @@ public VariableAnimationSet(ConfigNode node, InternalProp thisProp, RasterPropMo
10721072

10731073
if (reverse)
10741074
{
1075-
activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp);
1076-
passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp);
1075+
activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), rpmComp);
1076+
passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), rpmComp);
10771077
}
10781078
else
10791079
{
1080-
passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp);
1081-
activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp);
1080+
passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), rpmComp);
1081+
activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), rpmComp);
10821082
}
10831083
Renderer colorShiftRenderer = thisProp.FindModelComponent<Renderer>(node.GetValue("coloredObject"));
10841084
affectedMaterial = colorShiftRenderer.material;

RasterPropMonitor/Auxiliary modules/JSIVariableLabel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void Start()
7070

7171
try
7272
{
73-
rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);
73+
rpmComp = RasterPropMonitorComputer.FindFromProp(internalProp);
7474

7575
Transform textObjTransform = JUtil.FindPropTransform(internalProp, transformName);
7676
textObj = InternalComponents.Instance.CreateText("Arial", fontSize * 15.5f, textObjTransform, "", Color.green, false, "TopLeft");
@@ -95,9 +95,9 @@ public void Start()
9595

9696
if (!(string.IsNullOrEmpty(variableName) || string.IsNullOrEmpty(positiveColor) || string.IsNullOrEmpty(negativeColor) || string.IsNullOrEmpty(zeroColor)))
9797
{
98-
positiveColorValue = JUtil.ParseColor32(positiveColor, part, ref rpmComp);
99-
negativeColorValue = JUtil.ParseColor32(negativeColor, part, ref rpmComp);
100-
zeroColorValue = JUtil.ParseColor32(zeroColor, part, ref rpmComp);
98+
positiveColorValue = JUtil.ParseColor32(positiveColor, rpmComp);
99+
negativeColorValue = JUtil.ParseColor32(negativeColor, rpmComp);
100+
zeroColorValue = JUtil.ParseColor32(zeroColor, rpmComp);
101101
del = (Action<float>)Delegate.CreateDelegate(typeof(Action<float>), this, "OnCallback");
102102
rpmComp.RegisterVariableCallback(variableName, del);
103103
registeredVessel = vessel.id;

RasterPropMonitor/Core/RPMVCEvaluators.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal double GetPersistentVariable(string name, double defaultValue)
4040
{
4141
for (int partIdx = 0; partIdx < vessel.parts.Count; ++partIdx)
4242
{
43-
RasterPropMonitorComputer rpmc = RasterPropMonitorComputer.Instantiate(vessel.parts[partIdx], false);
43+
RasterPropMonitorComputer rpmc = vessel.parts[partIdx].FindModuleImplementing<RasterPropMonitorComputer>();
4444
if (rpmc != null)
4545
{
4646
if (rpmc.HasPersistentVariable(name, false))
@@ -67,7 +67,7 @@ internal bool HasPersistentVariable(string name)
6767
{
6868
for (int partIdx = 0; partIdx < vessel.parts.Count; ++partIdx)
6969
{
70-
RasterPropMonitorComputer rpmc = RasterPropMonitorComputer.Instantiate(vessel.parts[partIdx], false);
70+
RasterPropMonitorComputer rpmc = vessel.parts[partIdx].FindModuleImplementing<RasterPropMonitorComputer>();
7171
if (rpmc != null)
7272
{
7373
if (rpmc.HasPersistentVariable(name, false))
@@ -93,7 +93,7 @@ internal void SetPersistentVariable(string name, double value)
9393
{
9494
for (int partIdx = 0; partIdx < vessel.parts.Count; ++partIdx)
9595
{
96-
RasterPropMonitorComputer rpmc = RasterPropMonitorComputer.Instantiate(vessel.parts[partIdx], false);
96+
RasterPropMonitorComputer rpmc = vessel.parts[partIdx].FindModuleImplementing<RasterPropMonitorComputer>();
9797
if (rpmc != null)
9898
{
9999
rpmc.SetPersistentVariable(name, value, false);

0 commit comments

Comments
 (0)