mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-21 20:46:14 -04:00
Build 29079087
This commit is contained in:
parent
06843047d2
commit
8e4e67e33b
17 changed files with 199 additions and 234 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue