save angles and origins of puzzle pieces

This commit is contained in:
2022-08-12 23:50:27 +00:00
parent 52c90c67a9
commit 81587cb050

View File

@@ -69,6 +69,8 @@
(#when debug (#when debug
(when FlxG.keys.justPressed.CONTROL (when FlxG.keys.justPressed.CONTROL
(set save.data.storedPositions (new Map<Int,FlxPoint>)) (set save.data.storedPositions (new Map<Int,FlxPoint>))
(set save.data.storedAngles (new Map<Int,Float>))
(set save.data.storedOrigins (new Map<Int,FlxPoint>))
(save.flush))) (save.flush)))
(when FlxG.keys.justPressed.DELETE (when FlxG.keys.justPressed.DELETE
@@ -78,7 +80,12 @@
{ {
(when FlxG.keys.justPressed.Q (when FlxG.keys.justPressed.Q
(when draggingSprite (when draggingSprite
(draggingSprite.rotate 90))) (draggingSprite.rotate 90)
(doFor s (recursivelyConnectedPieces draggingSprite)
(dictSet (the Map<Int,Float> save.data.storedAngles) (dictGet indexMap s) s.angle)
(dictSet (the Map<Int,FlxPoint> save.data.storedOrigins) (dictGet indexMap s) s.origin))
(save.flush)))
(when (and FlxG.keys.justPressed.SPACE !entryNameText) (when (and FlxG.keys.justPressed.SPACE !entryNameText)
(defAndCall method toggleBackgroundColor (defAndCall method toggleBackgroundColor
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#) (set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
@@ -189,6 +196,10 @@
(save.bind currentRewardFile.path) (save.bind currentRewardFile.path)
(unless save.data.storedPositions (unless save.data.storedPositions
(set save.data.storedPositions (new Map<Int,FlxPoint>))) (set save.data.storedPositions (new Map<Int,FlxPoint>)))
(unless save.data.storedAngles
(set save.data.storedAngles (new Map<Int,Float>)))
(unless save.data.storedOrigins
(set save.data.storedOrigins (new Map<Int,FlxPoint>)))
(unless save.data.backgroundIndex (unless save.data.backgroundIndex
(set save.data.backgroundIndex 0)) (set save.data.backgroundIndex 0))
(set pieceCamera.bgColor (nth backgroundOptions save.data.backgroundIndex)) (set pieceCamera.bgColor (nth backgroundOptions save.data.backgroundIndex))
@@ -228,10 +239,12 @@
(/ rewardSprite.width PUZZLE_WIDTH) (/ rewardSprite.width PUZZLE_WIDTH)
PIECE_HEIGHT PIECE_HEIGHT
(/ rewardSprite.height PUZZLE_HEIGHT) (/ rewardSprite.height PUZZLE_HEIGHT)
:Array<FlxPoint> startingPoints []] :Array<FlxPoint> startingPoints []
:Array<Float> startingAngles []]
(let [&mut i 0] (let [&mut i 0]
(doFor y (range PUZZLE_HEIGHT) (doFor y (range PUZZLE_HEIGHT)
(doFor x (range PUZZLE_WIDTH) (doFor x (range PUZZLE_WIDTH)
(startingAngles.push (* 90 (r.int 0 3)))
(startingPoints.push (startingPoints.push
(new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT)))) (new FlxPoint (+ rewardSprite.x (* x PIECE_WIDTH)) (+ rewardSprite.y (* y PIECE_HEIGHT))))
(+= i 1)))) (+= i 1))))
@@ -245,10 +258,16 @@
pos (ifLet [point (dictGet (the Map<Int,FlxPoint> save.data.storedPositions) i)] pos (ifLet [point (dictGet (the Map<Int,FlxPoint> save.data.storedPositions) i)]
point point
(nth startingPoints i)) (nth startingPoints i))
angle (ifLet [angle (dictGet (the Map<Int,Float> save.data.storedAngles) i)]
angle
(nth startingAngles i))
s (new KissExtendedSprite pos.x pos.y) s (new KissExtendedSprite pos.x pos.y)
source (new FlxSprite) source (new FlxSprite)
mask (new FlxSprite) mask (new FlxSprite)
sourceRect (new Rectangle (/ jig.xy.x ros) (/ jig.xy.y ros) (/ jig.wh.x ros) (/ jig.wh.y ros))] sourceRect (new Rectangle (/ jig.xy.x ros) (/ jig.xy.y ros) (/ jig.wh.x ros) (/ jig.wh.y ros))]
(whenLet [origin (dictGet (the Map<Int,FlxPoint> save.data.storedOrigins) i)]
(s.origin.set origin.x origin.y))
(set s.angle angle)
(set s.priorityID i) (set s.priorityID i)
(setNth spriteGrid jig.row jig.col s) (setNth spriteGrid jig.row jig.col s)
(setNth indexGrid jig.row jig.col i) (setNth indexGrid jig.row jig.col i)