// 《崩坏童话：蜜糖村》入口：Phaser 3 + TypeScript + Vite
// 逻辑分辨率 320×180，整数倍放大居中，pixelArt，禁用纹理平滑
import Phaser from "phaser";
import { BootScene } from "./scenes/BootScene";
import { TitleScene } from "./scenes/TitleScene";
import {
  HouseScene, PlazaScene, BakeryScene, StoreScene, ClinicScene, LakeScene,
  FieldScene, WellScene, FogwallScene, WhiteCorridorScene, WhiteWardScene,
} from "./scenes/WorldScene";
import { UIScene } from "./scenes/UIScene";
import { DreamScene } from "./scenes/DreamScene";
import { EndingScene } from "./scenes/EndingScene";
import { setupDebug } from "./core/debug";

function intZoom(): number {
  return Math.max(1, Math.floor(Math.min(window.innerWidth / 320, window.innerHeight / 180)));
}

const game = new Phaser.Game({
  type: Phaser.WEBGL,
  parent: "game",
  width: 320,
  height: 180,
  backgroundColor: "#1a1a22",
  pixelArt: true,
  roundPixels: true,
  physics: { default: "arcade", arcade: { debug: false } },
  scale: { mode: Phaser.Scale.NONE, zoom: intZoom() },
  scene: [
    BootScene, TitleScene,
    HouseScene, PlazaScene, BakeryScene, StoreScene, ClinicScene,
    LakeScene, FieldScene, WellScene, FogwallScene, WhiteCorridorScene, WhiteWardScene,
    UIScene, DreamScene, EndingScene,
  ],
});

window.addEventListener("resize", () => game.scale.setZoom(intZoom()));
setupDebug(game);

// 服务验收的只读钩子（与 Debug 面板同源，不影响正常游玩）
import { director } from "./core/director";
(window as any).__game = game;
(window as any).__director = director;
