-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSetup.cs
188 lines (159 loc) · 5.04 KB
/
Setup.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
184
185
186
187
188
using System;
using System.IO;
using System.Text.Json;
namespace SetupDiff {
// Mimics the ACC setup file JSON structure.
public class Setup {
// name and path are set after the setup is loaded from the JSON file.
public string Name {get;set;} = string.Empty;
public string Path {get;set;} = string.Empty;
public DateTime LastWriteTime {get;set;} = new DateTime(DateTime.MinValue.Ticks);
public string CarName {get;set;} = string.Empty;
public BasicSetup BasicSetup {get;set;} = new BasicSetup();
public AdvancedSetup AdvancedSetup {get;set;} = new AdvancedSetup();
// Shortcut to tyre offsets.
public Tyres Tyres {
get {
return this.BasicSetup.Tyres;
}
}
// Shortcut to alignment offsets.
public Alignment Align {
get {
return this.BasicSetup.Alignment;
}
}
// Shortcut to electronic offsets.
public Electronics Elec {
get {
return this.BasicSetup.Electronics;
}
}
// Shortcut to strategy offsets.
public Strategy Strat {
get {
return this.BasicSetup.Strategy;
}
}
// Shortcut to mechanical offsets.
public MechanicalBalance Mech {
get {
return this.AdvancedSetup.MechanicalBalance;
}
}
// Shortcut to damper offsets.
public Dampers Dampers {
get {
return this.AdvancedSetup.Dampers;
}
}
// Shortcut to aero offsets.
public AeroBalance Aero {
get {
return this.AdvancedSetup.AeroBalance;
}
}
// Front ride height.
// The ride height is stored as a 4-element array with the first
// and third elements being the actual ride height while the second
// and fourth elements appear to be the "base" ride height values
// on the setup screen.
public int RideHeightF {
get {
return this.AdvancedSetup.AeroBalance.RideHeight[0];
}
}
// Rear ride height.
// See the front ride height shortcut accessor for an explanation.
public int RideHeightR {
get {
return this.AdvancedSetup.AeroBalance.RideHeight[2];
}
}
// Shortcut to the preload offset
public int Preload {
get {
return this.AdvancedSetup.Drivetrain.Preload;
}
}
private static JsonSerializerOptions opts = new JsonSerializerOptions() {
PropertyNameCaseInsensitive = true
};
// Deserialise a setup file.
public static Setup FromFile(string path, DateTime lastWriteTime) {
// open the file
var stream = File.Open(path, FileMode.Open);
// deserialize into Setup
var setup = JsonSerializer.Deserialize<Setup>(stream, opts);
// close the file
stream.Close();
if (setup == null) {
throw new Exception(string.Format("Could not load setup: {0}", path));
}
// set the setup name and path
setup.Path = path;
setup.Name = System.IO.Path.GetFileNameWithoutExtension(path);
setup.LastWriteTime = lastWriteTime;
return setup;
}
}
public class BasicSetup {
public Tyres Tyres {get;set;} = new Tyres();
public Alignment Alignment {get;set;} = new Alignment();
public Electronics Electronics {get;set;} = new Electronics();
public Strategy Strategy {get;set;} = new Strategy();
}
public class Tyres {
public int TyreCompound {get;set;} = 0;
public int[] TyrePressure {get;set;} = new int[4];
}
public class Alignment {
public int[] Camber {get;set;} = new int[4];
public int[] Toe {get;set;} = new int[4];
public int CasterLF {get;set;} = 0;
public int CasterRF {get;set;} = 0;
public int SteerRatio {get;set;} = 0;
}
public class Electronics {
public int TC1 {get;set;} = 0;
public int TC2 {get;set;} = 0;
public int ABS {get;set;} = 0;
public int ECUMap {get;set;} = 0;
}
public class Strategy {
public int Fuel {get;set;} = 0;
public int TyreSet {get;set;} = 0;
public int FrontBrakePadCompound {get;set;} = 0;
public int RearBrakePadCompound {get;set;} = 0;
}
public class AdvancedSetup {
public MechanicalBalance MechanicalBalance {get;set;} = new MechanicalBalance();
public Dampers Dampers {get;set;} = new Dampers();
public AeroBalance AeroBalance {get;set;} = new AeroBalance();
public Drivetrain Drivetrain {get;set;} = new Drivetrain();
}
public class MechanicalBalance {
public int ARBFront {get;set;} = 0;
public int ARBRear {get;set;} = 0;
public int[] WheelRate {get;set;} = new int[4];
public int[] BumpStopRateUp {get;set;} = new int[4];
public int[] BumpStopWindow {get;set;} = new int[4];
public int BrakeTorque {get;set;} = 0;
public int BrakeBias {get;set;} = 0;
}
public class Dampers {
public int[] BumpSlow {get;set;} = new int[4];
public int[] BumpFast {get;set;} = new int[4];
public int[] ReboundSlow {get;set;} = new int[4];
public int[] ReboundFast {get;set;} = new int[4];
}
public class AeroBalance {
public int[] RideHeight {get;set;} = new int[2];
public int Splitter {get;set;} = 0;
public int RearWing {get;set;} = 0;
public int[] BrakeDuct {get;set;} = new int[2];
}
public class Drivetrain {
public int Preload {get;set;} = 0;
}
}