All files / web/src/types player.ts

0% Statements 0/48
0% Branches 0/1
0% Functions 0/1
0% Lines 0/48

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                                                                                                 
/**
 * Default player colors (used during player creation)
 */
export const DEFAULT_PLAYER_COLORS = [
  '#3b82f6', // Blue
  '#8b5cf6', // Purple
  '#10b981', // Green
  '#f59e0b', // Orange
  '#ef4444', // Red
  '#14b8a6', // Teal
  '#f97316', // Deep Orange
  '#6366f1', // Indigo
  '#ec4899', // Pink
  '#84cc16', // Lime
]

/**
 * Client-side Player type (for contexts/components)
 * Matches database Player type but with flexible createdAt
 */
export interface Player {
  id: string
  name: string
  emoji: string
  color: string
  createdAt: Date | number
  isActive?: boolean
  isLocal?: boolean
  /** Teacher notes about this student */
  notes?: string | null
}

/**
 * Get a color for a new player (cycles through defaults)
 */
export function getNextPlayerColor(existingPlayers: Player[]): string {
  const usedColors = new Set(existingPlayers.map((p) => p.color))

  // Find first unused color
  for (const color of DEFAULT_PLAYER_COLORS) {
    if (!usedColors.has(color)) {
      return color
    }
  }

  // If all colors used, cycle back
  return DEFAULT_PLAYER_COLORS[existingPlayers.length % DEFAULT_PLAYER_COLORS.length]
}