-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocoBase.cs
67 lines (61 loc) · 2.44 KB
/
LocoBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using JetBrains.Annotations;
namespace DvRemoteRemote
{
public class LocoBase : Loco<BaseLocoState, BaseLocoActions>
{
[NotNull] private readonly LocoControllerBase _inner;
public LocoBase([NotNull] LocoControllerBase inner)
{
_inner = inner;
}
public override void GetState([NotNull] BaseLocoState state)
{
state.Reverser = _inner.reverser;
state.ReverserSymbol = _inner.GetReverserSymbol();
state.Throttle = (float) Math.Round(_inner.throttle, 2);
state.TargetThrottle = (float) Math.Round(_inner.targetThrottle, 2);
state.Break = (float) Math.Round(_inner.brake, 2);
state.TargetBreak = (float) Math.Round(_inner.targetBrake, 2);
state.Derailed = _inner.IsDerailed();
state.WheelSlip = _inner.IsWheelslipping();
state.Speed = (float) Math.Round(_inner.GetSpeedKmH(), 2);
state.CanCouple = _inner.IsCouplerInRange();
state.MinCouplePos = -_inner.GetNumberOfCarsInRear() - 1;
state.MaxCouplePos = _inner.GetNumberOfCarsInFront() + 1;
state.LocoType = "base";
}
public override void GetActions([NotNull] BaseLocoActions actions)
{
actions.SetThrottle = _inner.SetThrottle;
actions.SetBreak = _inner.SetBrake;
actions.SetReverser = _inner.SetReverser;
actions.Couple = _inner.Couple;
actions.UnCouple = _inner.Uncouple;
}
}
public class BaseLocoState
{
public string LocoType { get; set; }
public float Throttle { get; set; }
public float TargetThrottle { get; set; }
public float Break { get; set; }
public float TargetBreak { get; set; }
public float Reverser { get; set; }
public string ReverserSymbol { get; set; }
public bool Derailed { get; set; }
public bool WheelSlip { get; set; }
public float Speed { get; set; }
public int MinCouplePos { get; set; }
public int MaxCouplePos { get; set; }
public bool CanCouple { get; set; }
}
public class BaseLocoActions
{
public Action<float> SetThrottle { get; set; }
public Action<float> SetBreak { get; set; }
public Action<float> SetReverser { get; set; }
public Action<int> Couple { get; set; }
public Action<int> UnCouple { get; set; }
}
}