Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
733 lines (672 loc) · 27.3 KB
/
Copy pathscript.js
File metadata and controls
733 lines (672 loc) · 27.3 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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/**
* StickTalk AI Printer Prototype
* Logic: State Machine + Input Handler + Simple DOM Renderer
*/
// --- Global State ---
const State = {
currentScreen: null,
history: [],
data: {
wifiList: [
{ ssid: "Home_WiFi_5G", signal: 3, locked: true },
{ ssid: "Guest_Network", signal: 2, locked: true },
{ ssid: "Neighbour_A", signal: 1, locked: true }
],
gallery: [
{ id: 1, prompt: "可爱的小猫吃披萨", date: "2023-10-01" },
{ id: 2, prompt: "火箭发射升空", date: "2023-10-02" },
{ id: 3, prompt: "恐龙踢足球", date: "2023-10-05" }
],
wifiConnected: false,
batteryLevel: 80,
},
// Focus System
focusList: [], // Array of DOM IDs or Elements
focusIndex: 0
};
// --- DOM Elements ---
const elContent = document.getElementById('layer-content');
const elOverlay = document.getElementById('layer-overlay');
const elStatus = {
wifi: document.getElementById('status-wifi'),
paper: document.getElementById('status-paper'),
temp: document.getElementById('status-temp'),
battery: document.getElementById('status-battery')
};
// --- Utilities ---
function renderIcon(name) {
return Icons[name] || '';
}
function updateStatusBar() {
elStatus.wifi.innerHTML = State.data.wifiConnected ? renderIcon('wifi') : renderIcon('wifi_off');
elStatus.paper.innerHTML = renderIcon('paper');
elStatus.temp.innerHTML = '';
elStatus.battery.innerHTML = renderIcon('battery_full');
}
function setFocus(index) {
// Remove focus from all
State.focusList.forEach(el => el.classList.remove('focus-active'));
// Validate index
if (index < 0) index = State.focusList.length - 1;
if (index >= State.focusList.length) index = 0;
State.focusIndex = index;
const target = State.focusList[State.focusIndex];
if (target) {
target.classList.add('focus-active');
// Scroll into view if needed
target.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
// --- Screen Renderers ---
const Screens = {
// 01 Splash
SPLASH: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%;">
<h1>贴纸魔法机</h1>
<div class="anim-float">${Assistant.wave()}</div>
<div style="margin-top:20px; font-size:24px;">● ● ●</div>
</div>
`;
setTimeout(() => Router.go('BOOTSTRAP'), 2000);
}
},
// 02 Bootstrap
BOOTSTRAP: {
render: () => {
elContent.innerHTML = `
<div style="padding:40px;">
<h2>我在准备中…</h2>
<div style="margin-top:20px; display:flex; flex-direction:column; gap:15px;">
<div class="hand-drawn-box" style="display:flex; justify-content:space-between;">
<span>麦克风</span> <span>${renderIcon('check')}</span>
</div>
<div class="hand-drawn-box" style="display:flex; justify-content:space-between;">
<span>打印机</span> <span>...</span>
</div>
</div>
</div>
`;
setTimeout(() => {
Router.go('HOME');
}, 1500);
}
},
// 03 Home
HOME: {
render: () => {
elContent.innerHTML = `
<div style="text-align:center; padding-top:40px; height:100%; display:flex; flex-direction:column;">
<h2 style="margin-bottom:5px;">按住大按键</h2>
<p>说出你想要的贴纸!</p>
<div style="flex:1; display:flex; align-items:center; justify-content:center;">
<div style="width:120px; height:120px; border-radius:50%; border:4px solid black; display:flex; align-items:center; justify-content:center;">
<span style="font-size:40px;">🎙️</span>
</div>
</div>
<div style="display:flex; gap:20px; padding:20px; justify-content:center;">
<div id="nav-gallery" class="hand-drawn-box">作品库</div>
<div id="nav-settings" class="hand-drawn-box">设置</div>
</div>
</div>
`;
State.focusList = [
document.getElementById('nav-gallery'),
document.getElementById('nav-settings')
];
setFocus(0);
},
onEnter: () => {
if (State.focusIndex === 0) Router.go('GALLERY_LIST');
if (State.focusIndex === 1) Router.go('SETTINGS');
},
},
// 04 Listening
LISTENING: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; padding-top:60px;">
<h2>我在听~</h2>
<div style="margin:40px;">${Assistant.listening()}</div>
<div style="font-size:30px; font-weight:bold;">00:03</div>
<p style="margin-top:20px; color:#666;">松开就开始画</p>
</div>
`;
}
},
// 11 Gallery List
GALLERY_LIST: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px;">
<h2 style="margin-bottom:20px;">作品库</h2>
<div id="gallery-grid" style="display:grid; grid-template-columns:1fr; gap:10px; max-height:350px; overflow-y:auto;">
${State.data.gallery.map((item, idx) => `
<div id="gal-item-${idx}" class="hand-drawn-box" style="display:flex; gap:10px; align-items:center;">
<div style="width:50px; height:50px; background:#eee; border:2px solid black;"></div>
<div>
<div style="font-weight:bold;">${item.prompt}</div>
<div style="font-size:12px; color:#666;">#${item.id}</div>
</div>
</div>
`).join('')}
</div>
<div style="text-align:center; font-size:14px; margin-top:10px;">长按返回</div>
</div>
`;
State.focusList = State.data.gallery.map((_, idx) => document.getElementById(`gal-item-${idx}`));
setFocus(0);
},
onEnter: () => {
Router.go('GALLERY_ITEM');
}
},
// 13 Settings
SETTINGS: {
render: () => {
const items = ['Wi-Fi配网', '音量', '打印浓度', '关于设备'];
elContent.innerHTML = `
<div style="padding:20px;">
<h2>设置</h2>
<div style="display:flex; flex-direction:column; gap:10px;">
${items.map((it, idx) => `
<div id="set-item-${idx}" class="hand-drawn-box" style="padding:15px; font-size:20px;">
${it}
</div>
`).join('')}
</div>
</div>
`;
State.focusList = items.map((_, idx) => document.getElementById(`set-item-${idx}`));
setFocus(0);
},
onEnter: () => {
if (State.focusIndex === 0) Router.go('WIFI_SCAN');
if (State.focusIndex === 3) Router.go('ABOUT');
}
},
// 14 Wifi Scan
WIFI_SCAN: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%;">
<h2>找网络中…</h2>
<div class="anim-spin" style="font-size:40px;">↻</div>
<div style="margin-top:20px;">${Assistant.idle()}</div>
</div>
`;
setTimeout(() => Router.go('WIFI_LIST'), 1500);
}
},
// 15 Wifi List
WIFI_LIST: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px;">
<h2>选择Wi-Fi</h2>
<div style="display:flex; flex-direction:column; gap:10px;">
${State.data.wifiList.map((net, idx) => `
<div id="wifi-${idx}" class="hand-drawn-box" style="display:flex; justify-content:space-between;">
<span>${net.ssid}</span>
<span>🔒 ${net.signal}</span>
</div>
`).join('')}
</div>
</div>
`;
State.focusList = State.data.wifiList.map((_, idx) => document.getElementById(`wifi-${idx}`));
setFocus(0);
},
onEnter: () => {
Router.go('WIFI_PASSWORD');
}
},
// 16 Wifi Password
WIFI_PASSWORD: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; text-align:center;">
<h2>输入密码</h2>
<div class="hand-drawn-box" style="margin:20px 0; padding:15px; font-size:24px; letter-spacing:5px;">
••••••
</div>
<div class="hand-drawn-box" style="display:inline-block; padding:10px 20px;">ABC / 123</div>
<div style="margin-top:20px; font-size:14px;">旋转选字符,按下输入</div>
</div>
`;
State.focusList = [];
},
onEnter: () => {
Router.go('WIFI_CONNECTING');
}
},
// 17A Connecting
WIFI_CONNECTING: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%;">
<h2>正在连接…</h2>
${Assistant.thinking()}
</div>
`;
setTimeout(() => {
State.data.wifiConnected = true;
updateStatusBar();
Router.go('WIFI_SUCCESS');
}, 2000);
}
},
// 17B Success
WIFI_SUCCESS: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%;">
<h2>连上啦!</h2>
<div style="font-size:60px;">${renderIcon('check')}</div>
${Assistant.happy()}
<div class="hand-drawn-box" style="margin-top:20px;" id="btn-done">完成</div>
</div>
`;
State.focusList = [document.getElementById('btn-done')];
setFocus(0);
},
onEnter: () => {
Router.go('SETTINGS');
}
},
// 05 Processing
PROCESSING: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; padding-top:60px;">
<h2>我听懂啦!</h2>
<p>把你的话变成提示词中…</p>
<div class="anim-spin" style="margin:30px; font-size:50px;">✏️</div>
<div style="font-size:14px; margin-top:20px;">思考中...</div>
${Assistant.thinking()}
</div>
`;
setTimeout(() => Router.go('GENERATING'), 2000);
}
},
// 06 Generating
GENERATING: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; display:flex; flex-direction:column; height:100%;">
<div class="hand-drawn-box" style="flex:1; margin-bottom:10px;">
<h3>你的提示词:</h3>
<p style="font-size:20px;">"可爱的小猫吃披萨"</p>
</div>
<div style="padding:10px; text-align:center;">
<div>魔法画画中…</div>
<div style="width:100%; height:10px; border:2px solid black; margin-top:5px; border-radius:5px;">
<div class="progress-bar-fill" style="width:0%" id="gen-progress"></div>
</div>
</div>
<div style="margin-top:10px; text-align:center;">${Assistant.idle()}</div>
</div>
`;
let p = 0;
const bar = document.getElementById('gen-progress');
if (window.genInterval) clearInterval(window.genInterval);
window.genInterval = setInterval(() => {
p += 5;
if (bar) bar.style.width = p + '%';
if (p >= 100) {
clearInterval(window.genInterval);
Router.go('PREVIEW');
}
}, 100);
}
},
// 07 Gen Fail
GEN_FAIL: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%;">
<h2>哎呀,没画出来…</h2>
<p>网络不稳定</p>
<div style="margin:20px;">${Assistant.idle()}</div>
<div style="display:flex; gap:10px;">
<button id="btn-retry" class="hand-drawn-box">重试</button>
<button id="btn-home" class="hand-drawn-box">回主页</button>
</div>
</div>
`;
State.focusList = [document.getElementById('btn-retry'), document.getElementById('btn-home')];
setFocus(0);
},
onEnter: () => {
if (State.focusIndex === 0) Router.go('PROCESSING');
else Router.go('HOME');
}
},
// 08 Preview
PREVIEW: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; display:flex; flex-direction:column; align-items:center;">
<h2>看!你的贴纸~</h2>
<div class="hand-drawn-box" style="width:250px; height:250px; display:flex; align-items:center; justify-content:center; margin-bottom:10px;">
<span style="font-size:80px;">🖼️</span>
</div>
<p>马上打印啦!</p>
<div style="font-size:12px;">3... 2... 1...</div>
</div>
`;
setTimeout(() => Router.go('PRINTING'), 3000);
}
},
// 09 Printing
PRINTING: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; text-align:center;">
<h2>正在打印…</h2>
<div style="height:200px; display:flex; align-items:flex-start; justify-content:center; padding-top:20px;">
<div class="hand-drawn-box" style="width:220px; height:auto; border-bottom:none; position:relative;">
<div class="paper-printing">
<span style="font-size:50px; display:block; margin-top:20px;">🖼️</span>
</div>
</div>
</div>
<div style="width:80%; margin:20px auto; height:10px; border:2px solid black;">
<div class="progress-bar-fill" style="width:50%"></div>
</div>
</div>
`;
setTimeout(() => Router.go('DONE'), 3500);
}
},
// 10 Done
DONE: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%;">
<h2>完成!拿走贴纸~</h2>
<p></p>
${Assistant.happy()}
<div style="display:flex; gap:10px; margin-top:30px;">
<div id="btn-new" class="hand-drawn-box">再来一张</div>
<div id="btn-view" class="hand-drawn-box">查看作品</div>
<div id="btn-home-d" class="hand-drawn-box">回主页</div>
</div>
</div>
`;
State.focusList = [
document.getElementById('btn-new'),
document.getElementById('btn-view'),
document.getElementById('btn-home-d')
];
setFocus(0);
},
onEnter: () => {
if (State.focusIndex === 0) Router.go('HOME');
if (State.focusIndex === 1) Router.go('GALLERY_ITEM');
if (State.focusIndex === 2) Router.go('HOME');
}
},
// 12 Gallery Item
GALLERY_ITEM: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; display:flex; flex-direction:column; height:100%;">
<div class="hand-drawn-box" style="flex:1; display:flex; align-items:center; justify-content:center;">
<span style="font-size:30px;">🖼️ 大图</span>
</div>
<div class="hand-drawn-box" style="margin-top:10px; padding:10px;">
"可爱的小猫吃披萨"
</div>
<div style="display:flex; gap:10px; margin-top:10px;">
<div id="btn-reprint" class="hand-drawn-box">再打印</div>
<div id="btn-back-list" class="hand-drawn-box">返回</div>
</div>
</div>
`;
State.focusList = [document.getElementById('btn-reprint'), document.getElementById('btn-back-list')];
setFocus(0);
},
onEnter: () => {
if (State.focusIndex === 0) Router.go('PRINTING');
else Router.go('GALLERY_LIST');
}
},
// 18 Paper Tutorial
PAPER_TUTORIAL: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; text-align:center;">
<h2>装纸小教程</h2>
<div class="hand-drawn-box" style="height:250px; margin:20px 0; display:flex; align-items:center; justify-content:center;">
第1步:打开盖子
</div>
<div id="btn-ok-tut" class="hand-drawn-box" style="display:inline-block; padding:10px 30px;">我知道了</div>
</div>
`;
State.focusList = [document.getElementById('btn-ok-tut')];
setFocus(0);
},
onEnter: () => Router.go('SETTINGS')
},
// 19A Errors: Paper
ERR_PAPER: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%; background:#ffeeee;">
<div style="font-size:60px;">🧻</div>
<h2>没纸啦!</h2>
<p>装上纸再试试</p>
${Assistant.idle()}
<div id="btn-err-ok" class="hand-drawn-box" style="margin-top:20px;">我知道了</div>
</div>
`;
State.focusList = [document.getElementById('btn-err-ok')];
setFocus(0);
},
onEnter: () => Router.go('HOME')
},
// 19B Open Cover
ERR_COVER: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%; background:#ffeeee;">
<h2>盖子没关好</h2>
<p>把盖子按紧</p>
${Assistant.idle()}
<div id="btn-err-cover" class="hand-drawn-box" style="margin-top:20px;">我知道了</div>
</div>
`;
State.focusList = [document.getElementById('btn-err-cover')];
setFocus(0);
},
onEnter: () => Router.go('HOME')
},
// 19C Jam
ERR_JAM: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%; background:#ffeeee;">
<h2>卡纸了</h2>
${Assistant.thinking()}
<div id="btn-err-jam" class="hand-drawn-box" style="margin-top:20px;">我知道了</div>
</div>
`;
State.focusList = [document.getElementById('btn-err-jam')];
setFocus(0);
},
onEnter: () => Router.go('HOME')
},
// 19D Overheat
ERR_HEAT: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%; background:#ffeeee;">
<h2>有点烫,冷却中…</h2>
<div style="font-size:40px;">🌡️</div>
<p>请稍等</p>
${Assistant.idle()}
</div>
`;
State.focusList = [];
setTimeout(() => Router.go('HOME'), 3000);
}
},
// 20A Low Battery
BAT_LOW: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%;">
<h2>电量低啦,快充电~</h2>
<div style="font-size:60px;">🪫</div>
<p>插上充电线</p>
${Assistant.thinking()}
<div id="btn-bat" class="hand-drawn-box" style="margin-top:20px;">我知道了</div>
</div>
`;
State.focusList = [document.getElementById('btn-bat')];
setFocus(0);
},
onEnter: () => Router.go('HOME')
},
// 20B Charging
BAT_CHARGING: {
render: () => {
elContent.innerHTML = `
<div style="display:flex; flex-direction:column; align-items:center; justify-content:center; height:100%; background:#e0ffe0;">
<h2>充电中…</h2>
<div class="anim-float" style="font-size:60px;">⚡</div>
${Assistant.happy()}
</div>
`;
State.focusList = [];
}
},
// 21 Device Info
ABOUT: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px;">
<h2>关于设备</h2>
<div class="hand-drawn-box" style="padding:20px; line-height:2;">
<p><strong>版本号:</strong> 1.0.0</p>
<p><strong>序列号:</strong> ST-2026-001</p>
<p><strong>存储空间:</strong> 80% 空闲</p>
</div>
<div style="text-align:center; margin-top:20px; font-size:14px;">长按返回</div>
</div>
`;
State.focusList = [];
}
},
// 22 Factory Reset
RESET: {
render: () => {
elContent.innerHTML = `
<div style="padding:20px; text-align:center; display:flex; flex-direction:column; justify-content:center; height:100%;">
<h2>真的要清空吗?</h2>
<p>会删除作品库和设置</p>
${Assistant.thinking()}
<div style="display:flex; gap:20px; justify-content:center; margin-top:20px;">
<div id="btn-cancel" class="hand-drawn-box">取消</div>
<div id="btn-confirm" class="hand-drawn-box" style="border-width:5px;">确认清空</div>
</div>
</div>
`;
State.focusList = [document.getElementById('btn-cancel'), document.getElementById('btn-confirm')];
setFocus(0);
},
onEnter: () => {
if (State.focusIndex === 1) {
alert('正在重置...');
Router.go('SPLASH');
} else {
Router.go('SETTINGS');
}
}
}
};
// --- Router ---
const Router = {
go: (screenName) => {
if (!Screens[screenName]) {
console.error("Screen not found:", screenName);
return;
}
// Save history if needed (skipping for simple prototype flow logic)
if (State.currentScreen && screenName !== 'SPLASH' && screenName !== 'BOOTSTRAP') {
State.history.push(State.currentScreen);
}
State.currentScreen = screenName;
Screens[screenName].render();
updateStatusBar();
renderDebugButtons(); // Update highlight
},
back: () => {
if (State.history.length > 0) {
const prev = State.history.pop();
// Avoid loops or specific logic
Router.go(prev);
} else {
Router.go('HOME');
}
}
};
// --- Input Handling ---
function handleInput(key) {
const current = Screens[State.currentScreen];
// Global Back Handler
if (key === 'Escape' || key === 'Backspace') {
Router.back();
return;
}
// Pass to screen specific handler if exists?
// Or use generic focus logic
if (key === 'ArrowUp' || key === 'ArrowLeft') {
// Prev Focus
setFocus(State.focusIndex - 1);
} else if (key === 'ArrowDown' || key === 'ArrowRight') {
// Next Focus
setFocus(State.focusIndex + 1);
} else if (key === 'Enter') {
// Trigger Click or Action
if (current && current.onEnter) {
current.onEnter();
}
}
// Special: Spacebar for PTT at Home
if (key === ' ' && State.currentScreen === 'HOME') {
Router.go('LISTENING');
setTimeout(() => Router.go('PROCESSING'), 3000); // Fake logic
}
}
// Global Listener
document.addEventListener('keydown', (e) => {
// Map physical keys
const validKeys = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Enter', 'Escape', 'Backspace', ' '];
if (validKeys.includes(e.key)) {
handleInput(e.key);
}
});
// Click Simulation
document.getElementById('controls-panel').addEventListener('click', (e) => {
const btn = e.target.closest('button');
if (btn && btn.dataset.key) {
handleInput(btn.dataset.key);
}
});
// --- Debug Panel ---
function renderDebugButtons() {
const container = document.getElementById('debug-state-buttons');
container.innerHTML = Object.keys(Screens).map(k => `
<button onclick="Router.go('${k}')" style="${k === State.currentScreen ? 'background:#ccc;' : ''}">
${k}
</button>
`).join('');
}
// --- Init ---
window.onload = () => {
updateStatusBar();
Router.go('SPLASH');
}