Make sure the puzzle piece on top is dragged. Close #100
This commit is contained in:
@@ -40,7 +40,10 @@
|
|||||||
(set draggingLastPos (new FlxPoint draggingSprite.x draggingSprite.y))
|
(set draggingLastPos (new FlxPoint draggingSprite.x draggingSprite.y))
|
||||||
(doFor s (recursivelyConnectedPieces draggingSprite)
|
(doFor s (recursivelyConnectedPieces draggingSprite)
|
||||||
(+= s.x dx)
|
(+= s.x dx)
|
||||||
(+= s.y dy))))
|
(+= s.y dy)))
|
||||||
|
// This hacks around a tricky edge case
|
||||||
|
(when FlxG.mouse.justReleased
|
||||||
|
(draggingSprite.stopDrag)))
|
||||||
|
|
||||||
|
|
||||||
// Left and right arrow keys can switch between unlocked puzzles
|
// Left and right arrow keys can switch between unlocked puzzles
|
||||||
@@ -172,15 +175,22 @@
|
|||||||
(s.enableMouseDrag false true)
|
(s.enableMouseDrag false true)
|
||||||
(set s.mouseStartDragCallback
|
(set s.mouseStartDragCallback
|
||||||
->:Void [s x y]
|
->:Void [s x y]
|
||||||
{
|
(let [t (topClickedPiece)]
|
||||||
// Bring currently held pieces to the front:
|
(if !(= s t)
|
||||||
(rewardSprites.bringToFront s)
|
{
|
||||||
(doFor connected (recursivelyConnectedPieces s)
|
(s.stopDrag)
|
||||||
(rewardSprites.bringToFront connected))
|
(set FlxMouseControl.dragTarget t)
|
||||||
|
(t.startDrag)
|
||||||
(set draggingSprite s)
|
}
|
||||||
(set draggingLastPos (new FlxPoint s.x s.y))
|
{
|
||||||
})
|
// Bring currently held pieces to the front:
|
||||||
|
(rewardSprites.bringToFront t)
|
||||||
|
(doFor connected (recursivelyConnectedPieces t)
|
||||||
|
(rewardSprites.bringToFront connected))
|
||||||
|
|
||||||
|
(set draggingSprite t)
|
||||||
|
(set draggingLastPos (new FlxPoint t.x t.y))
|
||||||
|
})))
|
||||||
(set s.mouseStopDragCallback
|
(set s.mouseStopDragCallback
|
||||||
->:Void [s x y]
|
->:Void [s x y]
|
||||||
{
|
{
|
||||||
@@ -191,8 +201,7 @@
|
|||||||
(doFor connected (recursivelyConnectedPieces s)
|
(doFor connected (recursivelyConnectedPieces s)
|
||||||
(checkMatches (dictGet indexMap connected))
|
(checkMatches (dictGet indexMap connected))
|
||||||
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) (dictGet indexMap connected) (new FlxPoint connected.x connected.y)))
|
(dictSet (the Map<Int,FlxPoint> save.data.storedPositions) (dictGet indexMap connected) (new FlxPoint connected.x connected.y)))
|
||||||
|
|
||||||
|
|
||||||
(pieceCamera.calculateScrollBounds rewardSprites SCROLL_BOUND_MARGIN)
|
(pieceCamera.calculateScrollBounds rewardSprites SCROLL_BOUND_MARGIN)
|
||||||
(save.flush)
|
(save.flush)
|
||||||
})
|
})
|
||||||
@@ -271,6 +280,14 @@
|
|||||||
(shortcutHandler.start)))
|
(shortcutHandler.start)))
|
||||||
(shortcutHandler.start))
|
(shortcutHandler.start))
|
||||||
|
|
||||||
|
(method topClickedPiece []
|
||||||
|
(doFor idx (reverse (collect (range rewardSprites.members.length)))
|
||||||
|
(let [s (nth rewardSprites.members idx)]
|
||||||
|
(when s
|
||||||
|
(when (s.pixelsOverlapPoint (FlxG.mouse.getWorldPosition) 0xFF pieceCamera)
|
||||||
|
(return s)))))
|
||||||
|
null)
|
||||||
|
|
||||||
(prop &mut textY 0)
|
(prop &mut textY 0)
|
||||||
// Color currently used for making text, may be inverted or lightened to contrast with background:
|
// Color currently used for making text, may be inverted or lightened to contrast with background:
|
||||||
(prop &mut :FlxColor _color FlxColor.BLACK)
|
(prop &mut :FlxColor _color FlxColor.BLACK)
|
||||||
@@ -355,7 +372,7 @@
|
|||||||
|
|
||||||
(method :Array<FlxExtendedSprite> recursivelyConnectedPieces [s &opt :Array<FlxExtendedSprite> collected]
|
(method :Array<FlxExtendedSprite> recursivelyConnectedPieces [s &opt :Array<FlxExtendedSprite> collected]
|
||||||
(unless collected (set collected []))
|
(unless collected (set collected []))
|
||||||
(let [directlyConnected (dictGet connectedPieces (dictGet indexMap s))]
|
(whenLet [directlyConnected (dictGet connectedPieces (dictGet indexMap s))]
|
||||||
(doFor piece directlyConnected
|
(doFor piece directlyConnected
|
||||||
(unless (contains collected piece)
|
(unless (contains collected piece)
|
||||||
(collected.push piece)
|
(collected.push piece)
|
||||||
|
Reference in New Issue
Block a user