From dc66e2fc8170a2239b6471929f0c660028fa591b Mon Sep 17 00:00:00 2001 From: skedwards88 Date: Thu, 29 Aug 2024 09:34:11 -0700 Subject: [PATCH] make validity opacity setting --- src/components/App.js | 25 +++++++++++++++++++------ src/components/Game.js | 6 +++--- src/components/Settings.js | 20 ++++++++++++-------- src/logic/gameInit.js | 2 -- src/logic/gameReducer.js | 5 ----- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/components/App.js b/src/components/App.js index 68bd5a1..be7f7d0 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -51,6 +51,12 @@ export default function App() { getInitialState(savedDisplay, hasVisited), ); + // Determine the opacity for the validity indicator + const savedValidityOpacity = + JSON.parse(localStorage.getItem("crossjigValidityOpacity")) ?? 0.15; + const [validityOpacity, setValidityOpacity] = + React.useState(savedValidityOpacity); + // Set up states that will be used by the handleAppInstalled and handleBeforeInstallPrompt listeners const [installPromptEvent, setInstallPromptEvent] = React.useState(); const [showInstallButton, setShowInstallButton] = React.useState(true); @@ -166,6 +172,13 @@ export default function App() { window.localStorage.setItem("crossjigDisplay", JSON.stringify(display)); }, [display]); + React.useEffect(() => { + window.localStorage.setItem( + "crossjigValidityOpacity", + JSON.stringify(validityOpacity), + ); + }, [validityOpacity]); + React.useEffect(() => { window.localStorage.setItem("crossjigState", JSON.stringify(gameState)); }, [gameState]); @@ -197,6 +210,8 @@ export default function App() { setDisplay={setDisplay} dispatchGameState={dispatchGameState} gameState={gameState} + setValidityOpacity={setValidityOpacity} + originalValidityOpacity={validityOpacity} /> ); @@ -224,11 +239,8 @@ export default function App() { @@ -309,7 +321,7 @@ export default function App() { @@ -362,6 +374,7 @@ export default function App() { ); diff --git a/src/components/Game.js b/src/components/Game.js index 8cca973..72d82e5 100644 --- a/src/components/Game.js +++ b/src/components/Game.js @@ -4,7 +4,7 @@ import Result from "./Result"; import Board from "./Board"; import DragGroup from "./DragGroup"; -function Game({dispatchGameState, gameState, setDisplay}) { +function Game({dispatchGameState, gameState, setDisplay, validityOpacity}) { // dragCount ensures a different key each time, so a fresh DragGroup is mounted even if there's // no render between one drag ending and the next one starting. const dragGroup = gameState.dragState ? ( @@ -20,7 +20,7 @@ function Game({dispatchGameState, gameState, setDisplay}) { style={{ "--grid-rows": gameState.gridSize, "--grid-columns": gameState.gridSize, - "--validity-opacity": gameState.validityOpacity, + "--validity-opacity": validityOpacity, }} > 0} + indicateValidity={validityOpacity > 0} > {gameState.allPiecesAreUsed ? ( {`Valid words are indicated with a strikethrough. This controls the brightness of the strikethrough.`}
EXAMPLE
@@ -61,13 +68,10 @@ export default function Settings({setDisplay, dispatchGameState, gameState}) { type="range" min={0} max={100} - defaultValue={gameState.validityOpacity * 100 || 15} + defaultValue={originalValidityOpacity * 100 || 15} onChange={(event) => { const newValidityOpacity = event.target.value / 100; - dispatchGameState({ - action: "changeValidityOpacity", - newValidityOpacity, - }); + setValidityOpacity(newValidityOpacity); }} />
diff --git a/src/logic/gameInit.js b/src/logic/gameInit.js index 073e8b5..3b02e83 100644 --- a/src/logic/gameInit.js +++ b/src/logic/gameInit.js @@ -30,7 +30,6 @@ function validateSavedState(savedState) { export function gameInit({ numLetters, - validityOpacity = 0.15, useSaved = true, isDaily = false, isCustom = false, @@ -157,7 +156,6 @@ export function gameInit({ hintTally: 0, dragCount: 0, dragState: undefined, - validityOpacity, isCustom, }; } diff --git a/src/logic/gameReducer.js b/src/logic/gameReducer.js index 9f9b67d..88d8026 100644 --- a/src/logic/gameReducer.js +++ b/src/logic/gameReducer.js @@ -555,11 +555,6 @@ export function gameReducer(currentGameState, payload) { seed: payload.representativeString, isCustom: true, }); - } else if (payload.action === "changeValidityOpacity") { - return { - ...currentGameState, - validityOpacity: payload.newValidityOpacity, - }; } else if (payload.action === "getHint") { sendAnalytics("hint");