Build 29079087

This commit is contained in:
Renan LE CARO 2025-04-15 21:28:00 +02:00
parent 06843047d2
commit 8e4e67e33b
17 changed files with 199 additions and 234 deletions

View file

@ -2,15 +2,14 @@
let cachedSettings: { [key: string]: unknown } = {};
try {
for(let key in localStorage){
try {
cachedSettings[key] = JSON.parse(localStorage.getItem(key)||'null') ;
} catch (e) {
console.warn(e);
}
}
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);
}
@ -20,24 +19,23 @@ export function getSettingValue<T>(key: string, defaultValue: T) {
}
// We avoid using localstorage synchronously for perf reasons
let needsSaving= new Set()
let needsSaving: Set<string> = new Set();
export function setSettingValue<T>(key: string, value: T) {
if(cachedSettings[key] !==value){
needsSaving.add(key)
cachedSettings[key] = value;
if (cachedSettings[key] !== value) {
needsSaving.add(key);
cachedSettings[key] = value;
}
}
setInterval(()=>{
setInterval(() => {
try {
for(let key of needsSaving){
localStorage.setItem(key, JSON.stringify(cachedSettings[key]));
for (let key of needsSaving) {
localStorage.setItem(key, JSON.stringify(cachedSettings[key]));
}
needsSaving.clear()
needsSaving.clear();
} catch (e) {
console.warn(e);
}
}, 500)
}, 500);
export function getTotalScore() {
return getSettingValue("breakout_71_total_score", 0);
@ -47,7 +45,7 @@ export function getCurrentMaxCoins() {
return Math.pow(2, getSettingValue("max_coins", 2)) * 200;
}
export function getCurrentMaxParticles() {
return getCurrentMaxCoins()
return getCurrentMaxCoins();
}
export function cycleMaxCoins() {
setSettingValue("max_coins", (getSettingValue("max_coins", 2) + 1) % 7);