// main.ts: Phaser game config & entry point.
import Phaser from 'phaser';
import { BootScene } from './scenes/BootScene';
import { TitleScene } from './scenes/TitleScene';
import { UIScene } from './scenes/UIScene';
import { HouseScene } from './scenes/maps/HouseScene';
import { PlazaScene } from './scenes/maps/PlazaScene';
import { BakeryScene } from './scenes/maps/BakeryScene';
import { ShopScene } from './scenes/maps/ShopScene';
import { ClinicScene } from './scenes/maps/ClinicScene';
import { LakeScene } from './scenes/maps/LakeScene';
import { FieldScene } from './scenes/maps/FieldScene';
import { WellAreaScene } from './scenes/maps/WellAreaScene';
import { FogBoundaryScene } from './scenes/maps/FogBoundaryScene';
import { WhiteLayerScene } from './scenes/maps/WhiteLayerScene';
import { EndingScene } from './scenes/EndingScene';
import { DebugScene } from './scenes/DebugScene';

const W = 320, H = 180;
const SCALE = Math.max(1, Math.floor(Math.min(window.innerWidth / W, window.innerHeight / H)));

const config: Phaser.Types.Core.GameConfig = {
  type: Phaser.AUTO,
  parent: 'game',
  width: W,
  height: H,
  zoom: SCALE,
  pixelArt: true,
  render: { pixelArt: true, antialias: false, roundPixels: true, preserveDrawingBuffer: true },
  physics: { default: 'arcade', arcade: { debug: false, gravity: { x: 0, y: 0 } } },
  scale: { mode: Phaser.Scale.FIT, autoCenter: Phaser.Scale.CENTER_BOTH, width: W, height: H },
  backgroundColor: '#000000',
  scene: [
    BootScene, TitleScene, UIScene,
    HouseScene, PlazaScene, BakeryScene, ShopScene, ClinicScene,
    LakeScene, FieldScene, WellAreaScene, FogBoundaryScene, WhiteLayerScene,
    EndingScene, DebugScene,
  ],
};

const game = new Phaser.Game(config);
// expose for debugging/testing (no functional impact)
;(globalThis as any).game = game;
import { director } from './systems/CorruptionDirector';
;(globalThis as any).director = director;

// responsive resize keeps integer scaling via FIT; nothing else needed.
window.addEventListener('keydown', (e) => {
  if (['ArrowUp','ArrowDown','ArrowLeft','ArrowRight',' '].includes(e.key)) e.preventDefault();
});

export { game };
