// 白色层（20×14：上半 20×6 走廊 + 左下 10×8 病房）。
// 仅梦境闪切与 E3 使用。E3 模式：穿过走廊走进病房 → 病历特写（EndingScene）。

import Phaser from 'phaser';
import { MapScene } from './MapScene';

export class WhiteScene extends MapScene {
  readonly mapKey = 'white';

  constructor() {
    super('WhiteScene');
  }

  private e3 = false;
  private wardTriggered = false;
  private wardX = 80;
  private wardY = 120;

  protected onReady(data: { spawn?: string; e3?: boolean }): void {
    this.e3 = !!data?.e3;
    this.wardTriggered = false;
    // 病房内部（20×14：走廊行 1-5，病房行 7-12 列 1-8，入口缺口在列 4-5 行 6）
    this.wardX = 4.5 * 16;
    this.wardY = 9 * 16;
  }

  protected extraUpdate(): void {
    if (!this.e3 || this.wardTriggered) return;
    const d = Phaser.Math.Distance.Between(this.player.x, this.player.y, this.wardX, this.wardY);
    if (d <= 24) {
      this.wardTriggered = true;
      this.cameras.main.fadeOut(800, 255, 255, 255);
      this.cameras.main.once('camerafadeoutcomplete', () => {
        this.scene.start('EndingScene', { ending: 'E3' });
      });
    }
  }
}
