localstorage key via query string

This commit is contained in:
azykov@mail.ru
2026-09-04 14:13:47 +03:00
parent 75050aaaa3
commit d154880c4c
+8 -3
View File
@@ -1,15 +1,20 @@
import { defaultGame } from "./prefabs/game";
import { Game, serializeGameToString, deserializeGame, deserializeGameFromString } from '@incgame/engine';
const KEY_GAME = 'incgame';
const DEFAULT_KEY_GAME = 'incgame';
function getLocalStorageKey(): string {
const params = new URLSearchParams(window.location.search);
return params.get('game') || DEFAULT_KEY_GAME;
}
export function save(game: Game) {
localStorage.setItem(KEY_GAME, serializeGameToString(game));
localStorage.setItem(getLocalStorageKey(), serializeGameToString(game));
}
export function load(): Game {
try {
const raw = localStorage.getItem(KEY_GAME);
const raw = localStorage.getItem(getLocalStorageKey());
if (raw)
return deserializeGameFromString(raw);
} catch (e) {