import Phaser from 'phaser';
import { createInitialRunState, createInitialMetaState } from '@/types';

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

  create(): void {
    // Initialize registry with game state
    this.registry.set('runState', createInitialRunState());

    // Load meta state from localStorage or create new
    const savedMeta = localStorage.getItem('roguelite_save');
    if (savedMeta) {
      try {
        const parsed = JSON.parse(savedMeta);
        this.registry.set('metaState', parsed);
        console.log('Loaded metaState:', parsed.gasCoins, 'GasCoins');
      } catch (e) {
        console.error('Failed to parse save:', e);
        this.registry.set('metaState', createInitialMetaState());
      }
    } else {
      console.log('No save found, creating new metaState');
      this.registry.set('metaState', createInitialMetaState());
    }

    // Proceed to preload
    this.scene.start('PreloadScene');
  }
}
