Skip to content

Commit 418a87c

Browse files
authored
Merge pull request #443 from cjakeman/api-cabcontrols3
CVCDiscrete extended to report correct MaxValue. Update to PR #377
2 parents 74a0467 + 922cd92 commit 418a87c

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

Source/Orts.Formats.Msts/CabViewFile.cs

+29-11
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ public enum CABViewControlUnits
311311
LBS
312312
}
313313

314+
public enum DiscreteStates
315+
{
316+
LEVER,
317+
TWO_STATE,
318+
TRI_STATE,
319+
MULTI_STATE,
320+
COMBINED_CONTROL,
321+
CAB_SIGNAL_DISPLAY
322+
}
323+
314324
public class CabViewControls : List<CabViewControl>
315325
{
316326
public CabViewControls(STFReader stf, string basepath)
@@ -322,14 +332,14 @@ public CabViewControls(STFReader stf, string basepath)
322332
new STFReader.TokenProcessor("ortsanimateddisplay", ()=>{ Add(new CVCAnimatedDisplay(stf, basepath)); }),
323333
new STFReader.TokenProcessor("dial", ()=>{ Add(new CVCDial(stf, basepath)); }),
324334
new STFReader.TokenProcessor("gauge", ()=>{ Add(new CVCGauge(stf, basepath)); }),
325-
new STFReader.TokenProcessor("lever", ()=>{ Add(new CVCDiscrete(stf, basepath)); }),
326-
new STFReader.TokenProcessor("twostate", ()=>{ Add(new CVCDiscrete(stf, basepath)); }),
327-
new STFReader.TokenProcessor("tristate", ()=>{ Add(new CVCDiscrete(stf, basepath)); }),
328-
new STFReader.TokenProcessor("multistate", ()=>{ Add(new CVCDiscrete(stf, basepath)); }),
335+
new STFReader.TokenProcessor("lever", ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.LEVER)); }),
336+
new STFReader.TokenProcessor("twostate", ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.TWO_STATE)); }),
337+
new STFReader.TokenProcessor("tristate", ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.TRI_STATE)); }),
338+
new STFReader.TokenProcessor("multistate", ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.MULTI_STATE)); }),
329339
new STFReader.TokenProcessor("multistatedisplay", ()=>{ Add(new CVCMultiStateDisplay(stf, basepath)); }),
330-
new STFReader.TokenProcessor("cabsignaldisplay", ()=>{ Add(new CVCSignal(stf, basepath)); }),
340+
new STFReader.TokenProcessor("cabsignaldisplay", ()=>{ Add(new CVCSignal(stf, basepath, DiscreteStates.CAB_SIGNAL_DISPLAY)); }),
331341
new STFReader.TokenProcessor("digital", ()=>{ Add(new CVCDigital(stf, basepath)); }),
332-
new STFReader.TokenProcessor("combinedcontrol", ()=>{ Add(new CVCDiscrete(stf, basepath)); }),
342+
new STFReader.TokenProcessor("combinedcontrol", ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.COMBINED_CONTROL)); }),
333343
new STFReader.TokenProcessor("firebox", ()=>{ Add(new CVCFirebox(stf, basepath)); }),
334344
new STFReader.TokenProcessor("dialclock", ()=>{ ProcessDialClock(stf, basepath); }),
335345
new STFReader.TokenProcessor("digitalclock", ()=>{ Add(new CVCDigitalClock(stf, basepath)); }),
@@ -845,7 +855,7 @@ public class CVCDiscrete : CVCWithFrames
845855
private int numPositions;
846856
private bool canFill = true;
847857

848-
public CVCDiscrete(STFReader stf, string basepath)
858+
public CVCDiscrete(STFReader stf, string basepath, DiscreteStates discreteState)
849859
{
850860
// try
851861
{
@@ -1149,6 +1159,15 @@ public CVCDiscrete(STFReader stf, string basepath)
11491159
ControlStyle = CABViewControlStyles.WHILE_PRESSED;
11501160
if (ControlType == CABViewControlTypes.DIRECTION && Orientation == 0)
11511161
Direction = 1 - Direction;
1162+
1163+
switch (discreteState)
1164+
{
1165+
case DiscreteStates.TRI_STATE:
1166+
MaxValue = 2.0f; // So that LocomotiveViewerExtensions.GetWebControlValueList() returns right value to web server
1167+
break;
1168+
default:
1169+
break;
1170+
}
11521171
}
11531172
// catch (Exception error)
11541173
// {
@@ -1293,8 +1312,8 @@ protected void ParseCustomParameters(STFReader stf)
12931312
#region other controls
12941313
public class CVCSignal : CVCDiscrete
12951314
{
1296-
public CVCSignal(STFReader inf, string basepath)
1297-
: base(inf, basepath)
1315+
public CVCSignal(STFReader inf, string basepath, DiscreteStates discreteState)
1316+
: base(inf, basepath, discreteState)
12981317
{
12991318
FramesCount = 8;
13001319
FramesX = 4;
@@ -1308,5 +1327,4 @@ public CVCSignal(STFReader inf, string basepath)
13081327
}
13091328
}
13101329
#endregion
1311-
}
1312-
1330+
}

0 commit comments

Comments
 (0)