import { makeAutoObservable } from "mobx"; import { WorldState } from "./worldState"; import { WorldEditorState } from "./worldEditorState"; import { GameState } from "./gameState"; import { MenuState } from "./menuState"; export type RenderInfo = { calls: number, triangles: number, shaders: number, geometries: number, textures: number, } export class RootState { public readonly world = new WorldState(); public readonly worldEditor: WorldEditorState; public game: GameState | undefined; public renderInfo: RenderInfo | undefined; public readonly menu = new MenuState(); constructor() { this.worldEditor = new WorldEditorState(this.world); makeAutoObservable( this, { world: false, menu: false, }, ); } public get isGamePlaying(): boolean { return this.game !== undefined; } public startGame(): void { state.worldEditor.resetSelection(); if (this.game) this.stopGame(); this.game = new GameState(this.world); } public stopGame(): void { if (!this.game) return; this.game.pause(); this.game = undefined; } public setRenderInfo(value: RenderInfo | undefined) { this.renderInfo = value; } } export const state = new RootState(); state.world.load();