SOURCE / PINNED RELEASE
Made of little things.
Browser Side Quest
- Release
- b9d42f5768e4…
- Author-recorded commit
- c267690145fa…
- License
- LICENSE
- Author’s source reference
- nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.shakespeare.diy%2F/browser-side-quest
Archive hash verified: 6d4b90b8a5f328f7…. 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;
touchControls: boolean;
multiplayer: boolean;
}
export const defaultSettings: GameSettings = { sound: true, touchControls: true, multiplayer: true };
/**
* Subscribe to host-managed settings. Config is optional: without it the
* defaults apply. Calls back once with the initial values when available.
*/
export function watchSettings(onChange: (settings: GameSettings) => void): () => void {
if (!runtimeHasDomain('config')) return () => undefined;
let close: () => void = () => undefined;
void (async () => {
// Do not replace a schema that the host already supplied.
if (!config.schema) {
await config.registerSchema(settingsSchema as Parameters<typeof config.registerSchema>[0]);
}
const subscription = config.subscribe((values) => {
onChange({
sound: values.sound !== false,
touchControls: values.touchControls !== false,
multiplayer: values.multiplayer !== false,
});
});
close = () => subscription.close();
})().catch(() => {
// Optional operations may be unavailable even when a host exposes the domain.
});
return () => close();
}
