Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
505 lines (495 loc) · 14.8 KB
/
Copy pathindex.html
File metadata and controls
505 lines (495 loc) · 14.8 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
---
layout: null
title: Games
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#f4f0d8">
<title>Games</title>
<style>
:root {
color-scheme: light;
--ink: #2c2416;
--paper: #f4f0d8;
--card: #fffdf6;
--sun: #ffc857;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
min-height: 100%;
font-family: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", sans-serif;
color: var(--ink);
background: var(--paper);
}
header { padding: 20px 16px 0; }
h1 { margin: 0; font-size: 36px; line-height: 1.1; }
header p { margin: 8px 0 0; font-size: 16px; line-height: 1.3; }
.grid {
display: grid;
grid-template-columns: 1fr;
gap: 16px;
padding: 16px;
}
@media (min-width: 1024px) {
.grid { grid-template-columns: repeat(4, minmax(112px, 1fr)); }
}
a.tile {
display: flex;
flex-direction: column;
justify-content: center;
min-width: 112px;
min-height: 112px;
padding: 16px 18px;
background: var(--card);
color: var(--ink);
text-decoration: none;
border-radius: 18px;
border: 3px solid transparent;
border-top: 8px solid var(--sun);
box-shadow: 0 4px 0 #e2d0b4;
}
a.tile:focus-visible { outline: 3px solid #1d6fd4; outline-offset: 2px; }
a.tile .name { font-size: 28px; line-height: 1.15; font-weight: 800; }
a.tile .line {
display: block;
margin-top: 6px;
font-size: 16px;
line-height: 1.3;
color: #5c4e3a;
font-weight: 700;
}
#gaze {
--p: 0%;
position: fixed; z-index: 60; width: 54px; height: 54px;
margin: 0; border-radius: 50%; pointer-events: none;
transform: translate(-50%, -50%);
background: conic-gradient(#2f8a3e var(--p), rgba(244, 240, 216, 0.45) 0);
box-shadow: 0 0 0 3px rgba(244, 240, 216, 0.95);
}
#eyes {
position: fixed; z-index: 28; pointer-events: none;
right: 12px; bottom: 12px;
background: var(--card); border-radius: 999px; padding: 8px 12px;
font-weight: 800; font-size: 16px;
}
[hidden] { display: none !important; }
</style>
</head>
<body>
<header>
<h1>Games</h1>
<p>Look at a tile, or tap it.</p>
</header>
<div class="grid">
{% assign raw_rows = "" %}
{% assign games = site.static_files | where: "name", "index.html" %}
{% for f in games %}
{% assign path = f.path %}
{% assign lead = path | slice: 0 %}
{% if lead == "/" %}
{% assign path = path | remove_first: "/" %}
{% endif %}
{% assign parts = path | split: "/" %}
{% if parts.size == 2 %}
{% assign folder = parts[0] %}
{% assign first = folder | slice: 0 %}
{% unless folder == "docs" or folder == "" or first == "_" or first == "." %}
{% assign entry = site.data.games[folder] %}
{% if entry.name %}
{% assign label = entry.name %}
{% else %}
{% assign words = folder | replace: "-", " " | split: " " %}
{% assign label = "" %}
{% for word in words %}
{% if word != "" %}
{% assign cap = word | capitalize %}
{% if label == "" %}
{% assign label = cap %}
{% else %}
{% assign label = label | append: " " | append: cap %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% assign line = entry.line | default: "" %}
{% assign sortkey = label | downcase %}
{% assign row = sortkey | append: "||" | append: label | append: "||" | append: folder | append: "||" | append: line %}
{% assign raw_rows = raw_rows | append: "@@" | append: row %}
{% endunless %}
{% endif %}
{% endfor %}
{% assign rows = raw_rows | split: "@@" | sort %}
{% for row in rows %}
{% if row != "" %}
{% assign bits = row | split: "||" %}
<a class="tile" id="{{ bits[2] | escape }}" href="{{ bits[2] | escape }}/">
<span class="name">{{ bits[1] | escape }}</span>
{% if bits[3] != "" %}<span class="line">{{ bits[3] | escape }}</span>{% endif %}
</a>
{% endif %}
{% endfor %}
</div>
<div id="eyes" hidden>Eyes</div>
<div id="gaze" hidden></div>
<script>
(function () {
"use strict";
const GAZE_URL = "ws://127.0.0.1:7081";
const PLAY_DWELL_MS = 650;
const MENU_DWELL_MS = 1300;
const GAZE_FRESH_MS = 500;
const LEAVE_MS = 280;
const eyesEl = document.getElementById("eyes");
const gazeEl = document.getElementById("gaze");
let checking = false;
let suppressReconnect = false;
let trailOn = false;
let clock = 0;
let pointerDown = false;
let armedId = null;
let gazeSock = null;
let gazeTimer = 0;
let gazeBuf = new Uint8Array(0);
let gazeWarp = null;
let gazeHold = null;
let refreshHold = false;
let haveSmooth = false;
let smoothed = null;
let gazePoint = null;
let gazeAt = 0;
let dwellKey = null;
let dwellStart = 0;
let dwellFired = false;
let dwellProgress = 0;
let dwellMs = MENU_DWELL_MS;
let dwellOffAt = 0;
function reducedMotion() {
return !!(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
}
function buttonVisible(btn) {
if (!btn) return false;
let el = btn;
while (el) {
if (el.hidden) return false;
el = el.parentElement;
}
const r = btn.getBoundingClientRect();
return r.width > 0 && r.height > 0;
}
function buttonAt(x, y) {
const el = document.elementFromPoint(x, y);
const btn = el && el.closest ? el.closest("a") : null;
if (!btn || !buttonVisible(btn)) return null;
return btn;
}
function centers() {
const w = window.innerWidth;
const h = window.innerHeight;
const targets = [];
const buttons = document.querySelectorAll("a.tile");
for (let i = 0; i < buttons.length; i++) {
const btn = buttons[i];
if (!buttonVisible(btn)) continue;
const r = btn.getBoundingClientRect();
targets.push({
id: btn.id,
nx: w ? (r.left + r.width / 2) / w : 0,
ny: h ? (r.top + r.height / 2) / h : 0,
x: r.left,
y: r.top,
w: r.width,
h: r.height,
play: btn.getAttribute("data-play") === "true"
});
}
return { targets: targets };
}
function activate(btn) {
if (!btn || !buttonVisible(btn)) return;
const href = btn.getAttribute("href");
if (!href) return;
window.location.assign(btn.href);
}
function clearDwell() {
dwellKey = null;
dwellStart = 0;
dwellFired = false;
dwellProgress = 0;
dwellMs = MENU_DWELL_MS;
dwellOffAt = 0;
trailOn = false;
}
function beginDwell(key, now, ms) {
dwellKey = key;
dwellStart = now;
dwellFired = false;
dwellProgress = 0;
dwellMs = ms;
dwellOffAt = 0;
trailOn = false;
}
function eyesOn() {
return !!(gazeHold || (gazeSock && gazeSock.readyState === 1));
}
function eyesLive(now) {
return !!(gazePoint && eyesOn() && now - gazeAt < GAZE_FRESH_MS);
}
function gazeTarget() {
if (!gazePoint) return null;
const btn = buttonAt(gazePoint.x, gazePoint.y);
if (!btn) return null;
const play = btn.getAttribute("data-play") === "true";
return { id: btn.id, ms: play ? PLAY_DWELL_MS : MENU_DWELL_MS, play: play };
}
function clamp01(p) {
if (p < 0) return 0;
if (p > 1) return 1;
return p;
}
function stepGaze(now) {
const on = eyesOn();
eyesEl.hidden = !on;
const live = eyesLive(now);
if (!live) {
gazeEl.hidden = true;
clearDwell();
gazeEl.style.setProperty("--p", "0%");
return;
}
gazeEl.hidden = false;
gazeEl.style.left = gazePoint.x + "px";
gazeEl.style.top = gazePoint.y + "px";
if (pointerDown) {
clearDwell();
gazeEl.style.setProperty("--p", "0%");
return;
}
const target = gazeTarget();
const key = target ? target.id : null;
const ms = target ? target.ms : MENU_DWELL_MS;
if (dwellKey && key !== dwellKey) {
if (key) beginDwell(key, now, ms);
else clearDwell();
} else if (key && !dwellKey) {
beginDwell(key, now, ms);
}
const onButton = !!(dwellKey && key === dwellKey);
if (!dwellKey) {
dwellProgress = 0;
trailOn = false;
} else if (dwellFired && onButton) {
dwellProgress = 1;
trailOn = false;
} else if (!dwellFired && onButton) {
const elapsed = now - dwellStart;
if (elapsed >= dwellMs) {
dwellFired = true;
dwellProgress = 1;
trailOn = false;
const btn = document.getElementById(dwellKey);
if (btn && buttonVisible(btn)) activate(btn);
} else {
const p = clamp01(dwellMs > 0 ? elapsed / dwellMs : 0);
dwellProgress = p;
const btn = document.getElementById(dwellKey);
trailOn = p > 0 && !!(btn && btn.getAttribute("data-play") === "true") && !reducedMotion();
}
} else {
dwellProgress = 0;
trailOn = false;
}
gazeEl.style.setProperty("--p", Math.round(dwellProgress * 100) + "%");
}
function step(now) {
clock = now;
if (gazeHold) {
if (!haveSmooth || checking) {
smoothed = { x: gazeHold.x, y: gazeHold.y };
haveSmooth = true;
} else {
smoothed = {
x: smoothed.x + (gazeHold.x - smoothed.x) * 0.45,
y: smoothed.y + (gazeHold.y - smoothed.y) * 0.45
};
}
gazePoint = smoothed;
if (refreshHold) gazeAt = now;
}
stepGaze(now);
}
function look(nx, ny) {
gazeHold = { x: nx * window.innerWidth, y: ny * window.innerHeight };
refreshHold = true;
if (checking || !haveSmooth) {
smoothed = { x: gazeHold.x, y: gazeHold.y };
haveSmooth = true;
gazePoint = smoothed;
gazeAt = clock;
}
}
function releaseLook() {
gazeHold = null;
refreshHold = false;
haveSmooth = false;
smoothed = null;
gazePoint = null;
gazeAt = 0;
clearDwell();
gazeEl.hidden = true;
eyesEl.hidden = true;
gazeEl.style.setProperty("--p", "0%");
}
function hold(nx, ny) {
if (pointerDown) return;
pointerDown = true;
clearDwell();
const btn = buttonAt(nx * window.innerWidth, ny * window.innerHeight);
armedId = btn ? btn.id : null;
}
function release() {
pointerDown = false;
armedId = null;
}
function tap(nx, ny) {
if (pointerDown) return;
const btn = buttonAt(nx * window.innerWidth, ny * window.innerHeight);
if (btn) activate(btn);
}
function dwell() {
return dwellProgress;
}
function eyes() {
return { on: eyesOn(), live: eyesLive(clock) };
}
function scheduleGaze() {
if (gazeTimer || suppressReconnect || checking) return;
gazeTimer = setTimeout(function () {
gazeTimer = 0;
connectGaze();
}, 2000);
}
function connectGaze() {
if (suppressReconnect || checking) return;
if (location.protocol === "https:") return;
if (gazeSock && gazeSock.readyState <= 1) return;
let sock;
try { sock = new WebSocket(GAZE_URL); }
catch (err) { scheduleGaze(); return; }
gazeSock = sock;
sock.binaryType = "arraybuffer";
sock.onopen = function () {
if (checking) { sock.close(); return; }
gazeBuf = new Uint8Array(0);
sock.send(new Uint8Array([1, 4, 0, 0, 0, 0, 5, 0, 0]));
};
sock.onmessage = function (ev) {
if (ev.data instanceof ArrayBuffer) takeGaze(new Uint8Array(ev.data));
};
sock.onerror = function () {};
sock.onclose = function () {
if (gazeSock === sock) gazeSock = null;
if (!gazeHold && !checking) { gazePoint = null; gazeAt = 0; }
if (!suppressReconnect && !checking) scheduleGaze();
};
}
function concatBytes(a, b) {
const out = new Uint8Array(a.length + b.length);
out.set(a, 0);
out.set(b, a.length);
return out;
}
function takeGaze(chunk) {
if (checking || gazeHold) return;
const buf = gazeBuf.length ? concatBytes(gazeBuf, chunk) : chunk;
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
let pos = 0;
while (pos + 5 <= buf.length) {
const len = view.getUint32(pos + 1, true);
if (len > 1048576) { gazeBuf = new Uint8Array(0); return; }
if (pos + 5 + len > buf.length) break;
const payload = new DataView(buf.buffer, buf.byteOffset + pos + 5, len);
if (buf[pos] === 1 && len >= 56) applyGaze(payload);
else if (buf[pos] === 4) applyWarpMessage(payload);
pos += 5 + len;
}
gazeBuf = pos === 0 ? buf : buf.slice(pos);
}
function pushRaw(raw) {
if (!haveSmooth) {
smoothed = { x: raw.x, y: raw.y };
haveSmooth = true;
} else {
smoothed = {
x: smoothed.x + (raw.x - smoothed.x) * 0.45,
y: smoothed.y + (raw.y - smoothed.y) * 0.45
};
}
gazePoint = smoothed;
if (clock) gazeAt = clock;
else if (!checking) gazeAt = performance.now();
}
function applyGaze(view) {
const mask = view.getUint32(0, true);
if ((mask & 64) === 0) return;
if (mask & 12) {
const left = (mask & 4) ? view.getUint32(8, true) : 4;
const right = (mask & 8) ? view.getUint32(12, true) : 4;
if (left !== 0 && right !== 0) return;
}
const x = view.getFloat64(40, true);
const y = view.getFloat64(48, true);
if (!Number.isFinite(x) || !Number.isFinite(y) || x < 0 || y < 0) return;
const point = warpPoint(x, y);
pushRaw({ x: point.x * window.innerWidth, y: point.y * window.innerHeight });
}
function applyWarpMessage(view) {
if (view.byteLength === 0) { gazeWarp = null; return; }
if (view.byteLength < 72) return;
const next = new Float64Array(9);
for (let i = 0; i < 9; i++) next[i] = view.getFloat64(i * 8, true);
for (let i = 0; i < 9; i++) if (!Number.isFinite(next[i])) return;
gazeWarp = next;
}
function warpPoint(x, y) {
const hm = gazeWarp;
if (!hm) return { x: x, y: y };
const w = hm[6] * x + hm[7] * y + hm[8];
if (Math.abs(w) < 1e-9) return { x: x, y: y };
return {
x: (hm[0] * x + hm[1] * y + hm[2]) / w,
y: (hm[3] * x + hm[4] * y + hm[5]) / w
};
}
document.addEventListener("pointerdown", function (ev) {
if (pointerDown) return;
if (ev.pointerType === "mouse" && ev.button !== 0) return;
pointerDown = true;
clearDwell();
const btn = buttonAt(ev.clientX, ev.clientY);
armedId = btn ? btn.id : null;
});
document.addEventListener("pointerup", function (ev) {
const btn = buttonAt(ev.clientX, ev.clientY);
if (!btn || btn.id !== armedId) armedId = null;
pointerDown = false;
});
document.addEventListener("click", function (ev) {
const btn = ev.target && ev.target.closest ? ev.target.closest("a") : null;
if (!btn || btn.id !== armedId) return;
armedId = null;
});
function frame(now) {
if (checking) return;
step(now);
if (!checking) requestAnimationFrame(frame);
}
connectGaze();
requestAnimationFrame(frame);
})();
</script>
</body>
</html>