feat: add player ownership helper to player-manager API

Added getPlayerOwnershipMap() as a convenience re-export of the
centralized buildPlayerOwnershipMap() utility.

This allows modules to access player ownership data through the
player-manager API, which is the natural home for player-related
server-side operations.

New function:
- getPlayerOwnershipMap(roomId?) - Returns PlayerOwnershipMap

Benefits:
- Consistent API: player data + ownership through same module
- Discovery: developers naturally look in player-manager for player ops
- Flexibility: can add room-filtering logic in future if needed
- Documentation: JSDoc example shows usage pattern

Example usage:
  const ownership = await getPlayerOwnershipMap()
  const isOwned = ownership[playerId] === userId

This is phase 3 of the player ownership centralization plan.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Thomas Hallock
2025-10-10 08:56:15 -05:00
parent d3b7cc25ca
commit 6b59a828aa

View File

@@ -6,6 +6,7 @@
import { and, eq } from 'drizzle-orm'
import { db, schema } from '@/db'
import type { Player } from '@/db/schema/players'
import { type PlayerOwnershipMap, buildPlayerOwnershipMap } from './player-ownership'
/**
* Get all players for a user (regardless of isActive status)
@@ -128,3 +129,21 @@ export async function getPlayers(playerIds: string[]): Promise<Player[]> {
return players
}
/**
* Get player ownership map for a room
*
* Convenience re-export of the centralized player ownership utility.
* This allows other modules to get player ownership data through
* the player-manager API.
*
* @param roomId - Optional room ID (currently unused by underlying utility)
* @returns Promise resolving to playerOwnership map (playerId -> userId)
*
* @example
* const ownership = await getPlayerOwnershipMap()
* const isOwned = ownership[playerId] === userId
*/
export async function getPlayerOwnershipMap(roomId?: string): Promise<PlayerOwnershipMap> {
return buildPlayerOwnershipMap(roomId)
}