defAndCall macro for refactoring

This commit is contained in:
2022-07-27 16:32:16 +00:00
parent 8f58f02ef5
commit 2d53027da3
2 changed files with 23 additions and 6 deletions

View File

@@ -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)))

View 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)})