breakout71/src/settings.ts

44 lines
972 B
TypeScript
Raw Normal View History

2025-03-15 21:29:38 +01:00
// Settings
let cachedSettings: { [key: string]: unknown } = {};
2025-04-15 17:31:57 +02:00
try {
for(let key in localStorage){
try {
cachedSettings[key] = JSON.parse(localStorage.getItem(key)||'null') ;
} catch (e) {
console.warn(e);
}
}
} catch (e) {
console.warn(e);
}
2025-03-15 21:29:38 +01:00
export function getSettingValue<T>(key: string, defaultValue: T) {
2025-03-16 17:45:29 +01:00
return (cachedSettings[key] as T) ?? defaultValue;
2025-03-15 21:29:38 +01:00
}
export function setSettingValue<T>(key: string, value: T) {
2025-03-16 17:45:29 +01:00
cachedSettings[key] = value;
try {
localStorage.setItem(key, JSON.stringify(value));
} catch (e) {
console.warn(e);
}
2025-03-15 21:29:38 +01:00
}
export function getTotalScore() {
2025-03-16 17:45:29 +01:00
return getSettingValue("breakout_71_total_score", 0);
}
2025-03-23 16:11:12 +01:00
export function getCurrentMaxCoins() {
2025-04-15 17:31:57 +02:00
return Math.pow(2, getSettingValue("max_coins", 2)) * 200;
2025-03-23 16:11:12 +01:00
}
export function getCurrentMaxParticles() {
2025-04-15 16:47:04 +02:00
return getCurrentMaxCoins()
}
2025-03-23 16:11:12 +01:00
export function cycleMaxCoins() {
2025-04-15 17:31:57 +02:00
setSettingValue("max_coins", (getSettingValue("max_coins", 2) + 1) % 10);
}