zippy-game-engine
Version:
A lightweight game engine for web games
62 lines • 2.01 kB
JavaScript
import { SceneSystem } from "../scene-system/scene-system.js";
export class GameEngine {
inputSystem;
sceneSystem;
debugMode = false;
sceneMode = "current";
constructor(inputSystem, sceneSystem) {
this.inputSystem = inputSystem;
this.sceneSystem = sceneSystem;
}
handleDebugToggle() {
this.debugMode = !this.debugMode;
console.log(`Debug mode: ${this.debugMode ? "ON" : "OFF"}`);
}
toggleSceneMode() {
this.sceneMode = this.sceneMode === "current" ? "all" : "current";
this.sceneSystem.setMode(this.sceneMode);
if (this.debugMode)
console.log(`Scene mode: ${this.sceneMode.toUpperCase()}`);
}
setSceneMode(mode) {
this.sceneMode = mode;
this.sceneSystem.setMode(mode);
if (this.debugMode)
console.log(`Scene mode set to: ${mode.toUpperCase()}`);
}
getSceneMode() {
return this.sceneMode;
}
frameTick = (context) => {
this.inputSystem.update();
//this.sceneSystem.currentScene?.update?.(context);
//this.sceneSystem.currentScene?.render?.(context);
if (this.sceneMode === "current") {
this.sceneSystem.currentScene?.update?.(context);
this.sceneSystem.currentScene?.render?.(context);
}
else {
this.sceneSystem.updateAllScenes(context);
this.sceneSystem.renderAllScenes(context);
}
};
get availableScenes() {
return this.sceneSystem.availableScenes;
}
get activeScene() {
return this.sceneSystem.activeScene;
}
get input() {
return this.inputSystem;
}
onSceneChange(callback) {
return this.sceneSystem.onSceneChange(callback);
}
transitionToScene(name) {
return this.sceneSystem.transitionToScene(name);
}
registerScene(name, sceneModule) {
this.sceneSystem.registerScene(name, sceneModule);
}
}
//# sourceMappingURL=game-engine.js.map