import * as React from 'react' import { useEffect } from 'react' import Split from 'react-split' import { Box, CircularProgress } from '@mui/material' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faArrowRight } from '@fortawesome/free-solid-svg-icons' import { GameIdContext } from '../app' import { useAppDispatch, useAppSelector } from '../hooks' import { changedOpenedIntro, selectOpenedIntro } from '../state/progress' import { useGetGameInfoQuery, useLoadInventoryOverviewQuery } from '../state/api' import { Button } from './button' import { MobileContext } from './infoview/context' import { InventoryPanel } from './inventory' import { ErasePopup } from './popup/erase' import { InfoPopup } from './popup/game_info' import { PrivacyPolicyPopup } from './popup/privacy_policy' import { RulesHelpPopup } from './popup/rules_help' import { UploadPopup } from './popup/upload' import { WorldTreePanel } from './world_tree' import '../css/welcome.css' import { WelcomeAppBar } from './app_bar' import { Hint } from './hints' /** the panel showing the game's introduction text */ function IntroductionPanel({introduction, setPageNumber}: {introduction: string, setPageNumber}) { const {mobile} = React.useContext(MobileContext) const gameId = React.useContext(GameIdContext) const dispatch = useAppDispatch() // TODO: I left the setup for splitting up the introduction in place, but if it's not needed // then this can be simplified. // let text: Array = introduction.split(/\n(\s*\n)+/) let text: Array = introduction ? [introduction] : [] return
{text?.map(((t, i) => t.trim() ? : <> ))}
{mobile &&
}
} /** main page of the game showing among others the tree of worlds/levels */ function Welcome() { const gameId = React.useContext(GameIdContext) const {mobile} = React.useContext(MobileContext) const gameInfo = useGetGameInfoQuery({game: gameId}) const inventory = useLoadInventoryOverviewQuery({game: gameId}) // For mobile only const openedIntro = useAppSelector(selectOpenedIntro(gameId)) const [pageNumber, setPageNumber] = React.useState(openedIntro ? 1 : 0) // pop-ups const [eraseMenu, setEraseMenu] = React.useState(false) const [impressum, setImpressum] = React.useState(false) const [info, setInfo] = React.useState(false) const [rulesHelp, setRulesHelp] = React.useState(false) const [uploadMenu, setUploadMenu] = React.useState(false) function closeEraseMenu() {setEraseMenu(false)} function closeImpressum() {setImpressum(false)} function closeInfo() {setInfo(false)} function closeRulesHelp() {setRulesHelp(false)} function closeUploadMenu() {setUploadMenu(false)} function toggleEraseMenu() {setEraseMenu(!eraseMenu)} function toggleImpressum() {setImpressum(!impressum)} function toggleInfo() {setInfo(!info)} function toggleUploadMenu() {setUploadMenu(!uploadMenu)} // set the window title useEffect(() => { if (gameInfo.data?.title) { window.document.title = gameInfo.data.title } }, [gameInfo.data?.title]) return gameInfo.isLoading ? : <>
{ mobile ?
{(pageNumber == 0 ? : pageNumber == 1 ? : )}
: }
{impressum ? : null} {rulesHelp ? : null} {eraseMenu? : null} {uploadMenu? : null} {info ? : null} } export default Welcome