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
7 changes: 5 additions & 2 deletions src/components/game/IdleWorkerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ export function IdleWorkerButton() {
// Update idle worker count via event-driven approach + throttled polling
// Note: Hooks must be called unconditionally, so spectator check is after all hooks
useEffect(() => {
// Skip for spectators
if (isSpectator) return;
// Skip for spectators and reset count
if (isSpectator) {
setIdleWorkerCount(0);
return;
}
const bridge = getWorkerBridge();
if (!bridge) return;

Expand Down
2 changes: 2 additions & 0 deletions src/components/game/WebGPUGameCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export function WebGPUGameCanvas() {
const handleLoadingComplete = useCallback(() => {
setIsLoading(false);
useGameStore.getState().setGameReady(true);
// Sync playerId with game setup (handles spectator mode where localPlayerId is null)
useGameStore.getState().syncWithGameSetup();

setTimeout(() => {
const eventBus = workerBridgeRef.current?.eventBus;
Expand Down
6 changes: 3 additions & 3 deletions src/store/gameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ export const useGameStore = create<GameState>((set, get) => ({

syncWithGameSetup: () => {
const localPlayerId = getLocalPlayerId();
if (localPlayerId) {
set({ playerId: localPlayerId });
}
// Set playerId to local player, or empty string if spectating
// This ensures we don't keep showing player1's data when spectating
set({ playerId: localPlayerId ?? '' });
},

reset: () => set(initialState),
Expand Down