Fix RiverRun EventBus module name validation errors
🐛 Bug Fixed: "Module name must be a non-empty string" errors throughout RiverRun gameplay 🔍 Root Causes: 1. Module constructor not ensuring this.name is always defined 2. EventBus.emit() calls missing required third parameter (moduleName) 3. GameLoader may instantiate modules without providing a name 🔧 Solutions Applied: **Constructor (lines 5, 11-14):** - Added fallback: super(name || 'river-run', ['eventBus']) - Explicit check: if (!this.name) this.name = 'river-run' - Guarantees this.name is always 'river-run' if undefined **_collectWord() (line 617):** - Added missing third parameter to emit call - Before: emit('game:score-update', {...}) - After: emit('game:score-update', {...}, this.name) **_endGame() (line 719):** - Added fallback for module name in emit - emit('game:end', {...}, this.name || 'river-run') ✅ Result: - All EventBus validation passes - Game works during gameplay (collecting words, scoring) - Game Over screen works without errors - Play Again button works correctly 🎮 Tested: - Launch game ✅ - Collect correct words ✅ - Miss words ✅ - Game over ✅ - Replay ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6cafb9218b
commit
cdae675f9c
@ -2,12 +2,17 @@ import Module from '../core/Module.js';
|
|||||||
|
|
||||||
class RiverRun extends Module {
|
class RiverRun extends Module {
|
||||||
constructor(name, dependencies, config = {}) {
|
constructor(name, dependencies, config = {}) {
|
||||||
super(name, ['eventBus']);
|
super(name || 'river-run', ['eventBus']);
|
||||||
|
|
||||||
if (!dependencies.eventBus || !dependencies.content) {
|
if (!dependencies.eventBus || !dependencies.content) {
|
||||||
throw new Error('RiverRun requires eventBus and content dependencies');
|
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._eventBus = dependencies.eventBus;
|
||||||
this._content = dependencies.content;
|
this._content = dependencies.content;
|
||||||
this._config = {
|
this._config = {
|
||||||
@ -609,7 +614,7 @@ class RiverRun extends Module {
|
|||||||
gameId: 'river-run',
|
gameId: 'river-run',
|
||||||
score: this._score,
|
score: this._score,
|
||||||
module: this.name
|
module: this.name
|
||||||
});
|
}, this.name);
|
||||||
|
|
||||||
this._setNextTarget();
|
this._setNextTarget();
|
||||||
this._playSuccessSound(wordElement.textContent);
|
this._playSuccessSound(wordElement.textContent);
|
||||||
@ -688,6 +693,9 @@ class RiverRun extends Module {
|
|||||||
localStorage.setItem('river-run-best-score', currentScore.toString());
|
localStorage.setItem('river-run-best-score', currentScore.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emit game end event BEFORE showing popup
|
||||||
|
this._endGame();
|
||||||
|
|
||||||
this._showVictoryPopup({
|
this._showVictoryPopup({
|
||||||
gameTitle: 'River Run',
|
gameTitle: 'River Run',
|
||||||
currentScore,
|
currentScore,
|
||||||
@ -703,11 +711,12 @@ class RiverRun extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_endGame() {
|
_endGame() {
|
||||||
|
// Use gameId instead of this.name which might be undefined
|
||||||
this._eventBus.emit('game:end', {
|
this._eventBus.emit('game:end', {
|
||||||
gameId: 'river-run',
|
gameId: 'river-run',
|
||||||
score: this._score,
|
score: this._score,
|
||||||
module: this.name
|
module: this.name || 'river-run'
|
||||||
});
|
}, this.name || 'river-run');
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateHUD() {
|
_updateHUD() {
|
||||||
@ -1406,11 +1415,6 @@ class RiverRun extends Module {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
document.body.appendChild(popup);
|
document.body.appendChild(popup);
|
||||||
|
|
||||||
// Emit completion event after showing popup
|
|
||||||
setTimeout(() => {
|
|
||||||
this._endGame();
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_removeCSS() {
|
_removeCSS() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user