-
Notifications
You must be signed in to change notification settings - Fork 0
/
shipslog.html
183 lines (168 loc) · 5.87 KB
/
shipslog.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
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>UTILITY - SHIP'S LOG</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--
<link rel="stylesheet" href="/normalize.css" type="text/css">
<link rel="stylesheet" href="/style.css" type="text/css">
-->
<link href="./blueprint.css" rel="stylesheet" />
<link href="./snis-blueprint.css" rel="stylesheet" />
<link href="./snis-basic.css" rel="stylesheet" type="text/css" />
<style>
table.details{ margin-top:2em;}
a.buttonize {
margin-bottom: .5em;
min-width: 12em;
width: 12em;
display: block;
text-align: left;
margin-left: 1em;
}
label {
display: block;
margin-bottom: .5em;
}
ul.log > li > span {
margin-right:2em;
}
#btn_purge {
font-size:.85em;
}
</style>
</head>
<body>
<div id="main" bp="grid 6@md">
<div>
<div class="panel">
<h1 onClick="toggleFullScreen();">SHIP'S LOG</h1>
</div>
<div class="panel">
<label for="logentry" id="logentry_label">STARDATE</label>
<textarea id="logentry" name="logentry" rows="10" cols="60"></textarea>
<button id="btn_record">ENTER RECORD</button>
<p id="tempdisplay">
<ul class="log">
</ul>
</p>
<div class="panel">
<!-- perhaps this should be a partialpage/client-injection (ajax'd into dom), or SSI, "navigation.nonsense.html_fragment" file ...-->
<!-- BEGIN CHUNK -->
<table class="details">
<tr><th>STATION ID</th><th>OPSEC CODE</th></tr>
<tr><td>01</td><td>0307</td></tr>
<tr><td>02</td><td>2600</td></tr>
</table>
<!-- END CHUNK -->
<ul class="button_stack">
<li><button class="secondary" id="btn_purge">⊗ PURGE LOGS ⊗</button></li>
</ul>
</div>
<div><a id="btn_main_menu" class="buttonize" href="menu.html">MAIN MENU</a></div>
</div>
</div>
</body>
<script>//--Utility Function definitions--//
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();
});
}
//TODO: something more robust? like json, or RSS-schema XML doc? update semantics?
function recordLogEntry(tag,text) {
let existing = localStorage["shipslog."+tag];
if (existing) {
existing += "<br/>\n";
} else {
existing =""
}
localStorage["shipslog."+tag] = (existing + text).replace(/(<br\/>\n*)+/gi,"<br/>\n");
document.getElementById("logentry").value = "";
}
function retrieveLogEntries(tag) {
let elDisplay = document.getElementById("tempdisplay");
elDisplay.innerHTML='';
if (tag) {
console.info("single entry retrieveal NOT IMPLEMENTED YET!");
} else {
//TODO: create raw array and fill it with keys, sort and then display
for(var lskey in localStorage) {
if (lskey.match("^shipslog\.")) {
let entry = localStorage[lskey];
console.log(entry);
elDisplay.innerHTML+= "<li><span>"+lskey.replace("shipslog\.","")+"</span> "+entry+"</li>";
}
}
elDisplay.innerHTML='<ul class="log">'+elDisplay.innerHTML+"</ul>";
}
}
//--Wire-up--//
const btn_record = document.getElementById("btn_record");
btn_record.addEventListener("click",(event)=>{
let l_stardate = new Date().toISOString().slice(0, 16).replace("T",".");
//recordLogEntry(stardate,document.getElementById("logentry").value);
recordLogEntry(l_stardate,document.getElementById("logentry").value);
retrieveLogEntries();
//TODO: IFF stardate hasn't advanced (minute change) and/or button pressed, then we are just kind updating, but once a button has been pressed, with content unchanged, clean out the box.
soundACK.play();
});
const btn_purge = document.getElementById("btn_purge");
btn_purge .addEventListener("click",(event)=>{
for(var lskey in localStorage) {
if (lskey.match("^shipslog\.")) {
let entry = localStorage[lskey];
console.log("DELETING FROM LOCAL STORAGE: " + lskey + " : " + entry);
localStorage.removeItem(lskey);
}
}
retrieveLogEntries();
soundNACK.play();
});
</script>
<script src="./howler.js"></script>
<script>//--UI kickstart--//
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);
}
//TODO: define and call a function to list/iterate over all stardate entries and apply to template.
var stardate = new Date().toISOString().slice(0, 16).replace("T",".");
retrieveLogEntries();
document.getElementById("logentry_label").innerText += " " + stardate;
//TODO: timer to update once per minute.
//TODO: wire up a localstorage commit on btn_record click
//possibly, this is "RSS" based internally. which would lead to other possibilities like a master daemonscreen/GM "rss feed subscription feed"
// or maybe in-game, occasional access of another ship's log remotely (salvage/explore derelicts, espionage/"hacking" of active ships
</script>
</html>