Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9caa47a830 |
+8
-3
@@ -5,15 +5,20 @@ export const saveParams = {
|
|||||||
path: 'default',
|
path: 'default',
|
||||||
}
|
}
|
||||||
|
|
||||||
const KEY_GAME = 'incgame';
|
const DEFAULT_KEY_GAME = 'incgame';
|
||||||
|
|
||||||
|
function getKeyGame(): string {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
return params.get('game') || DEFAULT_KEY_GAME;
|
||||||
|
}
|
||||||
|
|
||||||
export function save(game: Game) {
|
export function save(game: Game) {
|
||||||
localStorage.setItem(`${saveParams.path}_${KEY_GAME}`, serializeGameToString(game));
|
localStorage.setItem(`${saveParams.path}_${getKeyGame()}`, serializeGameToString(game));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function load(): Game {
|
export function load(): Game {
|
||||||
try {
|
try {
|
||||||
const raw = localStorage.getItem(`${saveParams.path}_${KEY_GAME}`);
|
const raw = localStorage.getItem(`${saveParams.path}_${getKeyGame()}`);
|
||||||
if (raw)
|
if (raw)
|
||||||
return deserializeGameFromString(raw);
|
return deserializeGameFromString(raw);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user