From ad540e4c4b261ea1383c171d5382f7e962da57a1 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Tue, 3 Oct 2023 20:32:47 -0700 Subject: [PATCH] Fix bug whereby arrow ignored ephemeral tiles --- ui/src/Game.tsx | 11 ++++++++++- ui/src/utils.ts | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ui/src/Game.tsx b/ui/src/Game.tsx index 51f476a..2c21f20 100644 --- a/ui/src/Game.tsx +++ b/ui/src/Game.tsx @@ -95,7 +95,15 @@ export function Game(props: { } const new_position = current_x + current_y * GRID_LENGTH; - if(current_x < GRID_LENGTH && current_y < GRID_LENGTH && boardLetters[new_position] == null) { + let tray_letter_at_position = false; // need to also check if the player put a letter in the spot + for (const letter of update.playerLetters) { + if (letter != null && letter.location == LocationType.GRID && letter.index == new_position) { + tray_letter_at_position = true; + break + } + } + + if(current_x < GRID_LENGTH && current_y < GRID_LENGTH && boardLetters[new_position] == null && !tray_letter_at_position) { return { direction: existing.direction, position: new_position, @@ -184,6 +192,7 @@ export function Game(props: { }; gridArrowDispatch({ action: GridArrowDispatchActionType.SHIFT, + playerLetters: playerLetters }); return movePlayableLetters(playerLetters, { action: TileDispatchActionType.MOVE, diff --git a/ui/src/utils.ts b/ui/src/utils.ts index e225cfc..cea6532 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -55,7 +55,12 @@ export enum GridArrowDispatchActionType { SHIFT, } -export type GridArrowDispatchAction = {action: GridArrowDispatchActionType, position?: number}; +// I need to include the playerLetters as an argument because I can't define gridArrow after defining the playerLetters in +export type GridArrowDispatchAction = { + action: GridArrowDispatchActionType, + position?: number, + playerLetters?: PlayableLetterData[] // only needs to be defined on action type SHIFT +}; export type GridArrowDispatch = React.Dispatch; export function matchCoordinate(playerLetters: PlayableLetterData[], coords: CoordinateData): number {