|
|
@ -2,13 +2,13 @@ import type { Request, Response } from "express"; |
|
|
|
import { rewriteQueryParamsWith, safeGetQueryValue } from "../utils.ts"; |
|
|
|
import { rewriteQueryParamsWith, safeGetQueryValue } from "../utils.ts"; |
|
|
|
import { BoardgameState } from "../../shared/boardgame-state.ts"; |
|
|
|
import { BoardgameState } from "../../shared/boardgame-state.ts"; |
|
|
|
import { getBoardgameHtml } from "../components/boardgame.tsx"; |
|
|
|
import { getBoardgameHtml } from "../components/boardgame.tsx"; |
|
|
|
import { gamesRules } from "../../shared/rules.ts"; |
|
|
|
import { GameVariantName, gamesRules } from "../../shared/rules.ts"; |
|
|
|
import { getTargetGameState } from "../../shared/boardgame.ts"; |
|
|
|
import { getTargetGameState } from "../../shared/boardgame.ts"; |
|
|
|
|
|
|
|
|
|
|
|
// Returns nothing if query parameter is uninitialized and a redirect was made,
|
|
|
|
// Returns nothing if query parameter is uninitialized and a redirect was made,
|
|
|
|
// or component if query parameter is initialized.
|
|
|
|
// or component if query parameter is initialized.
|
|
|
|
export const handleBoardgame = (req: Request, res: Response, key: string) => { |
|
|
|
export const handleBoardgame = (req: Request, res: Response, key: string, gameVariant: GameVariantName) => { |
|
|
|
const rules = gamesRules.tictactoe; |
|
|
|
const rules = gamesRules[gameVariant]; |
|
|
|
|
|
|
|
|
|
|
|
const serializedState = safeGetQueryValue(req, key); |
|
|
|
const serializedState = safeGetQueryValue(req, key); |
|
|
|
const inputState = BoardgameState.fromSerialized(serializedState); |
|
|
|
const inputState = BoardgameState.fromSerialized(serializedState); |
|
|
@ -19,5 +19,5 @@ export const handleBoardgame = (req: Request, res: Response, key: string) => { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return getBoardgameHtml(key, state, rules); |
|
|
|
return getBoardgameHtml(key, state, gameVariant); |
|
|
|
}; |
|
|
|
}; |
|
|
|