Skip to content

Commit

Permalink
Code style in playground
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Oct 21, 2024
1 parent 33b45f4 commit e2114e5
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions app/playground/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import * as React from "react";
import { useAction, useMutation, useQuery } from "convex/react";
import { CircleAlertIcon, EraserIcon, SendIcon, UploadIcon, ChevronLeft } from "lucide-react";
import { CopyMapButton } from "@/components/CopyMapButton";
import { MapBuilder } from "@/components/MapBuilder";
import { ChevronLeft, UploadIcon } from "lucide-react";
import { Map } from "@/components/Map";
import { MapStatus } from "@/components/MapStatus";
import { ModelSelector } from "@/components/ModelSelector";
import { Visualizer } from "@/components/Visualizer";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { useToast } from "@/components/ui/use-toast";
import { api } from "@/convex/_generated/api";
import { errorMessage } from "@/lib/utils";
import { ZombieSurvival } from "@/simulators/zombie-survival";
import { Card } from "@/components/ui/card";
import { Map } from "@/components/Map";

const STORAGE_MAP_KEY = "playground-map";

Expand Down Expand Up @@ -112,10 +110,10 @@ export default function PlaygroundPage() {
setReasoning(null);
setUserPlaying(false);
setVisualizingUserSolution(false);

// Remove players and blocks from the map
const cleanedMap = map.map(row =>
row.map(cell => (cell === "P" || cell === "B") ? " " : cell)
const cleanedMap = map.map((row) =>
row.map((cell) => (cell === "P" || cell === "B" ? " " : cell)),
);
setMap(cleanedMap);
window.localStorage.setItem(STORAGE_MAP_KEY, JSON.stringify(cleanedMap));
Expand Down Expand Up @@ -181,15 +179,19 @@ export default function PlaygroundPage() {
<Card className="p-4">
{!visualizing && !userPlaying && (
<p className="mb-2 text-sm text-gray-600">
Click on the board to place or remove units. Use the buttons below to switch between unit types.
Click on the board to place or remove units. Use the buttons
below to switch between unit types.
</p>
)}
{!visualizing && userPlaying && (
<p className="mb-2 text-sm text-gray-600">
Place a player (P) and blocks (B) on the board to create your escape route. Click to toggle between empty, player, and block.
Place a player (P) and blocks (B) on the board to create your
escape route. Click to toggle between empty, player, and block.
</p>
)}
<div className={`flex justify-center ${visualizing ? "pt-[28px]" : ""}`}>
<div
className={`flex justify-center ${visualizing ? "pt-[28px]" : ""}`}
>
{visualizing && (
<Visualizer
autoReplay
Expand All @@ -213,8 +215,12 @@ export default function PlaygroundPage() {
<div
key={`${x}-${y}`}
className={`${
cell === " " || cell === "Z" || cell === "R" || cell === "P" || cell === "B"
? "z-10 cursor-pointer hover:border-2 hover:border-dashed hover:border-slate-300 "
cell === " " ||
cell === "Z" ||
cell === "R" ||
cell === "P" ||
cell === "B"
? "z-10 cursor-pointer hover:border-2 hover:border-dashed hover:border-slate-300"
: ""
} border border-transparent`}
onClick={() => {
Expand All @@ -223,8 +229,12 @@ export default function PlaygroundPage() {
: [...map];
if (userPlaying) {
// Count existing players and blocks
const playerCount = newMap.flat().filter(c => c === "P").length;
const blockCount = newMap.flat().filter(c => c === "B").length;
const playerCount = newMap
.flat()
.filter((c) => c === "P").length;
const blockCount = newMap
.flat()
.filter((c) => c === "B").length;

// Toggle logic for play mode
if (cell === " ") {
Expand Down Expand Up @@ -252,7 +262,7 @@ export default function PlaygroundPage() {
: handleChangeMap(newMap);
}}
/>
))
)),
)}
</div>
</div>
Expand Down

0 comments on commit e2114e5

Please sign in to comment.