From 71b24fedeee964961c1d460d1cc2214502a37dc5 Mon Sep 17 00:00:00 2001 From: Martin Berg Alstad <600878@stud.hvl.no> Date: Fri, 21 Jul 2023 16:49:56 +0200 Subject: [PATCH] Fixed typeError on vitest --- .../ClientApp/src/components/gameComponent.tsx | 1 + .../ClientApp/src/game/possibleMovesAlgorithm.ts | 16 ++++++++-------- pac-man-board-game/ClientApp/src/utils/api.ts | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pac-man-board-game/ClientApp/src/components/gameComponent.tsx b/pac-man-board-game/ClientApp/src/components/gameComponent.tsx index 6039958..8b12e13 100644 --- a/pac-man-board-game/ClientApp/src/components/gameComponent.tsx +++ b/pac-man-board-game/ClientApp/src/components/gameComponent.tsx @@ -19,6 +19,7 @@ const wsService = new WebSocketService(import.meta.env.VITE_API_WS); // TODO bug, when refreshing page, some data is missing until other clients make a move // TODO bug, teleportation doesn't work +// TODO guest users // TODO store map in backend and save it in state on each client // TODO add debug menu on dev, for testing and cheating // TODO sign up player page diff --git a/pac-man-board-game/ClientApp/src/game/possibleMovesAlgorithm.ts b/pac-man-board-game/ClientApp/src/game/possibleMovesAlgorithm.ts index 17cb44a..025402f 100644 --- a/pac-man-board-game/ClientApp/src/game/possibleMovesAlgorithm.ts +++ b/pac-man-board-game/ClientApp/src/game/possibleMovesAlgorithm.ts @@ -18,26 +18,26 @@ export default function findPossiblePositions(board: GameMap, character: Charact }; /** - * Uses recursion to move through the board and find all the possible positions - * @param board The board the character is on + * Uses recursion to move through the map and find all the possible positions + * @param map The map the character is on * @param currentPath The current path the character is on * @param steps The number of steps the character can move * @param character The current character * @param characters * @returns An array of paths the character can move to */ -function findPossibleRecursive(board: GameMap, currentPath: Path, steps: number, character: Character, characters: Character[]): Path[] { +function findPossibleRecursive(map: GameMap, currentPath: Path, steps: number, character: Character, characters: Character[]): Path[] { const paths: Path[] = []; - if (isOutsideBoard(currentPath, board.length)) { // TODO not working on new map + if (isOutsideBoard(currentPath, map.length)) { // TODO not working on new map if (character.isPacMan()) { - return addTeleportationTiles(board, currentPath, steps, character, characters); + return addTeleportationTiles(map, currentPath, steps, character, characters); } - } else if (!isWall(board, currentPath)) { + } else if (!isWall(map, currentPath)) { if (!characterHitsAnotherCharacter(character, currentPath, characters)) { if (steps <= 0) { - if (!(isSpawn(board, currentPath) && !isOwnSpawn(currentPath, character))) { + if (!(isSpawn(map, currentPath) && !isOwnSpawn(currentPath, character))) { paths.push(currentPath); } @@ -47,7 +47,7 @@ function findPossibleRecursive(board: GameMap, currentPath: Path, steps: number, steps--; for (const direction of getDirections()) { - paths.push(...tryMove(board, currentPath, direction, steps, character, characters)); + paths.push(...tryMove(map, currentPath, direction, steps, character, characters)); } } } else { diff --git a/pac-man-board-game/ClientApp/src/utils/api.ts b/pac-man-board-game/ClientApp/src/utils/api.ts index 32cfb36..b9ab872 100644 --- a/pac-man-board-game/ClientApp/src/utils/api.ts +++ b/pac-man-board-game/ClientApp/src/utils/api.ts @@ -1,4 +1,5 @@ export const getData: Api = async (path, {headers} = {}) => { + if (import.meta.env.MODE === "test") return Promise.resolve(new Response(JSON.stringify([]))); return await fetch(import.meta.env.VITE_API_HTTP + path, { method: "GET", headers: headers