24 lines
932 B
TypeScript
24 lines
932 B
TypeScript
'use client';
|
|
|
|
import { faction } from '@/game/catalog';
|
|
import { coalitionAllies } from '@/game/coalition-alliance';
|
|
import type { GameView } from '@/game/engine';
|
|
|
|
/** Alliance membership is public; a staged larger alliance has no scalar
|
|
* player.ally value, so use its authoritative public membership ledger. */
|
|
export function RosterAlliance({game, playerId}: {
|
|
game: Pick<GameView, 'players' | 'coalitionState'>;
|
|
playerId: string;
|
|
}) {
|
|
const player = game.players.find(seat => seat.id === playerId);
|
|
if (!player) return null;
|
|
const ids = game.coalitionState
|
|
? coalitionAllies(game.players, game.coalitionState, playerId)
|
|
: player.ally ? [player.ally] : [];
|
|
const names = ids.flatMap(id => {
|
|
const ally = game.players.find(seat => seat.id === id);
|
|
return ally ? [faction(ally.faction).name] : [];
|
|
});
|
|
return names.length ? <div className="fine">Allied with {names.join(' and ')}</div> : null;
|
|
}
|