Skip to content

Commit

Permalink
dragend also clears pool index if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
skedwards88 committed Aug 20, 2023
1 parent efb6dbf commit a3562be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO

- use lodash deep clone
- hide drag image do like did in sector

- make small puzzle more interconnected -- maybe by limiting grid size during generation?
Expand Down
29 changes: 24 additions & 5 deletions src/logic/gameReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,31 @@ export function gameReducer(currentGameState, payload) {
// according to the HTML spec, the drop event fires before the dragEnd event,
// so we can assume that we can safely clear any drag data now
// (This is here to handle the case where the user drops the pieces somewhere
// that is not a drop target, meaning the drop event didn't fire)
// that is not a drop target, meaning the drop event didn't fire.)
// In this case, we need to clear the drag data.
// We also want to make sure that the dragged piece isn't registered both as on the board and on the pool

return {
...currentGameState,
dragData: {},
};
const draggedPieceID = currentGameState.dragData?.pieceID;
if (
draggedPieceID != undefined &&
currentGameState.pieces[draggedPieceID].poolIndex != undefined &&
currentGameState.pieces[draggedPieceID].boardTop != undefined &&
currentGameState.pieces[draggedPieceID].boardLeft != undefined
) {
let newPieces = JSON.parse(JSON.stringify(currentGameState.pieces));
newPieces[draggedPieceID].poolIndex = undefined;

return {
...currentGameState,
dragData: {},
pieces: newPieces,
};
} else {
return {
...currentGameState,
dragData: {},
};
}
} else if (payload.action === "clearStreakIfNeeded") {
const lastDateWon = currentGameState.stats.lastDateWon;
const wonYesterday = isYesterday(lastDateWon);
Expand Down

0 comments on commit a3562be

Please sign in to comment.