KeyShortcutHandler allow special keys

This commit is contained in:
2022-08-20 21:51:11 +00:00
parent 3c892debd6
commit 738c876c89
2 changed files with 28 additions and 17 deletions

View File

@@ -86,12 +86,7 @@
(entryWindow.hide)
(entryWindow.show))))
(when (and FlxG.keys.justPressed.SPACE !entryNameText)
(defAndCall method toggleBackgroundColor
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
(save.flush)
// setModel so the entry text gets remade in inverted/lightened colors when necessary
(refreshModel)))
(#when debug
(when FlxG.keys.justPressed.SEMICOLON
@@ -262,7 +257,13 @@
(map (m.activeTodoEntries) makeText)
(set entryWindow.textColor FlxColor.GRAY)
(when m.rewardFiles
(_makeText "[SPACE] Cycle background color" 0))
(_makeText "{space} Cycle background color" 0
->_
(defAndCall method toggleBackgroundColor
(set save.data.backgroundIndex #{(save.data.backgroundIndex + 1) % backgroundOptions.length;}#)
(save.flush)
// setModel so the entry text gets remade in inverted/lightened colors when necessary
(refreshModel))))
(when windowWasShown
(entryWindow.show))

View File

@@ -47,17 +47,27 @@
(tryCallOrThrow onBadKey "Key $key is not defined in $currentMap and no onBadKey event was given" key currentMap)))))
// Extract [k]eyboard [s]hortcuts from a string:
(method extractKeyboardShortcuts [str &opt :Stream stream :String shortcuts]
(method extractKeyboardShortcuts [str &opt :Stream stream :Array<String> shortcuts]
(unless stream (set stream (Stream.fromString str)))
(unless shortcuts (set shortcuts ""))
(case (stream.takeUntilAndDrop "[")
(unless shortcuts (set shortcuts []))
(case (stream.takeUntilOneOf ["[" "{"] false)
((Some _)
(case (stream.takeUntilAndDrop "]")
((Some newShortcuts)
(extractKeyboardShortcuts str stream (+ shortcuts newShortcuts)))
(otherwise
(tryCallOrThrow onBadShortcut "unclosed [ in $str" str null)
"")))
(case (stream.takeChars 1)
((Some "[")
(case (stream.takeUntilAndDrop "]")
((Some newShortcuts)
(extractKeyboardShortcuts str stream (shortcuts.concat (newShortcuts.split ""))))
(otherwise
(tryCallOrThrow onBadShortcut "unclosed [ in $str" str null)
[])))
((Some "{")
(case (stream.takeUntilAndDrop "}")
((Some newShortcut)
(extractKeyboardShortcuts str stream (shortcuts.concat [newShortcut])))
(otherwise
(tryCallOrThrow onBadShortcut "unclosed { in $str" str null)
[])))
(otherwise (throw "takeUntilOneOf lied"))))
(otherwise
shortcuts)))
@@ -85,4 +95,4 @@
(method :Void registerItem [description :T item]
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
(registerShortcut (keyboardShortcut.split "") description item)))
(registerShortcut keyboardShortcut description item)))