fix(know-your-world): use localPlayerId for cursor updates in all modes
Each player now broadcasts their own cursor using their local player ID, not state.currentPlayer. This fixes collaborative mode where only one cursor was visible because all players were using the same player ID. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,7 @@ interface KnowYourWorldContextValue {
|
||||
|
||||
// Cursor position sharing (for multiplayer)
|
||||
otherPlayerCursors: Record<string, { x: number; y: number } | null>
|
||||
sendCursorUpdate: (cursorPosition: { x: number; y: number } | null) => void
|
||||
sendCursorUpdate: (playerId: string, cursorPosition: { x: number; y: number } | null) => void
|
||||
}
|
||||
|
||||
const KnowYourWorldContext = createContext<KnowYourWorldContextValue | null>(null)
|
||||
@@ -122,14 +122,14 @@ export function KnowYourWorldProvider({ children }: { children: React.ReactNode
|
||||
applyMove: (state) => state, // Server handles all state updates
|
||||
})
|
||||
|
||||
// Wrap sendCursorUpdate to automatically include the current player ID
|
||||
// Pass through cursor updates with the provided player ID
|
||||
const sendCursorUpdate = useCallback(
|
||||
(cursorPosition: { x: number; y: number } | null) => {
|
||||
if (state.currentPlayer) {
|
||||
sessionSendCursorUpdate(state.currentPlayer, cursorPosition)
|
||||
(playerId: string, cursorPosition: { x: number; y: number } | null) => {
|
||||
if (playerId) {
|
||||
sessionSendCursorUpdate(playerId, cursorPosition)
|
||||
}
|
||||
},
|
||||
[state.currentPlayer, sessionSendCursorUpdate]
|
||||
[sessionSendCursorUpdate]
|
||||
)
|
||||
|
||||
// Action: Start Game
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo } from 'react'
|
||||
import { useCallback, useMemo } from 'react'
|
||||
import { css } from '@styled/css'
|
||||
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels'
|
||||
import { useKnowYourWorld } from '../Provider'
|
||||
@@ -28,6 +28,14 @@ export function PlayingPhase() {
|
||||
return Array.from(activePlayers)[0] || ''
|
||||
}, [activePlayers, players])
|
||||
|
||||
// Wrap sendCursorUpdate to include localPlayerId
|
||||
const handleCursorUpdate = useCallback(
|
||||
(cursorPosition: { x: number; y: number } | null) => {
|
||||
sendCursorUpdate(localPlayerId, cursorPosition)
|
||||
},
|
||||
[localPlayerId, sendCursorUpdate]
|
||||
)
|
||||
|
||||
const mapData = getFilteredMapDataSync(
|
||||
state.selectedMap,
|
||||
state.selectedContinent,
|
||||
@@ -136,7 +144,7 @@ export function PlayingPhase() {
|
||||
currentPlayer={state.currentPlayer}
|
||||
localPlayerId={localPlayerId}
|
||||
otherPlayerCursors={otherPlayerCursors}
|
||||
onCursorUpdate={sendCursorUpdate}
|
||||
onCursorUpdate={handleCursorUpdate}
|
||||
/>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
Reference in New Issue
Block a user