import Phaser from 'phaser';
import { MAP_KEYS } from '../data';

export class BootScene extends Phaser.Scene {
  constructor() { super('BootScene'); }

  preload(): void {
    this.load.image('tiles', 'assets/tileset.png');
    this.load.spritesheet('characters', 'assets/characters.png', { frameWidth: 16, frameHeight: 24 });
    this.load.spritesheet('portraits', 'assets/portraits.png', { frameWidth: 48, frameHeight: 48 });
    MAP_KEYS.forEach((key) => this.load.tilemapTiledJSON(key, `maps/${key}.json`));
  }

  create(): void {
    const directionFrames = [
      ['walk-down', 0], ['walk-up', 4], ['walk-left', 8], ['walk-right', 12],
    ] as const;
    directionFrames.forEach(([key, start]) => {
      if (!this.anims.exists(key)) this.anims.create({ key, frames: this.anims.generateFrameNumbers('characters', { start, end: start + 3 }), frameRate: 8, repeat: -1 });
    });
    if (!this.anims.exists('birds-sing')) this.anims.create({ key: 'birds-sing', frames: [{ key: 'characters', frame: 42 }, { key: 'characters', frame: 43 }], frameRate: 3, repeat: -1 });
    this.scene.start('TitleScene');
  }
}
