parent
404617e16c
commit
d3be8915c0
@ -0,0 +1,24 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
class AssetManager {
|
||||||
|
constructor(assetDir) {
|
||||||
|
this.assetDir = path.resolve(assetDir);
|
||||||
|
this.assets = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
loadAssets() {
|
||||||
|
if (!fs.existsSync(this.assetDir)) return;
|
||||||
|
const files = fs.readdirSync(this.assetDir);
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = path.join(this.assetDir, file);
|
||||||
|
this.assets[file] = filePath;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getAsset(name) {
|
||||||
|
return this.assets[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = AssetManager;
|
@ -0,0 +1,15 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
class ConfigLoader {
|
||||||
|
static load(configPath) {
|
||||||
|
const fullPath = path.resolve(configPath);
|
||||||
|
if (!fs.existsSync(fullPath)) {
|
||||||
|
throw new Error(`Config file not found: ${fullPath}`);
|
||||||
|
}
|
||||||
|
const raw = fs.readFileSync(fullPath);
|
||||||
|
return JSON.parse(raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ConfigLoader;
|
@ -0,0 +1,20 @@
|
|||||||
|
class EventBus {
|
||||||
|
constructor() {
|
||||||
|
this.listeners = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
on(event, callback) {
|
||||||
|
if (!this.listeners[event]) {
|
||||||
|
this.listeners[event] = [];
|
||||||
|
}
|
||||||
|
this.listeners[event].push(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(event, data) {
|
||||||
|
if (this.listeners[event]) {
|
||||||
|
this.listeners[event].forEach(cb => cb(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = EventBus;
|
@ -0,0 +1,23 @@
|
|||||||
|
class GameLoop {
|
||||||
|
constructor({ onUpdate, onEnd }) {
|
||||||
|
this.running = false;
|
||||||
|
this.onUpdate = onUpdate;
|
||||||
|
this.onEnd = onEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
this.running = true;
|
||||||
|
while (this.running) {
|
||||||
|
if (this.onUpdate) this.onUpdate();
|
||||||
|
// Simpel voorbeeld: direct stoppen
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
if (this.onEnd) this.onEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
this.running = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = GameLoop;
|
@ -0,0 +1,26 @@
|
|||||||
|
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();
|
Loading…
Reference in new issue