diff --git a/src/components/game/hooks/useGameInput.ts b/src/components/game/hooks/useGameInput.ts index 64899819..36c52d07 100644 --- a/src/components/game/hooks/useGameInput.ts +++ b/src/components/game/hooks/useGameInput.ts @@ -70,7 +70,7 @@ export function useGameInput({ cameraRef, gameRef, worldProviderRef, - eventBusRef: _eventBusRef, + eventBusRef, isGameInitialized, placementPreviewRef, wallPlacementPreviewRef: _wallPlacementPreviewRef, @@ -156,6 +156,32 @@ export function useGameInput({ }); }, [cameraRef, gameRef, worldProviderRef, isGameInitialized]); + // ============================================================================= + // VISUAL FEEDBACK EVENT FORWARDING + // ============================================================================= + + // Forward visual feedback events from game.eventBus to bridge.eventBus + // OverlayScene (Phaser) listens on bridge.eventBus for ground click indicators + useEffect(() => { + const gameEventBus = gameRef.current?.eventBus; + const bridgeEventBus = eventBusRef?.current; + + // Only set up forwarding if both event buses exist and are different + if (!gameEventBus || !bridgeEventBus || gameEventBus === bridgeEventBus) return; + + // Forward ground click visual feedback events + const forwardMoveGround = (data: unknown) => bridgeEventBus.emit('command:moveGround', data); + const forwardAttackGround = (data: unknown) => bridgeEventBus.emit('command:attackGround', data); + + gameEventBus.on('command:moveGround', forwardMoveGround); + gameEventBus.on('command:attackGround', forwardAttackGround); + + return () => { + gameEventBus.off('command:moveGround', forwardMoveGround); + gameEventBus.off('command:attackGround', forwardAttackGround); + }; + }, [gameRef, eventBusRef, isGameInitialized]); + // Update building handler with placement preview useEffect(() => { if (handlersRef.current?.building) { diff --git a/src/engine/input/handlers/CommandInputHandler.ts b/src/engine/input/handlers/CommandInputHandler.ts index a3995a28..7947b2cd 100644 --- a/src/engine/input/handlers/CommandInputHandler.ts +++ b/src/engine/input/handlers/CommandInputHandler.ts @@ -69,10 +69,12 @@ export class CommandInputHandler implements InputHandler { switch (commandMode) { case 'attack': + // Use ATTACK_MOVE when clicking ground (no target entity) + // This ensures MovementOrchestrator handles pathfinding game.issueCommand({ tick: game.getCurrentTick(), playerId: localPlayer, - type: 'ATTACK', + type: 'ATTACK_MOVE', entityIds: selectedUnits, targetPosition: targetPos, queue: state.modifiers.shift,