mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-04-21 20:46:14 -04:00
Build 29035725
This commit is contained in:
parent
a1bf54af71
commit
819197031f
64 changed files with 3494 additions and 6921 deletions
|
@ -1,37 +1,35 @@
|
|||
// Settings
|
||||
|
||||
import {GameState} from "./types";
|
||||
import { GameState } from "./types";
|
||||
|
||||
let cachedSettings: { [key: string]: unknown } = {};
|
||||
|
||||
export function getSettingValue<T>(key: string, defaultValue: T) {
|
||||
if (typeof cachedSettings[key] == "undefined") {
|
||||
try {
|
||||
const ls = localStorage.getItem( key);
|
||||
if (ls) cachedSettings[key] = JSON.parse(ls) as T;
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
if (typeof cachedSettings[key] == "undefined") {
|
||||
try {
|
||||
const ls = localStorage.getItem(key);
|
||||
if (ls) cachedSettings[key] = JSON.parse(ls) as T;
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
return cachedSettings[key] as T ?? defaultValue;
|
||||
}
|
||||
return (cachedSettings[key] as T) ?? defaultValue;
|
||||
}
|
||||
|
||||
export function setSettingValue<T>(key: string, value: T) {
|
||||
cachedSettings[key] = value
|
||||
try {
|
||||
localStorage.setItem( key, JSON.stringify(value));
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
cachedSettings[key] = value;
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
} catch (e) {
|
||||
console.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
export function getTotalScore() {
|
||||
return getSettingValue('breakout_71_total_score', 0)
|
||||
|
||||
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)
|
||||
if (gameState.isCreativeModeRun) return;
|
||||
setSettingValue("breakout_71_total_score", getTotalScore() + points);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue