Skip to content

Commit

Permalink
clean up some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skedwards88 committed Aug 25, 2024
1 parent b8b0acd commit 7ec7e61
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/CustomCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function CustomCreation({dispatchCustomState, customState, validityOpacity}) {
indicateValidity={validityOpacity > 0}
dragPieceIDs={customState.dragState?.pieceIDs}
dragDestination={customState.dragState?.destination}
gridSize={12}
gridSize={customState.gridSize}
customCreation={true}
></Board>
<Pool
Expand Down
2 changes: 1 addition & 1 deletion src/logic/convertGridToRepresentativeString.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {cipherLetter} from "./cipherLetter";
// Spaces are represented by an integer indicating the number of consecutive spaces.
// (Spaces that span rows are considered part of the same consecutive group of spaces.)
// Letters in the string are shifted by the cipherShift amount,
// and the shift amount is prepended to the string
// and the shift amount is prepended to the string.
export function convertGridToRepresentativeString(grid, cipherShift = 0) {
// Error if cipherShift is not an int between 0 and 9
if (!Number.isInteger(cipherShift) || cipherShift < 0 || cipherShift > 9) {
Expand Down
1 change: 1 addition & 0 deletions src/logic/convertRepresentativeStringToGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function convertRepresentativeStringToGrid(string) {
// so I don't need to remove whitespace from the edges or center the grid.
// (Since this is done when the custom query is generated via the UI.)
// By this same logic, I'm not validating that the puzzle consists of known words.
// (Since that is done when a player tries to generate the query string via the UI.)

const grid = arrayToGrid(list);
return grid;
Expand Down
8 changes: 4 additions & 4 deletions src/logic/gameInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export function gameInit({
if (
savedState &&
savedState.seed &&
//todo verify comment clarity
// If daily or custom, use the saved state if the seed matches
// otherwise, we don't care if the seed matches
// Make sure the seed matches (unless this isn't a daily or custom game)
((!isDaily && !isCustom) || savedState.seed == seed) &&
validateSavedState(savedState) &&
// Use the saved state if daily even if the game is solved
Expand Down Expand Up @@ -90,7 +88,9 @@ export function gameInit({
maxShiftDown,
} = generatePuzzleFromRepresentativeString({representativeString: seed}));
} catch (error) {
console.error(error);
console.error(
`Error generating custom puzzle from seed ${seed}. Will proceed to generate random game instead. Caught error: ${error}`,
);

({pieces, maxShiftLeft, maxShiftRight, maxShiftUp, maxShiftDown} =
generatePuzzle({
Expand Down
9 changes: 6 additions & 3 deletions src/logic/gameReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function updateStateForDragStart({
};
}

// (For custom creation only) If dragging from the pool, add a dummy placeholder
// (For custom creation only)
// If dragging from the pool, add a dummy placeholder
let placeholderPoolPieces = [];
if (isCustomCreation && groupBoardTop === undefined) {
placeholderPoolPieces = piecesBeingDragged.map((piece) =>
Expand Down Expand Up @@ -289,8 +290,9 @@ function updateStateForCustomDragEnd(currentGameState) {
newPieces.push(piece);
}
}
} else if (destination.where === "pool" && origin.where === "board") {
// If dragging from board to pool, clear the piece from the board but don't add it to the pool
}
// If dragging from board to pool, clear the piece from the board but don't add it to the pool
else if (destination.where === "pool" && origin.where === "board") {
for (const piece of currentGameState.pieces) {
if (draggedPieceIDs.includes(piece.id)) {
continue;
Expand All @@ -300,6 +302,7 @@ function updateStateForCustomDragEnd(currentGameState) {
}
}
// If dragging from pool to pool, readd the piece to the pool at its original position
// (and get rid of the empty placeholder piece)
else if (destination.where === "pool" && origin.where === "pool") {
for (const piece of currentGameState.pieces) {
if (draggedPieceIDs.includes(piece.id)) {
Expand Down
8 changes: 4 additions & 4 deletions src/logic/generatePuzzleFromRepresentativeString.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export function generatePuzzleFromRepresentativeString({representativeString}) {

return {
pieces: pieceData,
maxShiftLeft: maxShiftLeft,
maxShiftRight: maxShiftRight,
maxShiftUp: maxShiftUp,
maxShiftDown: maxShiftDown,
maxShiftLeft,
maxShiftRight,
maxShiftUp,
maxShiftDown,
gridSize,
minLetters,
};
Expand Down

0 comments on commit 7ec7e61

Please sign in to comment.