-
Notifications
You must be signed in to change notification settings - Fork 0
/
navigation.html
157 lines (147 loc) · 4.99 KB
/
navigation.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
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>NAVIGATION</title>
<meta name="viewport" content="width=device-width">
<link rel="manifest" href="manifest.json">
<link href="./snis-basic.css" rel="stylesheet" type="text/css" />
<link href="./snis-grid.css" rel="stylesheet" type="text/css" />
<link href="./snis-radar.css" rel="stylesheet" type="text/css" />
<style>
div.radar.righteous {
left-margin: auto;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
}
#btn_docking_magnets{ margin-bottom:.5em;}
</style>
</head>
<body>
<div class="panel">
<h1 onClick="toggleFullScreen();">NAVIGATION</h1>
</div>
<div id="main" class="panelsection">
<div class="panel" >
<button id="btn_rudder_port" data-cmd="YAW PORT">YAW <br/>◂ PORT</button>
</div>
<div class="panel" >
<div bp=" text-center">
<button id="btn_elevator_up" data-cmd="ELEVATOR UP">ELEVATOR ▴ UP</button>
<button id="btn_elevator_down" data-cmd="ELEVATOR DOWN">ELEVATOR ▾ DOWN</button>
</div>
</div>
<div class="panel righteous" >
<button id="btn_rudder_starboard" data-cmd="YAW STARBOARD">YAW STARBOARD ▸</button>
</div>
<div>
<table class="fauxmutator">
<thead>
<tr><th>Inertial Comp.</th><th>Aspect</th><th>Delta</th></tr>
</thead>
<tbody>
<tr><td>01</td><td>03</td><td>05</td></tr>
<tr><td>02</td><td>04</td><td>06</td></tr>
<tr><td>03</td><td>05</td><td>07</td></tr>
</tbody>
</table>
</div>
<div>
<fieldset name="throttle">
<legend>THROTTLE</legend>
<button id="btn_throttle_up" data-cmd="THROTTLE UP">THROTTLE UP</button>
<button id="btn_reverse_thrust" class="secondary" data-cmd="REVERSE THRUST">REVERSE ◬ THRUST</button>
<button id="btn_throttle_down" data-cmd="THROTTLE DOWN">THROTTLE DOWN</button>
</fieldset>
</div>
<div>
<div><button id="btn_docking_magnets" data-cmd="DOCKING MAGNETS" class="action">DOCKING MAGNETS</button></div>
<div> STATUS: NOMINAL </div>
<div class="radar righteous" >
<div class="waveguide"></div>
</div>
</div>
</div>
<!-- pushing screen too big?
<div class="panelsection">
<div><a id="btn_main_menu" class="buttonize" href="menu.html">MAIN MENU</a></div>
<div> </div>
<div class="radar righteous" >
<div class="waveguide"></div>
</div>
</div>
-->
</body>
<script>
function toggleFullScreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}
function command(text) {
var data = { command: text };
//sanitize data?
console.info("Transmitting command: "+text);
//fetch('/SHIP/STATIONNAME/TARGETNOUN/VERB?parametername=value', {
fetch("/SHIP/NAVIGATION/" + text.toUpperCase().replace(" ","/"), {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
soundACK.play();
})
.catch((error) => {
console.error('Error:', error);
soundNACK.play();
});
}
document.addEventListener('click', function (event) {
// Don't follow the link (unless back to menu...)
if (event.target.id == "btn_main_menu") {
console.log("Exception: main menu button should navigate as normal...");
} else {
event.preventDefault();
if (event.target.dataset.cmd) {
console.info("FYI: this element had a cmd attribute: " + event.target.dataset.cmd);
//todo: mild validation (alphanumeric+space?)
command(event.target.dataset.cmd);
} else {
console.error("ERROR: element did not contain recognized command data. Add data-cmd attribute in correct format to the control element tag.");
}
}
// Log the clicked element in the console
console.log(event.target.tagName);
}, false);
</script>
<script src="./howler.js"></script>
<script>
var soundACK = new Howl({ src: ['./sounds/tactinput_acknowledge.ogg', './sounds/tactinput_acknowledge.m4a', './sounds/tactinput_acknowledge.webm'] });
var soundNACK = new Howl({ src: ['./sounds/tactinput_neg_acknowledge.ogg', './sounds/tactinput_neg_acknowledge.m4a', './sounds/tactinput_neg_acknowledge.webm'] });
try {
toggleFullScreen();
} catch (error) {
console.warn("just warning, kinda expected this..." + error);
}
function faux_mutation() {
var row = Math.floor(Math.random() * 2) + 2;
var col = Math.floor(Math.random() * 3) + 1;
var dd = document.querySelector("table.fauxmutator > tbody > tr:nth-child("+row+") > td:nth-child("+col+")");
dd.innerText = (Math.floor(dd.innerText) * Math.floor(Math.random() * 99) ) % 999 + (Math.floor(Math.random() * 100)/10);
//quasi-recursion
var tmr = setTimeout(function() {
faux_mutation();
},1000*Math.floor(Math.random() * 12));
}
faux_mutation();
</script>
</html>