import type { Game, RuntimeGameScene, RuntimeScene, World } from "../types"; import { clone } from "../utils"; import { populateRuntimeScene } from "../utils/runtime"; export class GameFactory { public static create(world: World): Game { const scene = populateRuntimeScene(clone(world.initialScene), world); return { paused: false, time: 0, scene: GameFactory.initGameScene(scene), } } public static load(): Game | undefined { const json = localStorage.getItem("game"); if (json) { return JSON.parse(json) as Game; } } public static save(game: Game): void { localStorage.setItem("game", JSON.stringify(game)); } private static initGameScene(scene: RuntimeScene): RuntimeGameScene { return scene as RuntimeGameScene; } }