feat:mod管理器
This commit is contained in:
+47
-12
@@ -4,15 +4,54 @@ 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 { eventBus } from './core/EventBus';
|
||||
|
||||
injectGlobalTheme();
|
||||
|
||||
let gameStarted = false;
|
||||
|
||||
async function initGame(): Promise<void> {
|
||||
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', () => {
|
||||
startGame();
|
||||
});
|
||||
|
||||
eventBus.on('game:continue', () => {
|
||||
startGame();
|
||||
});
|
||||
|
||||
eventBus.on('game:loadMenu', () => {
|
||||
// For now, just start game - full load menu would show save list
|
||||
startGame();
|
||||
});
|
||||
|
||||
// Handle resize (debounced)
|
||||
let resizeTimer: ReturnType<typeof setTimeout>;
|
||||
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,
|
||||
@@ -22,15 +61,10 @@ async function initGame(): Promise<void> {
|
||||
[GameScene]
|
||||
);
|
||||
|
||||
// Handle resize
|
||||
window.addEventListener('resize', () => {
|
||||
const game = gameManager.getGame();
|
||||
if (game) {
|
||||
game.scale.resize(window.innerWidth, window.innerHeight);
|
||||
}
|
||||
// Allow returning to title menu
|
||||
eventBus.on('game:returnToMenu', () => {
|
||||
gameStarted = false;
|
||||
});
|
||||
|
||||
console.log('OES-WEB initialized');
|
||||
}
|
||||
|
||||
async function loadExampleMods(): Promise<void> {
|
||||
@@ -38,20 +72,21 @@ async function loadExampleMods(): Promise<void> {
|
||||
'/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',
|
||||
];
|
||||
|
||||
for (const url of mods) {
|
||||
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);
|
||||
console.log(`Loaded mod: ${mod.manifest.id}`);
|
||||
}
|
||||
} catch {
|
||||
console.log(`Mod not found: ${url}, skipping`);
|
||||
// Mod not found, skip
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
initGame();
|
||||
|
||||
Reference in New Issue
Block a user