Skip to content

Commit

Permalink
make custom pool ui reflect possible actions
Browse files Browse the repository at this point in the history
  • Loading branch information
skedwards88 committed Aug 19, 2024
1 parent 72736cf commit 82236bd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ For screenshots:
// todo wip new, incomplete file
- Use the hasVisited state to announce
- put arrayToGrid to common or to word-logic package
- make way to share (of if can't share, to get link)
21 changes: 0 additions & 21 deletions src/components/CustomPool.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React from "react";
import Piece from "./Piece";
import DragShadow from "./DragShadow";
import {countingGrid} from "./Board";

export default function CustomPool({
pieces,
dragDestination,
dispatchGameState,
}) {
const poolPieces = pieces.filter((piece) => piece.poolIndex >= 0);
Expand All @@ -24,24 +21,6 @@ export default function CustomPool({
</div>
));

if (dragDestination?.where === "pool") {
const draggedPieces = pieces.filter((piece) => piece.dragGroupTop >= 0);
pieceElements.splice(
dragDestination.index,
0,
draggedPieces.map((piece) => (
<div className="pool-slot shadow" key={piece.id}>
<DragShadow
key={`shadow-piece-${piece.id}`}
grid={countingGrid(piece.letters.length, piece.letters[0].length, [
{...piece, dragGroupTop: 0, dragGroupLeft: 0},
])}
/>
</div>
)),
);
}

return <div id="pool">{pieceElements}</div>;
}

Expand Down
19 changes: 15 additions & 4 deletions src/logic/customReducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {updatePieceDatum} from "./assemblePiece";
import {getConnectedPieceIDs} from "./getConnectedPieceIDs";
import {updateDragState} from "./updateDragState";
import {arraysMatchQ} from "@skedwards88/word_logic";

function updateStateForDragStart({
currentGameState,
Expand Down Expand Up @@ -91,6 +90,17 @@ function updateStateForDragStart({
};
}

// If dragging from the pool, add a dummy placeholder
let placeholderPoolPieces = [];
if (groupBoardTop === undefined) {
placeholderPoolPieces = piecesBeingDragged.map((piece) =>
updatePieceDatum(piece, {
letters: [[""]],
id: (piece.id + 1) * (-1)
}),
)
}

currentGameState = {
...currentGameState,
pieces: piecesNotBeingDragged.concat(
Expand All @@ -106,7 +116,7 @@ function updateStateForDragStart({
groupBoardLeft === undefined ? 0 : piece.boardLeft - groupBoardLeft,
}),
),
),
).concat(placeholderPoolPieces),
dragCount: currentGameState.dragCount + 1,
dragState: updateDragState({
pieceIDs: piecesBeingDragged.map((piece) => piece.id),
Expand Down Expand Up @@ -193,6 +203,7 @@ function updateStateForDragEnd(currentGameState) {
);
}
} else if (
piece.letters[0][0] !== "" &&
!overwrittenPositions.some(
(position) =>
position[0] == piece.boardTop && position[1] == piece.boardLeft,
Expand All @@ -206,7 +217,7 @@ function updateStateForDragEnd(currentGameState) {
for (const piece of currentGameState.pieces) {
if (draggedPieceIDs.includes(piece.id)) {
continue;
} else {
} else if (piece.letters[0][0] !== ""){
newPieces.push(piece);
}
}
Expand All @@ -222,7 +233,7 @@ function updateStateForDragEnd(currentGameState) {
dragGroupLeft: undefined,
}),
);
} else {
} else if (piece.letters[0][0] !== ""){
newPieces.push(piece);
}
}
Expand Down

0 comments on commit 82236bd

Please sign in to comment.