-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.html
317 lines (262 loc) · 10.3 KB
/
app.html
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
<!DOCTYPE html>
<html>
<head>
<!-- Insert this line above script imports -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<!-- <style src="./css/app-style.css"></style> -->
<link rel="stylesheet" type="text/css" href="./css/app-style.css">
<script src="./libs/jquery-3.2.1.min.js"></script>
<!-- Insert this line after script imports -->
<script>if (window.module) module = window.module;</script>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body id=bodyTag">
<img id="gameImmage" src="" style=""/>
<!-- All of the Node.js APIs are available in this renderer process. -->
<!-- We are using Node.js <script>document.write(process.versions.node)</script>,
Chromium <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.<br> -->
<div>
<h1 class="product-title">Thrust Master 2020</h1>
</div>
<div class="game-history">
<span>Longest Thrust Sessions:</span><br>
<div id="historicalScoresHolder">
</div>
<button id="resetScoresButton">Reset Scores</button>
</div>
<table class="game-info-table">
<tr>
<td class="game-stats-col">
<div class="game-stats">
<span>Game State:</span><br>
<span>Thrust Duration:</span><br>
<span>Last Thrust Duration:</span><br>
<span>Game Message:</span><br>
</div>
</td>
<td>
<div class="game-stats-data">
<span id="curGameState"></span><br>
<span id="curThrustDuration"></span><br>
<span id="lastThrustDuration"></span><br>
<span id="gameMessage"></span><br>
</div>
</td>
</tr>
</table>
<div class="debugging-info debuggingInfo" style="">
<span>Device SN: </span><span id="DEVICE_SN"></span><br>
<span>Current Time: </span><span id="CURRENT_TIME"></span><br>
<span>Standing?</span> <span id="isStandingOnLadder"></span><br>
<span>Ladder Feet on Ground?</span> <span id="areFeetOnGround"></span><br>
<span>Balancing?</span> <span id="isBalancingOnLadder"></span><br>
<span>Values: FIO4(</span>
<span id="FIO4_VAL"></span>
<span>) FIO5(</span>
<span id="FIO5_VAL"></span>
<span>)</span><br>
<button id="enterFullScreen">Full Screen</button>
<button id="exitFullScreen">Exit Full Screen</button>
<button id="reloadPage">Reload Page</button>
</div>
<!-- AIN0 Value: <span id="AIN0_VAL"></span><br> -->
<script>
const fs = require('fs');
const path = require('path');
var failImages = fs.readdirSync('./funny_gifs/fails').map((file)=>{
return path.join('.','funny_gifs','fails',file);
});
var thrustImages = fs.readdirSync('./funny_gifs/thrusts').map((file)=>{
return path.join('.','funny_gifs','thrusts',file);
});
// var fs = [
// './funny_gifs/duff_man.gif',
// './funny_gifs/jim-carrey.gif',
// './funny_gifs/storm_trooper.gif',
// ];
// var failImages = [
// './funny_gifs/spiderman_fail.webp',
// './funny_gifs/mr_garrison_fail.webp',
// ]
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function getRandomImage(array) {
var index = Math.round(getRandomArbitrary(0, array.length-1));
// console.log('index...', index);
return array[index];
}
function hideImage() {
cachedElements.gameImmage.attr('src','');
}
function displayRandomFail() {
console.log('in displayRandomFail');
// var failImage = getRandomImage(failImages);
var url = getRandomImage(failImages);
cachedElements.gameImmage.attr('src',url);
// cachedElements.bodyTag.css('background-image',url);
console.log('in displayRandomFail',url);
setTimeout(hideImage, 1500);
}
function displayRandomThrust() {
console.log('in displayRandomThrust');
// var thrustImages = getRandomImage(thrustImages);
// $('myOjbect').css('background-image', 'url(' + imageUrl + ')');
var url = getRandomImage(thrustImages) ;
cachedElements.gameImmage.attr('src',url);
// cachedElements.bodyTag.css('background-image',url);
console.log('in displayRandomThrust',url);
setTimeout(hideImage, 1500);
}
var handlebars = require('./libs/handlebars.js');
var scoreHistoryTemplate = handlebars.compile('<ol>{{#each scores}}<li>{{score}}</li>{{/each}}</ol>')
var scoreHistory = [];
var numScoresToHold = 10;
function compareNumbers(a, b) {
return a - b;
}
function addTime(newTime) {
scoreHistory = scoreHistory.sort(compareNumbers);
if(scoreHistory.length < numScoresToHold) {
scoreHistory.push(newTime);
} else {
var addNewTime = false;
scoreHistory.forEach(function(score) {
if(score < newTime) {
addNewTime = true;
}
});
if(addNewTime) {
scoreHistory = scoreHistory.splice(1);
scoreHistory.push(newTime);
}
}
scoreHistory = scoreHistory.sort(compareNumbers);
}
function updateScores() {
scoreHistory = scoreHistory.sort(compareNumbers);
var data = {
scores:[],
}
scoreHistory.reverse().forEach(function(score) {
data.scores.push({score:score});
})
// console.log('Score History', scoreHistory.reverse());
var newHTML = scoreHistoryTemplate(data);
cachedElements.historicalScoresHolder.html(newHTML);
}
var cachedElements = {
sn:$('#DEVICE_SN'),
currentTime: $('#CURRENT_TIME'),
ain0Val: $('#AIN0_VAL'),
isStandingOnLadder: $('#isStandingOnLadder'),
areFeetOnGround: $('#areFeetOnGround'),
isBalancingOnLadder: $('#isBalancingOnLadder'),
curGameState: $('#curGameState'),
FIO4_VAL: $('#FIO4_VAL'),
FIO5_VAL: $('#FIO5_VAL'),
curThrustDuration:$('#curThrustDuration'),
lastThrustDuration:$('#lastThrustDuration'),
gameMessage: $('#gameMessage'),
historicalScoresHolder: $('#historicalScoresHolder'),
resetScoresButton: $('#resetScoresButton'),
enterFullScreen: $('#enterFullScreen'),
exitFullScreen: $('#exitFullScreen'),
reloadPage: $('#reloadPage'),
gameImmage: $('#gameImmage'),
'debuggingInfo': $('.debuggingInfo'),
bodyTag: $('#bodyTag'),
};
cachedElements.resetScoresButton.on('click', function() {
scoreHistory = [];
updateScores();
})
cachedElements.reloadPage.on('click',function() {
location.reload();
});
cachedElements.enterFullScreen.on('click', function() {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
})
cachedElements.exitFullScreen.on('click', function() {
document.webkitExitFullscreen()
})
// You can also require other files to run in this process
var backend_manager = require('./backend_manager.js');
var backendManager = backend_manager.backendManager;
backendManager.on(backend_manager.events.BACKEND_STARTED, () => {
console.log('backend has started');
});
backendManager.on(backend_manager.events.UPDATE_CURRENT_TIME, (time) => {
// console.log('updating time');
cachedElements.currentTime.text(time.toString());
});
var toGUIState = {
'readyForNewUser': 'Ready for next thruster.',
'ready': 'Ready for some thrusting.',
'balancing': 'Keep Thrusting!',
'notReady': 'Thats not how you thrust :(',
}
backendManager.on(backend_manager.events.UPDATE_GAME_STATE, (data) => {
// console.log('updating state',data);
if(data.updateDebugInfoVisibility) {
console.log('Need to update info', data.updateDebugInfoVisibility,data.debugInfoIsVisible);
if(data.debugInfoIsVisible) {
cachedElements.debuggingInfo.hide();
} else {
cachedElements.debuggingInfo.hide();
}
}
console.log('FIO5_VAL',data.FIO4_VAL,data.FIO5_val);
cachedElements.FIO4_VAL.text(data.FIO4_VAL);
cachedElements.FIO5_VAL.text(data.FIO5_VAL);
cachedElements.ain0Val.text(data.AIN0_VAL);
cachedElements.currentTime.text(data.curTime.toString());
cachedElements.sn.text(data.sn);
// Update states
if(data.FIO4) {
cachedElements.areFeetOnGround.text('Yes');
} else {
cachedElements.areFeetOnGround.text('No')
}
if(data.FIO5) {
cachedElements.isStandingOnLadder.text('Yes')
} else {
cachedElements.isStandingOnLadder.text('No')
}
if(data.currentState === 'balancing') {
cachedElements.isBalancingOnLadder.text('Yes')
} else {
cachedElements.isBalancingOnLadder.text('No')
}
cachedElements.curGameState.text(toGUIState[data.currentState])
// Always update the current duration...
cachedElements.curThrustDuration.text(data.duration.toString());
if(data.displayRandomThrust) {
displayRandomThrust()
}
if(data.displayRandomFail) {
displayRandomFail()
}
if(!data.timeReported) {
cachedElements.lastThrustDuration.text(data.duration.toString());
addTime(data.duration);
updateScores();
}
if(!data.messageReported) {
cachedElements.gameMessage.text(data.message);
}
// cachedElements.currentTime.text(time.toString());
});
$(document).ready(function() {
console.log('READY');
backendManager.initialize();
});
$(window).on('beforeunload', function(){
console.log('unloading...');
backendManager.terminate();
});
</script>
</body>
</html>