breakout71/src/options.ts

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-03-15 21:29:38 +01:00
import {fitSize} from "./game";
import {t} from "./i18n/i18n";
import {getSettingValue, setSettingValue} from "./settings";
2025-03-07 11:34:11 +01:00
export const options = {
2025-03-07 20:18:18 +01:00
sound: {
default: true,
2025-03-15 21:29:38 +01:00
name: t('main_menu.sounds'),
help: t('main_menu.sounds_help'),
2025-03-11 13:56:42 +01:00
afterChange: () => {},
2025-03-07 20:18:18 +01:00
disabled: () => false,
},
"mobile-mode": {
default: window.innerHeight > window.innerWidth,
2025-03-15 21:29:38 +01:00
name: t('main_menu.mobile'),
help: t('main_menu.mobile_help'),
2025-03-07 20:18:18 +01:00
afterChange() {
fitSize();
2025-03-07 11:34:11 +01:00
},
2025-03-07 20:18:18 +01:00
disabled: () => false,
},
basic: {
default: false,
2025-03-15 21:29:38 +01:00
name: t('main_menu.basic'),
help: t('main_menu.basic_help'),
2025-03-11 13:56:42 +01:00
afterChange: () => {},
2025-03-07 20:18:18 +01:00
disabled: () => false,
},
pointerLock: {
default: false,
2025-03-15 21:29:38 +01:00
name: t('main_menu.pointer_lock'),
help: t('main_menu.pointer_lock_help'),
2025-03-11 13:56:42 +01:00
afterChange: () => {},
2025-03-14 12:23:19 +01:00
disabled: () => !document.body.requestPointerLock,
2025-03-07 20:18:18 +01:00
},
easy: {
default: false,
2025-03-15 21:29:38 +01:00
name: t('main_menu.kid'),
help: t('main_menu.kid_help'),
2025-03-11 13:56:42 +01:00
afterChange: () => {},
2025-03-07 20:18:18 +01:00
disabled: () => false,
2025-03-15 21:29:38 +01:00
},
// Could not get the sharing to work without loading androidx and all the modern android things so for now I'll just disable sharing in the android app
2025-03-07 20:18:18 +01:00
record: {
default: false,
2025-03-15 21:29:38 +01:00
name: t('main_menu.record'),
help: t('main_menu.record_help'),
2025-03-11 13:56:42 +01:00
afterChange: () => {},
2025-03-07 20:18:18 +01:00
disabled() {
return window.location.search.includes("isInWebView=true");
2025-03-07 11:34:11 +01:00
},
},
2025-03-11 13:56:42 +01:00
} as const satisfies { [k: string]: OptionDef };
2025-03-07 11:34:11 +01:00
export type OptionDef = {
2025-03-07 20:18:18 +01:00
default: boolean;
name: string;
help: string;
disabled: () => boolean;
afterChange: () => void;
2025-03-07 20:18:18 +01:00
};
2025-03-11 13:56:42 +01:00
export type OptionId = keyof typeof options;
2025-03-15 21:29:38 +01:00
export function isOptionOn(key: OptionId) {
return getSettingValue(key, options[key]?.default)
}
export function toggleOption(key: OptionId) {
setSettingValue(key, !isOptionOn(key))
options[key].afterChange();
}