c64-ready 2.5.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/bin/admin.mjs +7 -1
- package/bin/headless.mjs +1 -1
- package/dist/assets/BeachHead-CuSwFD4k.js +1 -0
- package/dist/assets/ChuckieEgg-CPqBnAOF.js +1 -0
- package/dist/assets/ForbiddenForest-DsQ9jsc8.js +1 -0
- package/dist/assets/Galaga-Cutc3p9s.js +1 -0
- package/dist/assets/Gribbly-DdZ_hHFt.js +1 -0
- package/dist/assets/Hercules-vZYKm7GG.js +1 -0
- package/dist/assets/LegendOfWilf-CxSMOjsj.js +1 -0
- package/dist/assets/MariosCementFactory-z0IZ0q30.js +1 -0
- package/dist/assets/MoleAttack-buC6ChYy.js +1 -0
- package/dist/assets/MunchyWorm-D2Zv7i0Q.js +1 -0
- package/dist/assets/ParkPatrol-CVj7hyoB.js +1 -0
- package/dist/assets/PottyPigeon-0SYpIUBa.js +1 -0
- package/dist/assets/RainbowIslands-BjfmJB8z.js +1 -0
- package/dist/assets/Stix-BU-qUCeC.js +1 -0
- package/dist/assets/Tilt-C5KtKisF.js +1 -0
- package/dist/assets/UpNDown-CATRO7Mz.js +1 -0
- package/dist/assets/Uridium-DanS2KoH.js +1 -0
- package/dist/assets/VegetablesDeluxe-C41ViimS.js +1 -0
- package/dist/assets/index-B8DSjPqI.js +243 -0
- package/dist/assets/src-DX0rJQsE.js +1 -0
- package/dist/assets/src-_trgwTvp.js +2 -0
- package/dist/assets/string-utils-CMVABfx0.js +1 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-emulator.d.ts +2 -2
- package/dist-ts/emulator/c64-emulator.js +2 -2
- package/dist-ts/emulator/c64-keys.d.ts +69 -0
- package/dist-ts/emulator/c64-keys.d.ts.map +1 -0
- package/dist-ts/emulator/c64-keys.js +69 -0
- package/dist-ts/emulator/c64-keys.js.map +1 -0
- package/dist-ts/emulator/c64-wasm.d.ts +1 -1
- package/dist-ts/emulator/gamepad-mapping.d.ts +64 -0
- package/dist-ts/emulator/gamepad-mapping.d.ts.map +1 -0
- package/dist-ts/emulator/gamepad-mapping.js +154 -0
- package/dist-ts/emulator/gamepad-mapping.js.map +1 -0
- package/dist-ts/emulator/input.d.ts +27 -78
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +94 -215
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/headless/audio-capture.d.ts +1 -1
- package/dist-ts/headless/c64-headless.d.ts +2 -2
- package/dist-ts/headless/c64-headless.js +4 -4
- package/dist-ts/headless/frame-capture.d.ts +1 -1
- package/dist-ts/headless/input-bridge.d.ts +1 -1
- package/dist-ts/player/c64-player.d.ts +21 -5
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +32 -5
- package/dist-ts/player/c64-player.js.map +1 -1
- package/dist-ts/player/canvas-renderer.d.ts +2 -2
- package/dist-ts/player/cheevos-dev.d.ts +65 -0
- package/dist-ts/player/cheevos-dev.d.ts.map +1 -0
- package/dist-ts/player/cheevos-dev.js +237 -0
- package/dist-ts/player/cheevos-dev.js.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts +21 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.js +242 -0
- package/dist-ts/player/cheevos-tracker-panel.js.map +1 -0
- package/dist-ts/player/index.d.ts +10 -7
- package/dist-ts/player/index.d.ts.map +1 -1
- package/dist-ts/player/index.js +6 -4
- package/dist-ts/player/index.js.map +1 -1
- package/dist-ts/player/input-handler.d.ts +7 -3
- package/dist-ts/player/input-handler.d.ts.map +1 -1
- package/dist-ts/player/input-handler.js +24 -1
- package/dist-ts/player/input-handler.js.map +1 -1
- package/dist-ts/player/load-formats.d.ts +1 -1
- package/dist-ts/player/local-rom-store.d.ts +23 -0
- package/dist-ts/player/local-rom-store.d.ts.map +1 -0
- package/dist-ts/player/local-rom-store.js +87 -0
- package/dist-ts/player/local-rom-store.js.map +1 -0
- package/dist-ts/player/startup-params.d.ts +7 -0
- package/dist-ts/player/startup-params.d.ts.map +1 -0
- package/dist-ts/player/startup-params.js +47 -0
- package/dist-ts/player/startup-params.js.map +1 -0
- package/dist-ts/player/ui-controller.d.ts +23 -1
- package/dist-ts/player/ui-controller.d.ts.map +1 -1
- package/dist-ts/player/ui-controller.js +665 -1
- package/dist-ts/player/ui-controller.js.map +1 -1
- package/package.json +2 -1
- package/src/emulator/c64-keys.ts +68 -0
- package/src/emulator/gamepad-mapping.ts +212 -0
- package/src/emulator/input.ts +106 -209
- package/src/headless/headless-cli.mjs +10 -4
- package/src/headless/input-server.mjs +92 -17
- package/src/headless/webrtc-server.mjs +344 -22
- package/src/main.ts +177 -12
- package/src/player/c64-player.ts +36 -0
- package/src/player/cheevos-dev.ts +340 -0
- package/src/player/cheevos-tracker-panel.ts +309 -0
- package/src/player/index.ts +19 -0
- package/src/player/input-handler.ts +32 -0
- package/src/player/local-rom-store.ts +126 -0
- package/src/player/startup-params.ts +40 -0
- package/src/player/ui-controller.ts +740 -0
- package/src/types/c64-cheevos.d.ts +6 -0
- package/dist/assets/index-BAsZcXuS.js +0 -178
- /package/dist/assets/{marked.esm--kBm026b.js → marked.esm-fTuuvbcB.js} +0 -0
- /package/dist/assets/{purify.es-BcoGFDcJ.js → purify.es-CRM-GE0Y.js} +0 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import type { CheevosDevAchievement, CheevosDevSet, CheevosDevTrackerField } from './cheevos-dev';
|
|
2
|
+
|
|
3
|
+
export const CHEEVOS_TRACKER_VISIBLE_STORAGE_KEY = 'c64-cheevos-tracker-visible';
|
|
4
|
+
|
|
5
|
+
type PoppedCheevo = { achievement: CheevosDevAchievement };
|
|
6
|
+
|
|
7
|
+
type TrackerState = {
|
|
8
|
+
detectorId: string;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
visiblePreference: boolean;
|
|
11
|
+
displayMode: string;
|
|
12
|
+
cheevosSet: CheevosDevSet;
|
|
13
|
+
popped: CheevosDevAchievement[];
|
|
14
|
+
score?: string | number | boolean;
|
|
15
|
+
lives?: string | number | boolean;
|
|
16
|
+
isGameOver?: boolean;
|
|
17
|
+
fields: Record<string, string | number | boolean | undefined>;
|
|
18
|
+
lastMessage: string;
|
|
19
|
+
expandedLists: Record<string, boolean>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const COLLAPSED_ACHIEVEMENT_LIMIT = 6;
|
|
23
|
+
|
|
24
|
+
const css = `
|
|
25
|
+
.c64-cheevos-tracker{position:fixed;inset-block-start:50%;inset-inline-start:calc(50% + 410px);transform:translateY(-50%);box-sizing:border-box;inline-size:min(520px,calc(50vw - 430px));max-block-size:calc(100dvh - 48px);overflow:auto;scrollbar-gutter:stable;background:#101623;border:2px solid #333e5f;border-radius:8px;color:#d8def6;font-family:monospace;font-size:13px;padding:14px;z-index:900;box-shadow:0 12px 36px rgba(0,0,0,.35)}.c64-cheevos-tracker.hidden{display:none}.c64-cheevos-tracker h2{margin:0 0 4px;color:#8da2ff;font-size:15px;letter-spacing:.08em;text-transform:uppercase}.c64-cheevos-tracker-subtitle{color:#8790aa;font-size:12px;margin:0 0 10px}.c64-cheevos-tracker-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:0 0 10px}.c64-cheevos-stat{background:#151d2e;border:1px solid #26314c;border-radius:5px;padding:7px}.c64-cheevos-stat-label{display:block;color:#8995b5;font-size:11px;text-transform:uppercase}.c64-cheevos-stat-value{display:block;color:#fff;font-size:16px;margin-block-start:2px;overflow:hidden;text-overflow:ellipsis}.c64-cheevos-field-list{display:grid;gap:7px;margin:0 0 10px}.c64-cheevos-field{background:#151d2e;border:1px solid #26314c;border-radius:5px;padding:7px}.c64-cheevos-field-row{display:flex;justify-content:space-between;gap:8px}.c64-cheevos-bar{block-size:7px;background:#26314c;border-radius:999px;margin-block-start:6px;overflow:hidden}.c64-cheevos-bar-fill{block-size:100%;background:#8da2ff;border-radius:inherit}.c64-cheevos-list-header{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:10px 0 6px}.c64-cheevos-list-title{margin:0;color:#8da2ff;font-size:12px;text-transform:uppercase}.c64-cheevos-list-toggle{background:transparent;border:1px solid #38486f;border-radius:4px;color:#b8c4ff;cursor:pointer;font:inherit;font-size:11px;padding:2px 6px}.c64-cheevos-list-toggle:hover{border-color:#8da2ff;color:#fff}.c64-cheevos-list{display:grid;gap:6px;margin:0;padding:0;list-style:none}.c64-cheevos-list.cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.c64-cheevos-list.cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.c64-cheevos-item{background:#151d2e;border:1px solid #26314c;border-radius:5px;padding:6px;min-inline-size:0}.c64-cheevos-item.popped{border-color:#557a36;background:#152416}.c64-cheevos-item-title{display:block;color:#f1f4ff;overflow:hidden;text-overflow:ellipsis}.c64-cheevos-item-description{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;line-clamp:2;overflow:clip;color:#8790aa;font-size:11px;margin-block-start:2px}.c64-cheevos-empty{color:#8790aa;font-size:12px;margin:0}.c64-cheevos-message{color:#f3c36b;font-size:12px;margin:10px 0 0}@media (max-width:1480px){.c64-cheevos-tracker{inline-size:min(360px,calc(50vw - 430px))}.c64-cheevos-list.cols-3{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (max-width:1180px){.c64-cheevos-tracker{display:none}}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
export class CheevosTrackerPanel {
|
|
29
|
+
private root: HTMLElement | null = null;
|
|
30
|
+
private state: TrackerState = {
|
|
31
|
+
detectorId: '',
|
|
32
|
+
enabled: false,
|
|
33
|
+
visiblePreference: localStorage.getItem(CHEEVOS_TRACKER_VISIBLE_STORAGE_KEY) !== '0',
|
|
34
|
+
displayMode: 'standard',
|
|
35
|
+
cheevosSet: { cheevos: [], trackerFields: [] },
|
|
36
|
+
popped: [],
|
|
37
|
+
fields: {},
|
|
38
|
+
lastMessage: '',
|
|
39
|
+
expandedLists: {},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
init(): void {
|
|
43
|
+
this.injectCSS();
|
|
44
|
+
this.root = document.createElement('aside');
|
|
45
|
+
this.root.className = 'c64-cheevos-tracker hidden';
|
|
46
|
+
this.root.setAttribute('aria-label', 'Cheevos tracker');
|
|
47
|
+
document.body.appendChild(this.root);
|
|
48
|
+
this.render();
|
|
49
|
+
|
|
50
|
+
window.addEventListener('c64-cheevos-status', this.handleStatus as EventListener);
|
|
51
|
+
window.addEventListener('c64-cheevos-event', this.handleCheevosEvent as EventListener);
|
|
52
|
+
window.addEventListener('c64-cheevos-score', this.handleScore as EventListener);
|
|
53
|
+
window.addEventListener('c64-cheevos-popped', this.handlePopped as EventListener);
|
|
54
|
+
window.addEventListener('c64-cheevos-snapshot', this.handleSnapshot as EventListener);
|
|
55
|
+
window.addEventListener('c64-cheevos-error', this.handleError as EventListener);
|
|
56
|
+
window.addEventListener('c64-cheevos-tracker-toggle', this.handleToggle as EventListener);
|
|
57
|
+
window.addEventListener('c64-display-mode-changed', this.handleDisplayMode as EventListener);
|
|
58
|
+
this.root.addEventListener('click', this.handleClick);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
destroy(): void {
|
|
62
|
+
window.removeEventListener('c64-cheevos-status', this.handleStatus as EventListener);
|
|
63
|
+
window.removeEventListener('c64-cheevos-event', this.handleCheevosEvent as EventListener);
|
|
64
|
+
window.removeEventListener('c64-cheevos-score', this.handleScore as EventListener);
|
|
65
|
+
window.removeEventListener('c64-cheevos-popped', this.handlePopped as EventListener);
|
|
66
|
+
window.removeEventListener('c64-cheevos-snapshot', this.handleSnapshot as EventListener);
|
|
67
|
+
window.removeEventListener('c64-cheevos-error', this.handleError as EventListener);
|
|
68
|
+
window.removeEventListener('c64-cheevos-tracker-toggle', this.handleToggle as EventListener);
|
|
69
|
+
window.removeEventListener('c64-display-mode-changed', this.handleDisplayMode as EventListener);
|
|
70
|
+
this.root?.removeEventListener('click', this.handleClick);
|
|
71
|
+
this.root?.remove();
|
|
72
|
+
this.root = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private readonly handleStatus = (event: CustomEvent): void => {
|
|
76
|
+
const detail = event.detail as {
|
|
77
|
+
detectorId?: string;
|
|
78
|
+
status?: string;
|
|
79
|
+
cheevosSet?: CheevosDevSet;
|
|
80
|
+
poppedCheevos?: PoppedCheevo[];
|
|
81
|
+
};
|
|
82
|
+
if (detail.status === 'enabled') {
|
|
83
|
+
this.state.enabled = true;
|
|
84
|
+
this.state.detectorId = detail.detectorId ?? '';
|
|
85
|
+
this.state.cheevosSet = detail.cheevosSet ?? { cheevos: [], trackerFields: [] };
|
|
86
|
+
this.state.popped = normalisePopped(detail.poppedCheevos ?? []);
|
|
87
|
+
this.state.isGameOver = undefined;
|
|
88
|
+
this.state.lastMessage = '';
|
|
89
|
+
this.state.expandedLists = {};
|
|
90
|
+
this.render();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (detail.status === 'popped-cleared') {
|
|
94
|
+
this.state.popped = [];
|
|
95
|
+
this.render();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
private readonly handleCheevosEvent = (event: CustomEvent): void => {
|
|
100
|
+
const detail = event.detail as { type?: string; payload?: Record<string, unknown> };
|
|
101
|
+
if (detail.type === 'newGame') {
|
|
102
|
+
this.state.isGameOver = false;
|
|
103
|
+
this.state.lastMessage = 'New game started';
|
|
104
|
+
} else if (detail.type === 'gameOver') {
|
|
105
|
+
this.state.isGameOver = true;
|
|
106
|
+
this.state.score = normaliseValue(detail.payload?.score) ?? this.state.score;
|
|
107
|
+
this.state.lastMessage = 'Game over';
|
|
108
|
+
} else if (detail.type === 'livesChange') {
|
|
109
|
+
this.state.lives = normaliseValue(detail.payload?.lives) ?? this.state.lives;
|
|
110
|
+
} else if (detail.type === 'cheevo') {
|
|
111
|
+
this.state.lastMessage = String(detail.payload?.title ?? 'Achievement unlocked');
|
|
112
|
+
}
|
|
113
|
+
this.render();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
private readonly handleScore = (event: CustomEvent): void => {
|
|
117
|
+
const detail = event.detail as { score?: { score?: number } };
|
|
118
|
+
this.state.score = detail.score?.score ?? this.state.score;
|
|
119
|
+
this.render();
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
private readonly handlePopped = (event: CustomEvent): void => {
|
|
123
|
+
const detail = event.detail as {
|
|
124
|
+
achievement?: CheevosDevAchievement;
|
|
125
|
+
poppedCheevos?: PoppedCheevo[];
|
|
126
|
+
};
|
|
127
|
+
if (detail.poppedCheevos) this.state.popped = normalisePopped(detail.poppedCheevos);
|
|
128
|
+
else if (
|
|
129
|
+
detail.achievement &&
|
|
130
|
+
!this.state.popped.some((item) => item._id === detail.achievement?._id)
|
|
131
|
+
) {
|
|
132
|
+
this.state.popped = [...this.state.popped, detail.achievement];
|
|
133
|
+
}
|
|
134
|
+
if (detail.achievement) this.state.lastMessage = `Popped: ${detail.achievement.title}`;
|
|
135
|
+
this.render();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
private readonly handleSnapshot = (event: CustomEvent): void => {
|
|
139
|
+
const detail = event.detail as {
|
|
140
|
+
score?: string | number | boolean;
|
|
141
|
+
lives?: string | number | boolean;
|
|
142
|
+
isGameOver?: boolean;
|
|
143
|
+
fields?: Record<string, string | number | boolean | undefined>;
|
|
144
|
+
};
|
|
145
|
+
if (detail.score !== undefined) this.state.score = detail.score;
|
|
146
|
+
if (detail.lives !== undefined) this.state.lives = detail.lives;
|
|
147
|
+
if (detail.isGameOver !== undefined) this.state.isGameOver = detail.isGameOver;
|
|
148
|
+
if (detail.fields) this.state.fields = detail.fields;
|
|
149
|
+
this.render();
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
private readonly handleError = (event: CustomEvent): void => {
|
|
153
|
+
const detail = event.detail as { error?: string };
|
|
154
|
+
this.state.lastMessage = `Error: ${detail.error ?? 'Unknown error'}`;
|
|
155
|
+
this.render();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
private readonly handleToggle = (event: CustomEvent): void => {
|
|
159
|
+
const detail = event.detail as { visible?: boolean };
|
|
160
|
+
this.state.visiblePreference = detail.visible !== false;
|
|
161
|
+
localStorage.setItem(
|
|
162
|
+
CHEEVOS_TRACKER_VISIBLE_STORAGE_KEY,
|
|
163
|
+
this.state.visiblePreference ? '1' : '0',
|
|
164
|
+
);
|
|
165
|
+
this.render();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
private readonly handleDisplayMode = (event: CustomEvent): void => {
|
|
169
|
+
const detail = event.detail as { mode?: string };
|
|
170
|
+
this.state.displayMode = detail.mode ?? 'standard';
|
|
171
|
+
this.render();
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
private readonly handleClick = (event: MouseEvent): void => {
|
|
175
|
+
const target = event.target;
|
|
176
|
+
if (!(target instanceof HTMLElement)) return;
|
|
177
|
+
const button = target.closest<HTMLButtonElement>('[data-cheevos-list-toggle]');
|
|
178
|
+
if (!button) return;
|
|
179
|
+
const listKey = button.dataset.cheevosListToggle;
|
|
180
|
+
if (!listKey) return;
|
|
181
|
+
this.state.expandedLists = {
|
|
182
|
+
...this.state.expandedLists,
|
|
183
|
+
[listKey]: !this.state.expandedLists[listKey],
|
|
184
|
+
};
|
|
185
|
+
this.render();
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
private render(): void {
|
|
189
|
+
if (!this.root) return;
|
|
190
|
+
this.root.classList.toggle(
|
|
191
|
+
'hidden',
|
|
192
|
+
!this.state.enabled || !this.state.visiblePreference || this.state.displayMode !== 'standard',
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const cheevos = this.state.cheevosSet.cheevos ?? [];
|
|
196
|
+
const poppedIds = new Set(this.state.popped.map((achievement) => achievement._id));
|
|
197
|
+
const remaining = cheevos.filter((achievement) => !poppedIds.has(achievement._id));
|
|
198
|
+
|
|
199
|
+
this.root.innerHTML = `
|
|
200
|
+
<h2>Cheevos</h2>
|
|
201
|
+
<p class="c64-cheevos-tracker-subtitle">${escapeHtml(this.state.detectorId || 'No detector')}</p>
|
|
202
|
+
<div class="c64-cheevos-tracker-grid">
|
|
203
|
+
${renderStat('Score', this.state.score ?? '-')}
|
|
204
|
+
${renderStat('Lives', this.state.lives ?? '-')}
|
|
205
|
+
${renderStat('Status', this.state.isGameOver ? 'Game Over' : this.state.isGameOver === false ? 'Playing' : 'Waiting')}
|
|
206
|
+
${renderStat('Popped', `${this.state.popped.length}/${cheevos.length}`)}
|
|
207
|
+
</div>
|
|
208
|
+
${this.renderFields()}
|
|
209
|
+
${renderList('popped', 'Popped', this.state.popped, true, !!this.state.expandedLists.popped)}
|
|
210
|
+
${renderList('remaining', 'Remaining', remaining, false, !!this.state.expandedLists.remaining)}
|
|
211
|
+
${this.state.lastMessage ? `<p class="c64-cheevos-message">${escapeHtml(this.state.lastMessage)}</p>` : ''}
|
|
212
|
+
`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private renderFields(): string {
|
|
216
|
+
const fields = this.state.cheevosSet.trackerFields ?? [];
|
|
217
|
+
if (fields.length === 0) return '';
|
|
218
|
+
return `<div class="c64-cheevos-field-list">${fields
|
|
219
|
+
.map((field) => renderField(field, this.state.fields[field.key]))
|
|
220
|
+
.join('')}</div>`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private injectCSS(): void {
|
|
224
|
+
if (document.querySelector('style[data-c64-cheevos-tracker]')) return;
|
|
225
|
+
const style = document.createElement('style');
|
|
226
|
+
style.setAttribute('data-c64-cheevos-tracker', '');
|
|
227
|
+
style.textContent = css;
|
|
228
|
+
document.head.appendChild(style);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function renderStat(label: string, value: string | number | boolean): string {
|
|
233
|
+
return `<div class="c64-cheevos-stat"><span class="c64-cheevos-stat-label">${escapeHtml(label)}</span><span class="c64-cheevos-stat-value">${escapeHtml(String(value))}</span></div>`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function renderField(
|
|
237
|
+
field: CheevosDevTrackerField,
|
|
238
|
+
value: string | number | boolean | undefined,
|
|
239
|
+
): string {
|
|
240
|
+
const label = field.label ?? field.key;
|
|
241
|
+
const displayValue = value ?? '-';
|
|
242
|
+
const bar =
|
|
243
|
+
field.display === 'bar' &&
|
|
244
|
+
typeof value === 'number' &&
|
|
245
|
+
typeof field.max === 'number' &&
|
|
246
|
+
field.max > 0
|
|
247
|
+
? `<div class="c64-cheevos-bar"><div class="c64-cheevos-bar-fill" style="inline-size:${Math.max(0, Math.min(100, (value / field.max) * 100))}%"></div></div>`
|
|
248
|
+
: '';
|
|
249
|
+
return `<div class="c64-cheevos-field"><div class="c64-cheevos-field-row"><span>${escapeHtml(label)}</span><strong>${escapeHtml(String(displayValue))}</strong></div>${bar}</div>`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function renderList(
|
|
253
|
+
key: string,
|
|
254
|
+
title: string,
|
|
255
|
+
achievements: CheevosDevAchievement[],
|
|
256
|
+
popped: boolean,
|
|
257
|
+
expanded: boolean,
|
|
258
|
+
): string {
|
|
259
|
+
const hasMore = achievements.length > COLLAPSED_ACHIEVEMENT_LIMIT;
|
|
260
|
+
const visibleAchievements = expanded
|
|
261
|
+
? achievements
|
|
262
|
+
: achievements.slice(0, COLLAPSED_ACHIEVEMENT_LIMIT);
|
|
263
|
+
const columnClass = getColumnClass(visibleAchievements.length);
|
|
264
|
+
const items = visibleAchievements
|
|
265
|
+
.map(
|
|
266
|
+
(achievement) =>
|
|
267
|
+
`<li class="c64-cheevos-item${popped ? ' popped' : ''}"><span class="c64-cheevos-item-title">${escapeHtml(achievement.title)}</span>${
|
|
268
|
+
achievement.description
|
|
269
|
+
? `<span class="c64-cheevos-item-description" title="${achievement.description}">${escapeHtml(achievement.description)}</span>`
|
|
270
|
+
: ''
|
|
271
|
+
}</li>`,
|
|
272
|
+
)
|
|
273
|
+
.join('');
|
|
274
|
+
const toggle = hasMore
|
|
275
|
+
? `<button class="c64-cheevos-list-toggle" type="button" data-cheevos-list-toggle="${escapeHtml(key)}">${expanded ? 'Show less' : `Show all ${achievements.length}`}</button>`
|
|
276
|
+
: '';
|
|
277
|
+
return `<div class="c64-cheevos-list-header"><h3 class="c64-cheevos-list-title">${escapeHtml(title)}</h3>${toggle}</div>${
|
|
278
|
+
items
|
|
279
|
+
? `<ul class="c64-cheevos-list ${columnClass}">${items}</ul>`
|
|
280
|
+
: '<p class="c64-cheevos-empty">None</p>'
|
|
281
|
+
}`;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function getColumnClass(count: number): string {
|
|
285
|
+
if (count >= 9) return 'cols-3';
|
|
286
|
+
if (count >= 4) return 'cols-2';
|
|
287
|
+
return 'cols-1';
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function normalisePopped(popped: PoppedCheevo[]): CheevosDevAchievement[] {
|
|
291
|
+
return popped.map((item) => item.achievement).filter(Boolean);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function normaliseValue(value: unknown): string | number | boolean | undefined {
|
|
295
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
296
|
+
return value;
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function escapeHtml(value: string): string {
|
|
301
|
+
return value
|
|
302
|
+
.replace(/&/g, '&')
|
|
303
|
+
.replace(/</g, '<')
|
|
304
|
+
.replace(/>/g, '>')
|
|
305
|
+
.replace(/"/g, '"')
|
|
306
|
+
.replace(/'/g, ''');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export default CheevosTrackerPanel;
|
package/src/player/index.ts
CHANGED
|
@@ -4,6 +4,25 @@ export type { C64PlayerOptions, ProgressCallback } from './c64-player';
|
|
|
4
4
|
export { AudioEngine } from './audio-engine';
|
|
5
5
|
export type { AudioEngineOptions, AudioStateChangeCallback, SidBufferReader } from './audio-engine';
|
|
6
6
|
export { default as InputHandler } from './input-handler';
|
|
7
|
+
export { C64_KEY } from '../emulator/c64-keys';
|
|
8
|
+
export {
|
|
9
|
+
DEFAULT_GAMEPAD_MAPPING,
|
|
10
|
+
GAMEPAD_BUTTONS,
|
|
11
|
+
GAMEPAD_DIRECTIONS,
|
|
12
|
+
resolveGamepadMapping,
|
|
13
|
+
restrictDirections,
|
|
14
|
+
} from '../emulator/gamepad-mapping';
|
|
15
|
+
export type {
|
|
16
|
+
ControlAction,
|
|
17
|
+
GamepadButton,
|
|
18
|
+
GamepadControl,
|
|
19
|
+
GamepadDirection,
|
|
20
|
+
GamepadMapping,
|
|
21
|
+
GamepadState,
|
|
22
|
+
JoystickAction,
|
|
23
|
+
ResolvedGamepadMapping,
|
|
24
|
+
StickMode,
|
|
25
|
+
} from '../emulator/gamepad-mapping';
|
|
7
26
|
export type {
|
|
8
27
|
C64Config,
|
|
9
28
|
C64State,
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { EmulatorInput } from '../emulator/input';
|
|
2
2
|
import type { InputMode, KeyboardJoystickMap } from '../emulator/input';
|
|
3
|
+
import type {
|
|
4
|
+
GamepadMapping,
|
|
5
|
+
GamepadState,
|
|
6
|
+
ResolvedGamepadMapping,
|
|
7
|
+
} from '../emulator/gamepad-mapping';
|
|
3
8
|
import type { JoystickPort } from '../emulator/constants';
|
|
4
9
|
import type { C64Emulator } from '../emulator/c64-emulator';
|
|
5
10
|
|
|
@@ -65,7 +70,20 @@ export default class InputHandler {
|
|
|
65
70
|
return this.emulatorInput.getActiveGamepadIndex();
|
|
66
71
|
}
|
|
67
72
|
|
|
73
|
+
setGamepadMapping(mapping?: GamepadMapping | null): void {
|
|
74
|
+
this.emulatorInput.setGamepadMapping(mapping);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getGamepadMapping(): ResolvedGamepadMapping {
|
|
78
|
+
return this.emulatorInput.getGamepadMapping();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setVirtualGamepadState(state: GamepadState): void {
|
|
82
|
+
this.emulatorInput.setVirtualGamepadState(state);
|
|
83
|
+
}
|
|
84
|
+
|
|
68
85
|
private onCaptureKeyDown(e: KeyboardEvent): void {
|
|
86
|
+
if (isEditableEventTarget(e.target)) return;
|
|
69
87
|
if (this.handleFastForwardShortcut(e)) return;
|
|
70
88
|
|
|
71
89
|
// Block joystick-mapped keys (standard + mixed mode) when overlays are
|
|
@@ -116,6 +134,8 @@ export default class InputHandler {
|
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
private onCaptureKeyUp(e: KeyboardEvent): void {
|
|
137
|
+
if (isEditableEventTarget(e.target)) return;
|
|
138
|
+
|
|
119
139
|
// Only block joystick-mapped keys (standard + mixed mode)
|
|
120
140
|
if (!this.isJoystickKey(e)) return;
|
|
121
141
|
|
|
@@ -169,3 +189,15 @@ export default class InputHandler {
|
|
|
169
189
|
return true;
|
|
170
190
|
}
|
|
171
191
|
}
|
|
192
|
+
|
|
193
|
+
function isEditableEventTarget(target: EventTarget | null): boolean {
|
|
194
|
+
if (!(target instanceof Element)) return false;
|
|
195
|
+
if (target instanceof HTMLInputElement) {
|
|
196
|
+
return target.type !== 'button' && target.type !== 'checkbox' && target.type !== 'radio';
|
|
197
|
+
}
|
|
198
|
+
return (
|
|
199
|
+
target instanceof HTMLTextAreaElement ||
|
|
200
|
+
target instanceof HTMLSelectElement ||
|
|
201
|
+
(target instanceof HTMLElement && target.isContentEditable)
|
|
202
|
+
);
|
|
203
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAcceptForLoadTypeSelection,
|
|
3
|
+
inferLoadTypeFromFilename,
|
|
4
|
+
isSupportedLoadType,
|
|
5
|
+
} from './load-formats';
|
|
6
|
+
import type { LoadType } from './load-formats';
|
|
7
|
+
|
|
8
|
+
const DB_NAME = 'c64-ready-local-roms';
|
|
9
|
+
const STORE_NAME = 'rom-files';
|
|
10
|
+
const DB_VERSION = 2;
|
|
11
|
+
|
|
12
|
+
export type LocalRomFile = {
|
|
13
|
+
file: File;
|
|
14
|
+
type: LoadType;
|
|
15
|
+
romPath: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type StoredRomRecord = {
|
|
19
|
+
romPath: string;
|
|
20
|
+
name: string;
|
|
21
|
+
type: LoadType;
|
|
22
|
+
blob: Blob;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type WindowWithFilePicker = Window & {
|
|
26
|
+
showOpenFilePicker?: (options?: {
|
|
27
|
+
multiple?: boolean;
|
|
28
|
+
types?: Array<{ description: string; accept: Record<string, string[]> }>;
|
|
29
|
+
}) => Promise<FileSystemFileHandle[]>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function getCheevosRomPath(set: { romPath?: unknown; rom?: { path?: unknown } }): string {
|
|
33
|
+
const value = typeof set.romPath === 'string' ? set.romPath : set.rom?.path;
|
|
34
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getCheevosRomType(set: {
|
|
38
|
+
romPath?: unknown;
|
|
39
|
+
rom?: { path?: unknown; type?: unknown };
|
|
40
|
+
}): LoadType | undefined {
|
|
41
|
+
if (isSupportedLoadType(set.rom?.type)) return set.rom.type;
|
|
42
|
+
const romPath = getCheevosRomPath(set);
|
|
43
|
+
return inferLoadTypeFromFilename(romPath) ?? undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function getStoredCheevosRom(
|
|
47
|
+
romPath: string,
|
|
48
|
+
type?: LoadType,
|
|
49
|
+
): Promise<LocalRomFile | null> {
|
|
50
|
+
const record = await getStoredRomRecord(romPath);
|
|
51
|
+
if (!record) return null;
|
|
52
|
+
const file = new File([record.blob], record.name, { type: record.blob.type });
|
|
53
|
+
return { file, type: type ?? record.type, romPath };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function chooseAndStoreCheevosRom(
|
|
57
|
+
romPath: string,
|
|
58
|
+
type?: LoadType,
|
|
59
|
+
): Promise<LocalRomFile | null> {
|
|
60
|
+
const picker = (window as WindowWithFilePicker).showOpenFilePicker;
|
|
61
|
+
if (!picker) return null;
|
|
62
|
+
const [handle] = await picker({
|
|
63
|
+
multiple: false,
|
|
64
|
+
types: [
|
|
65
|
+
{
|
|
66
|
+
description: 'C64 ROM files',
|
|
67
|
+
accept: {
|
|
68
|
+
'application/octet-stream': getAcceptForLoadTypeSelection(type ?? 'auto').split(','),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
if (!handle) return null;
|
|
74
|
+
const file = await handle.getFile();
|
|
75
|
+
await storeCheevosRomFile(romPath, file, type);
|
|
76
|
+
return { file, type: type ?? inferLoadTypeFromFilename(file.name) ?? 'crt', romPath };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function storeCheevosRomFile(
|
|
80
|
+
romPath: string,
|
|
81
|
+
file: File,
|
|
82
|
+
type?: LoadType,
|
|
83
|
+
): Promise<void> {
|
|
84
|
+
const resolvedType = type ?? inferLoadTypeFromFilename(file.name) ?? 'crt';
|
|
85
|
+
const db = await openDb();
|
|
86
|
+
await new Promise<void>((resolve, reject) => {
|
|
87
|
+
const tx = db.transaction(STORE_NAME, 'readwrite');
|
|
88
|
+
tx.objectStore(STORE_NAME).put({
|
|
89
|
+
romPath,
|
|
90
|
+
name: file.name,
|
|
91
|
+
type: resolvedType,
|
|
92
|
+
blob: file,
|
|
93
|
+
} satisfies StoredRomRecord);
|
|
94
|
+
tx.oncomplete = () => resolve();
|
|
95
|
+
tx.onerror = () => reject(tx.error ?? new Error('Unable to store ROM file'));
|
|
96
|
+
});
|
|
97
|
+
db.close();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function getStoredRomRecord(romPath: string): Promise<StoredRomRecord | null> {
|
|
101
|
+
if (typeof indexedDB === 'undefined') return null;
|
|
102
|
+
const db = await openDb();
|
|
103
|
+
const record = await new Promise<StoredRomRecord | undefined>((resolve, reject) => {
|
|
104
|
+
const tx = db.transaction(STORE_NAME, 'readonly');
|
|
105
|
+
const request = tx.objectStore(STORE_NAME).get(romPath);
|
|
106
|
+
request.onsuccess = () => resolve(request.result as StoredRomRecord | undefined);
|
|
107
|
+
request.onerror = () => reject(request.error ?? new Error('Unable to read ROM file'));
|
|
108
|
+
});
|
|
109
|
+
db.close();
|
|
110
|
+
if (!record?.blob || !record.name || !isSupportedLoadType(record.type)) return null;
|
|
111
|
+
return record;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function openDb(): Promise<IDBDatabase> {
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
|
117
|
+
request.onupgradeneeded = () => {
|
|
118
|
+
const db = request.result;
|
|
119
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
120
|
+
db.createObjectStore(STORE_NAME, { keyPath: 'romPath' });
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
request.onsuccess = () => resolve(request.result);
|
|
124
|
+
request.onerror = () => reject(request.error ?? new Error('Unable to open local ROM store'));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function resolveGameFromParam(
|
|
2
|
+
raw: string | null,
|
|
3
|
+
baseUrl: string,
|
|
4
|
+
options: { disableDefault?: boolean } = {},
|
|
5
|
+
): string {
|
|
6
|
+
if (!raw) return options.disableDefault ? '' : `${baseUrl}games/cartridges/legend-of-wilf.crt`;
|
|
7
|
+
const value = raw.trim();
|
|
8
|
+
if (!value) return options.disableDefault ? '' : `${baseUrl}games/cartridges/legend-of-wilf.crt`;
|
|
9
|
+
if (value.toLowerCase() === 'null') return '';
|
|
10
|
+
if (/^https?:\/\//i.test(value)) return value;
|
|
11
|
+
if (value.startsWith('/')) return value;
|
|
12
|
+
return `${baseUrl}${value.replace(/^\/+/, '')}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function resolveUrlFromParam(raw: string | null, baseUrl: string): string {
|
|
16
|
+
if (!raw) return '';
|
|
17
|
+
const value = raw.trim();
|
|
18
|
+
if (!value) return '';
|
|
19
|
+
if (/^https?:\/\//i.test(value)) return value;
|
|
20
|
+
if (value.startsWith('/@fs/')) return `${baseUrl.replace(/\/+$/, '')}${value}`;
|
|
21
|
+
if (value.startsWith('/')) return value;
|
|
22
|
+
return `${baseUrl}${value.replace(/^\/+/, '')}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function toViteFsUrl(pathOrUrl: string, baseUrl: string): string {
|
|
26
|
+
const value = pathOrUrl.trim();
|
|
27
|
+
if (!value) return '';
|
|
28
|
+
if (/^https?:\/\//i.test(value)) return value;
|
|
29
|
+
const base = baseUrl.replace(/\/+$/, '');
|
|
30
|
+
if (value.startsWith(`${base}/@fs/`)) return value.slice(base.length);
|
|
31
|
+
if (value.startsWith('/@fs/')) return value;
|
|
32
|
+
if (value.startsWith('/')) return `/@fs${value}`;
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function shouldDisableDefaultGameForCheevos(params: URLSearchParams): boolean {
|
|
37
|
+
return (
|
|
38
|
+
!params.has('game') && !!params.get('cheevos')?.trim() && !!params.get('cheevosSet')?.trim()
|
|
39
|
+
);
|
|
40
|
+
}
|