mirror of
https://github.com/Kugelschieber/breach.git
synced 2026-01-18 12:00:25 +00:00
Added function to save and load a save game.
This commit is contained in:
20
src/game/SaveGame.ts
Normal file
20
src/game/SaveGame.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export const saveGameKey = "save_game";
|
||||
|
||||
export interface SaveGame {
|
||||
Level: number
|
||||
Score: number
|
||||
}
|
||||
|
||||
export function saveGame(saveGame: SaveGame) {
|
||||
localStorage.setItem(saveGameKey, JSON.stringify(saveGame));
|
||||
}
|
||||
|
||||
export function loadGame(): SaveGame | null {
|
||||
const saveGame = localStorage.getItem(saveGameKey);
|
||||
|
||||
if(saveGame) {
|
||||
return JSON.parse(saveGame);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user