defAndCall macro for refactoring
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
(loadFrom "kiss-tools" "src/kiss_tools/RefactorUtil.kiss")
|
||||||
|
|
||||||
(prop &mut :Jigsawx jigsaw)
|
(prop &mut :Jigsawx jigsaw)
|
||||||
(prop &mut :FlxCamera pieceCamera)
|
(prop &mut :FlxCamera pieceCamera)
|
||||||
(prop &mut :FlxCamera uiCamera)
|
(prop &mut :FlxCamera uiCamera)
|
||||||
@@ -27,11 +29,18 @@
|
|||||||
(when FlxG.keys.justPressed.ESCAPE
|
(when FlxG.keys.justPressed.ESCAPE
|
||||||
(Sys.exit 0))
|
(Sys.exit 0))
|
||||||
|
|
||||||
|
// TODO provide a saner/configurable set of bindings to trigger these ui action functions
|
||||||
|
{
|
||||||
(when FlxG.keys.justPressed.SPACE
|
(when FlxG.keys.justPressed.SPACE
|
||||||
|
(defAndCall method toggleBackgroundColor
|
||||||
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
|
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
|
||||||
(save.flush)
|
(save.flush)
|
||||||
// setModel so the entry text gets remade in inverted colors
|
// setModel so the entry text gets remade in inverted/lightened colors when necessary
|
||||||
(setModel model (nth model.rewardFiles rewardFileIndex)))
|
(setModel model (nth model.rewardFiles rewardFileIndex))))
|
||||||
|
(when FlxG.keys.justPressed.ENTER
|
||||||
|
0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// drag along connected pieces
|
// drag along connected pieces
|
||||||
(when draggingSprite
|
(when draggingSprite
|
||||||
@@ -41,7 +50,7 @@
|
|||||||
(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
|
// This hacks around a tricky edge case -- or so I thought
|
||||||
(when FlxG.mouse.justReleased
|
(when FlxG.mouse.justReleased
|
||||||
(draggingSprite.stopDrag)))
|
(draggingSprite.stopDrag)))
|
||||||
|
|
||||||
|
8
projects/kiss-tools/src/kiss_tools/RefactorUtil.kiss
Normal file
8
projects/kiss-tools/src/kiss_tools/RefactorUtil.kiss
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// Quick and dirty way to make a block reusable without restructuring code
|
||||||
|
// TODO won't work if locals are used in the body
|
||||||
|
(defMacro defAndCall [type name &body body]
|
||||||
|
(assert (exprCase type
|
||||||
|
(function true)
|
||||||
|
(method true)
|
||||||
|
(_ false)) "the first argument to defAndCall must be a symbol: function or method")
|
||||||
|
`{(,type ,name [] ,@body) (,name)})
|
Reference in New Issue
Block a user