import { gameManager } from './core/GameManager'; import { GameScene } from './scenes/GameScene'; import { injectGlobalTheme } from './ui/theme'; import './ui/UIManager'; import { modManager } from './mods/ModManager'; import { dataRegistry } from './data/DataRegistry'; import { titleMenuUI } from './ui/components/TitleMenuUI'; import { CharacterCreationUI } from './ui/components/CharacterCreationUI'; import { eventBus } from './core/EventBus'; import './systems/AudioManager'; injectGlobalTheme(); let gameStarted = false; async function initGame(): Promise { modManager.loadConfig(); await loadExampleMods(); await dataRegistry.loadAll(); // Show title menu instead of starting game directly titleMenuUI.show(); // Listen for title menu actions eventBus.on('game:newGame', () => { const creationUI = new CharacterCreationUI(); creationUI.show(); }); eventBus.on('game:start', () => { startGame(); }); eventBus.on('game:continue', () => { startGame(); }); eventBus.on('game:loadMenu', () => { startGame(); }); // Handle resize (debounced) let resizeTimer: ReturnType; window.addEventListener('resize', () => { clearTimeout(resizeTimer); resizeTimer = setTimeout(() => { const game = gameManager.getGame(); if (game) { game.scale.resize(window.innerWidth, window.innerHeight); } }, 100); }); } function startGame(): void { if (gameStarted) return; gameStarted = true; gameManager.init( { width: window.innerWidth, height: window.innerHeight, parent: 'game-container', }, [GameScene] ); // Allow returning to title menu eventBus.on('game:returnToMenu', () => { gameStarted = false; }); } async function loadExampleMods(): Promise { const mods = [ '/data/mods/example-weapons-mod.json', '/data/mods/example-quest-mod.json', '/data/mods/base-scripts-mod.json', '/data/mods/example-spell-mod.json', '/data/mods/example-armor-mod.json', ]; await Promise.all(mods.map(async (url) => { try { const response = await fetch(url); if (response.ok) { const mod = await response.json(); await modManager.installMod(mod.manifest, mod.data, mod.scripts); } } catch { // Mod not found, skip } })); } initGame();