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
Last Ping: {gameState.last_global_ping}
{Object.entries(gameState.pings) .filter(([key, v]) => key && v !== undefined) .map(([k, v]) => (Powerup Available: {JSON.stringify(gameState.available_powerup)}{" "}
)} {gameState.held_powerup && (Held Powerup: {gameState.held_powerup} {(gameState.held_powerup === "PingSeeker" && ( (Will be used next ping) )) || }
)}