Compare commits

...

6 Commits

Author SHA1 Message Date
semantic-release-bot
8473b6d670 chore(release): 2.17.2 [skip ci]
## [2.17.2](https://github.com/antialias/soroban-abacus-flashcards/compare/v2.17.1...v2.17.2) (2025-10-10)

### Bug Fixes

* correct playerMetadata userId assignment for room-based multiplayer ([53797db](53797dbb2d))
2025-10-10 13:45:17 +00:00
Thomas Hallock
53797dbb2d fix: correct playerMetadata userId assignment for room-based multiplayer
The bug: In RoomMemoryPairsProvider, playerMetadata[playerId].userId was
being set to the LOCAL viewerId for ALL players, including remote players
from other room members. This caused:
1. Turn indicator showing "Your turn" even when it was a remote player's turn
2. Incorrect player ownership validation

Root cause: Lines 378-390 and 442-454 in RoomMemoryPairsProvider were using
`userId: viewerId` for all players without checking actual ownership.

Fix:
- Added buildPlayerMetadata helper that builds a reverse mapping from
  roomData.memberPlayers (userId -> players[]) to determine correct ownership
- Uses playerOwnership map to assign correct userId to each player
- Updated both startGame and resetGame to use this helper

Testing:
- Added unit test documenting the bug and correct behavior
- Test verifies that local players get local userId and remote players
  get their actual owner's userId

Related files:
- PlayerStatusBar.tsx: Already correctly uses player.userId === viewerId
- MemoryGrid.tsx: Correctly filters avatars by current player

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-10 08:44:25 -05:00
semantic-release-bot
6b890b30f4 chore(release): 2.17.1 [skip ci]
## [2.17.1](https://github.com/antialias/soroban-abacus-flashcards/compare/v2.17.0...v2.17.1) (2025-10-10)

### Bug Fixes

* correct hover avatar and turn indicator to show only current player ([0596ef6](0596ef6587))
2025-10-10 13:31:44 +00:00
Thomas Hallock
0596ef6587 fix: correct hover avatar and turn indicator to show only current player
Previously, hover avatars were showing for remote players while the
current player's avatar was hidden. Also, the turn indicator was
incorrectly showing "Your turn" for all players regardless of whether
they belonged to the current viewer.

Changes:
- MemoryGrid: Filter hover avatars to show only for current player
  (playerId === state.currentPlayer) instead of remote players
- PlayerStatusBar: Check player ownership by comparing player.userId
  with viewerId instead of hardcoded gameMode check

This ensures:
1. Only the current player (whose turn it is) displays their hover avatar
2. Turn indicator correctly shows "Your turn" vs "Their turn" based on
   whether the current player belongs to the local viewer

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-10 08:30:58 -05:00
semantic-release-bot
debf786ed9 chore(release): 2.17.0 [skip ci]
## [2.17.0](https://github.com/antialias/soroban-abacus-flashcards/compare/v2.16.7...v2.17.0) (2025-10-10)

### Features

* hide hover avatar when card is flipped to reveal value ([a2aada2](a2aada2e69))
2025-10-10 13:18:37 +00:00
Thomas Hallock
a2aada2e69 feat: hide hover avatar when card is flipped to reveal value
Avatar now fades out when the card it's hovering over is flipped, ensuring
all users can clearly see revealed card values.

Changes:
- Add isCardFlipped prop to HoverAvatar component
- Check if hovered card is in flippedCards array or matched
- Update opacity calculation to hide avatar when card is flipped
- Avatar smoothly fades out via react-spring when card reveals

This ensures remote players' consideration doesn't obscure card values
during gameplay.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-10 08:17:37 -05:00
6 changed files with 235 additions and 41 deletions

View File

