2025-03-15 21:29:38 +01:00
|
|
|
// Settings
|
|
|
|
|
2025-03-16 14:29:14 +01:00
|
|
|
import {GameState} from "./types";
|
|
|
|
|
2025-03-15 21:29:38 +01:00
|
|
|
let cachedSettings: { [key: string]: unknown } = {};
|
|
|
|
|
|
|
|
export function getSettingValue<T>(key: string, defaultValue: T) {
|
|
|
|
if (typeof cachedSettings[key] == "undefined") {
|
|
|
|
try {
|
2025-03-16 14:29:14 +01:00
|
|
|
const ls = localStorage.getItem( key);
|
2025-03-15 21:29:38 +01:00
|
|
|
if (ls) cachedSettings[key] = JSON.parse(ls) as T;
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cachedSettings[key] as T ?? defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setSettingValue<T>(key: string, value: T) {
|
|
|
|
cachedSettings[key] = value
|
|
|
|
try {
|
2025-03-16 14:29:14 +01:00
|
|
|
localStorage.setItem( key, JSON.stringify(value));
|
2025-03-15 21:29:38 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-16 14:29:14 +01:00
|
|
|
export function getTotalScore() {
|
|
|
|
return getSettingValue('breakout_71_total_score', 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addToTotalScore(gameState: GameState, points: number) {
|
|
|
|
if (gameState.isCreativeModeRun) return;
|
|
|
|
setSettingValue('breakout_71_total_score', getTotalScore() + points)
|
|
|
|
}
|
|
|
|
|