-
Notifications
You must be signed in to change notification settings - Fork 2
/
EventSystem.Event.cs
183 lines (146 loc) · 4.04 KB
/
EventSystem.Event.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
namespace IRSDKSharper
{
public partial class EventSystem
{
public abstract class Event
{
public int SessionNum { get; private set; }
public double SessionTime { get; private set; }
protected readonly IRacingSdkDatum datum;
public Event( int sessionNum, double sessionTime, IRacingSdkDatum datum )
{
SessionNum = sessionNum;
SessionTime = sessionTime;
this.datum = datum;
}
public string SessionTimeAsString
{
get
{
return TimeSpan.FromSeconds( (double) (object) SessionTime ).ToString( @"hh\:mm\:ss\.ffff" );
}
}
public abstract string ValueAsString { get; }
}
public class Event<T> : Event
{
public T Value { get; private set; }
public Event( int sessionNum, double sessionTime, T value, IRacingSdkDatum datum ) : base( sessionNum, sessionTime, datum )
{
Value = value;
}
public override string ValueAsString
{
get
{
if ( datum == null )
{
return Value.ToString() ?? "";
}
else
{
var valueAsString = "";
switch ( datum.Unit )
{
case "irsdk_TrkLoc":
valueAsString = EnumAsString<IRacingSdkEnum.TrkLoc>();
break;
case "irsdk_TrkSurf":
valueAsString = EnumAsString<IRacingSdkEnum.TrkSurf>();
break;
case "irsdk_SessionState":
valueAsString = EnumAsString<IRacingSdkEnum.SessionState>();
break;
case "irsdk_CarLeftRight":
valueAsString = EnumAsString<IRacingSdkEnum.CarLeftRight>();
break;
case "irsdk_PitSvStatus":
valueAsString = EnumAsString<IRacingSdkEnum.PitSvStatus>();
break;
case "irsdk_PaceMode":
valueAsString = EnumAsString<IRacingSdkEnum.PaceMode>();
break;
case "irsdk_TrackWetness":
valueAsString = EnumAsString<IRacingSdkEnum.TrackWetness>();
break;
default:
switch ( datum.VarType )
{
case IRacingSdkEnum.VarType.Char:
case IRacingSdkEnum.VarType.Int:
valueAsString = Value.ToString() ?? "";
break;
case IRacingSdkEnum.VarType.Bool:
valueAsString = ( (bool) (object) Value ) ? "True" : "False";
break;
case IRacingSdkEnum.VarType.BitField:
valueAsString = $"0x{Value:X8}";
var bitsAsString = string.Empty;
switch ( datum.Unit )
{
case "irsdk_EngineWarnings":
bitsAsString = EnumAsString<IRacingSdkEnum.EngineWarnings>();
break;
case "irsdk_Flags":
bitsAsString = EnumAsString<IRacingSdkEnum.Flags>();
break;
case "irsdk_CameraState":
bitsAsString = EnumAsString<IRacingSdkEnum.CameraState>();
break;
case "irsdk_PitSvFlags":
bitsAsString = EnumAsString<IRacingSdkEnum.PitSvFlags>();
break;
case "irsdk_PaceFlags":
bitsAsString = EnumAsString<IRacingSdkEnum.PaceFlags>();
break;
}
if ( bitsAsString != string.Empty )
{
valueAsString += " - " + bitsAsString;
}
break;
case IRacingSdkEnum.VarType.Float:
case IRacingSdkEnum.VarType.Double:
valueAsString = $"{Value,0:N4}";
break;
}
break;
}
return valueAsString;
}
}
}
private string EnumAsString<E>() where E : Enum
{
if ( datum == null )
{
return Value.ToString() ?? "";
}
else if ( datum.VarType == IRacingSdkEnum.VarType.Int )
{
var enumValue = (E) (object) Value;
return enumValue.ToString();
}
else
{
var bits = (uint) (object) Value;
var bitsString = string.Empty;
foreach ( uint bitMask in Enum.GetValues( typeof( E ) ) )
{
if ( ( bits & bitMask ) != 0 )
{
if ( bitsString != string.Empty )
{
bitsString += " | ";
}
bitsString += Enum.GetName( typeof( E ), bitMask );
}
}
return bitsString;
}
}
}
}
}