@@ -1,3 +1,24 @@
## [2.17.2](https://github.com/antialias/soroban-abacus-flashcards/compare/v2.17.1...v2.17.2) (2025-10-10)
### Bug Fixes
* correct playerMetadata userId assignment for room-based multiplayer ([53797db](https://github.com/antialias/soroban-abacus-flashcards/commit/53797dbb2d5ccb80e61cbc186ca0a344fe1fbd96))
## [2.17.1](https://github.com/antialias/soroban-abacus-flashcards/compare/v2.17.0...v2.17.1) (2025-10-10)
### Bug Fixes
* correct hover avatar and turn indicator to show only current player ([0596ef6](https://github.com/antialias/soroban-abacus-flashcards/commit/0596ef65879a303f1f71863ef307af69bf270c70))
## [2.17.0](https://github.com/antialias/soroban-abacus-flashcards/compare/v2.16.7...v2.17.0) (2025-10-10)
### Features
* hide hover avatar when card is flipped to reveal value ([a2aada2](https://github.com/antialias/soroban-abacus-flashcards/commit/a2aada2e6922fb3af363e0d191275e06b8f8f040))
## [2.16.7](https://github.com/antialias/soroban-abacus-flashcards/compare/v2.16.6...v2.16.7) (2025-10-10)

View File

@@ -1,9 +1,9 @@
'use client'
import { useSpring, animated } from '@react-spring/web'
import { animated, useSpring } from '@react-spring/web'
import { useEffect, useMemo, useRef, useState } from 'react'
import { css } from '../../../../../styled-system/css'
import { useViewerId } from '@/hooks/useViewerId'
import { css } from '../../../../../styled-system/css'
import { useMemoryPairs } from '../context/MemoryPairsContext'
import { getGridConfiguration } from '../utils/cardGeneration'
import { GameCard } from './GameCard'
@@ -88,11 +88,13 @@ function HoverAvatar({
playerInfo,
cardElement,
isPlayersTurn,
isCardFlipped,
}: {
playerId: string
playerInfo: { emoji: string; name: string; color?: string }
cardElement: HTMLElement | null
isPlayersTurn: boolean
isCardFlipped: boolean
}) {
const [position, setPosition] = useState<{ x: number; y: number } | null>(null)
const isFirstRender = useRef(true)
@@ -116,7 +118,8 @@ function HoverAvatar({
const springProps = useSpring({
x: position?.x ?? 0,
y: position?.y ?? 0,
opacity: position && isPlayersTurn && cardElement ? 1 : 0,
// Hide avatar if: no position, not player's turn, no card element, OR card is flipped
opacity: position && isPlayersTurn && cardElement && !isCardFlipped ? 1 : 0,
config: {
tension: 280,
friction: 60,
@@ -376,15 +379,13 @@ export function MemoryGrid() {
)}
{/* Animated Hover Avatars - Rendered as fixed positioned elements that smoothly transition */}
{/* Render one avatar per remote player - key by playerId to keep component alive */}
{/* Render one avatar per player - key by playerId to keep component alive */}
{state.playerHovers &&
Object.entries(state.playerHovers)
.filter(([playerId]) => {
// Don't show your own hover avatar (only show remote players)
// In local games, all players belong to this user
// In room games, check if player belongs to different user
const player = state.playerMetadata?.[playerId]
return player?.userId !== viewerId
// Only show avatar for the CURRENT player whose turn it is
// Don't show for other players (they're waiting for their turn)
return playerId === state.currentPlayer
})
.map(([playerId, cardId]) => {
const playerInfo = getPlayerHoverInfo(playerId)
@@ -392,6 +393,11 @@ export function MemoryGrid() {
const cardElement = cardId ? cardRefs.current.get(cardId) : null
// Check if it's this player's turn
const isPlayersTurn = state.currentPlayer === playerId
// Check if the card being hovered is flipped
const hoveredCard = cardId ? state.gameCards.find((c) => c.id === cardId) : null
const isCardFlipped = hoveredCard
? state.flippedCards.some((c) => c.id === hoveredCard.id) || hoveredCard.matched
: false
if (!playerInfo) return null
@@ -403,6 +409,7 @@ export function MemoryGrid() {
playerInfo={playerInfo}
cardElement={cardElement}
isPlayersTurn={isPlayersTurn}
isCardFlipped={isCardFlipped}
/>
)
})}

View File

@@ -1,5 +1,6 @@
'use client'
import { useViewerId } from '@/hooks/useViewerId'
import { css } from '../../../../../styled-system/css'
import { gamePlurals } from '../../../../utils/pluralization'
import { useMemoryPairs } from '../context/MemoryPairsContext'
@@ -10,6 +11,7 @@ interface PlayerStatusBarProps {
export function PlayerStatusBar({ className }: PlayerStatusBarProps) {
const { state } = useMemoryPairs()
const { data: viewerId } = useViewerId()
// Get active players from game state (not GameModeContext)
// This ensures we only show players actually in this game
@@ -25,8 +27,8 @@ export function PlayerStatusBar({ className }: PlayerStatusBarProps) {
displayEmoji: player.emoji,
score: state.scores[player.id] || 0,
consecutiveMatches: state.consecutiveMatches?.[player.id] || 0,
// In local games all players are local, in room games check metadata
isLocalPlayer: state.gameMode === 'single' || state.gameMode === 'multiplayer',
// Check if this player belongs to the current viewer
isLocalPlayer: player.userId === viewerId,
}))
// Check if current player is local (your turn) or remote (waiting)

View File

@@ -365,6 +365,43 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
return !!state.pausedGamePhase && !!state.pausedGameState && !hasConfigChanged
}, [state.pausedGamePhase, state.pausedGameState, hasConfigChanged])
// Helper to build player metadata with correct userId ownership
// This uses roomData.memberPlayers to determine which user owns which player
const buildPlayerMetadata = useCallback(
(playerIds: string[]) => {
const playerMetadata: { [playerId: string]: any } = {}
// Build reverse mapping: playerId -> userId from roomData.memberPlayers
const playerOwnership = new Map<string, string>()
if (roomData?.memberPlayers) {
for (const [userId, userPlayers] of Object.entries(roomData.memberPlayers)) {
for (const player of userPlayers) {
playerOwnership.set(player.id, userId)
}
}
}
for (const playerId of playerIds) {
const playerData = players.get(playerId)
if (playerData) {
// Get the actual owner userId from roomData, or use local viewerId as fallback
const ownerUserId = playerOwnership.get(playerId) || viewerId || ''
playerMetadata[playerId] = {
id: playerId,
name: playerData.name,
emoji: playerData.emoji,
userId: ownerUserId, // CORRECT: Use actual owner's userId
color: playerData.color,
}
}
}
return playerMetadata
},
[players, roomData, viewerId]
)
// Action creators - send moves to arcade session
const startGame = useCallback(() => {
// Must have at least one active player
@@ -375,19 +412,7 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
// Capture player metadata from local players map
// This ensures all room members can display player info even if they don't own the players
const playerMetadata: { [playerId: string]: any } = {}
for (const playerId of activePlayers) {
const playerData = players.get(playerId)
if (playerData) {
playerMetadata[playerId] = {
id: playerId,
name: playerData.name,
emoji: playerData.emoji,
userId: viewerId || '',
color: playerData.color,
}
}
}
const playerMetadata = buildPlayerMetadata(activePlayers)
// Use current session state configuration (no local state!)
const cards = generateGameCards(state.gameType, state.difficulty)
@@ -402,7 +427,7 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
playerMetadata,
},
})
}, [state.gameType, state.difficulty, activePlayers, players, viewerId, sendMove])
}, [state.gameType, state.difficulty, activePlayers, buildPlayerMetadata, sendMove])
const flipCard = useCallback(
(cardId: string) => {
@@ -438,20 +463,8 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
return
}
// Capture player metadata from local players map
const playerMetadata: { [playerId: string]: any } = {}
for (const playerId of activePlayers) {
const playerData = players.get(playerId)
if (playerData) {
playerMetadata[playerId] = {
id: playerId,
name: playerData.name,
emoji: playerData.emoji,
userId: viewerId || '',
color: playerData.color,
}
}
}
// Capture player metadata with correct userId ownership
const playerMetadata = buildPlayerMetadata(activePlayers)
// Use current session state configuration (no local state!)
const cards = generateGameCards(state.gameType, state.difficulty)
@@ -466,7 +479,7 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
playerMetadata,
},
})
}, [state.gameType, state.difficulty, activePlayers, players, viewerId, sendMove])
}, [state.gameType, state.difficulty, activePlayers, buildPlayerMetadata, sendMove])
const setGameType = useCallback(
(gameType: typeof state.gameType) => {

View File

@@ -0,0 +1,151 @@
/**
* Unit test for player ownership bug in RoomMemoryPairsProvider
*
* Bug: playerMetadata[playerId].userId is set to the LOCAL viewerId for ALL players,
* including remote players from other room members. This causes "Your turn" to show
* even when it's a remote player's turn.
*
* Fix: Use player.isLocal from GameModeContext to determine correct userId ownership.
*/
import { describe, expect, it } from 'vitest'
describe('Player Metadata userId Assignment', () => {
it('should assign local userId to local players only', () => {
const viewerId = 'local-user-id'
const players = new Map([
[
'local-player-1',
{
id: 'local-player-1',
name: 'Local Player',
emoji: '😀',
color: '#3b82f6',
isLocal: true,
},
],
[
'remote-player-1',
{
id: 'remote-player-1',
name: 'Remote Player',
emoji: '🤠',
color: '#10b981',
isLocal: false,
},
],
])
const activePlayers = ['local-player-1', 'remote-player-1']
// CURRENT BUGGY IMPLEMENTATION (from RoomMemoryPairsProvider.tsx:378-390)
const buggyPlayerMetadata: Record<string, any> = {}
for (const playerId of activePlayers) {
const playerData = players.get(playerId)
if (playerData) {
buggyPlayerMetadata[playerId] = {
id: playerId,
name: playerData.name,
emoji: playerData.emoji,
userId: viewerId, // BUG: Always uses local viewerId!
color: playerData.color,
}
}
}
// BUG MANIFESTATION: Both players have local userId
expect(buggyPlayerMetadata['local-player-1'].userId).toBe('local-user-id')
expect(buggyPlayerMetadata['remote-player-1'].userId).toBe('local-user-id') // WRONG!
// CORRECT IMPLEMENTATION
const correctPlayerMetadata: Record<string, any> = {}
for (const playerId of activePlayers) {
const playerData = players.get(playerId)
if (playerData) {
correctPlayerMetadata[playerId] = {
id: playerId,
name: playerData.name,
emoji: playerData.emoji,
// FIX: Only use local viewerId for local players
// For remote players, we don't know their userId from this context,
// but we can mark them as NOT belonging to local user
userId: playerData.isLocal ? viewerId : `remote-user-${playerId}`,
color: playerData.color,
isLocal: playerData.isLocal, // Also include isLocal for clarity
}
}
}
// CORRECT BEHAVIOR: Each player has correct userId
expect(correctPlayerMetadata['local-player-1'].userId).toBe('local-user-id')
expect(correctPlayerMetadata['remote-player-1'].userId).not.toBe('local-user-id')
})
it('reproduces "Your turn" bug when checking current player', () => {
const viewerId = 'local-user-id'
const currentPlayer = 'remote-player-1' // Remote player's turn
// Buggy playerMetadata (all players have local userId)
const buggyPlayerMetadata = {
'local-player-1': {
id: 'local-player-1',
userId: 'local-user-id',
},
'remote-player-1': {
id: 'remote-player-1',
userId: 'local-user-id', // BUG!
},
}
// PlayerStatusBar logic (line 31 in PlayerStatusBar.tsx)
const buggyIsLocalPlayer = buggyPlayerMetadata[currentPlayer]?.userId === viewerId
// BUG: Shows "Your turn" even though it's remote player's turn!
expect(buggyIsLocalPlayer).toBe(true) // WRONG!
expect(buggyIsLocalPlayer ? 'Your turn' : 'Their turn').toBe('Your turn') // WRONG!
// Correct playerMetadata (each player has correct userId)
const correctPlayerMetadata = {
'local-player-1': {
id: 'local-player-1',
userId: 'local-user-id',
},
'remote-player-1': {
id: 'remote-player-1',
userId: 'remote-user-id', // CORRECT!
},
}
// PlayerStatusBar logic with correct data
const correctIsLocalPlayer = correctPlayerMetadata[currentPlayer]?.userId === viewerId
// CORRECT: Shows "Their turn" because it's remote player's turn
expect(correctIsLocalPlayer).toBe(false) // CORRECT!
expect(correctIsLocalPlayer ? 'Your turn' : 'Their turn').toBe('Their turn') // CORRECT!
})
it('reproduces hover avatar bug when filtering by current player', () => {
const viewerId = 'local-user-id'
const currentPlayer = 'remote-player-1' // Remote player's turn
// Buggy playerMetadata
const buggyPlayerMetadata = {
'remote-player-1': {
id: 'remote-player-1',
userId: 'local-user-id', // BUG!
},
}
// OLD WRONG logic from MemoryGrid.tsx (showed remote players)
const oldWrongFilter = buggyPlayerMetadata[currentPlayer]?.userId !== viewerId
expect(oldWrongFilter).toBe(false) // Would hide avatar incorrectly
// CURRENT logic in MemoryGrid.tsx (shows only current player)
// This is actually correct - show avatar for whoever's turn it is
const currentLogic = currentPlayer === 'remote-player-1'
expect(currentLogic).toBe(true) // Shows avatar for current player
// The REAL issue is in PlayerStatusBar showing "Your turn"
// when it should show "Their turn"
})
})

View File

@@ -1,6 +1,6 @@
{
"name": "soroban-monorepo",
"version": "2.16.7",
"version": "2.17.2",
"private": true,
"description": "Beautiful Soroban Flashcard Generator - Monorepo",
"workspaces": [