diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx index 7bd30598..11889cb7 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.hx @@ -15,6 +15,7 @@ import openfl.geom.Rectangle; import openfl.geom.Point; import openfl.geom.ColorTransform; import flixel.util.FlxSpriteUtil; +import flixel.util.FlxSave; import flixel.input.mouse.FlxMouseEventManager; import flixel.addons.display.FlxExtendedSprite; import flixel.addons.plugin.FlxMouseControl; diff --git a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss index 2ebd1de8..ff8e4fd7 100644 --- a/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss +++ b/projects/flixel-desktop-habit-puzzle-game/source/HabitState.kiss @@ -30,6 +30,7 @@ (when shortcutHandler (shortcutHandler.update))) +(prop &mut :FlxSave save null) (prop &mut :FlxTypedGroup entryTexts null) (prop &mut :FlxKeyShortcutHandler shortcutHandler null) @@ -60,8 +61,11 @@ (if (>= ++i m.rewardFiles.length) (break)))) - (when rewardSprites - (remove rewardSprites)) + (set save (new FlxSave)) + (save.bind currentRewardFile.path) + (unless save.data.storedPositions + (set save.data.storedPositions (new Map))) + (let [rewardSprite (new FlxSprite 0 0 (BitmapData.fromFile @@ -92,20 +96,31 @@ PIECE_HEIGHT (/ rewardSprite.height PUZZLE_HEIGHT) :Array startingPoints []] - (doFor y (range PUZZLE_HEIGHT) - (doFor x (range PUZZLE_WIDTH) - (startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT)))))) + (let [&mut i 0] + (doFor y (range PUZZLE_HEIGHT) + (doFor x (range PUZZLE_WIDTH) + (startingPoints.push + (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT)))) + (+= i 1)))) (r.shuffle startingPoints) (set jigsaw j) (doFor i (range (min TOTAL_PIECES (- p currentRewardFile.startingPoints))) (let [jig (nth jigsaw.jigs i) - pos (nth startingPoints i) + pos (ifLet [point ~(dictGet (the Map save.data.storedPositions) i)] + point + (nth startingPoints i)) s (new FlxExtendedSprite pos.x pos.y) source (new FlxSprite) mask (new FlxSprite) sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)] (set s.draggable true) (s.enableMouseDrag false true) + (set s.mouseStopDragCallback + ->:Void [s x y] + { + ~(dictSet (the Map save.data.storedPositions) i (new FlxPoint s.x s.y)) + (save.flush) + }) (source.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true) (source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))