Add initial configuration, HTML structure, and module loader implementation

master
SanjarBLZK 1 week ago
parent 6dfa10ca50
commit 1e55e1dd9a

@ -0,0 +1,5 @@
{
"name": "I love X (default)",
"assetsDir": "../assets/default",
"tickRate": 2
}

@ -1,10 +1,88 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>I Love X Engine</title> <title>I love X Engine</title>
<style>
body {
margin: 0;
padding: 0;
background: #000;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: Arial, sans-serif;
}
#game {
text-align: center;
}
.welcome-screen {
opacity: 1;
transition: opacity 0.5s;
}
.welcome-screen.hidden {
opacity: 0;
}
h1 {
font-size: 48px;
margin-bottom: 20px;
}
.start-message {
font-size: 24px;
color: #aaa;
}
.hidden {
display: none;
}
</style>
</head> </head>
<body> <body>
<h1>I Love X Engine (Electron)</h1> <div id="game">
<div id="welcome" class="welcome-screen">
<h1>Welkom bij I love X!</h1>
<p class="start-message">Druk op SPATIE om te beginnen</p>
</div>
</div>
<script>
const { ipcRenderer } = require('electron');
// Game state
let gameState = 'welcome';
// Handle keyboard input
document.addEventListener('keydown', (event) => {
if (event.code === 'Space' && gameState === 'welcome') {
startGame();
}
});
// Start game
function startGame() {
gameState = 'playing';
document.getElementById('welcome').classList.add('hidden');
ipcRenderer.send('game:start');
}
// Listen for engine events
ipcRenderer.on('engine:ready', (event, data) => {
console.log('Engine ready:', data);
});
ipcRenderer.on('game:started', () => {
console.log('Game started');
});
ipcRenderer.on('game:paused', () => {
console.log('Game paused');
});
</script>
</body> </body>
</html> </html>

@ -1,20 +1,23 @@
const { app, BrowserWindow } = require('electron'); const { app, BrowserWindow } = require('electron')
const path = require('path'); const path = require('path');
function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
function createWindow() { win.loadFile('index.html')
const win = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
});
win.loadFile('index.html');
} }
app.whenReady().then(createWindow); app.whenReady().then(() => {
createWindow()
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});

@ -0,0 +1,34 @@
const fs = require('fs');
const path = require('path');
class ModuleLoader {
constructor(modulesDir) {
this.modulesDir = path.resolve(modulesDir);
this.modules = {};
}
discover() {
if (!fs.existsSync(this.modulesDir)) return [];
const entries = fs.readdirSync(this.modulesDir, { withFileTypes: true });
return entries.filter(e => e.isDirectory()).map(d => d.name);
}
loadAll(engineContext) {
const names = this.discover();
names.forEach(name => {
const modPath = path.join(this.modulesDir, name);
try {
const mod = require(modPath);
if (typeof mod.init === 'function') {
mod.init(engineContext);
}
this.modules[name] = mod;
} catch (err) {
console.error(`Failed to load module ${name}:`, err && err.stack ? err.stack : err);
}
});
return this.modules;
}
}
module.exports = ModuleLoader;

@ -1,26 +0,0 @@
const ConfigLoader = require('./core/config-loader');
const AssetManager = require('./core/asset-manager');
const EventBus = require('./core/event-bus');
const GameLoop = require('./core/game-loop');
// Config pad kan via argumenten komen, standaard default.json
const configPath = process.argv[2] || '../configs/default.json';
const config = ConfigLoader.load(configPath);
const assetManager = new AssetManager(config.assetsDir || '../assets/default');
assetManager.loadAssets();
const eventBus = new EventBus();
const gameLoop = new GameLoop({
onUpdate: () => {
// Hier komt de game logica per tick
console.log('Game update');
},
onEnd: () => {
console.log('Game ended');
}
});
console.log('Engine gestart met config:', configPath);
gameLoop.start();

@ -0,0 +1,23 @@
class IntroScreen {
constructor(engine) {
this.engine = engine;
this.state = 'welcome';
}
init() {
// Intro screen is now handled by renderer process (HTML/CSS)
this.engine.events.emit('intro:ready');
}
}
module.exports = {
init(engine) {
console.log('[module:intro] Initializing...');
const intro = new IntroScreen(engine);
intro.init();
engine.events.on('intro:complete', () => {
console.log('[module:intro] Complete');
});
}
};
Loading…
Cancel
Save