Spaces:
Sleeping
Sleeping
File size: 1,489 Bytes
df2ef4f |
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 50 51 52 53 54 |
import { ServerGame } from "@/hooks/serverGame";
import { Id } from "../../convex/_generated/dataModel";
import { GameId } from "../../convex/aiTown/ids";
import { canVote } from "./Game";
import { useSendInput } from "../hooks/sendInput";
import { VoteModal } from "./VoteModal";
import { useState } from "react";
const getSelectablePlayers = (game: ServerGame, playerId: GameId<'players'>, players: Player[]) => {
if (game.world.gameCycle.cycleState === "WerewolfVoting") {
return players.filter(
(player) => (player.id !== playerId)
);
}
else if (game.world.gameCycle.cycleState === "PlayerKillVoting") {
return players.filter(
(player) => (player.id !== playerId) && game.playerDescriptions.get(player.id)?.type === 'villager'
);
}
return []
}
export default function GameVote({
engineId,
game,
playerId,
}: {
engineId: Id<'engines'>,
game: ServerGame,
playerId: GameId<'players'>,
}) {
const inputVote = useSendInput(engineId, "gameVote");
const [votes, setVotes] = useState<GameId<'players'>[]>([]);
const players = getSelectablePlayers(game, playerId, [...game.world.players.values()])
return (
<VoteModal
compact={true}
game={game}
engineId={engineId}
playerId={playerId}
maxVotes={1}
votes={votes}
players={players}
onVote={(newVotes) => {
setVotes(newVotes);
inputVote({voter: playerId, votedPlayerIds: newVotes});
}}
/>
);
}
|