import { BG_OUTER } from "./colors.ts"; import { D, I } from "./engine/public.ts"; import { IGame, Point, Size } from "./engine/datatypes.ts"; import { getHotbar, Hotbar } from "./hotbar.ts"; import { getSkillsModal, SkillsModal } from "./skillsmodal.ts"; import { getVNModal, VNModal } from "./vnmodal.ts"; import { Gameplay, getGameplay } from "./gameplay.ts"; import { getEndgameModal } from "./endgamemodal.ts"; import { CheckModal, getCheckModal } from "./checkmodal.ts"; export class Game implements IGame { #mainThing: Gameplay | VNModal | null; #bottomThing: CheckModal | SkillsModal | Hotbar | null; constructor() { this.#mainThing = null; this.#bottomThing = null; } update() { D.camera = new Point(0, 0); // state-specific updates this.updateGameplay(); } draw() { // draw screen background let oldCamera = D.camera; D.camera = new Point(0, 0); D.fillRect(new Point(0, 0), D.size, BG_OUTER); D.camera = oldCamera; this.drawGameplay(); // we draw all states at once and pan between them // mainFont.drawText({ctx: ctx, text: "You have been given a gift.", x: 0, y: 0}) let mouse = I.mousePosition?.offset(D.camera); if (mouse != null) { D.invertRect(mouse.offset(new Point(-1, -1)), new Size(3, 3)); } } updateGameplay() { this.#chooseMainThing(); this.#chooseBottomThing(); this.#mainThing?.update(); if (!this.#mainThing?.blocksHud) { this.#bottomThing?.update(); } } drawGameplay() { this.#mainThing?.draw(); if (!this.#mainThing?.blocksHud) { this.#bottomThing?.draw(); } } #chooseBottomThing() { // This is explicitly chosen because we would prefer that // the same bottomThing be used in both draw and update, // meaning that events after this in updateGameplay should not affect // its value let checkModal = getCheckModal(); if (checkModal.isShown) { this.#bottomThing = checkModal; return; } let skillsModal = getSkillsModal(); if (skillsModal.isShown) { this.#bottomThing = skillsModal; return; } // use the hotbar only as a matter of last resort this.#bottomThing = getHotbar(); } #chooseMainThing() { let vnModal = getVNModal(); if (vnModal.isShown) { this.#mainThing = vnModal; return; } let endgameModal = getEndgameModal(); if (endgameModal.isShown) { this.#mainThing = endgameModal; return; } this.#mainThing = getGameplay(); } } export let game = new Game();