feat: add browser PICO-8 player

Add v2 browser playback for .p8 and .p8.png cartridges, backed by the
FAKE-08 WebAssembly runtime, with canvas rendering, audio, fullscreen and
keyboard, gamepad, mouse and touch input. Wires up platform detection,
play actions, routing, localization, gallery navigation, play-session
tracking and lifecycle cleanup.

The runtime is fetched in the emulator stage of docker/Dockerfile, pinned
by source commit and verified with sha256, so it is provisioned the same
way as EmulatorJS, Ruffle and js-dos rather than committed to the repo.

DISABLE_PICO8 gates the player, matching the existing DISABLE_EMULATOR_JS,
DISABLE_RUFFLE_RS and DISABLE_JSDOS toggles.

Based on #4383.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bee
2026-09-08 17:59:52 -04:00
committed by Georges-Antoine Assi
parent 08f294d0fa
commit f50eacfcbd
44 changed files with 1137 additions and 17 deletions

View File

@@ -6,6 +6,8 @@ import {
getDownloadPath,
isJsDosBundle,
isJsDosEmulationSupported,
isPico8EmulationSupported,
isPico8Rom,
} from "./index";
function makeRom(overrides: Partial<SimpleRom>): SimpleRom {
@@ -102,6 +104,7 @@ function makeHeartbeat(
DISABLE_EMULATOR_JS: false,
DISABLE_RUFFLE_RS: false,
DISABLE_JSDOS: false,
DISABLE_PICO8: false,
...emulation,
},
} as Heartbeat;
@@ -167,3 +170,32 @@ describe("isJsDosBundle", () => {
expect(isJsDosBundle(undefined)).toBe(false);
});
});
describe("PICO-8 support", () => {
const withExt = (fs_extension: string) => makeRom({ fs_extension });
it("supports the pico platform and configured remaps", () => {
expect(isPico8EmulationSupported("pico", makeHeartbeat())).toBe(true);
expect(
isPico8EmulationSupported(
"custom-pico",
makeHeartbeat(),
makeConfig({ "custom-pico": "pico" }),
),
).toBe(true);
expect(isPico8EmulationSupported("snes", makeHeartbeat())).toBe(false);
});
it("respects the DISABLE_PICO8 admin toggle", () => {
expect(
isPico8EmulationSupported("pico", makeHeartbeat({ DISABLE_PICO8: true })),
).toBe(false);
});
it("accepts .p8 and .p8.png cartridges only", () => {
expect(isPico8Rom(withExt("p8"))).toBe(true);
expect(isPico8Rom(withExt("P8.PNG"))).toBe(true);
expect(isPico8Rom(withExt("zip"))).toBe(false);
expect(isPico8Rom(null)).toBe(false);
});
});

View File

@@ -734,6 +734,36 @@ export function isJsDosBundle(rom: SimpleRom | null | undefined) {
return rom?.fs_extension.toLowerCase() === "jsdos";
}
/**
* Check if PICO-8 emulation is supported for a given platform.
*
* @param platformSlug The platform slug.
* @param heartbeat The heartbeat object.
* @param config Optional configuration object.
* @returns True if supported, false otherwise.
*/
export function isPico8EmulationSupported(
platformSlug: string,
heartbeat: Heartbeat,
config?: Config,
) {
if (heartbeat.EMULATION.DISABLE_PICO8) return false;
const slug = resolvePlatformSlug(platformSlug, config);
return slug.toLowerCase() === "pico";
}
/**
* Check if a ROM file is a PICO-8 cartridge.
*
* @param rom The ROM to check.
* @returns True if the file is a PICO-8 cartridge, false otherwise.
*/
export function isPico8Rom(rom: SimpleRom | null | undefined) {
const extension = rom?.fs_extension.toLowerCase();
return extension === "p8" || extension === "p8.png";
}
export type PlayingStatus =
RomUserStatus | "backlogged" | "now_playing" | "hidden";