Skip to content

Commit 1267475

Browse files
author
Chris Jakeman
committed
CVCDiscrete extended to report correct MaxValue
Optional parameter added to CVCDiscrete constructor so it knows Lever|TwoState|TriState|MultiState and can set MaxValue correctly for use in CabControls API.
1 parent de02eda commit 1267475

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

Source/Orts.Formats.Msts/CabViewFile.cs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ public enum CABViewControlUnits
311311
LBS
312312
}
313313

314+
public static class DiscreteStates
315+
{
316+
public const string Lever = "lever";
317+
public const string TwoState = "twostate";
318+
public const string TriState = "tristate";
319+
public const string MultiState = "multistate";
320+
}
321+
314322
public class CabViewControls : List<CabViewControl>
315323
{
316324
public CabViewControls(STFReader stf, string basepath)
@@ -322,10 +330,10 @@ public CabViewControls(STFReader stf, string basepath)
322330
new STFReader.TokenProcessor("ortsanimateddisplay", ()=>{ Add(new CVCAnimatedDisplay(stf, basepath)); }),
323331
new STFReader.TokenProcessor("dial", ()=>{ Add(new CVCDial(stf, basepath)); }),
324332
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)); }),
333+
new STFReader.TokenProcessor(DiscreteStates.Lever, ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.Lever)); }),
334+
new STFReader.TokenProcessor(DiscreteStates.TwoState, ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.TwoState)); }),
335+
new STFReader.TokenProcessor(DiscreteStates.TriState, ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.TriState)); }),
336+
new STFReader.TokenProcessor(DiscreteStates.MultiState, ()=>{ Add(new CVCDiscrete(stf, basepath, DiscreteStates.MultiState)); }),
329337
new STFReader.TokenProcessor("multistatedisplay", ()=>{ Add(new CVCMultiStateDisplay(stf, basepath)); }),
330338
new STFReader.TokenProcessor("cabsignaldisplay", ()=>{ Add(new CVCSignal(stf, basepath)); }),
331339
new STFReader.TokenProcessor("digital", ()=>{ Add(new CVCDigital(stf, basepath)); }),
@@ -845,7 +853,7 @@ public class CVCDiscrete : CVCWithFrames
845853
private int numPositions;
846854
private bool canFill = true;
847855

848-
public CVCDiscrete(STFReader stf, string basepath)
856+
public CVCDiscrete(STFReader stf, string basepath, string discreteStates = null)
849857
{
850858
// try
851859
{
@@ -1149,14 +1157,23 @@ public CVCDiscrete(STFReader stf, string basepath)
11491157
ControlStyle = CABViewControlStyles.WHILE_PRESSED;
11501158
if (ControlType == CABViewControlTypes.DIRECTION && Orientation == 0)
11511159
Direction = 1 - Direction;
1160+
1161+
switch (discreteStates)
1162+
{
1163+
case DiscreteStates.TriState:
1164+
MaxValue = 2.0f; // So that LocomotiveViewerExtensions.GetWebControlValueList() returns right value to web server
1165+
break;
1166+
default:
1167+
break;
1168+
}
11521169
}
1153-
// catch (Exception error)
1154-
// {
1155-
// if (error is STFException) // Parsing error, so pass it on
1156-
// throw;
1157-
// else // Unexpected error, so provide a hint
1158-
// throw new STFException(stf, "Problem with NumPositions/NumValues/NumFrames/ScaleRange");
1159-
// } // End of Need check the Values collection for validity
1170+
// catch (Exception error)
1171+
// {
1172+
// if (error is STFException) // Parsing error, so pass it on
1173+
// throw;
1174+
// else // Unexpected error, so provide a hint
1175+
// throw new STFException(stf, "Problem with NumPositions/NumValues/NumFrames/ScaleRange");
1176+
// } // End of Need check the Values collection for validity
11601177
} // End of Constructor
11611178
}
11621179
#endregion

0 commit comments

Comments
 (0)