-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathLocoControl.cs
59 lines (56 loc) · 1.94 KB
/
LocoControl.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
using DV.Logic.Job;
using DV.RemoteControls;
using DV.Utils;
using System.Collections.Specialized;
using System.Linq;
using UnityEngine;
namespace DvMod.RemoteDispatch
{
public static class LocoControl
{
public static bool CanBeControlled(TrainCar trainCar)
{
return trainCar.GetComponent<RemoteControllerModule>() != null;
}
public static RemoteControllerModule? GetLocoController(string guid)
{
return SingletonBehaviour<IdGenerator>.Instance
.GetTrainCarByCarGuid(guid)
?.GetComponent<RemoteControllerModule>();
}
public static bool RunCommand(RemoteControllerModule controller, NameValueCollection queryString)
{
for (int i = 0; i < queryString.Count; i++)
{
if (!float.TryParse(queryString.Get(i), out var value))
return false;
var key = queryString.GetKey(i);
float value01 = Mathf.Clamp01(value);
switch (key)
{
case "trainBrake":
controller.controlsOverrider.Brake?.Set(value01);
break;
case "independentBrake":
controller.controlsOverrider.IndependentBrake?.Set(value01);
break;
case "reverser":
controller.controlsOverrider.Reverser?.Set(value01);
break;
case "throttle":
controller.controlsOverrider.Throttle?.Set(value01);
break;
case "couple":
controller.RemoteControllerCouple();
break;
case "uncouple":
controller.Uncouple((int)value);
break;
default:
return false;
}
}
return true;
}
}
}