-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated documentation * Added working server action * Updated hexgrid state * Added remaining algorithms and updated test suite to be a single parameterised test.
- Loading branch information
1 parent
136fecd
commit 6b2bc34
Showing
15 changed files
with
296 additions
and
77 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 +1,34 @@ | ||
"use server"; | ||
|
||
import { redirect } from "next/navigation"; | ||
import { z } from "zod"; | ||
import { ALGORITHM_ARRAY, PLAYERS_4, PLAYERS_6 } from "@/lib/constants"; | ||
import CatanBoardGenerator from "@/lib/CatanBoardGenerator"; | ||
|
||
const schema = z.object({ | ||
useSeafarers: z.boolean(), | ||
randAlgorithm: z.enum(ALGORITHM_ARRAY), | ||
numOfPlayers: z.enum([PLAYERS_4, PLAYERS_6]), | ||
}); | ||
|
||
export async function generateBoard(formData: FormData) { | ||
const serializedBoard = "RST-WBSB-WTDTR-TRWS-BWS"; | ||
console.log(formData); | ||
const validatedFields = schema.safeParse({ | ||
useSeafarers: formData.has("useSeafarers"), | ||
randAlgorithm: formData.get("randAlgorithm"), | ||
numOfPlayers: formData.get("numOfPlayers"), | ||
}); | ||
|
||
if (!validatedFields.success) { | ||
return { | ||
errors: validatedFields.error.flatten().fieldErrors, | ||
}; | ||
} | ||
// const serializedBoard = "RST-WBSB-WTDTR-TRWS-BWS"; | ||
|
||
const serializedBoard = new CatanBoardGenerator( | ||
validatedFields.data.useSeafarers, | ||
validatedFields.data.numOfPlayers, | ||
validatedFields.data.randAlgorithm, | ||
).toString(); | ||
redirect(`/${serializedBoard}`); | ||
} |
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,12 @@ | ||
import BoardGrid from "@/app/components/ui/BoardGrid"; | ||
import BoardForm from "@/app/components/ui/BoardForm"; | ||
import * as React from "react"; | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<BoardGrid /> | ||
<BoardForm /> | ||
</> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,12 +1,6 @@ | ||
import BoardGrid from "@/app/components/ui/BoardGrid"; | ||
import BoardForm from "@/app/components/ui/BoardForm"; | ||
import * as React from "react"; | ||
|
||
export default function Home() { | ||
return ( | ||
<> | ||
<BoardGrid /> | ||
<BoardForm /> | ||
</> | ||
); | ||
return <BoardForm />; | ||
} |
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.