Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
simlmx committed Jul 18, 2024
1 parent 4bcc13c commit 1bb1766
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions game-template/game/src/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof game>();
expectTypeOf(game).toEqualTypeOf<RollGame>();

const move = {
executeNow({ board, playerboard, payload }) {
Expand Down
4 changes: 2 additions & 2 deletions game-template/game/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GS, typeof game> {}
class MatchTester extends _MatchTester<GS, G> {}

test("sanity check", () => {
const match = new MatchTester({ game, numPlayers: 2 });
Expand Down
31 changes: 17 additions & 14 deletions game-template/game/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export type Board = {
players: Record<UserId, Player>;
};

type GS = GameState<Board>;
export type RollGameState = GameState<Board>;

type BMT = {
someBoardMove: never;
someBoardMoveWithArgs: { someArg: number };
};

const moveWithArg: PlayerMove<GS, { someArg: string }, BMT> = {
const moveWithArg: PlayerMove<RollGameState, { someArg: string }, BMT> = {
execute() {
//
},
};

const roll: PlayerMove<GS, never, BMT> = {
const roll: PlayerMove<RollGameState, never, BMT> = {
executeNow({ board, userId }) {
board.players[userId].isRolling = true;
},
Expand All @@ -36,26 +36,29 @@ const roll: PlayerMove<GS, never, BMT> = {
},
};

const initMove_: BoardMove<GS, never, BMT> = {
const initMove_: BoardMove<RollGameState, never, BMT> = {
execute() {
//
},
};

const someBoardMove: BoardMove<GS, never, BMT> = {
const someBoardMove: BoardMove<RollGameState, never, BMT> = {
execute() {
//
},
};

const someBoardMoveWithArgs: BoardMove<GS, BMT["someBoardMoveWithArgs"], BMT> =
{
execute() {
//
},
};
const someBoardMoveWithArgs: BoardMove<
RollGameState,
BMT["someBoardMoveWithArgs"],
BMT
> = {
execute() {
//
},
};

const game = {
export const game = {
initialBoards: ({ players }) => ({
board: {
count: 0,
Expand All @@ -68,6 +71,6 @@ const game = {
boardMoves: { initMove_, someBoardMove, someBoardMoveWithArgs },
minPlayers: 1,
maxPlayers: 10,
} satisfies Game<GS, BMT>;
} satisfies Game<RollGameState, BMT>;

export { game, GS };
export type RollGame = typeof game;
6 changes: 3 additions & 3 deletions game-template/ui/src/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<GS>();
const useSelectorShallow = makeUseSelectorShallow<GS>();
const useSelector = makeUseSelector<RollGameState>();
const useSelectorShallow = makeUseSelectorShallow<RollGameState>();
const useMakeMove = makeUseMakeMove<typeof game>();

function Player({ userId }: { userId: UserId }) {
Expand Down

0 comments on commit 1bb1766

Please sign in to comment.