From cdae675f9c4af0e0cceea33d30e9a2651520aea1 Mon Sep 17 00:00:00 2001 From: StillHammer Date: Mon, 13 Oct 2025 09:53:02 +0800 Subject: [PATCH] Fix RiverRun EventBus module name validation errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 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 --- src/games/RiverRun.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) 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() {