diff --git a/app/page.tsx b/app/page.tsx index 6bc535e..9d0a7ef 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -37,10 +37,10 @@ export default function GamePage() { } return ( -
+

Recent Games

-
+
{results.map((result) => ( ))} diff --git a/app/playground/page.tsx b/app/playground/page.tsx index 4e709ea..8cdabdb 100644 --- a/app/playground/page.tsx +++ b/app/playground/page.tsx @@ -1,7 +1,7 @@ "use client"; import React from "react"; -import { CircleAlertIcon } from "lucide-react"; +import { CircleAlertIcon, EraserIcon } from "lucide-react"; import { useAction, useMutation, useQuery } from "convex/react"; import { Button } from "@/components/ui/button"; import { CopyMapButton } from "@/components/CopyMapButton"; @@ -14,12 +14,14 @@ import { api } from "@/convex/_generated/api"; import { errorMessage } from "@/lib/utils"; import { useToast } from "@/components/ui/use-toast"; +const STORAGE_MAP_KEY = "playground-map"; + export default function PlaygroundPage() { const isAdmin = useQuery(api.users.isAdmin); const publishMap = useMutation(api.maps.publishMap); const testMap = useAction(api.maps.testMap); const { toast } = useToast(); - const [map, setMap] = React.useState([]); + const [map, setMap] = React.useState([[" "]]); const [model, setModel] = React.useState(""); const [error, setError] = React.useState(null); const [solution, setSolution] = React.useState(null); @@ -89,6 +91,7 @@ export default function PlaygroundPage() { function handleChangeMap(value: string[][]) { setMap(value); setError(null); + window.localStorage.setItem(STORAGE_MAP_KEY, JSON.stringify(value)); } function handleChangeModel(value: string) { @@ -103,6 +106,18 @@ export default function PlaygroundPage() { setVisualizingUserSolution(false); } + function handleReset() { + handleChangeMap([]); + + setSolution(null); + setReasoning(null); + setPublishing(false); + setSimulating(false); + setUserPlaying(false); + setUserSolution([]); + setVisualizingUserSolution(false); + } + function handleUserPlay() { if (!ZombieSurvival.mapHasZombies(map)) { alert("Add player to the map first"); @@ -131,6 +146,14 @@ export default function PlaygroundPage() { setVisualizingUserSolution(false); } + React.useEffect(() => { + const maybeMap = window.localStorage.getItem(STORAGE_MAP_KEY); + + if (maybeMap !== null) { + setMap(JSON.parse(maybeMap)); + } + }, []); + const visualizing = solution !== null || visualizingUserSolution; return ( @@ -143,9 +166,16 @@ export default function PlaygroundPage() {

- Map ({map.length}x{map[0]?.length ?? 0}) + Map ({ZombieSurvival.boardWidth(map)}x + {ZombieSurvival.boardHeight(map)})

+

* Click on a cell to place entity

@@ -199,18 +229,18 @@ export default function PlaygroundPage() { {simulating ? "Simulating..." : "Play With AI"} )} - {(solution !== null || userPlaying) && ( - - )} )} + {(solution !== null || userPlaying) && ( + + )} {solution === null && !simulating && !userPlaying && (