public/js/ui/gameLogic.js becomes a re-export barrel. The bodies move verbatim into public/js/ui/gameLogic/*.js (shared, phases, camera, watch, bonds, shop, placement, draft, enemies, format, shortcuts, settings, result, loadout, panel). The barrel re-exports the same 96 names in the same order. isObj and int gain export on shared.js so sibling modules can import them; they stay off the barrel. No importer changes.
27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
// ui/gameLogic/settings.js — settings defaults and sanitising. Re-exported from ../gameLogic.js.
|
|
|
|
import { clamp, isObj } from './shared.js';
|
|
|
|
|
|
// ---- settings ------------------------------------------------------------------------------------------------------
|
|
|
|
export const DEFAULT_SETTINGS = Object.freeze({ bgm: 0.6, sfx: 0.8, muted: false, damageNumbers: true, quality: 'high' });
|
|
const QUALITIES = ['high', 'medium', 'low'];
|
|
|
|
/**
|
|
* Sanitize persisted settings.
|
|
* @param {any} raw
|
|
* @returns {{ bgm: number, sfx: number, muted: boolean, damageNumbers: boolean, quality: 'high'|'medium'|'low' }}
|
|
*/
|
|
export function sanitizeSettings(raw) {
|
|
const r = isObj(raw) ? raw : {};
|
|
const vol = (v, d) => (Number.isFinite(v) ? clamp(Math.round(v * 100) / 100, 0, 1) : d);
|
|
return {
|
|
bgm: vol(r.bgm, DEFAULT_SETTINGS.bgm),
|
|
sfx: vol(r.sfx, DEFAULT_SETTINGS.sfx),
|
|
muted: typeof r.muted === 'boolean' ? r.muted : DEFAULT_SETTINGS.muted,
|
|
damageNumbers: typeof r.damageNumbers === 'boolean' ? r.damageNumbers : DEFAULT_SETTINGS.damageNumbers,
|
|
quality: QUALITIES.includes(r.quality) ? r.quality : DEFAULT_SETTINGS.quality,
|
|
};
|
|
}
|