From 3a14766563dde7dac27f847b79d2ff69070613dd Mon Sep 17 00:00:00 2001 From: MasterGordon Date: Sun, 13 Oct 2024 21:37:40 +0200 Subject: [PATCH] fixed build --- shared/game.test.ts | 2 ++ shared/game.ts | 1 + shared/testBoard.ts | 5 +++-- src/components/Board.tsx | 7 +++++-- src/themes/index.ts | 2 +- src/views/collection/Collection.tsx | 3 +-- src/views/endless/Endless.tsx | 2 -- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/shared/game.test.ts b/shared/game.test.ts index 8ef42a6..105ec4b 100644 --- a/shared/game.test.ts +++ b/shared/game.test.ts @@ -17,6 +17,7 @@ describe("Game", () => { it("should convert server to client game", () => { const serverGame: ServerGame = { + theme: "default", mines: [ [false, false, true, true, true], [true, false, true, false, true], @@ -52,6 +53,7 @@ describe("Game", () => { ], }; expect(serverToClientGame(serverGame)).toEqual({ + theme: "default", minesCount: 4, isRevealed: [ [false, false, true, false, true], diff --git a/shared/game.ts b/shared/game.ts index 31beff0..dec4b1b 100644 --- a/shared/game.ts +++ b/shared/game.ts @@ -39,5 +39,6 @@ export const serverToClientGame = (game: ServerGame): ClientGame => { lastClick: game.lastClick, started: game.started, stage: game.stage, + theme: game.theme, }; }; diff --git a/shared/testBoard.ts b/shared/testBoard.ts index 820d695..8f49804 100644 --- a/shared/testBoard.ts +++ b/shared/testBoard.ts @@ -4,7 +4,7 @@ const rotate = (arr: boolean[][]) => { return arr[0].map((_, colIndex) => arr.map((row) => row[colIndex])); }; -export const testBoard: ServerGame = { +export const testBoard: (theme: string) => ServerGame = (theme: string) => ({ user: "TestUser", uuid: "C270D7CD-AF97-42CE-A6C9-CB765102CA17", width: 11, @@ -38,4 +38,5 @@ export const testBoard: ServerGame = { [...Array(11).fill(false)], [...Array(11).fill(false)], ]), -}; + theme, +}); diff --git a/src/components/Board.tsx b/src/components/Board.tsx index 6653ecc..6b9274f 100644 --- a/src/components/Board.tsx +++ b/src/components/Board.tsx @@ -36,10 +36,10 @@ import "@pixi/canvas-renderer"; import "@pixi/canvas-sprite-tiling"; import "@pixi/canvas-sprite"; import "@pixi/canvas-text"; +import { themes } from "../themes"; interface BoardProps { className?: string; - theme: Theme; game: ServerGame | ClientGame; onLeftClick: (x: number, y: number) => void; onRightClick: (x: number, y: number) => void; @@ -120,7 +120,10 @@ const Board: React.FC = (props) => { resizeObserver.observe(ref.current); return () => resizeObserver.disconnect(); }, [onViewportChange]); - const theme = useTheme(props.theme); + const theme = useTheme( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + themes.find((t) => t.id === (game.theme as any))!.theme, + ); const boardWidth = game.width * (theme?.size || 0); const boardHeight = game.height * (theme?.size || 0); diff --git a/src/themes/index.ts b/src/themes/index.ts index cc9725f..dd252ad 100644 --- a/src/themes/index.ts +++ b/src/themes/index.ts @@ -45,7 +45,7 @@ interface ThemeEntry { tags: string[]; /** dont't ever change this! */ id: string; - theme: Theme; + theme: Readonly; } export const themes = [ diff --git a/src/views/collection/Collection.tsx b/src/views/collection/Collection.tsx index aad679b..2c175e8 100644 --- a/src/views/collection/Collection.tsx +++ b/src/views/collection/Collection.tsx @@ -68,8 +68,7 @@ const Collection = () => { {}} restartGame={() => {}} onRightClick={() => {}} diff --git a/src/views/endless/Endless.tsx b/src/views/endless/Endless.tsx index 19afa3b..47a5938 100644 --- a/src/views/endless/Endless.tsx +++ b/src/views/endless/Endless.tsx @@ -1,4 +1,3 @@ -import { defaultTheme } from "../../themes/default"; import Board from "../../components/Board"; import { useWSMutation, useWSQuery } from "../../hooks"; import { useAtom } from "jotai"; @@ -46,7 +45,6 @@ const Endless: React.FC = (props) => { { const gameId = await startGame.mutateAsync(null);