-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.js
419 lines (357 loc) · 16.9 KB
/
dashboard.js
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
var restMessage = '';
var driverWorkTime;
var driverSleepTime;
var roadTimeScale = 19;
function requestFullScreen(element) {
// Supports most browsers and their versions.
var requestMethod = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || element.msRequestFullScreen;
if (requestMethod) { // Native full screen.
requestMethod.call(element);
} else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}
Funbit.Ets.Telemetry.Dashboard.prototype.initialize = function (skinConfig, utils) {
// skinConfig - a copy of the skin configuration from config.json
// utils - an object containing several utility functions (see skin tutorial for more information)
// this function is called before everything else,
// so you may perform any DOM or resource initializations / image preloading here
/*
utils.preloadImages([
'images/bg-off.jpg', 'images/bg-on.jpg'
]);
*/
// WIP: Click entire page to switch pages
/* $(document).add('body').on('click', function () {
var elem = document.body; // Make the body go full screen.
requestFullScreen(elem);
}); */
}
Funbit.Ets.Telemetry.Dashboard.prototype.filter = function (data, utils) {
// data - telemetry data JSON object
// utils - an object containing several utility functions (see skin tutorial for more information)
// Called on each json / telemetry data update
// You can change existing values in data here or add new ones (subclass values, or new classes entirely)
// data subclasses are the same as the json output classes, e.g., the following json:
// "truck": {
// "id": "man",
// becomes
// data.truck.id == "man";
// * - The C# server code is doing conversions here (atleast for TelemetryServer4)
// currentSpeed gear
// TelemetryServer4 already accounts for all types of shifter (& gearbox?) and adds a special readable "Name" field.
// data.truck.gearName;
// Displayed gear
// data.truck.displayedGearName;
// Shifter gear group (false: Lower 1-6 / true: Upper 7-12)
var shifterGroupIndicator = document.getElementById("shifterGroupIndicator");
if (data.shifter.selector == 1) {
data.shifter.shifterGroupReadable = "High";
shifterGroupIndicator.style.color = "#00ff00";
} else {
data.shifter.shifterGroupReadable = "Low";
shifterGroupIndicator.style.color = "#fb8c00";
}
/* Not working
var shifterGroupIndicator = document.getElementById("shifterGroupIndicator");
if (data.shifter.shifterGroup) {
data.shifter.shifterGroupReadable = "High";
shifterGroupIndicator.style.color = "#00ff00";
} else {
data.shifter.shifterGroupReadable = "Low";
shifterGroupIndicator.style.color = "#fb8c00";
}
*/
// Shifter gear range (false: Low 1L / true: High 1H)
/* if (data.shifter.shifterRange) {
data.shifter.shifterRangeReadable = "High";
} else {
data.shifter.shifterRangeReadable = "Low";
} */
// Retarder
// data.truck.retarderBrake;
// Retarder step
// data.truck.retarderBrakeIndicator;
var retarderBrakeIndicator = document.getElementById("retarderBrakeIndicator");
if (data.truck.retarderBrake > 0) {
retarderBrakeIndicator.style.display = "block";
} else {
retarderBrakeIndicator.style.display = "none";
}
// Engine brake readable
// data.truck.motorBrakeOnReadable = data.truck.motorBrakeOn ? "On" : "Off";
// Engine brake enabled indicator
var engineBrakeIndicator = document.getElementById("engineBrakeIndicator");
if (data.truck.motorBrakeOn) {
engineBrakeIndicator.style.display = "block";
} else {
engineBrakeIndicator.style.display = "none";
}
// --- MPH ---
// Truck speed mph rounded (* kmh -> mph)
data.truck.speedRoundedMph = Math.abs(data.truck.speed > 0
? Math.floor(data.truck.speed)
: Math.round(data.truck.speed)) * 0.621371;
// Road speed limit mph rounded (* kmh -> mph)
data.navigation.speedLimitRoundedMph = Math.abs(data.navigation.speedLimit > 0
? Math.floor(data.navigation.speedLimit)
: Math.round(data.navigation.speedLimit)) * 0.621371;
// Cruise control speed mph rounded (* kmh -> mph)
data.truck.cruiseControlSpeedRoundedMph = Math.abs(data.truck.cruiseControlSpeed > 0
? Math.floor(data.truck.cruiseControlSpeed)
: Math.round(data.truck.cruiseControlSpeed)) * 0.621371;
// --- KPH ---
// Truck speed kmh rounded
data.truck.speedRounded = Math.abs(data.truck.speed > 0
? Math.floor(data.truck.speed)
: Math.round(data.truck.speed));
// Road speed limit kmh rounded
data.navigation.speedLimitRounded = Math.abs(data.navigation.speedLimit > 0
? Math.floor(data.navigation.speedLimit)
: Math.round(data.navigation.speedLimit));
// Cruise control speed kmh rounded
data.truck.cruiseControlSpeedRounded = Math.abs(data.truck.cruiseControlSpeed > 0
? Math.floor(data.truck.cruiseControlSpeed)
: Math.round(data.truck.cruiseControlSpeed));
// Dynamic speed limit indicator mph (adds more vertical bars (with gaps) the more you are speeding)
var overspeedLevel1 = document.getElementById("overspeedLevel-1");
var overspeedLevel2 = document.getElementById("overspeedLevel-2");
var overspeedLevel3 = document.getElementById("overspeedLevel-3");
if (data.navigation.speedLimit > 0) {
// Speeding +1mph
if (Math.floor(data.truck.speedRoundedMph) > data.navigation.speedLimitRoundedMph) {
overspeedLevel1.style.display = "block";
overspeedLevel2.style.display = "none";
overspeedLevel3.style.display = "none";
// Speeding +2mph
}
if (Math.floor(data.truck.speedRoundedMph) > data.navigation.speedLimitRoundedMph + 1) {
overspeedLevel1.style.display = "block";
overspeedLevel2.style.display = "block";
overspeedLevel3.style.display = "none";
// Speeding +3mph
}
if (Math.floor(data.truck.speedRoundedMph) > data.navigation.speedLimitRoundedMph + 2) {
overspeedLevel1.style.display = "block";
overspeedLevel2.style.display = "block";
overspeedLevel3.style.display = "block";
// Not speeding
}
if (Math.floor(data.truck.speedRoundedMph) <= data.navigation.speedLimitRoundedMph) {
overspeedLevel1.style.display = "none";
overspeedLevel2.style.display = "none";
overspeedLevel3.style.display = "none";
}
// Not speeding
} else {
overspeedLevel1.style.display = "none";
overspeedLevel2.style.display = "none";
overspeedLevel3.style.display = "none";
}
// Cruise Control enabled indicator
var cruiseControlIndicator = document.getElementById("cruiseControlIndicator");
if (data.truck.cruiseControlOn) {
cruiseControlIndicator.style.display = "block";
} else {
cruiseControlIndicator.style.display = "none";
data.truck.cruiseControlSpeedRounded = "";
data.truck.cruiseControlSpeedRoundedMph = "";
}
// Speed limit sign visibility
var speedLimitSign = document.getElementById("speedLimitSign");
var speedLimitSignMph = document.getElementById("speedLimitSignMph");
if (data.navigation.speedLimit > 0) {
speedLimitSign.style.opacity = 1;
speedLimitSignMph.style.opacity = 1;
} else {
speedLimitSign.style.opacity = 0;
speedLimitSignMph.style.opacity = 0;
}
/*
// ----- jobmonitor2P Implementations -----
// Time scale
if (isNaN(driverWorkTime)) {
if (data.game.gameName === 'ATS') {
if (unit === '') { unit = 'mi'; }
driverWorkTime = 14 * 60; // ATS times - checked
driverSleepTime = 10 * 60;
roadTimeScale = 20;
} else {
if (unit === '') { unit = 'km'; }
driverWorkTime = 11 * 60; // ETS standard times
driverSleepTime = 9 * 60;
//driverWorkTime = 17 * 60; // ETS Brazilian times
//driverSleepTime = 7 * 60; // Yes, we overwork a lot to have a decent income. That's a huge problem.
roadTimeScale = 19;
}
}
// Whether we have a job or not
if (data.job.jobMarket !== '' && !hasJob) {
// Do something when job changed
hasJob = true;
if (data.job.deadlineTime === '0001-01-01T00:00:00Z') {
// jobWoT = true;
}
} else if (data.job.jobMarket === '' && hasJob) {
hasJob = false;
// jobWoT = false;
}
data.hasJob = hasJob;
// Are we in city limits?
data.navigation.cityLimits = data.game.timeScale !== roadTimeScale ? 2 : 0;
// Job viability
remTime = new Date(data.job.remainingTime);
remTime = Math.round((remTime - zDay) / 60000);
var resTime = new Date(data.game.nextRestStopTime);
resTime = Math.round((resTime - zDay) / 60000);
var estTime = 0;
var idleTime = 0;
var overTime = 0;
// At current speed
data.navigation.currentSpeed = '--';
data.navigation.currentSpeedEstimatedTime = '?';
data.navigation.currentSpeedStopsNeeded = '--';
data.navigation.currentSpeedStopsAvailable = '--';
data.navigation.currentSpeedRemainingTime = '?';
data.navigation.currentSpeedLeavingTime = '?';
// Truck is stopped
if (Math.round(data.truck.speed) === 0) {
data.navigation.currentSpeed = 'stopped';
// Truck is moving
} else {
data.navigation.currentSpeed = Math.round(data.truck.speed / 5) * 5;
data.navigation.currentSpeed = data.navigation.currentSpeed < 5 ? 5 : data.navigation.currentSpeed;
// If we haven't arrived already
if (data.navigation.estimatedDistance > 0) {
// ETA
estTime = Math.round(3 * data.navigation.estimatedDistance / (50 * data.navigation.currentSpeed));
data.navigation.currentSpeedEstimatedTime = estTime;
// Overtime that will be required of you to complete this job
overTime = estTime - resTime;
// Available idle time
idleTime = remTime - estTime;
// If we have an active job
if (data.hasJob) {
data.navigation.currentSpeedStopsNeeded = overTime < 0 ? 0 : Math.ceil(overTime / driverWorkTime);
data.navigation.currentSpeedStopsAvailable = idleTime < 0 ? 0 : Math.floor(idleTime / driverSleepTime);
data.navigation.currentSpeedRemainingTime = idleTime - data.navigation.currentSpeedStopsNeeded * driverSleepTime;
} else {
data.navigation.currentSpeedStopsNeeded = '--';
data.navigation.currentSpeedStopsAvailable = '--';
data.navigation.currentSpeedRemainingTime = '--';
}
if (overTime < 0) { overTime += driverWorkTime; }
// Departure time
data.navigation.currentSpeedLeavingTime = (driverWorkTime - overTime % driverWorkTime) % driverWorkTime;
}
data.realEstimatedTime = estTime / roadTimeScale;
}
// Available rest stops
data.restStops = '--';
if (data.truck.speed > data.navigation.minimalSpeed) {
data.restStops = data.navigation.actualStopsNeeded + '/' + data.navigation.actualStopsAvailable;
} else {
data.restStops = data.navigation.minimalStopsNeeded + '/' + data.navigation.minimalStopsAvailable;
}
// Fatigue time
data.jobRemainingTime = data.job.remainingTime;
t = new Date(data.game.nextRestStopTime);
data.driverTimeTillRest = t.getUTCHours() * 60 + t.getUTCMinutes();
data.driverTimeTillRest = isNaN(data.driverTimeTillRest) ? '--' : minsToReadableTime(data.driverTimeTillRest, utils);
data.navigation.estimatedDistance = data.navigation.estimatedDistance > 300 ? Math.round(data.navigation.estimatedDistance / 1000) + ' ' + unit : '--';
// Warning close to deadline
// Adds a red box behind job time remaining text
if (hasJob) {
remTime = new Date(data.job.remainingTime);
remTime = Math.round((remTime - zDay) / 60000);
if (remTime === 0) {
if (data.job.deadlineTime === '0001-01-01T00:00:00Z') {
} else {
remTime = new Date(zDay);
t = (new Date(data.game.time) - new Date(data.job.deadlineTime)) / 60000;
remTime.setUTCMinutes(remTime.getUTCMinutes() + (new Date(data.game.time) - new Date(data.job.deadlineTime)) / 60000);
data.job.remainingTime = JSON.stringify(remTime).replace(/"/g, '');
$('td.PrincipalRemaining').css('animation', '');
$('td.PrincipalRemaining').css('color', '#a00');
message += '<font style="color: #a00;">' + tDeliveryOverdue + '</font>' + lb;
}
} else if (remTime < 60) {
$('td.PrincipalRemaining').css('animation', 'RedAlert 2s ease infinite alternate');
$('td.PrincipalRemaining').css('color', '#a00');
message += '<font style="color: #a00;">' + tDeliveryLast1h + '</font>' + lb;
if (data.navigation.minimalSpeed > 0) {
message += data.navigation.minimalSpeed < 60 ?
'<font style="color: #abdb30;">' + tScheduleOk + '</font>' + lb :
'<font style="color:#ff6b6b;">' + tSpeedUp + '</font>' + lb;
}
} else if (remTime < 120) {
$('td.PrincipalRemaining').css('animation', 'YellowAlert 4s ease infinite');
$('td.PrincipalRemaining').css('color', '#f7ff04');
message += tDeliveryLast2h + lb;
if (data.navigation.minimalSpeed > 0) {
message += data.navigation.minimalSpeed < 60 ?
'<font style="color: #abdb30;">' + tScheduleOk + '</font>' + lb :
'<font style="color:#ff6b6b;">' + tSpeedUp + '</font>' + lb;
}
} else {
$('td.PrincipalRemaining').css('animation', '');
$('td.PrincipalRemaining').css('color', '#f0e6d2');
}
} else {
$('td.PrincipalRemaining').css('animation', '');
$('td.PrincipalRemaining').css('color', '#f0e6d2');
}
// Rest messages - suggestions
if (data.driverTimeTillRest < 60) {
message += '<font style="color: #f00;">' + tYouNeedRest + '</font>' + lb;
} else if (data.driverTimeTillRest < 120) {
message += '<font style="color: #f0e6d2;">' + tGoodTimeRest + '</font>' + lb;
} else if (data.driverTimeTillRest < 300) {
message += '<font style="color: #f0e6d2;">' + tRestIfWish + '</font>' + lb;
} else if (data.driverTimeTillRest < 480) {
message += '<font style="color: #f0e6d2;">' + tDontNeedRest + '</font>' + lb;
} else {
message += '<font style="color: #f0e6d2;">' + tDontNeedRest + '</font>' + lb;
}
// Not enough time to rest
if (data.remainingJobTime < 480) {
message += '<font style="color: #f0e6d2;">' + tDoNotRest + '</font>' + lb;
}
// Rest messages - based on remaining stops - overrides above
// 1h till rest and stops available
if (data.driverTimeTillRest < 60) {
if (data.navigation.minimalStopsAvailable > 0) {
// Rest at next stop
}
if (data.truck.engineRpm !== 0 && data.navigation.minimalStopsAvailable > 0) {
message += '<font style="color: #f00;">' + tRestNextStop + '</font>' + lb;
if (data.navigation.newMinimalSpeed < 60) { message += '<font style="color: #abdb30;">' + tScheduleSeemsGood + '</font>' + lb; }
}
} else if (data.driverTimeTillRest < 120) {
if (data.navigation.minimalStopsAvailable > 0) $('td.PrincipalFatigue').css('animation', 'YellowAlert 2s ease infinite');
$('td.PrincipalFatigue').css('color', '#aa0');
$('g.PrincipalFatigue').css('fill', '#aa0');
if (data.truck.engineRpm !== 0 && data.navigation.minimalStopsAvailable > 0) {
message += tConsiderStop + lb;
if (data.navigation.newMinimalSpeed < 60) { message += '<font style="color: #abdb30;">' + tScheduleSeemsGood + '</font>' + lb; }
}
} else {
$('td.PrincipalFatigue').css('animation', '');
$('td.PrincipalFatigue').css('color', '#f0e6d2');
$('g.PrincipalFatigue').css('fill', '#00a000');
}
data.restMessage = restMessage;
restMessage = '';
*/
return data;
};
Funbit.Ets.Telemetry.Dashboard.prototype.render = function (data, utils) {
// data - telemetry data JSON object AFTER processing from filter function
// utils - an object containing several utility functions (see skin tutorial for more information)
// we don't have anything custom to render in this skin,
// but you may use jQuery here to update DOM or CSS
}