SOURCE / PINNED RELEASE
Made of little things.
Truffle Rush
- Release
- bf9d57a12f82…
- Author-recorded commit
- bf11c370d93c…
- License
- LICENSE
- Author’s source reference
- nostr://npub1dmmh0futyszl4445mv4xrygkgsgj8vpu79yx3qyy9qxmz4pemtzqlqmc87/wss%3A%2F%2Fgit.napplet.soy%2F/n-dad0644224b
Archive hash verified: 261cbd0dce1d32f5…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import { config } from '@napplet/sdk';
import { runtimeHasDomain } from './domain-availability.js';
import settingsSchema from '../config.schema.json';
export interface GameSettings {
sound: boolean;
screenShake: boolean;
}
const gameSettings: GameSettings = { sound: true, screenShake: true };
const listeners = new Set<(settings: GameSettings) => void>();
/** Subscribe to live NAP-CONFIG values. Returns an unsubscribe function. */
export function onSettingsChanged(
listener: (settings: GameSettings) => void,
): () => void {
listeners.add(listener);
listener(gameSettings);
return () => {
listeners.delete(listener);
};
}
function apply(values: Record<string, unknown>): void {
if (typeof values.sound === 'boolean') gameSettings.sound = values.sound;
if (typeof values.screenShake === 'boolean') {
gameSettings.screenShake = values.screenShake;
}
for (const listener of listeners) listener(gameSettings);
}
// The Vite plugin embeds config.schema.json in the signed build. Some hosts
// consume that metadata directly; others need the standard registration call.
// Keep the in-game defaults when config is absent or the schema is refused.
if (runtimeHasDomain('config')) {
void (async () => {
if (!config.schema) {
await config.registerSchema(
settingsSchema as Parameters<typeof config.registerSchema>[0],
);
}
const subscription = config.subscribe(apply);
window.addEventListener('pagehide', () => subscription.close(), { once: true });
})().catch(() => {
// Optional settings never block the arcade from booting.
});
}
