Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/components/game/hooks/useGameInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
cameraRef,
gameRef,
worldProviderRef,
eventBusRef: _eventBusRef,
eventBusRef,
isGameInitialized,
placementPreviewRef,
wallPlacementPreviewRef: _wallPlacementPreviewRef,
Expand Down Expand Up @@ -156,6 +156,32 @@
});
}, [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);

Check failure on line 180 in src/components/game/hooks/useGameInput.ts

View workflow job for this annotation

GitHub Actions / type-check

Argument of type '(data: unknown) => void' is not assignable to parameter of type 'number'.
gameEventBus.off('command:attackGround', forwardAttackGround);

Check failure on line 181 in src/components/game/hooks/useGameInput.ts

View workflow job for this annotation

GitHub Actions / type-check

Argument of type '(data: unknown) => void' is not assignable to parameter of type 'number'.
};
}, [gameRef, eventBusRef, isGameInitialized]);

// Update building handler with placement preview
useEffect(() => {
if (handlersRef.current?.building) {
Expand Down
4 changes: 3 additions & 1 deletion src/engine/input/handlers/CommandInputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading