Fix bug whereby arrow ignored ephemeral tiles

This commit is contained in:
Joel Therrien 2023-10-03 20:32:47 -07:00
parent ceb5d6c20d
commit ad540e4c4b
2 changed files with 16 additions and 2 deletions

View file

@ -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,

View file

@ -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 <Game>
export type GridArrowDispatchAction = {
action: GridArrowDispatchActionType,
position?: number,
playerLetters?: PlayableLetterData[] // only needs to be defined on action type SHIFT
};
export type GridArrowDispatch = React.Dispatch<GridArrowDispatchAction>;
export function matchCoordinate(playerLetters: PlayableLetterData[], coords: CoordinateData): number {