multirepo
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { defaultGame } from "./prefabs/game";
|
||||
import { Game, serializeGameToString, deserializeGame, deserializeGameFromString } from '@incgame/engine';
|
||||
|
||||
export const saveParams = {
|
||||
path: 'default',
|
||||
}
|
||||
|
||||
const KEY_GAME = 'incgame';
|
||||
|
||||
export function save(game: Game) {
|
||||
localStorage.setItem(`${saveParams.path}_${KEY_GAME}`, serializeGameToString(game));
|
||||
}
|
||||
|
||||
export function load(): Game {
|
||||
try {
|
||||
const raw = localStorage.getItem(`${saveParams.path}_${KEY_GAME}`);
|
||||
if (raw)
|
||||
return deserializeGameFromString(raw);
|
||||
} catch (e) {
|
||||
console.warn('Не удалось прочитать игру из localStorage', e);
|
||||
}
|
||||
const fresh = deserializeGame(defaultGame());
|
||||
save(fresh);
|
||||
return fresh;
|
||||
}
|
||||
Reference in New Issue
Block a user