import React from "react"; import { commands } from "@/bindings"; import { sharedSwrConfig, useTauriEvent } from "@/lib/hooks"; import useSWR from "swr"; export default function GameScreen() { const { data: profiles } = useSWR("game-get-profiles", commands.getProfiles); const { data: gameState, mutate } = useSWR( "fetch-game-state", commands.getGameState, sharedSwrConfig ); useTauriEvent("gameStateUpdate", () => { mutate(); }); const isSeeker = gameState.caught_state[gameState.my_id]; const markCaught = async () => { if (!isSeeker) { await commands.markCaught(); } }; const grabPowerup = async () => { if (gameState.available_powerup !== null) { await commands.grabPowerup(); } }; const activatePowerup = async () => { if (gameState.held_powerup !== null && gameState.held_powerup !== "PingSeeker") { await commands.activatePowerup(); } }; const quitToMenu = async () => { await commands.quitToMenu(); }; if (gameState.game_ended) { return

Game Over! Syncing histories...

; } else if (isSeeker && gameState.seekers_started === null) { return

Waiting for hiders to hide...

; } else { return ( <>

Hiders Left

{Object.keys(gameState.caught_state) .filter((k) => !gameState.caught_state[k]) .map((key) => (
  • {profiles?.[key]?.display_name ?? key}
  • ))} {!isSeeker && }

    Pings

    {gameState.last_global_ping !== null ? ( <>

    Last Ping: {gameState.last_global_ping}

    {Object.entries(gameState.pings) .filter(([key, v]) => key && v !== undefined) .map(([k, v]) => (
  • {profiles?.[v!.display_player]?.display_name ?? v!.display_player} : {v && JSON.stringify(v.loc)}
  • ))} ) : ( Pings haven't started yet )}

    Powerups

    {gameState.last_powerup_spawn === null && ( Powerups haven't started yet )} {gameState.available_powerup && (

    Powerup Available: {JSON.stringify(gameState.available_powerup)}{" "}

    )} {gameState.held_powerup && (

    Held Powerup: {gameState.held_powerup} {(gameState.held_powerup === "PingSeeker" && ( (Will be used next ping) )) || }

    )}

    Quit

    ); } }