c64-ready 2.4.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-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/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 +24 -75
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +93 -214
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/player/c64-player.d.ts +25 -0
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +77 -1
- package/dist-ts/player/c64-player.js.map +1 -1
- 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 +3 -0
- package/dist-ts/player/index.d.ts.map +1 -1
- package/dist-ts/player/index.js +2 -0
- package/dist-ts/player/index.js.map +1 -1
- package/dist-ts/player/input-handler.d.ts +12 -1
- package/dist-ts/player/input-handler.d.ts.map +1 -1
- package/dist-ts/player/input-handler.js +46 -1
- package/dist-ts/player/input-handler.js.map +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 +22 -0
- package/dist-ts/player/ui-controller.d.ts.map +1 -1
- package/dist-ts/player/ui-controller.js +666 -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 +96 -1
- 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 +63 -1
- package/src/player/local-rom-store.ts +126 -0
- package/src/player/startup-params.ts +40 -0
- package/src/player/ui-controller.ts +741 -0
- package/src/types/c64-cheevos.d.ts +6 -0
- package/dist/assets/index-Dxuihfdi.js +0 -177
- /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
|
@@ -1,16 +1,33 @@
|
|
|
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
|
|
|
11
|
+
export interface InputHandlerOptions {
|
|
12
|
+
onFastForwardIncrease?: () => void;
|
|
13
|
+
onFastForwardDecrease?: () => void;
|
|
14
|
+
onFastForwardReset?: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
export default class InputHandler {
|
|
7
18
|
private readonly emulatorInput: EmulatorInput;
|
|
19
|
+
private readonly options: InputHandlerOptions;
|
|
8
20
|
// capture-phase blockers
|
|
9
21
|
private readonly captureKeyDown = (e: KeyboardEvent) => this.onCaptureKeyDown(e);
|
|
10
22
|
private readonly captureKeyUp = (e: KeyboardEvent) => this.onCaptureKeyUp(e);
|
|
11
23
|
|
|
12
|
-
constructor(
|
|
24
|
+
constructor(
|
|
25
|
+
emulator: C64Emulator,
|
|
26
|
+
target: EventTarget = window,
|
|
27
|
+
options: InputHandlerOptions = {},
|
|
28
|
+
) {
|
|
13
29
|
this.emulatorInput = new EmulatorInput(emulator, target);
|
|
30
|
+
this.options = options;
|
|
14
31
|
}
|
|
15
32
|
|
|
16
33
|
attach(): void {
|
|
@@ -53,7 +70,22 @@ export default class InputHandler {
|
|
|
53
70
|
return this.emulatorInput.getActiveGamepadIndex();
|
|
54
71
|
}
|
|
55
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
|
+
|
|
56
85
|
private onCaptureKeyDown(e: KeyboardEvent): void {
|
|
86
|
+
if (isEditableEventTarget(e.target)) return;
|
|
87
|
+
if (this.handleFastForwardShortcut(e)) return;
|
|
88
|
+
|
|
57
89
|
// Block joystick-mapped keys (standard + mixed mode) when overlays are
|
|
58
90
|
// visible or the document is unfocused. Use the union of both key sets.
|
|
59
91
|
if (!this.isJoystickKey(e)) return;
|
|
@@ -102,6 +134,8 @@ export default class InputHandler {
|
|
|
102
134
|
}
|
|
103
135
|
|
|
104
136
|
private onCaptureKeyUp(e: KeyboardEvent): void {
|
|
137
|
+
if (isEditableEventTarget(e.target)) return;
|
|
138
|
+
|
|
105
139
|
// Only block joystick-mapped keys (standard + mixed mode)
|
|
106
140
|
if (!this.isJoystickKey(e)) return;
|
|
107
141
|
|
|
@@ -138,4 +172,32 @@ export default class InputHandler {
|
|
|
138
172
|
private isJoystickKey(e: KeyboardEvent): boolean {
|
|
139
173
|
return this.emulatorInput.isJoystickKeyCode(e.code);
|
|
140
174
|
}
|
|
175
|
+
|
|
176
|
+
private handleFastForwardShortcut(e: KeyboardEvent): boolean {
|
|
177
|
+
if (!e.altKey || e.ctrlKey || e.metaKey || e.repeat) return false;
|
|
178
|
+
|
|
179
|
+
const increase = e.key === '+' || e.key === '=' || e.code === 'Equal';
|
|
180
|
+
const decrease = e.key === '-' || e.code === 'Minus';
|
|
181
|
+
const reset = e.key === 'Backspace' || e.code === 'Backspace';
|
|
182
|
+
if (!increase && !decrease && !reset) return false;
|
|
183
|
+
|
|
184
|
+
if (increase) this.options.onFastForwardIncrease?.();
|
|
185
|
+
else if (decrease) this.options.onFastForwardDecrease?.();
|
|
186
|
+
else this.options.onFastForwardReset?.();
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
e.stopImmediatePropagation();
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
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
|
+
);
|
|
141
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
|
+
}
|