|
|
|
|
export const playerColors = [
|
|
|
|
|
{ id: 'amarillo', label: 'Amarillo', hex: '#ffde00' },
|
|
|
|
|
{ id: 'azul', label: 'Azul', hex: '#00aeef' },
|
|
|
|
|
{ id: 'rojo', label: 'Rojo', hex: '#ff2438' },
|
|
|
|
|
{ id: 'verde', label: 'Verde', hex: '#28c800' },
|
|
|
|
|
{ id: 'negro', label: 'Negro', hex: '#30343b' },
|
|
|
|
|
{ id: 'naranja', label: 'Naranja', hex: '#ff861c' },
|
|
|
|
|
{ id: 'violeta', label: 'Violeta', hex: '#9855ef' },
|
|
|
|
|
{ id: 'gris', label: 'Gris', hex: '#7d8794' },
|
|
|
|
|
];
|
|
|
|
|
export const parchisColorOrder = playerColors.slice(0, 4).map((c) => c.id);
|
|
|
|
|
export const canChooseColor = (room) =>
|
|
|
|
|
room.gameId === 'oca' ||
|
|
|
|
|
(room.gameId === 'parchis' && room.gameVersion !== '1.0.0');
|
|
|
|
|
export const paletteForRoom = (room) =>
|
|
|
|
|
playerColors.slice(0, room.maxPlayers > 4 ? 8 : 4);
|
|
|
|
|
export const receivesLastColor = (room, player) =>
|
|
|
|
|
room.maxPlayers === paletteForRoom(room).length &&
|
|
|
|
|
player?.seat === room.maxPlayers - 1;
|
|
|
|
|
export const colorForPlayer = (player) =>
|
|
|
|
|
playerColors.find((c) => c.id === player?.colorId) ??
|
|
|
|
|
playerColors[player?.seat ?? 0] ??
|
|
|
|
|
playerColors[0];
|
|
|
|
|
export const playerColorClass = (player) =>
|
|
|
|
|
`player-color-${playerColors.indexOf(colorForPlayer(player))}`;
|
|
|
|
|
export function assignLastColor(room) {
|
|
|
|
|
const last = room.players.find((p) => p.seat === room.maxPlayers - 1);
|
|
|
|
|
if (!receivesLastColor(room, last)) return;
|
|
|
|
|
const others = room.players.filter((p) => p !== last);
|
|
|
|
|
if (others.length === room.maxPlayers - 1 && others.every((p) => p.colorId))
|
|
|
|
|
last.colorId = paletteForRoom(room).find(
|
|
|
|
|
(c) => !others.some((p) => p.colorId === c.id),
|
|
|
|
|
).id;
|
|
|
|
|
else delete last.colorId;
|
|
|
|
|
}
|
|
|
|
|
export function chooseDefaultColor(room, player) {
|
|
|
|
|
if (player.colorId || receivesLastColor(room, player)) return;
|
|
|
|
|
const free = paletteForRoom(room).filter(
|
|
|
|
|
(c) =>
|
|
|
|
|
!room.players.some(
|
|
|
|
|
(p) =>
|
|
|
|
|
p !== player && !receivesLastColor(room, p) && p.colorId === c.id,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
player.colorId = (
|
|
|
|
|
free.find((c) => c.id === playerColors[player.seat]?.id) ?? free[0]
|
|
|
|
|
).id;
|
|
|
|
|
}
|