quasilyte / ebitengine-input

A Godot-inspired action input handling system for Ebitengine
MIT License
72 stars 8 forks source link

ActionKeyNames called with AnyDevice mask is not returning for all devices #26

Closed harbdog closed 1 year ago

harbdog commented 1 year ago

According to the doc using the AnyDevice mask from the ActionKeyNames function should return key names for all devices, but it is currently only returning keys for keyboard and mouse devices, but not gamepad. Adding the following to the Init code of the configfile example shows the problem:

        ...
    g.inputHandler = g.inputSystem.NewHandler(0, keymap)

    for a := range keymap {
        actionKey := actionString(a)
        fmt.Printf("%s: %v\n", actionKey, g.inputHandler.ActionKeyNames(a, input.AnyDevice))
    }

They keymap.json used in the example has some gamepad bindings, but they are not shown as expected of the AnyDevice mask

Restart: [ctrl+r]
Secret: [ctrl+shift+q]
Left: [left a]        
Right: [right d]      
Pause: [space]   
harbdog commented 1 year ago

@quasilyte I've found where the problem is, it appears to only want to show the gamepad key names when a gamepad is connected. So it did end up showing the gamepad_* keys after I turned the gamepad back on.

gamepadConnected := h.GamepadConnected()
...
    case keyGamepad, keyGamepadLeftStick, keyGamepadRightStick, keyGamepadStickMotion:
        enabled = gamepadConnected && (mask&GamepadDevice != 0)

While this may make sense for some cases, in my case I'm wanting to use it to export all configuration to json after allowing in-game remapping, that can later be imported as done in the "configfile" example. It would not be good to lose gamepad configuration settings just because the gamepad isn't currently connected.

quasilyte commented 1 year ago

This gamepadConnected filter is redundant.

The DefaultInputMask already tries to provide the same functionality. There is no point in duplicating this logic in ActionKeyNames function too.

So I guess it should just respect the given mask and return all keys if AnyDevice is used.

quasilyte commented 1 year ago

Would #31 solve this issue? I feel like this behavior would be more predictable.

quasilyte commented 1 year ago

Sorry for the late response. Sometimes the notifications just find their way to bypass me.

harbdog commented 1 year ago

@quasilyte yes the code from PR #31 appears to resolve the issue 👍:

$ go run ./_examples/configfile/main.go 
Pause: [space gamepad_start]
Restart: [ctrl+r gamepad_back]
Secret: [ctrl+shift+q]
Left: [left a gamepad_left]
Right: [right d gamepad_right]