import { useRef, useState } from 'react'; import PixiGame from './PixiGame.tsx'; import { useElementSize } from 'usehooks-ts'; import { Stage } from '@pixi/react'; import { ConvexProvider, useConvex, useQuery } from 'convex/react'; import PlayerDetails from './PlayerDetails.tsx'; import { api } from '../../convex/_generated/api'; import { useWorldHeartbeat } from '../hooks/useWorldHeartbeat.ts'; import { useHistoricalTime } from '../hooks/useHistoricalTime.ts'; import { DebugTimeManager } from './DebugTimeManager.tsx'; import { GameId } from '../../convex/aiTown/ids.ts'; import { useServerGame } from '../hooks/serverGame.ts'; import { VoteModal } from './VoteModal.tsx'; import { GameCycle } from '../../convex/aiTown/gameCycle.ts'; import { PlayerDescription } from '../../convex/aiTown/playerDescription.ts'; export const SHOW_DEBUG_UI = !!import.meta.env.VITE_SHOW_DEBUG_UI; export function VotingName(gameState: string) { switch (gameState) { case 'warewolf-vote': return { name: 'Warewolf Vote', desc: 'Select a player who is warewolf', type: 'warewolf-vote', }; case 'player-kill': return { name: 'Player Kill', desc: 'Select a player to kill', type: 'player-kill', }; default: return { name: 'Voting', desc: 'Select a player to vote', type: 'voting', }; } } export function isVotingState(gameCycle: GameCycle) { return gameCycle.cycleIndex === 0 || gameCycle.cycleIndex === 2; } function showMap(gameCycle: GameCycle, player: PlayerDescription) { // Here also check for player description return gameCycle.cycleIndex === 2 || gameCycle.cycleIndex == 1; } export default function Game() { const convex = useConvex(); const [selectedElement, setSelectedElement] = useState<{ kind: 'player'; id: GameId<'players'>; }>(); const [gameWrapperRef, { width, height }] = useElementSize(); const worldStatus = useQuery(api.world.defaultWorldStatus); const worldId = worldStatus?.worldId; const engineId = worldStatus?.engineId; const game = useServerGame(worldId); // Send a periodic heartbeat to our world to keep it alive. useWorldHeartbeat(); const worldState = useQuery(api.world.worldState, worldId ? { worldId } : 'skip'); const { historicalTime, timeManager } = useHistoricalTime(worldState?.engine); const scrollViewRef = useRef(null); // TODO: base this on the game state const [gameState, setGameState] = useState<'warewolf-vote' | 'player-kill' | 'none'>('none'); if (!worldId || !engineId || !game) { return null; } return ( <> {SHOW_DEBUG_UI && }
{/* Game area */}
{/* Re-propagate context because contexts are not shared between renderers. https://github.com/michalochman/react-pixi-fiber/issues/145#issuecomment-531549215 */}
{/* Right column area */}
{isVotingState(game.world.gameCycle) ? : }
); }