Skip to content

Commit f786fff

Browse files
committed
Add STF parsing
1 parent a208b1d commit f786fff

File tree

2 files changed

+84
-27
lines changed

2 files changed

+84
-27
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public class MSTSWagon : TrainCar
6868
{
6969
public Pantographs Pantographs;
7070
public ScriptedPassengerCarPowerSupply PassengerCarPowerSupply => PowerSupply as ScriptedPassengerCarPowerSupply;
71-
72-
public Door RightDoor;
73-
public Door LeftDoor;
71+
public Doors Doors;
72+
public Door RightDoor => Doors.RightDoor;
73+
public Door LeftDoor => Doors.LeftDoor;
7474
public bool MirrorOpen;
7575
public bool UnloadingPartsOpen;
7676
public bool WaitForAnimationReady; // delay counter to start loading/unliading is on;
@@ -346,8 +346,7 @@ public MSTSWagon(Simulator simulator, string wagFilePath)
346346
: base(simulator, wagFilePath)
347347
{
348348
Pantographs = new Pantographs(this);
349-
RightDoor = new Door(this, true);
350-
LeftDoor = new Door(this, false);
349+
Doors = new Doors(this);
351350
}
352351

353352
public void Load()
@@ -954,8 +953,7 @@ public void GetMeasurementUnits()
954953
public override void Initialize()
955954
{
956955
Pantographs.Initialize();
957-
RightDoor.Initialize();
958-
LeftDoor.Initialize();
956+
Doors.Initialize();
959957
PassengerCarPowerSupply?.Initialize();
960958

961959
base.Initialize();
@@ -1380,6 +1378,10 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
13801378
case "wagon(ortspantographs":
13811379
Pantographs.Parse(lowercasetoken, stf);
13821380
break;
1381+
case "wagon(ortsdoors(closingdelay":
1382+
case "wagon(ortsdoors(openingdelay":
1383+
Doors.Parse(lowercasetoken, stf);
1384+
break;
13831385
case "wagon(ortspowersupply":
13841386
case "wagon(ortspowerondelay":
13851387
case "wagon(ortsbattery(mode":
@@ -1544,8 +1546,7 @@ public virtual void Copy(MSTSWagon copy)
15441546
foreach (MSTSCoupling coupler in copy.Couplers)
15451547
Couplers.Add(coupler);
15461548
Pantographs.Copy(copy.Pantographs);
1547-
LeftDoor.Copy(copy.LeftDoor);
1548-
RightDoor.Copy(copy.RightDoor);
1549+
Doors.Copy(copy.Doors);
15491550
if (copy.FreightAnimations != null)
15501551
{
15511552
FreightAnimations = new FreightAnimations(copy.FreightAnimations, this);
@@ -1679,8 +1680,7 @@ public override void Save(BinaryWriter outf)
16791680
foreach (MSTSCoupling coupler in Couplers)
16801681
coupler.Save(outf);
16811682
Pantographs.Save(outf);
1682-
LeftDoor.Save(outf);
1683-
RightDoor.Save(outf);
1683+
Doors.Save(outf);
16841684
PassengerCarPowerSupply?.Save(outf);
16851685
if (FreightAnimations != null)
16861686
{
@@ -1733,8 +1733,7 @@ public override void Restore(BinaryReader inf)
17331733
MaxHandbrakeForceN = inf.ReadSingle();
17341734
Couplers = ReadCouplersFromSave(inf).ToList();
17351735
Pantographs.Restore(inf);
1736-
LeftDoor.Restore(inf);
1737-
RightDoor.Restore(inf);
1736+
Doors.Restore(inf);
17381737
PassengerCarPowerSupply?.Restore(inf);
17391738
if (FreightAnimations != null)
17401739
{
@@ -1907,8 +1906,7 @@ public override void Update(float elapsedClockSeconds)
19071906

19081907
Pantographs.Update(elapsedClockSeconds);
19091908

1910-
LeftDoor.Update(elapsedClockSeconds);
1911-
RightDoor.Update(elapsedClockSeconds);
1909+
Doors.Update(elapsedClockSeconds);
19121910

19131911
MSTSBrakeSystem.Update(elapsedClockSeconds);
19141912

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Door.cs

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,81 @@ public enum DoorState
3131
Opening,
3232
Open,
3333
}
34+
public class Doors : ISubSystem<Doors>
35+
{
36+
public Door RightDoor;
37+
public Door LeftDoor;
38+
39+
public Doors(MSTSWagon wagon)
40+
{
41+
LeftDoor = new Door(wagon, false);
42+
RightDoor = new Door(wagon, true);
43+
}
44+
45+
public virtual void Parse(string lowercasetoken, STFReader stf)
46+
{
47+
switch (lowercasetoken)
48+
{
49+
case "wagon(ortsdoors(closingdelay":
50+
{
51+
float delayS = stf.ReadFloatBlock(STFReader.UNITS.Time, 0f);
52+
LeftDoor.ClosingDelayS = delayS;
53+
RightDoor.ClosingDelayS = delayS;
54+
break;
55+
}
56+
case "wagon(ortsdoors(openingdelay":
57+
{
58+
float delayS = stf.ReadFloatBlock(STFReader.UNITS.Time, 0f);
59+
LeftDoor.OpeningDelayS = delayS;
60+
RightDoor.OpeningDelayS = delayS;
61+
break;
62+
}
63+
}
64+
}
65+
66+
public void Copy(Doors other)
67+
{
68+
LeftDoor.Copy(other.LeftDoor);
69+
RightDoor.Copy(other.RightDoor);
70+
}
71+
72+
public virtual void Initialize()
73+
{
74+
LeftDoor.Initialize();
75+
RightDoor.Initialize();
76+
}
77+
78+
/// <summary>
79+
/// Initialization when simulation starts with moving train
80+
/// </summary>
81+
public virtual void InitializeMoving()
82+
{
83+
}
84+
85+
public virtual void Save(BinaryWriter outf)
86+
{
87+
LeftDoor.Save(outf);
88+
RightDoor.Save(outf);
89+
}
90+
91+
public virtual void Restore(BinaryReader inf)
92+
{
93+
LeftDoor.Restore(inf);
94+
RightDoor.Restore(inf);
95+
}
96+
97+
public virtual void Update(float elapsedClockSeconds)
98+
{
99+
LeftDoor.Update(elapsedClockSeconds);
100+
RightDoor.Update(elapsedClockSeconds);
101+
}
102+
}
34103
public class Door : ISubSystem<Door>
35104
{
36105

37106
// Parameters
38-
public float OpeningDelayS { get; protected set; } = 0f;
39-
public float ClosingDelayS { get; protected set; } = 0f;
107+
public float OpeningDelayS { get; set; } = 0f;
108+
public float ClosingDelayS { get; set; } = 0f;
40109

41110
// Variables
42111
readonly MSTSWagon Wagon;
@@ -59,16 +128,6 @@ public Door(MSTSWagon wagon, bool right)
59128

60129
public virtual void Parse(string lowercasetoken, STFReader stf)
61130
{
62-
switch (lowercasetoken)
63-
{
64-
case "wagon(ortsdoors(closingdelay":
65-
ClosingDelayS = stf.ReadFloatBlock(STFReader.UNITS.Time, 0f);
66-
break;
67-
68-
case "engine(ortsdoors(openingdelay":
69-
OpeningDelayS = stf.ReadFloatBlock(STFReader.UNITS.Time, 0f);
70-
break;
71-
}
72131
}
73132

74133
public void Copy(Door other)

0 commit comments

Comments
 (0)