Fix vertical placement hover bug
- Improve handleCellHover logic to consider all ways a domino could cover the hovered cell, including vertical placements that start at the cell above. This ensures you can always put a vertical domino back to its original position by hovering over the relevant adjacent cell. X-Lovable-Edit-ID: edt-40e80a71-a4ae-4645-a1b3-e8105a8f3680
This commit is contained in:
commit
9ab07e0421
1 changed files with 17 additions and 8 deletions
|
|
@ -161,17 +161,26 @@ const DominoRetilingPuzzle: React.FC<DominoRetilingPuzzleProps> = ({ showSocialS
|
|||
const handleCellHover = (row: number, col: number) => {
|
||||
if (selectedDomino === null) return;
|
||||
|
||||
// Check which placements are valid for this cell
|
||||
const canH = canPlaceDomino(row, col, true, selectedDomino);
|
||||
const canV = canPlaceDomino(row, col, false, selectedDomino);
|
||||
// Check all possible placements where this cell could be part of a domino
|
||||
// A domino can be placed with this cell as the first cell, or as the second cell
|
||||
|
||||
// Horizontal placements: domino at (row, col) or (row, col-1)
|
||||
const canH_start = canPlaceDomino(row, col, true, selectedDomino);
|
||||
const canH_end = col > 0 && canPlaceDomino(row, col - 1, true, selectedDomino);
|
||||
|
||||
// Vertical placements: domino at (row, col) or (row-1, col)
|
||||
const canV_start = canPlaceDomino(row, col, false, selectedDomino);
|
||||
const canV_end = row > 0 && canPlaceDomino(row - 1, col, false, selectedDomino);
|
||||
|
||||
if (canH && canV) {
|
||||
// Prefer horizontal
|
||||
// Prioritize: horizontal starting here, horizontal ending here, vertical starting here, vertical ending here
|
||||
if (canH_start) {
|
||||
setHoverPlacement({ row, col, isHorizontal: true });
|
||||
} else if (canH) {
|
||||
setHoverPlacement({ row, col, isHorizontal: true });
|
||||
} else if (canV) {
|
||||
} else if (canH_end) {
|
||||
setHoverPlacement({ row, col: col - 1, isHorizontal: true });
|
||||
} else if (canV_start) {
|
||||
setHoverPlacement({ row, col, isHorizontal: false });
|
||||
} else if (canV_end) {
|
||||
setHoverPlacement({ row: row - 1, col, isHorizontal: false });
|
||||
} else {
|
||||
setHoverPlacement(null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue