"use client" import React, { Reducer, useEffect, useReducer } from "react"; import ZMQReceiver from "./zmqreceiver"; import TypewriterText from "./typewritertext"; import { GameState } from "./pelita_msg"; import Pelita from "./pelita"; 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 PelitaTournament() { const initialState: PelitaState = "initial"; const [state, dispatch] = useReducer(reducer, initialState); 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 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 ; }; return (
{state == "initial" && } {state == "movie" && } {state === "intro" && showIntro()} {state == "match" &&

ᗧ Pelita Tournament 2024

{ gameState && }
}
); }; export default PelitaTournament;