Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9caa47a830 |
+8
-3
@@ -5,15 +5,20 @@ export const saveParams = {
|
||||
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) {
|
||||
localStorage.setItem(`${saveParams.path}_${KEY_GAME}`, serializeGameToString(game));
|
||||
localStorage.setItem(`${saveParams.path}_${getKeyGame()}`, serializeGameToString(game));
|
||||
}
|
||||
|
||||
export function load(): Game {
|
||||
try {
|
||||
const raw = localStorage.getItem(`${saveParams.path}_${KEY_GAME}`);
|
||||
const raw = localStorage.getItem(`${saveParams.path}_${getKeyGame()}`);
|
||||
if (raw)
|
||||
return deserializeGameFromString(raw);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user