-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
573 lines (526 loc) · 19.1 KB
/
Copy pathindex.html
File metadata and controls
573 lines (526 loc) · 19.1 KB
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover" />
<title>JS-Hack — Browser Roguelike Dungeon Crawler</title>
<meta name="description" content="A browser roguelike dungeon crawler. Descend the dungeon, fight monsters, and die heroically — all in your browser." />
<meta name="keywords" content="roguelike, dungeon crawler, browser game, javascript game, ascii game, turn-based, RPG" />
<meta name="author" content="PJensen" />
<meta property="og:title" content="JS-Hack — Browser Roguelike Dungeon Crawler" />
<meta property="og:description" content="A browser roguelike. Descend the dungeon. Die heroically. Share the shame." />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://pjensen.github.io/JSHack/" />
<meta property="og:image" content="https://raw.githubusercontent.com/PJensen/JSHack/863c6687cd0f5e77e9ee7d47fc14d6b980610469/logo.jpg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="JS-Hack — Browser Roguelike Dungeon Crawler" />
<meta name="twitter:description" content="A browser roguelike. Descend the dungeon. Die heroically. Share the shame." />
<meta name="twitter:image" content="https://raw.githubusercontent.com/PJensen/JSHack/863c6687cd0f5e77e9ee7d47fc14d6b980610469/logo.jpg" />
<!-- Minimal inlined favicon to avoid 404 noise when serving locally -->
<link rel="icon" type="image/svg+xml"
href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%3E%3Crect%20width='100%25'%20height='100%25'%20fill='%230b0d12'/%3E%3Ctext%20x='50%25'%20y='50%25'%20font-family='monospace'%20font-size='12'%20text-anchor='middle'%20dominant-baseline='central'%20fill='%23ffffff'%3E%40%3C/text%3E%3C/svg%3E">
<link rel="manifest" href="./manifest.json">
<meta name="theme-color" content="#0b0e16">
<link rel="apple-touch-icon" href="./icon.svg">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0;
background: #0b0e16;
color: #9fb;
overflow: hidden;
/* hide scrollbars */
overflow-x: hidden;
overflow-y: hidden;
scrollbar-width: none;
/* firefox */
-ms-overflow-style: none;
/* IE/Edge */
touch-action: none;
/* disable browser gestures */
overscroll-behavior: none;
/* disable pull-to-refresh/back-forward swipe */
user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-webkit-touch-callout: none;
-webkit-tap-highlight-color: transparent;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar {
display: none;
}
body {
display: grid;
place-items: center;
/* Inset from notch / home indicator on iPhone X+ */
padding:
env(safe-area-inset-top, 0px)
env(safe-area-inset-right, 0px)
env(safe-area-inset-bottom, 0px)
env(safe-area-inset-left, 0px);
box-sizing: border-box;
}
canvas {
width: 100vw;
height: 100vh;
display: block;
image-rendering: -webkit-optimize-contrast;
image-rendering: pixelated;
image-rendering: crisp-edges;
touch-action: none;
-ms-touch-action: none;
-webkit-user-drag: none;
user-select: none;
outline: none;
/* Prevent double-tap zoom */
-webkit-touch-callout: none;
-webkit-tap-highlight-color: transparent;
/* Prevent context menu on long press */
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
#boot-loader {
position: fixed;
inset: 0;
z-index: 9999;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: radial-gradient(ellipse 120% 80% at 50% 38%, #11182a 0%, #090c14 68%);
opacity: 1;
transition: opacity 180ms ease;
font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color: #d6ecff;
}
#boot-loader[data-hidden="1"] {
opacity: 0;
pointer-events: none;
}
#boot-card {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
padding: 0 24px;
box-sizing: border-box;
}
#boot-brand {
margin: 0 0 24px;
font-size: 20px;
letter-spacing: 0.08em;
text-align: center;
color: #8bd4ff;
text-shadow: 0 0 8px rgba(139, 212, 255, 0.55);
animation: bootBrandPulse 1.2s ease-in-out infinite;
}
#boot-brand .at {
display: inline-block;
font-size: clamp(80px, 28vw, 180px);
line-height: 0.82;
color: #cffff4;
text-shadow:
0 0 20px rgba(170, 255, 220, 0.55),
0 0 60px rgba(139, 212, 255, 0.25);
}
#boot-label {
letter-spacing: 0.06em;
opacity: 0.9;
margin-bottom: 16px;
font-size: 13px;
text-transform: uppercase;
color: #9fc6df;
}
#boot-track {
width: min(600px, 80vw);
height: 4px;
border: none;
border-radius: 2px;
background: rgba(178, 212, 255, 0.12);
overflow: hidden;
}
#boot-fill {
width: 0%;
height: 100%;
border-radius: 2px;
background: linear-gradient(90deg, #4ea8ff 0%, #86e9ff 100%);
transition: width 90ms linear;
box-shadow: 0 0 8px rgba(134, 233, 255, 0.4);
}
#boot-fill.indeterminate {
width: 100%;
background: linear-gradient(90deg, transparent 0%, #4ea8ff 40%, #86e9ff 50%, #4ea8ff 60%, transparent 100%);
background-size: 200% 100%;
animation: bootShimmer 1.4s ease-in-out infinite;
}
@keyframes bootShimmer {
0% { background-position: 100% 0; }
100% { background-position: -100% 0; }
}
#boot-fraction {
margin-top: 8px;
color: #7a9db8;
font-size: 11px;
opacity: 0.7;
}
#boot-file-line {
margin-top: 12px;
width: min(600px, 80vw);
padding: 8px 10px;
border: 1px solid rgba(139, 212, 255, 0.18);
border-radius: 4px;
background: rgba(12, 22, 34, 0.35);
box-sizing: border-box;
font-size: 11px;
line-height: 1.3;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #8fb3cc;
}
#boot-file-line[data-status="requested"] { color: #9fc6df; }
#boot-file-line[data-status="loaded"] { color: #8bd4a8; }
#boot-file-line[data-status="error"] { color: #ff9b9b; }
#boot-install {
display: none;
margin-top: 16px;
padding: 7px 14px;
border: 1px solid rgba(139, 212, 255, 0.35);
border-radius: 4px;
background: rgba(30, 60, 100, 0.25);
color: #8bd4ff;
font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
cursor: pointer;
text-align: center;
letter-spacing: 0.04em;
transition: background 120ms ease;
}
#boot-install:active {
background: rgba(50, 90, 140, 0.5);
}
#boot-loader, #boot-loader * {
touch-action: none;
}
@keyframes bootBrandPulse {
0%, 100% { opacity: 0.7; transform: translateY(0); }
50% { opacity: 1; transform: translateY(-1px); }
}
</style>
</head>
<body>
<canvas id="stage"></canvas>
<div id="boot-loader">
<div id="boot-card">
<div id="boot-brand"><span class="at">@</span></div>
<div id="boot-label">Loading...</div>
<div id="boot-track"><div id="boot-fill" class="indeterminate"></div></div>
<div id="boot-fraction" style="visibility:hidden">0%</div>
<div id="boot-file-line" data-status="requested">[dl] booting...</div>
<div id="boot-hint" style="margin-top:20px;font-size:12px;color:#7aafcf;font-style:italic;text-align:center;opacity:0;transition:opacity 400ms ease;min-height:1.4em;letter-spacing:0.02em;max-width:min(520px,80vw)"></div>
<div id="boot-install"></div>
</div>
</div>
<!-- Entry module: must be a native ES module and use relative imports with extensions. -->
<script>
const bootLoader = document.getElementById('boot-loader');
const bootLabel = document.getElementById('boot-label');
const bootFill = document.getElementById('boot-fill');
const bootFraction = document.getElementById('boot-fraction');
const bootFileLine = document.getElementById('boot-file-line');
const bootInstall = document.getElementById('boot-install');
const saveKey = 'jshack:savegame:v1';
let bootDone = 0;
let bootTotal = 1;
let bootHidden = false;
let deferredInstallPrompt = null;
// PWA install prompt
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredInstallPrompt = e;
if (bootInstall && !bootHidden) {
bootInstall.textContent = '\u2b07 Install to Home Screen';
bootInstall.style.display = 'block';
}
});
// iOS has no beforeinstallprompt — show a manual hint
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.navigator.standalone) {
if (bootInstall) {
bootInstall.textContent = 'Tap Share \u2794 Add to Home Screen';
bootInstall.style.display = 'block';
bootInstall.style.cursor = 'default';
}
}
if (bootInstall) {
bootInstall.addEventListener('click', () => {
if (!deferredInstallPrompt) return;
deferredInstallPrompt.prompt();
deferredInstallPrompt.userChoice.then(() => {
deferredInstallPrompt = null;
bootInstall.style.display = 'none';
});
});
}
window.addEventListener('appinstalled', () => {
deferredInstallPrompt = null;
if (bootInstall) bootInstall.style.display = 'none';
});
function clamp01(v) { return Math.max(0, Math.min(1, v)); }
function hasValidFloorOverride() {
try {
const params = new URLSearchParams(window.location.search || '');
const raw = params.get('floor');
if (raw == null) return false;
const value = Number.parseInt(String(raw), 10);
return Number.isFinite(value) && value >= 0;
} catch { return false; }
}
function hasSavegame() {
try { return !!localStorage.getItem(saveKey); } catch { return false; }
}
function renderBoot() {
const pct = clamp01(bootDone / Math.max(1, bootTotal));
bootFill.style.width = `${(pct * 100).toFixed(2)}%`;
bootFraction.textContent = `${Math.round(pct * 100)}% (${Math.max(0, Math.floor(bootDone))}/${Math.max(1, Math.floor(bootTotal))})`;
}
function toBootFileName(resource) {
try {
const raw = String(resource || '').trim();
if (!raw) return '(unknown file)';
const url = new URL(raw, window.location.href);
const pathname = decodeURIComponent(url.pathname || '/');
const cleanPath = pathname.replace(/^\/+/, '');
const file = cleanPath || url.hostname || raw;
const qs = url.search ? url.search : '';
return `${file}${qs}`;
} catch {
return String(resource || '(unknown file)');
}
}
function addBootFile(resource, status = 'requested') {
if (!bootFileLine) return;
const fileName = toBootFileName(resource);
const marker = status === 'loaded' ? '[ok]' : status === 'error' ? '[err]' : '[dl]';
bootFileLine.dataset.status = status;
bootFileLine.textContent = `${marker} ${fileName}`;
}
(function installBootFileTelemetry() {
if (typeof window.fetch === 'function') {
const nativeFetch = window.fetch.bind(window);
window.fetch = (input, init) => {
const url = (typeof input === 'string')
? input
: (input && typeof input.url === 'string' ? input.url : String(input || ''));
addBootFile(url, 'requested');
return nativeFetch(input, init)
.then((res) => {
addBootFile(url, res && res.ok ? 'loaded' : 'error');
return res;
})
.catch((err) => {
addBootFile(url, 'error');
throw err;
});
};
}
if (typeof PerformanceObserver === 'function') {
try {
const observer = new PerformanceObserver((list) => {
const entries = list.getEntries();
for (const entry of entries) addBootFile(entry.name, 'loaded');
});
observer.observe({ type: 'resource', buffered: true });
} catch {}
}
})();
function applyBootProgress(progress = {}) {
const nextDone = Number(progress.done);
const nextTotal = Number(progress.total);
if (Number.isFinite(nextDone)) bootDone = Math.max(0, nextDone);
if (Number.isFinite(nextTotal)) bootTotal = Math.max(1, nextTotal);
if (typeof progress.label === 'string' && progress.label.length) bootLabel.textContent = progress.label;
renderBoot();
}
let _bootHintTimer = null;
function hideBootLoader() {
if (bootHidden) return;
bootHidden = true;
if (_bootHintTimer) { clearInterval(_bootHintTimer); _bootHintTimer = null; }
bootDone = bootTotal;
renderBoot();
bootLoader.setAttribute('data-hidden', '1');
setTimeout(() => bootLoader.remove(), 240);
}
window.__JSHACK_BOOT_PROGRESS = (progress = {}) => {
if (bootFill.classList.contains('indeterminate')) {
bootFill.classList.remove('indeterminate');
bootFill.style.width = '0%';
bootFraction.style.visibility = '';
}
applyBootProgress(progress);
};
window.__JSHACK_BOOT_DONE = () => {
hideBootLoader();
// Prevent auto-rotation on mobile
if (screen.orientation && screen.orientation.lock) {
screen.orientation.lock('portrait-primary').catch(() => {});
}
};
if (hasSavegame() && !hasValidFloorOverride()) bootLabel.textContent = 'Loading from Save';
renderBoot();
// ---- canonical oracular messages during load ----
{
let hints = [
'The seed determines the entire dungeon layout. Share it to give someone your exact world.',
'Rat corpse: disease. Snake corpse: poison. Floating eye corpse: you forget who you are. There is a pattern.',
'Items can be thrown. Some are more useful in flight than in hand.',
];
let formatHintHtml = null;
const hintEl = document.getElementById('boot-hint');
let hintIdx = Math.floor(Math.random() * hints.length);
function showNextHint() {
hintEl.style.opacity = '0';
setTimeout(() => {
const hint = hints[hintIdx];
if (typeof formatHintHtml === 'function') hintEl.innerHTML = formatHintHtml(hint);
else hintEl.textContent = hint;
hintEl.style.opacity = '1';
hintIdx = (hintIdx + 1) % hints.length;
}, 400);
}
showNextHint();
_bootHintTimer = setInterval(showNextHint, 3500);
import('./src/shared/data/hints.js')
.then((mod) => {
if (Array.isArray(mod.ORACULAR_MESSAGES) && mod.ORACULAR_MESSAGES.length) {
hints = mod.ORACULAR_MESSAGES;
hintIdx = Math.floor(Math.random() * hints.length);
}
if (typeof mod.formatOracularMessageHtml === 'function') {
formatHintHtml = mod.formatOracularMessageHtml;
}
showNextHint();
})
.catch(() => {});
}
async function loadAppVersion() {
try {
const res = await fetch('./VERSION', { cache: 'no-store' });
if (!res.ok) throw new Error('VERSION fetch failed');
const text = (await res.text()).trim();
if (text) return text;
} catch {}
return new Date().getTime().toString(16);
}
function withTimeout(promise, timeoutMs) {
return Promise.race([
promise,
new Promise((resolve) => setTimeout(() => resolve(null), timeoutMs)),
]);
}
const SW_BOOT_RELOAD_KEY = 'jshack:sw-bootstrap-reload';
function waitForServiceWorkerController(timeoutMs = 600) {
if (!('serviceWorker' in navigator)) return Promise.resolve(null);
if (navigator.serviceWorker.controller) return Promise.resolve(navigator.serviceWorker.controller);
return new Promise((resolve) => {
let settled = false;
const finish = (controller) => {
if (settled) return;
settled = true;
clearTimeout(timer);
navigator.serviceWorker.removeEventListener('controllerchange', onControllerChange);
resolve(controller || null);
};
const onControllerChange = () => finish(navigator.serviceWorker.controller);
const timer = setTimeout(() => finish(navigator.serviceWorker.controller), timeoutMs);
navigator.serviceWorker.addEventListener('controllerchange', onControllerChange);
});
}
function postVersionToWorker(worker, version, timeoutMs = 250) {
if (!worker || typeof worker.postMessage !== 'function') return Promise.resolve(false);
return new Promise((resolve) => {
let settled = false;
const channel = new MessageChannel();
const finish = (ok) => {
if (settled) return;
settled = true;
clearTimeout(timer);
channel.port1.onmessage = null;
try { channel.port1.close(); } catch {}
try { channel.port2.close(); } catch {}
resolve(ok);
};
const timer = setTimeout(() => finish(false), timeoutMs);
channel.port1.onmessage = (event) => {
if (event.data?.type === 'set-version:ack' && String(event.data.v) === String(version)) {
finish(true);
}
};
try {
worker.postMessage({ type: 'set-version', v: String(version) }, [channel.port2]);
} catch {
finish(false);
}
});
}
async function prepareServiceWorker(version) {
if (!('serviceWorker' in navigator)) return false;
try {
const reg = await navigator.serviceWorker.register('./sw.js', { updateViaCache: 'none' });
const readyReg = await withTimeout(navigator.serviceWorker.ready, 1500);
const firstWorker = navigator.serviceWorker.controller
|| (readyReg && readyReg.active)
|| reg.active
|| reg.waiting
|| reg.installing
|| null;
if (firstWorker) await postVersionToWorker(firstWorker, version);
const controller = navigator.serviceWorker.controller || await waitForServiceWorkerController(1500);
if (controller && controller !== firstWorker) {
await postVersionToWorker(controller, version);
}
return Boolean(navigator.serviceWorker.controller || controller);
} catch {}
return false;
}
async function bootApp() {
const version = await loadAppVersion();
window.VERSION = version;
const hasController = await prepareServiceWorker(version);
const reloadToken = `pending:${version}`;
if ('serviceWorker' in navigator && !hasController) {
try {
if (sessionStorage.getItem(SW_BOOT_RELOAD_KEY) !== reloadToken) {
sessionStorage.setItem(SW_BOOT_RELOAD_KEY, reloadToken);
location.reload();
return;
}
} catch {}
}
try {
if (sessionStorage.getItem(SW_BOOT_RELOAD_KEY) === reloadToken) {
sessionStorage.removeItem(SW_BOOT_RELOAD_KEY);
}
} catch {}
const script = document.createElement('script');
script.type = 'module';
script.src = `./src/main.js?v=${encodeURIComponent(version)}`;
applyBootProgress({ label: 'Starting game runtime...', done: 0, total: 1 });
addBootFile(script.src, 'requested');
script.addEventListener('load', () => addBootFile(script.src, 'loaded'), { once: true });
script.addEventListener('error', () => addBootFile(script.src, 'error'), { once: true });
document.body.appendChild(script);
}
bootApp();
</script>
</body>
</html>