feat:mod管理器

This commit is contained in:
Evilom
2026-05-13 21:17:58 +08:00
parent 93961c10bb
commit 86ceec98b3
41 changed files with 4533 additions and 400 deletions
+47 -12
View File
@@ -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();