"use client" import React, { Reducer, useEffect, useReducer } from "react"; import Maze from "./maze"; import ZMQReceiver from "./zmqreceiver"; import TypewriterText from "./typewritertext"; import { GameState } from "./zmqreceiver"; import anime from "animejs"; type PelitaState = "initial" | "movie" | "intro" | "match" | "faulted"; type PelitaEvent = "start-movie" | "start-intro" | "game-playing" | "clear-page" | "fail"; const MAX_LINES = 20; const reducer: Reducer = (state, event) => { switch (state) { case "initial": if (event === "start-movie") return "movie"; break; case "movie": if (event === "start-intro") return "intro"; break; case "intro": if (event === "game-playing") return "match"; if (event === "clear-page") return "intro"; break; case "match": if (event === "game-playing") return "match"; if (event === "clear-page") return "intro"; break; } return state; }; function PelitaMain({ gameState }: { gameState: GameState }) { const [team1, team2] = gameState.team_names; return

{team1} {gameState.game_stats.score[0]} : {gameState.game_stats.score[1]} {team2}

Errors: {gameState.game_stats.num_errors[0]}, Kills: {gameState.game_stats.kills[0] + gameState.game_stats.kills[2]}, Deaths: {gameState.game_stats.deaths[0] + gameState.game_stats.deaths[2]}, Time: {gameState.game_stats.team_time[0].toFixed(2)}
Errors: {gameState.game_stats.num_errors[1]}, Kills: {gameState.game_stats.kills[1] + gameState.game_stats.kills[3]}, Deaths: {gameState.game_stats.deaths[1] + gameState.game_stats.deaths[3]}, Time: {gameState.game_stats.team_time[1].toFixed(2)}
ᗧ Pelita Tournament, ASPP 2024 Ηράκλειο
Round {gameState.round ?? "-"}/{gameState.max_rounds}
} function Pelita() { const initialState: PelitaState = "initial"; const [state, dispatch] = useReducer(reducer, initialState); const [showPre, setShowPre] = React.useState(true); const [showMain, setShowMain] = React.useState(true); const [typewriterText, setTypewriterText] = React.useState([]); const [gameState, setGameState] = React.useState(); const bg_color = ((state) => { switch (state) { case "initial": case "movie": case "intro": return "#000" case "match": default: return "#fff"; } })(state); const crt = ((state) => { switch (state) { case "initial": case "movie": case "intro": return "crt" case "match": default: return ""; } })(state); useEffect(() => { anime.timeline() .add({ targets: 'body', background: bg_color, easing: 'linear', duration: 2000, }, 3000) }, [bg_color]); const flip = () => { //setShowMain(!showMain); //setShowPre(!showPre); }; const updateGameState = (gameState: GameState) => { dispatch("game-playing"); setGameState((oldState) => { if (oldState?.game_uuid === gameState.game_uuid) { // we keep the walls array so that the effects are not re-run // TODO: Maybe the effect should depend on only the game_uuid having changed? const newState = { ...gameState, "walls": oldState.walls, }; return newState; } return gameState; }); } const updateMessage = (msg: string) => { let split_str = msg.split(/\r?\n/); setTypewriterText(oldText => [...oldText, ...split_str]); } const clearPage = () => { dispatch("clear-page"); setTypewriterText([]); } const handleClick = async () => { switch (state) { case "initial": dispatch("start-movie"); break; case "movie": dispatch("start-intro"); break default: break; } }; function showIntro() { return ; } function inner() { if (state == "initial") { return ; } else if (state == "movie") { return ; } else if (state == "intro" || state == "match") { return (

ᗧ Pelita Tournament 2024

{state === "intro" ? showIntro() : null} {state === "match" && gameState ? : null }
); } }; return (
{ inner() }
); }; export default Pelita;