Skip to content

Commit e1fb4ec

Browse files
committed
refactoring in StringProcesserFormatter from @andymac-2
1 parent a476486 commit e1fb4ec

File tree

5 files changed

+12
-23
lines changed

5 files changed

+12
-23
lines changed

RasterPropMonitor/Auxiliary modules/JSILabel.cs

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

231231
if (oneshot)
232232
{
233-
textObj.text = labels[0].Get();
233+
textObj.text = labels[0].GetFormattedString();
234234

235235
var propBatcher = internalModel.GetComponentInChildren<PropBatcher>();
236236
if (propBatcher != null && canBatch)
@@ -338,7 +338,7 @@ public void Click()
338338
activeLabel = 0;
339339
}
340340

341-
textObj.text = labels[activeLabel].Get();
341+
textObj.text = labels[activeLabel].GetFormattedString();
342342

343343
// do we need to activate the update loop?
344344
if (labels.Count > 1 && !labels[activeLabel].IsConstant)
@@ -492,7 +492,7 @@ public override void OnUpdate()
492492

493493
if (UpdateCheck() && JUtil.RasterPropMonitorShouldUpdate(part))
494494
{
495-
textObj.text = labels[activeLabel].Get();
495+
textObj.text = labels[activeLabel].GetFormattedString();
496496
}
497497
}
498498
}

RasterPropMonitor/Auxiliary modules/JSISwitchableVariableLabel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public override void OnUpdate()
190190
{
191191
if (UpdateCheck())
192192
{
193-
textObj.text.text = StringProcessor.ProcessString(labelsEx[activeLabel].label, rpmComp);
193+
textObj.text.text = labelsEx[activeLabel].label.GetFormattedString();
194194

195195
if (labelsEx[activeLabel].oneShot)
196196
{
@@ -232,7 +232,7 @@ void UpdateActiveLabel(int direction)
232232

233233
if (labelsEx[activeLabel].hasText)
234234
{
235-
textObj.text.text = StringProcessor.ProcessString(labelsEx[activeLabel].label, rpmComp);
235+
textObj.text.text = labelsEx[activeLabel].label.GetFormattedString();
236236
}
237237

238238
// Force an update.

RasterPropMonitor/Auxiliary modules/JSIVariableLabel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public override void OnUpdate()
190190

191191
if (UpdateCheck())
192192
{
193-
textObj.text.text = StringProcessor.ProcessString(spf, rpmComp);
193+
textObj.text.text = spf.GetFormattedString();
194194
oneshotComplete = true;
195195
}
196196
}

RasterPropMonitor/Core/MonitorPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void UpdateText(RasterPropMonitorComputer rpmComp)
156156
{
157157
if (spf[i] != null)
158158
{
159-
outputLines[i] = StringProcessor.ProcessString(spf[i], rpmComp);
159+
outputLines[i] = spf[i].GetFormattedString();
160160
}
161161
}
162162
}

RasterPropMonitor/Core/StringProcessor.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace JSI
2525
{
2626
public class StringProcessorFormatter
2727
{
28+
internal static readonly SIFormatProvider fp = new SIFormatProvider();
29+
2830
// The formatString or plain text (if usesComp is false).
2931
private readonly string formatString;
3032
// An array of source variables
@@ -69,7 +71,7 @@ public StringProcessorFormatter(string input, RasterPropMonitorComputer rpmComp)
6971
sourceValues[i] = sourceVariables[i].Get();
7072
}
7173

72-
cachedResult = string.Format(StringProcessor.fp, formatString, sourceValues);
74+
cachedResult = string.Format(fp, formatString, sourceValues);
7375

7476
// if every variable is a constant, we can run the format once and cache the result
7577
if (allVariablesConstant)
@@ -116,27 +118,14 @@ public bool UpdateValues()
116118
return anyChanged;
117119
}
118120

119-
public string Get()
121+
public string GetFormattedString()
120122
{
121123
if (UpdateValues())
122124
{
123-
cachedResult = string.Format(StringProcessor.fp, formatString, sourceValues);
125+
cachedResult = string.Format(fp, formatString, sourceValues);
124126
}
125127

126128
return cachedResult;
127129
}
128130
}
129-
130-
public static class StringProcessor
131-
{
132-
internal static readonly SIFormatProvider fp = new SIFormatProvider();
133-
134-
public static string ProcessString(StringProcessorFormatter formatter, RasterPropMonitorComputer rpmComp)
135-
{
136-
Profiler.BeginSample("ProcessString_cached");
137-
string result = formatter.Get();
138-
Profiler.EndSample();
139-
return result;
140-
}
141-
}
142131
}

0 commit comments

Comments
 (0)