Skip to content

Commit df8d7e9

Browse files
committed
label batching is now opt-in, and allow batching labels that differ in color if they're not linked to a variable
1 parent 8b7cb67 commit df8d7e9

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

GameData/JSI/RasterPropMonitor/PropBatching.cfg

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,42 @@ PROP_BATCH
347347
modelPath = ASET/ASET_Props/Control/SwitchRotary/model/Switch_Rotary_Dimmer_Mark
348348
transformName = swRotaryCircleMarkObj
349349
}
350-
}
350+
}
351+
352+
@PROP:HAS[@MODULE[JSILabel]:HAS[#transformName[Legend_Center]]]
353+
{
354+
@MODULE[JSILabel]:HAS[#transformName[Legend_Center]]
355+
{
356+
canBatch = false
357+
}
358+
}
359+
@PROP:HAS[@MODULE[JSILabel]:HAS[#transformName[Legend_Upper]]]
360+
{
361+
@MODULE[JSILabel]:HAS[#transformName[Legend_Upper]]
362+
{
363+
canBatch = false
364+
}
365+
}
366+
@PROP:HAS[@MODULE[JSILabel]:HAS[#transformName[Legend_Lower]]]
367+
{
368+
@MODULE[JSILabel]:HAS[#transformName[Legend_Lower]]
369+
{
370+
canBatch = false
371+
}
372+
}
373+
374+
@PROP:HAS[@MODULE[JSILabel]:HAS[#variableName[CUSTOM_ALCOR_BACKLIGHT_ON]&~canBatch]]
375+
{
376+
@MODULE[JSILabel]:HAS[#variableName[CUSTOM_ALCOR_BACKLIGHT_ON]&~canBatch]
377+
{
378+
canBatch = true
379+
}
380+
}
381+
382+
@PROP:HAS[@MODULE[JSILabel]:HAS[~variableName&~canBatch]]
383+
{
384+
@MODULE[JSILabel]:HAS[~variableName&~canBatch]
385+
{
386+
canBatch = true
387+
}
388+
}

RasterPropMonitor/Auxiliary modules/JSILabel.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,15 @@ void ReadColor(ConfigNode node, string key, RasterPropMonitorComputer rpmComp, r
6262

6363
public override bool Equals(object obj)
6464
{
65+
// TODO: technically we don't need to differentiate labels by color even if they are connected to a variable, but we do need to store the colors per-label...
6566
return obj is TextBatchInfo info &&
6667
variableName == info.variableName &&
6768
font == info.font &&
68-
EqualityComparer<Color32>.Default.Equals(zeroColor, info.zeroColor) &&
69-
EqualityComparer<Color32>.Default.Equals(positiveColor, info.positiveColor) &&
70-
EqualityComparer<Color32>.Default.Equals(negativeColor, info.negativeColor) &&
69+
(variableName == null ||
70+
(EqualityComparer<Color32>.Default.Equals(zeroColor, info.zeroColor) &&
71+
EqualityComparer<Color32>.Default.Equals(positiveColor, info.positiveColor) &&
72+
EqualityComparer<Color32>.Default.Equals(negativeColor, info.negativeColor))
73+
) &&
7174
flashRate == info.flashRate;
7275
}
7376

@@ -76,9 +79,14 @@ public override int GetHashCode()
7679
var hashCode = -1112470117;
7780
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(variableName);
7881
hashCode = hashCode * -1521134295 + font.GetHashCode();
79-
hashCode = hashCode * -1521134295 + zeroColor.GetHashCode();
80-
hashCode = hashCode * -1521134295 + positiveColor.GetHashCode();
81-
hashCode = hashCode * -1521134295 + negativeColor.GetHashCode();
82+
83+
if (variableName != null)
84+
{
85+
hashCode = hashCode * -1521134295 + zeroColor.GetHashCode();
86+
hashCode = hashCode * -1521134295 + positiveColor.GetHashCode();
87+
hashCode = hashCode * -1521134295 + negativeColor.GetHashCode();
88+
}
89+
8290
hashCode = hashCode * -1521134295 + flashRate.GetHashCode();
8391
return hashCode;
8492
}
@@ -132,6 +140,8 @@ public enum EmissiveMode
132140
public int refreshRate = 10;
133141
[KSPField]
134142
public bool oneshot;
143+
[KSPField]
144+
public bool canBatch;
135145

136146
private bool variablePositive = false;
137147
private bool flashOn = true;
@@ -214,10 +224,11 @@ public void Start()
214224

215225
if (oneshot)
216226
{
227+
textObj.text = labels[0].Get();
228+
217229
var propBatcher = internalModel.GetComponentInChildren<PropBatcher>();
218-
if (propBatcher != null)
230+
if (propBatcher != null && canBatch)
219231
{
220-
textObj.text = labels[0].Get();
221232
propBatcher.AddStaticLabel(this);
222233
return;
223234
}

0 commit comments

Comments
 (0)