Back to super-platformer
SOURCE / PINNED RELEASE

Made of little things.

super-platformer

Release
b61593abc2c6…
Author-recorded commit
bbd35ca510f6…
License
LICENSE
Author’s source reference
nostr://npub16uawymqtmdg4j6zcl6snt5apzfp4ek2g8lpasnqa75tspdpglcqsgpatvc/wss%3A%2F%2Fgit.napplet.soy%2F/n-01288b1ab38

Archive hash verified: d2529eb9ad1961f2…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

src/napplet-settings.ts
import { config } from '@napplet/sdk';
import { runtimeHasDomain } from './domain-availability.js';

export interface AppSettings {
  textSize: number;
  controlSize: number;
  touchControls: boolean;
  sound: boolean;
}

const settings: AppSettings = {
  textSize: 13,
  controlSize: 30,
  touchControls: false,
  sound: true,
};

const listeners = new Set<(value: AppSettings) => void>();

function apply(values: Record<string, unknown>): void {
  settings.textSize = typeof values.textSize === 'number' ? values.textSize : 13;
  settings.controlSize = typeof values.controlSize === 'number' ? values.controlSize : 30;
  settings.touchControls = values.touchControls === true;
  settings.sound = values.sound !== false;

  const root = document.documentElement;
  root.style.fontSize = `${settings.textSize}px`;
  root.style.setProperty('--control-h', `${settings.controlSize}px`);
  document.body.classList.toggle('force-touch', settings.touchControls);

  for (const listener of listeners) listener(settings);
}

export function getSettings(): AppSettings {
  return settings;
}

export function onSettings(listener: (value: AppSettings) => void): () => void {
  listeners.add(listener);
  listener(settings);
  return () => {
    listeners.delete(listener);
  };
}

// The upstream Vite plugin embeds config.schema.json into the signed build.
// Config is optional here: the stylesheet also supplies these defaults.
if (runtimeHasDomain('config')) {
  try {
    const subscription = config.subscribe((values) => apply(values));
    window.addEventListener('pagehide', () => subscription.close(), { once: true });
  } catch {
    // Optional operations may be unavailable even when a host exposes the domain.
    // Keep the stylesheet defaults so the game still works in a limited host.
  }
}