Skip to content

Commit

Permalink
when sent custom puzzle, show game instead of daily
Browse files Browse the repository at this point in the history
  • Loading branch information
skedwards88 committed Nov 11, 2024
1 parent 09d21aa commit 6881314
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
21 changes: 1 addition & 20 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,7 @@
- piece rotation
- transpose grid/game solved logic will only work for square grid

For screenshots:

const grid = [
["","","","","","","","","","","",""],
["","","","","","","","","","","",""],
["","","","","","","","","","B","",""],
["","","P","U","Z","Z","L","E","","R","",""],
["","","L","","","","E","","","A","",""],
["","G","A","M","E","","T","","","I","",""],
["","","Y","","","","T","H","I","N","K",""],
["","","","","","","E","","","","",""],
["","","","","W","O","R","D","","","",""],
["","","","","","","","","","","",""],
["","","","","","","","","","","",""],
["","","","","","","","","","","",""]
]

const pieces = [{"letters":[["P","U","Z"],["L","",""],["A","",""]],"solutionTop":3,"solutionLeft":2},{"letters":[["B"],["R"],["A"]],"solutionTop":2,"solutionLeft":9},{"letters":[["","T","H"],["","E",""],["O","R","D"]],"solutionTop":6,"solutionLeft":5},{"letters":[["M","E"]],"solutionTop":5,"solutionLeft":3},{"letters":[["","I",""],["I","N","K"]],"solutionTop":5,"solutionLeft":8},{"letters":[["W"]],"solutionTop":8,"solutionLeft":4},{"letters":[["G"]],"solutionTop":5,"solutionLeft":1},{"letters":[["Y"]],"solutionTop":6,"solutionLeft":2},{"letters":[["Z","L","E"],["","E",""],["","T",""]],"solutionTop":3,"solutionLeft":5}];

// todo later PR:
For screenshots: https://crossjig.com/?id=custom-833T4HMRRDW1J4D3W2S3YSEW1L2A4Q3LZAFC7W9OGJV40

- add some custom daily puzzles

Expand Down
11 changes: 10 additions & 1 deletion src/common/getInitialState.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export function getInitialState(savedDisplay, hasVisitedEver, hasSeenWhatsNew) {
export function getInitialState(
savedDisplay,
hasVisitedEver,
hasSeenWhatsNew,
isCustom,
) {
if (!hasVisitedEver) {
return "rules";
}
Expand All @@ -7,6 +12,10 @@ export function getInitialState(savedDisplay, hasVisitedEver, hasSeenWhatsNew) {
return "whatsNew";
}

if (isCustom) {
return "game";
}

if (savedDisplay === "game" || savedDisplay === "daily") {
return savedDisplay;
}
Expand Down
18 changes: 11 additions & 7 deletions src/common/getInitialState.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ import {getInitialState} from "./getInitialState";

describe("getInitialState", () => {
test("returns 'rules' if hasVisitedEver is false", () => {
expect(getInitialState("game", false, true)).toBe("rules");
expect(getInitialState("game", false, true, true)).toBe("rules");

expect(getInitialState("game", false, false)).toBe("rules");
expect(getInitialState("game", false, false, true)).toBe("rules");
});

test("returns 'whatsNew' if hasSeenWhatsNew is false", () => {
expect(getInitialState("game", true, false)).toBe("whatsNew");
expect(getInitialState("game", true, false, true)).toBe("whatsNew");
});

test("returns 'game' if hasVisitedEver and hasSeenWhatsNew are true and savedDisplay is 'game", () => {
expect(getInitialState("game", true, true)).toBe("game");
expect(getInitialState("game", true, true, false)).toBe("game");
});

test("returns 'daily' if hasVisitedEver and hasSeenWhatsNew are true and savedDisplay is 'daily", () => {
expect(getInitialState("daily", true, true)).toBe("daily");
expect(getInitialState("daily", true, true, false)).toBe("daily");
});

test("returns 'game' if hasVisitedEver and hasSeenWhatsNew are and savedDisplay is not 'game' or 'daily", () => {
expect(getInitialState("rules", true, true)).toBe("game");
test("returns 'game' if hasVisitedEver and hasSeenWhatsNew are true and savedDisplay is 'daily but isCustom is true", () => {
expect(getInitialState("daily", true, true, true)).toBe("game");
});

test("returns 'game' if hasVisitedEver and hasSeenWhatsNew are true and savedDisplay is not 'game' or 'daily", () => {
expect(getInitialState("rules", true, true, false)).toBe("game");
});
});
2 changes: 1 addition & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function App() {
// Determine what view to show the user
const savedDisplay = JSON.parse(localStorage.getItem("crossjigDisplay"));
const [display, setDisplay] = React.useState(
getInitialState(savedDisplay, hasVisitedEver, hasSeenWhatsNew),
getInitialState(savedDisplay, hasVisitedEver, hasSeenWhatsNew, isCustom),
);

// Determine the opacity for the validity indicator
Expand Down

0 comments on commit 6881314

Please sign in to comment.