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
2 changes: 2 additions & 0 deletions src/components/game/WebGPUGameCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function WebGPUGameCanvas() {
gameRef,
worldProviderRef,
eventBusRef,
isInitialized: isWorkerInitialized,
isGameFinished,
initializeWorkerBridge,
spawnEntities,
Expand Down Expand Up @@ -143,6 +144,7 @@ export function WebGPUGameCanvas() {
gameRef,
worldProviderRef,
eventBusRef,
isGameInitialized: isWorkerInitialized,
placementPreviewRef: refs.placementPreview,
wallPlacementPreviewRef: refs.wallPlacementPreview,
overlayManagerRef: refs.overlayManager,
Expand Down
15 changes: 11 additions & 4 deletions src/components/game/hooks/useGameInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface UseGameInputProps {
worldProviderRef?: MutableRefObject<IWorldProvider | null>;
/** Event bus for emitting commands - if provided, uses this instead of game.eventBus */
eventBusRef?: MutableRefObject<EventBus | null>;
/** Signal that game is initialized - triggers InputManager dependency update */
isGameInitialized?: boolean;
placementPreviewRef: MutableRefObject<BuildingPlacementPreview | null>;
/** @deprecated No longer used - wall placement handled by BuildingInputHandler */
wallPlacementPreviewRef?: MutableRefObject<WallPlacementPreview | null>;
Expand Down Expand Up @@ -68,7 +70,8 @@ export function useGameInput({
cameraRef,
gameRef,
worldProviderRef,
eventBusRef,
eventBusRef: _eventBusRef,
isGameInitialized,
placementPreviewRef,
wallPlacementPreviewRef: _wallPlacementPreviewRef,
overlayManagerRef: _overlayManagerRef,
Expand Down Expand Up @@ -114,11 +117,13 @@ export function useGameInput({
inputManager.registerHandler('landing', buildingHandler);

// Initialize with container
// Use game.eventBus for selection events - these are internal to main thread
// and SelectionSystem listens on game.eventBus, not bridge.eventBus
inputManager.initialize(container, {
camera: cameraRef.current,
game: gameRef.current,
worldProvider: worldProviderRef?.current ?? (gameRef.current?.world as unknown as IWorldProvider),
eventBus: eventBusRef?.current ?? gameRef.current?.eventBus,
eventBus: gameRef.current?.eventBus,
getLocalPlayerId,
});

Expand All @@ -141,13 +146,15 @@ export function useGameInput({
if (!initializedRef.current) return;

const inputManager = InputManager.getInstance();
// Use game.eventBus for selection events - these are internal to main thread
// and SelectionSystem listens on game.eventBus, not bridge.eventBus
inputManager.updateDependencies({
camera: cameraRef.current,
game: gameRef.current,
worldProvider: worldProviderRef?.current ?? (gameRef.current?.world as unknown as IWorldProvider),
eventBus: eventBusRef?.current ?? gameRef.current?.eventBus,
eventBus: gameRef.current?.eventBus,
});
}, [cameraRef, gameRef, worldProviderRef, eventBusRef]);
}, [cameraRef, gameRef, worldProviderRef, isGameInitialized]);

// Update building handler with placement preview
useEffect(() => {
Expand Down
Loading