diff --git a/src/games/RiverRun.js b/src/games/RiverRun.js index 37f5c3e..7424706 100644 --- a/src/games/RiverRun.js +++ b/src/games/RiverRun.js @@ -2,12 +2,17 @@ import Module from '../core/Module.js'; class RiverRun extends Module { constructor(name, dependencies, config = {}) { - super(name, ['eventBus']); + super(name || 'river-run', ['eventBus']); if (!dependencies.eventBus || !dependencies.content) { throw new Error('RiverRun requires eventBus and content dependencies'); } + // Ensure name is always defined (fallback to gameId) + if (!this.name) { + this.name = 'river-run'; + } + this._eventBus = dependencies.eventBus; this._content = dependencies.content; this._config = { @@ -609,7 +614,7 @@ class RiverRun extends Module { gameId: 'river-run', score: this._score, module: this.name - }); + }, this.name); this._setNextTarget(); this._playSuccessSound(wordElement.textContent); @@ -688,6 +693,9 @@ class RiverRun extends Module { localStorage.setItem('river-run-best-score', currentScore.toString()); } + // Emit game end event BEFORE showing popup + this._endGame(); + this._showVictoryPopup({ gameTitle: 'River Run', currentScore, @@ -703,11 +711,12 @@ class RiverRun extends Module { } _endGame() { + // Use gameId instead of this.name which might be undefined this._eventBus.emit('game:end', { gameId: 'river-run', score: this._score, - module: this.name - }); + module: this.name || 'river-run' + }, this.name || 'river-run'); } _updateHUD() { @@ -1406,11 +1415,6 @@ class RiverRun extends Module { `; document.body.appendChild(popup); - - // Emit completion event after showing popup - setTimeout(() => { - this._endGame(); - }, 1000); } _removeCSS() {