allow switching between habit puzzles

This commit is contained in:
2022-07-09 01:16:39 +00:00
parent 5cd71fa8b8
commit 2618bf44ae

View File

@@ -16,6 +16,16 @@
(super.update elapsed) (super.update elapsed)
// Hold left-click to hide the habit text and see the image clearly: // Hold left-click to hide the habit text and see the image clearly:
(when entryTexts (if FlxG.mouse.pressed (remove entryTexts) (add entryTexts))) (when entryTexts (if FlxG.mouse.pressed (remove entryTexts) (add entryTexts)))
// Left and right arrow keys can switch between unlocked puzzles
(when FlxG.keys.justPressed.LEFT
(unless (= rewardFileIndex 0)
(-= rewardFileIndex 1)
(setModel model (nth model.rewardFiles rewardFileIndex))))
(when FlxG.keys.justPressed.RIGHT
(unless (= rewardFileIndex maxRewardFile)
(+= rewardFileIndex 1)
(setModel model (nth model.rewardFiles rewardFileIndex))))
// Handle keyboard input: // Handle keyboard input:
(when shortcutHandler (when shortcutHandler
(shortcutHandler.update))) (shortcutHandler.update)))
@@ -31,19 +41,24 @@
(var TOTAL_PIECES (* PUZZLE_WIDTH PUZZLE_HEIGHT)) (var TOTAL_PIECES (* PUZZLE_WIDTH PUZZLE_HEIGHT))
(prop &mut :FlxTypedGroup<FlxExtendedSprite> rewardSprites null) (prop &mut :FlxTypedGroup<FlxExtendedSprite> rewardSprites null)
(method setModel [m] (prop &mut rewardFileIndex 0)
(prop &mut maxRewardFile 0)
(method setModel [m &opt :RewardFile currentRewardFile]
(set model m) (set model m)
(set shortcutHandler (new FlxKeyShortcutHandler)) (set shortcutHandler (new FlxKeyShortcutHandler))
(let [p (m.totalPoints) (let [p (m.totalPoints)
&mut i 0 &mut i 0 ]
&mut currentRewardFile null]
// Find, load, and add the current reward image as big as possible: // Find, load, and add the current reward image as big as possible:
(set currentRewardFile (nth m.rewardFiles 0)) (unless currentRewardFile
(while (> p .startingPoints (nth m.rewardFiles i)) (set currentRewardFile (nth m.rewardFiles 0))
(set currentRewardFile (nth m.rewardFiles i)) (while (> p .startingPoints (nth m.rewardFiles i))
(if (>= ++i m.rewardFiles.length) (set rewardFileIndex i)
(break))) (set currentRewardFile (nth m.rewardFiles i))
(set maxRewardFile i)
(if (>= ++i m.rewardFiles.length)
(break))))
(when rewardSprites (when rewardSprites
(remove rewardSprites)) (remove rewardSprites))
@@ -53,6 +68,8 @@
(joinPath (joinPath
(Path.directory m.textFile) (Path.directory m.textFile)
currentRewardFile.path)))] currentRewardFile.path)))]
(when rewardSprites
(remove rewardSprites))
(rewardSprite.setGraphicSize FlxG.width 0) (rewardSprite.setGraphicSize FlxG.width 0)
(rewardSprite.updateHitbox) (rewardSprite.updateHitbox)
(when (> rewardSprite.height FlxG.height) (when (> rewardSprite.height FlxG.height)