-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hooking all mutations and actions together
- Loading branch information
1 parent
7956e3b
commit b8bc586
Showing
13 changed files
with
380 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use client"; | ||
|
||
import { Map } from "@/app/map"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { Id } from "@/convex/_generated/dataModel"; | ||
import { useQuery } from "convex/react"; | ||
import { Result } from "./result"; | ||
|
||
export default function GamePage({ params }: { params: { gameId: string } }) { | ||
const game = useQuery(api.games.getGame, { | ||
gameId: params.gameId as Id<"games">, | ||
}); | ||
const results = useQuery(api.results.getResults, { | ||
gameId: params.gameId as Id<"games">, | ||
}); | ||
|
||
return ( | ||
<div className="container mx-auto min-h-screen flex flex-col items-center pt-12 gap-8"> | ||
<h1>Game {params.gameId}</h1> | ||
<h2>Model: {game?.modelId}</h2> | ||
|
||
<div className="flex flex-col gap-12"> | ||
{results === undefined || results.length === 0 ? ( | ||
<div className="flex flex-col justify-center items-center gap-8"> | ||
<div className="animate-spin rounded-full h-16 w-16 border-b-2 border-gray-900"></div> | ||
<p className="ml-4">Game starting...</p> | ||
</div> | ||
) : ( | ||
results.map((result) => <Result result={result} key={result._id} />) | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client"; | ||
|
||
import { Map } from "@/app/map"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { Doc } from "@/convex/_generated/dataModel"; | ||
import { useQuery } from "convex/react"; | ||
|
||
export const Result = ({ result }: { result: Doc<"results"> }) => { | ||
const map = useQuery(api.maps.getMapByLevel, { | ||
level: result.level, | ||
}); | ||
|
||
if (!map) return null; | ||
|
||
if (result.status === "inProgress") { | ||
return <div>Game in progress...</div>; | ||
} | ||
|
||
return ( | ||
<div className="flex items-center gap-8" key={map._id}> | ||
<div>Level {map.level}</div> | ||
<Map map={map.grid} /> | ||
<div | ||
className={`font-bold ${result.isWin ? "text-green-500" : "text-red-500"}`} | ||
> | ||
{result.isWin ? "Won" : "Lost"} | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,74 @@ | ||
"use client"; | ||
|
||
import { Map } from "@/app/map"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { useAction } from "convex/react"; | ||
import React, { useState } from "react"; | ||
import { Button } from "./ui/button"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "./ui/select"; | ||
import { AI_MODELS } from "@/app/constants"; | ||
// import { Map } from "@/app/map"; | ||
// import { api } from "@/convex/_generated/api"; | ||
// import { useAction } from "convex/react"; | ||
// import React, { useState } from "react"; | ||
// import { Button } from "./ui/button"; | ||
// import { | ||
// Select, | ||
// SelectContent, | ||
// SelectItem, | ||
// SelectTrigger, | ||
// SelectValue, | ||
// } from "./ui/select"; | ||
// import { AI_MODELS } from "@/convex/constants"; | ||
// import { Id } from "@/convex/_generated/dataModel"; | ||
|
||
const MapTester = ({ map }: { map: string[][] }) => { | ||
const getPlayerMap = useAction(api.openai.playMapAction); | ||
const [resMap, setResMap] = useState<null | string[][]>(); | ||
const [loading, setLoading] = useState(false); | ||
const [model, setModel] = useState(AI_MODELS[0].model); | ||
return null; | ||
|
||
const handleClick = async () => { | ||
setLoading(true); | ||
try { | ||
const res = await getPlayerMap({ | ||
level: 1, | ||
mapId: "zombiemap", | ||
map, | ||
}); | ||
// const getPlayerMap = useAction(api.openai.playMapAction); | ||
// const [resMap, setResMap] = useState<null | string[][]>(); | ||
// const [loading, setLoading] = useState(false); | ||
// const [model, setModel] = useState(AI_MODELS[0].model); | ||
|
||
// type safe resulting object | ||
console.log(res); | ||
setResMap(res?.map); | ||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
// const handleClick = async () => { | ||
// setLoading(true); | ||
// try { | ||
// const res = await getPlayerMap({ | ||
// level: 1, | ||
// mapId: "zombiemap", | ||
// map, | ||
// modelId: model, | ||
// gameId: "zombiegame" as Id<"games">, | ||
// }); | ||
|
||
return ( | ||
<> | ||
<div className="flex gap-4"> | ||
<Select value={model} onValueChange={(value) => setModel(value)}> | ||
<SelectTrigger className="w-[180px]"> | ||
<SelectValue placeholder="Select model" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{AI_MODELS.map((model) => ( | ||
<SelectItem key={model.model} value={model.model}> | ||
{model.name} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
<Button onClick={handleClick} disabled={loading}> | ||
Run Simulation | ||
</Button> | ||
</div> | ||
<div className="flex flex-col gap-4"> | ||
{loading && <p>Loading result map...</p>} | ||
{resMap && <Map map={resMap} />} | ||
</div> | ||
</> | ||
); | ||
// // type safe resulting object | ||
// console.log(res); | ||
// setResMap(res?.map); | ||
// } catch (error) { | ||
// console.error(error); | ||
// } finally { | ||
// setLoading(false); | ||
// } | ||
// }; | ||
|
||
// return ( | ||
// <> | ||
// <div className="flex gap-4"> | ||
// <Select value={model} onValueChange={(value) => setModel(value)}> | ||
// <SelectTrigger className="w-[180px]"> | ||
// <SelectValue placeholder="Select model" /> | ||
// </SelectTrigger> | ||
// <SelectContent> | ||
// {AI_MODELS.map((model) => ( | ||
// <SelectItem key={model.model} value={model.model}> | ||
// {model.name} | ||
// </SelectItem> | ||
// ))} | ||
// </SelectContent> | ||
// </Select> | ||
// <Button onClick={handleClick} disabled={loading}> | ||
// Run Simulation | ||
// </Button> | ||
// </div> | ||
// <div className="flex flex-col gap-4"> | ||
// {loading && <p>Loading result map...</p>} | ||
// {resMap && <Map map={resMap} />} | ||
// </div> | ||
// </> | ||
// ); | ||
}; | ||
|
||
export default MapTester; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.