From 11ffa7512954ff95d843474a94cb8a14a088c796 Mon Sep 17 00:00:00 2001 From: Jason Reed Date: Tue, 5 Mar 2024 18:24:07 -0500 Subject: [PATCH] Make safe-storage work (fix #179) --- src/core/grid.ts | 6 +++++- src/core/state-helpers.ts | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/grid.ts b/src/core/grid.ts index 3f0c23d..4388125 100644 --- a/src/core/grid.ts +++ b/src/core/grid.ts @@ -1,6 +1,6 @@ import { DEBUG } from "../util/debug"; import { Point, Rect } from "../util/types"; -import { boundRect } from "../util/util"; +import { boundRect, mapval } from "../util/util"; import { vtrans } from "../util/vutil"; import { AbstractLetter, stringOfLetter } from "./letters"; import { MainTile, TileNoId } from './state-types'; @@ -231,3 +231,7 @@ export function gridKeys(x: UbGrid): Point[] { export function unionGrids(x: UbGrid, y: UbGrid): UbGrid { return { elems: { ...x.elems, ...y.elems } }; } + +export function mapGrid(x: UbGrid, f: (x: T) => U): UbGrid { + return { elems: mapval(x.elems, f) }; +} diff --git a/src/core/state-helpers.ts b/src/core/state-helpers.ts index be29240..c0be09f 100644 --- a/src/core/state-helpers.ts +++ b/src/core/state-helpers.ts @@ -15,7 +15,7 @@ import { PauseData, WORD_BONUS_INTERVAL_MS, now_in_game } from "./clock"; import { DrawForce, getLetterSample } from "./distribution"; import { updateFogOfWar } from "./fog-of-war"; import { freshPanic } from "./fresh-panic"; -import { checkConnected, checkGridWords, gridKeys, mkGridOfMainTiles } from "./grid"; +import { checkConnected, checkGridWords, gridKeys, mapGrid, mkGridOfMainTiles, unionGrids } from "./grid"; import { mkOverlayFrom, overlayAny, overlayPoints, setOverlay } from "./layer"; import { AbstractLetter } from "./letters"; import { addRandomMob } from "./mob-helpers"; @@ -156,7 +156,9 @@ export function checkValid(state: CoreState): CoreState { const oldConnectedSet = state.connectedSet; const { validWords, invalidWords } = checkGridWords(grid, word => getAssets().dictionary[word] || DEBUG.allWords); - const { allConnected, connectedSet } = checkConnected(grid); + const { allConnected, connectedSet: realConnectedSet } = checkConnected(grid); + const connectedSet = unionGrids(realConnectedSet, mapGrid(mkGridOfMainTiles(safeTiles), _ => true)); + let allValid = false; if (invalidWords.length == 0 && allConnected && get_hand_tiles(state).length == 0) { state = resolveValid(state, new Set(validWords.map(x => x.word)));