FlxKeyShortcutHandler first pass at gamepad support

This commit is contained in:
2023-07-06 09:46:58 -06:00
parent 02712865b3
commit 913be1e6c8
2 changed files with 21 additions and 1 deletions

View File

@@ -7,6 +7,10 @@ import kiss.List;
import kiss_tools.KeyShortcutHandler;
import flixel.input.keyboard.FlxKey;
import flixel.FlxG;
import flixel.input.actions.FlxAction;
import flixel.input.actions.FlxActionInput;
import flixel.input.FlxInput;
import flixel.input.gamepad.FlxGamepadInputID;
@:build(kiss.Kiss.build())
class FlxKeyShortcutHandler<T> extends KeyShortcutHandler<T> {}

View File

@@ -28,8 +28,24 @@
// TODO generic error handlers
)
// automatically pass the last pressed key to handle key
(prop &mut :Array<FlxActionDigital> buttonActions [])
(method enableGamepadInput [:Map<FlxGamepadInputID,String> buttonToKeyMappings &opt :Int gamepadId]
(unless gamepadId (set gamepadId FlxInputDeviceID.ALL))
(set buttonActions
(for =>buttonId keyString buttonToKeyMappings
(.addGamepad
(new FlxActionDigital
"${buttonId}->${keyString}"
->:Void _ (handleKey keyString))
buttonId
JUST_PRESSED
gamepadId))))
(method :Void update []
(doFor action buttonActions
(action.update))
// automatically pass the last pressed key to super.handleKey
(let [:FlxKey id (FlxG.keys.firstJustPressed)]
(unless (= id -1)
(let [key (id.toString)]