FlxKeyShortcutHandler first pass at gamepad support
This commit is contained in:
@@ -7,6 +7,10 @@ import kiss.List;
|
|||||||
import kiss_tools.KeyShortcutHandler;
|
import kiss_tools.KeyShortcutHandler;
|
||||||
import flixel.input.keyboard.FlxKey;
|
import flixel.input.keyboard.FlxKey;
|
||||||
import flixel.FlxG;
|
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())
|
@:build(kiss.Kiss.build())
|
||||||
class FlxKeyShortcutHandler<T> extends KeyShortcutHandler<T> {}
|
class FlxKeyShortcutHandler<T> extends KeyShortcutHandler<T> {}
|
||||||
|
@@ -28,8 +28,24 @@
|
|||||||
// TODO generic error handlers
|
// 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 []
|
(method :Void update []
|
||||||
|
(doFor action buttonActions
|
||||||
|
(action.update))
|
||||||
|
|
||||||
|
// automatically pass the last pressed key to super.handleKey
|
||||||
(let [:FlxKey id (FlxG.keys.firstJustPressed)]
|
(let [:FlxKey id (FlxG.keys.firstJustPressed)]
|
||||||
(unless (= id -1)
|
(unless (= id -1)
|
||||||
(let [key (id.toString)]
|
(let [key (id.toString)]
|
||||||
|
Reference in New Issue
Block a user