All files / web/src/components/create/abacus abacus-identity-source.ts

100% Statements 31/31
100% Branches 5/5
100% Functions 1/1
100% Lines 31/31

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 321x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 22x 22x 22x 22x 5x 2x 2x 2x 2x 2x 3x 5x 17x 17x 17x 17x 17x 17x  
import type { AbacusIdentity } from '@/lib/abacus/identity'
import type { DisplayConfigInput } from './abacus-model'
 
/**
 * The identity source the studio's `synced` follow-effect mirrors.
 *
 * Player selected → the player's saved "my abacus" row, or null while it's
 * still in flight (the follow-effect holds — it never seeds a fake). No
 * player → the viewer's own live display config, exactly the pre-player
 * behavior.
 */
export function selectSourceIdentity(
  playerId: string | null,
  playerRow: AbacusIdentity | null | undefined,
  displayConfig: DisplayConfigInput
): DisplayConfigInput | null {
  if (playerId) {
    return playerRow
      ? {
          colorScheme: playerRow.colorScheme,
          colorPalette: playerRow.colorPalette,
          physicalAbacusColumns: playerRow.columns,
        }
      : null
  }
  return {
    colorScheme: displayConfig.colorScheme,
    colorPalette: displayConfig.colorPalette,
    physicalAbacusColumns: displayConfig.physicalAbacusColumns,
  }
}