fix pieces matching with non-matching pieces

This commit is contained in:
2022-08-12 19:13:05 +00:00
parent 2a438f43b5
commit 175a956294

View File

@@ -224,7 +224,7 @@
(set jigsaw j) (set jigsaw j)
(r.shuffle jigsaw.jigs) (r.shuffle jigsaw.jigs)
(localVar spriteGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) null))) (localVar spriteGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) null)))
(localVar indexGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) 0))) (localVar indexGrid (for y (range PUZZLE_HEIGHT) (for x (range PUZZLE_WIDTH) -1)))
(doFor i (range (min TOTAL_PIECES (* currentRewardFile.piecesPerPoint (- p currentRewardFile.startingPoints)))) (doFor i (range (min TOTAL_PIECES (* currentRewardFile.piecesPerPoint (- p currentRewardFile.startingPoints))))
(let [jig (nth jigsaw.jigs i) (let [jig (nth jigsaw.jigs i)
pos (ifLet [point (dictGet (the Map<Int,FlxPoint> save.data.storedPositions) i)] pos (ifLet [point (dictGet (the Map<Int,FlxPoint> save.data.storedPositions) i)]
@@ -286,17 +286,19 @@
(doFor row (range PUZZLE_HEIGHT) (doFor row (range PUZZLE_HEIGHT)
(doFor col (range PUZZLE_WIDTH) (doFor col (range PUZZLE_WIDTH)
(let [id (nth indexGrid row col)] (let [id (nth indexGrid row col)]
// combination of try/whenLet should cover target languages (when (= id -1) (continue))
// where out-of-bounds nth throws an error AND languages (when (>= (- col 1) 0)
// where it returns null (let [toLeft (nth spriteGrid row (- col 1))]
(try (whenLet [toLeft (nth spriteGrid row (- col 1))] (dictSet matchingPiecesLeft id toLeft)))
(dictSet matchingPiecesLeft id toLeft)) (catch [e] null)) (when (< (+ col 1) PUZZLE_WIDTH)
(try (whenLet [toRight (nth spriteGrid row (+ col 1))] (let [toRight (nth spriteGrid row (+ col 1))]
(dictSet matchingPiecesRight id toRight)) (catch [e] null)) (dictSet matchingPiecesRight id toRight)))
(try (whenLet [toUp (nth spriteGrid (- row 1) col)] (when (>= (- row 1) 0)
(dictSet matchingPiecesUp id toUp)) (catch [e] null)) (let [toUp (nth spriteGrid (- row 1) col)]
(try (whenLet [toDown (nth spriteGrid (+ row 1) col)] (dictSet matchingPiecesUp id toUp)))
(dictSet matchingPiecesDown id toDown)) (catch [e] null))))) (when (< (+ row 1) PUZZLE_HEIGHT)
(let [toDown (nth spriteGrid (+ row 1) col)]
(dictSet matchingPiecesDown id toDown))))))
(add rewardSprites) (add rewardSprites)
(doFor i (range TOTAL_PIECES) (doFor i (range TOTAL_PIECES)
(checkMatches i)))) (checkMatches i))))