save jigsaw positions
This commit is contained in:
@@ -15,6 +15,7 @@ import openfl.geom.Rectangle;
|
|||||||
import openfl.geom.Point;
|
import openfl.geom.Point;
|
||||||
import openfl.geom.ColorTransform;
|
import openfl.geom.ColorTransform;
|
||||||
import flixel.util.FlxSpriteUtil;
|
import flixel.util.FlxSpriteUtil;
|
||||||
|
import flixel.util.FlxSave;
|
||||||
import flixel.input.mouse.FlxMouseEventManager;
|
import flixel.input.mouse.FlxMouseEventManager;
|
||||||
import flixel.addons.display.FlxExtendedSprite;
|
import flixel.addons.display.FlxExtendedSprite;
|
||||||
import flixel.addons.plugin.FlxMouseControl;
|
import flixel.addons.plugin.FlxMouseControl;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
(when shortcutHandler
|
(when shortcutHandler
|
||||||
(shortcutHandler.update)))
|
(shortcutHandler.update)))
|
||||||
|
|
||||||
|
(prop &mut :FlxSave save null)
|
||||||
(prop &mut :FlxTypedGroup<FlxText> entryTexts null)
|
(prop &mut :FlxTypedGroup<FlxText> entryTexts null)
|
||||||
(prop &mut :FlxKeyShortcutHandler<Entry> shortcutHandler null)
|
(prop &mut :FlxKeyShortcutHandler<Entry> shortcutHandler null)
|
||||||
|
|
||||||
@@ -60,8 +61,11 @@
|
|||||||
(if (>= ++i m.rewardFiles.length)
|
(if (>= ++i m.rewardFiles.length)
|
||||||
(break))))
|
(break))))
|
||||||
|
|
||||||
(when rewardSprites
|
(set save (new FlxSave))
|
||||||
(remove rewardSprites))
|
(save.bind currentRewardFile.path)
|
||||||
|
(unless save.data.storedPositions
|
||||||
|
(set save.data.storedPositions (new Map<Int,FlxPoint>)))
|
||||||
|
|
||||||
(let [rewardSprite
|
(let [rewardSprite
|
||||||
(new FlxSprite 0 0
|
(new FlxSprite 0 0
|
||||||
(BitmapData.fromFile
|
(BitmapData.fromFile
|
||||||
@@ -92,20 +96,31 @@
|
|||||||
PIECE_HEIGHT
|
PIECE_HEIGHT
|
||||||
(/ rewardSprite.height PUZZLE_HEIGHT)
|
(/ rewardSprite.height PUZZLE_HEIGHT)
|
||||||
:Array<FlxPoint> startingPoints []]
|
:Array<FlxPoint> startingPoints []]
|
||||||
(doFor y (range PUZZLE_HEIGHT)
|
(let [&mut i 0]
|
||||||
(doFor x (range PUZZLE_WIDTH)
|
(doFor y (range PUZZLE_HEIGHT)
|
||||||
(startingPoints.push (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_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)
|
(r.shuffle startingPoints)
|
||||||
(set jigsaw j)
|
(set jigsaw j)
|
||||||
(doFor i (range (min TOTAL_PIECES (- p currentRewardFile.startingPoints)))
|
(doFor i (range (min TOTAL_PIECES (- p currentRewardFile.startingPoints)))
|
||||||
(let [jig (nth jigsaw.jigs i)
|
(let [jig (nth jigsaw.jigs i)
|
||||||
pos (nth startingPoints i)
|
pos (ifLet [point ~(dictGet (the Map<Int,FlxPoint> save.data.storedPositions) i)]
|
||||||
|
point
|
||||||
|
(nth startingPoints i))
|
||||||
s (new FlxExtendedSprite pos.x pos.y)
|
s (new FlxExtendedSprite pos.x pos.y)
|
||||||
source (new FlxSprite)
|
source (new FlxSprite)
|
||||||
mask (new FlxSprite)
|
mask (new FlxSprite)
|
||||||
sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)]
|
sourceRect (new Rectangle jig.xy.x jig.xy.y jig.wh.x jig.wh.y)]
|
||||||
(set s.draggable true)
|
(set s.draggable true)
|
||||||
(s.enableMouseDrag false true)
|
(s.enableMouseDrag false true)
|
||||||
|
(set s.mouseStopDragCallback
|
||||||
|
->:Void [s x y]
|
||||||
|
{
|
||||||
|
~(dictSet (the Map<Int,FlxPoint> 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.makeGraphic (Std.int sourceRect.width) (Std.int sourceRect.height) FlxColor.TRANSPARENT true)
|
||||||
(source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))
|
(source.pixels.copyPixels rewardSprite.pixels sourceRect (new Point 0 0))
|
||||||
|
|||||||
Reference in New Issue
Block a user