Skip to content

Commit

Permalink
Prevent reset glitch on win
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijsgroen committed Jan 21, 2025
1 parent 161f598 commit 6913cda
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/modules/Level/Level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ export const Level: React.FC<Props> = ({

const localRandom = mulberry32(levelNr * 386);

const [levelState, setLevelState, deleteLevelState] =
const [storedLevelState, setLevelState, deleteLevelState] =
useGameStorage<LevelState>(storageKey, initialLevelState);
const [frozenLevelState, setFrozenLevelState] = useState<LevelState | null>(
null
);
const levelState = frozenLevelState ?? storedLevelState;

const [lostCounter, setLostCounter] = useGameStorage(
`${storagePrefix}lostCounter`,
Expand Down Expand Up @@ -133,6 +137,7 @@ export const Level: React.FC<Props> = ({
if (hasWon(levelState)) {
setPlayState("won");
setLostCounter(0);
setFrozenLevelState(levelState);
} else if (isStuck(levelState)) {
setPlayState("lost");
setLostCounter((a) => a + 1);
Expand Down Expand Up @@ -305,12 +310,12 @@ export const Level: React.FC<Props> = ({
if (hintMode === "off" && useStreak) {
setStreak((s) => (s ? s + 1 : 1));
}
onComplete(playState === "won");
deleteMoves();
deletePreviousMoves();
deleteRevealed();
clearThemeOverride();
deleteLevelState(false);
onComplete(playState === "won");
}}
onShow={() => {
sound.play("win");
Expand Down

0 comments on commit 6913cda

Please sign in to comment.