From 1bb17668a73eadba0c8d02e55cedbfae9ed2286e Mon Sep 17 00:00:00 2001 From: Simon Lemieux <1105380+simlmx@users.noreply.github.com> Date: Thu, 18 Jul 2024 20:22:54 +0000 Subject: [PATCH] fixup --- game-template/game/src/index.test-d.ts | 4 ++-- game-template/game/src/index.test.ts | 4 ++-- game-template/game/src/index.ts | 31 ++++++++++++++------------ game-template/ui/src/Board.tsx | 6 ++--- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/game-template/game/src/index.test-d.ts b/game-template/game/src/index.test-d.ts index 6165f32..595b675 100644 --- a/game-template/game/src/index.test-d.ts +++ b/game-template/game/src/index.test-d.ts @@ -2,10 +2,10 @@ import { expectTypeOf, test } from "vitest"; import { MatchTester, PlayerMove } from "@lefun/game"; -import { game, GS } from "."; +import { game, RollGame, RollGameState as GS } from "."; test("inside PlayerMove", () => { - expectTypeOf(game).toEqualTypeOf(); + expectTypeOf(game).toEqualTypeOf(); const move = { executeNow({ board, playerboard, payload }) { diff --git a/game-template/game/src/index.test.ts b/game-template/game/src/index.test.ts index 1a5494c..c1b7ec0 100644 --- a/game-template/game/src/index.test.ts +++ b/game-template/game/src/index.test.ts @@ -2,9 +2,9 @@ import { test } from "vitest"; import { MatchTester as _MatchTester } from "@lefun/game"; -import { game, GS } from "."; +import { game, RollGame as G, RollGameState as GS } from "."; -class MatchTester extends _MatchTester {} +class MatchTester extends _MatchTester {} test("sanity check", () => { const match = new MatchTester({ game, numPlayers: 2 }); diff --git a/game-template/game/src/index.ts b/game-template/game/src/index.ts index cfc0bed..e014cc0 100644 --- a/game-template/game/src/index.ts +++ b/game-template/game/src/index.ts @@ -11,20 +11,20 @@ export type Board = { players: Record; }; -type GS = GameState; +export type RollGameState = GameState; type BMT = { someBoardMove: never; someBoardMoveWithArgs: { someArg: number }; }; -const moveWithArg: PlayerMove = { +const moveWithArg: PlayerMove = { execute() { // }, }; -const roll: PlayerMove = { +const roll: PlayerMove = { executeNow({ board, userId }) { board.players[userId].isRolling = true; }, @@ -36,26 +36,29 @@ const roll: PlayerMove = { }, }; -const initMove_: BoardMove = { +const initMove_: BoardMove = { execute() { // }, }; -const someBoardMove: BoardMove = { +const someBoardMove: BoardMove = { execute() { // }, }; -const someBoardMoveWithArgs: BoardMove = - { - execute() { - // - }, - }; +const someBoardMoveWithArgs: BoardMove< + RollGameState, + BMT["someBoardMoveWithArgs"], + BMT +> = { + execute() { + // + }, +}; -const game = { +export const game = { initialBoards: ({ players }) => ({ board: { count: 0, @@ -68,6 +71,6 @@ const game = { boardMoves: { initMove_, someBoardMove, someBoardMoveWithArgs }, minPlayers: 1, maxPlayers: 10, -} satisfies Game; +} satisfies Game; -export { game, GS }; +export type RollGame = typeof game; diff --git a/game-template/ui/src/Board.tsx b/game-template/ui/src/Board.tsx index ed85e89..2d42120 100644 --- a/game-template/ui/src/Board.tsx +++ b/game-template/ui/src/Board.tsx @@ -12,13 +12,13 @@ import { useUsername, } from "@lefun/ui"; -import { game, GS } from "roll-game"; +import { game, RollGameState } from "roll-game"; // Dice symbol characters const DICE = ["", "\u2680", "\u2681", "\u2682", "\u2683", "\u2684", "\u2685"]; -const useSelector = makeUseSelector(); -const useSelectorShallow = makeUseSelectorShallow(); +const useSelector = makeUseSelector(); +const useSelectorShallow = makeUseSelectorShallow(); const useMakeMove = makeUseMakeMove(); function Player({ userId }: { userId: UserId }) {