import React from "react"; import { useConsent, useGame, useGlobal, usePlayer, usePlayerID, useRound, useStage, } from "../hooks"; import { isDevelopment } from "../utils/debug"; import { Consent } from "./Consent"; import { Loading } from "./Loading"; import { Lobby as DefaultLobby } from "./Lobby"; import { PlayerID } from "./PlayerID"; import { Steps } from "./Steps"; interface ConsentProps { onConsent: () => void; } interface PlayerIDProps { onPlayerID: (playerID: string) => void; } interface GameFrameProps { children: React.ReactNode; noGames?: React.ElementType; consent?: React.ElementType; playerIDForm?: React.ElementType; lobby?: React.ElementType; introSteps: React.ElementType[]; exitSteps: React.ElementType[]; } export function GameFrame({ children, noGames: NoGames = DefaultNoGames, lobby = DefaultLobby, playerIDForm: PlayerIDForm = PlayerID, consent: ConsentComp = Consent, introSteps = [], exitSteps = [], }: GameFrameProps) { const { experimentOpen } = useGlobal(); const player = usePlayer(); const game = useGame(); const [hasPlayer, onPlayerID] = usePlayerID(); const [consented, onConsent] = useConsent(); if (!game && !experimentOpen) { return ; } if (!consented) { return ; } if (!hasPlayer && onPlayerID) { return ; } if (!player) { return ; } return ( {children} ); } interface PostIntroProps { children: React.ReactNode; lobby: React.ElementType; exitSteps: React.ElementType[]; } export function PostIntro({ children, lobby: Lobby, exitSteps, }: PostIntroProps) { const game = useGame(); const stage = useStage(); const round = useRound(); if (!game) { return ; } if (!stage || !round) { return ; } if (game.state == "ended") { return ( ); } return <>{children}; } export function Finished() { return (

Finished

Thank you for participating

); } export function DefaultNoGames() { return (

No experiments available

There are currently no available experiments. Please wait until an experiment becomes available or come back at a later date.

{isDevelopment ? (

Go to{" "} Admin {" "} to get started

) : ( "" )}
); }