[SOLVED] How to remap Joysticks in Lemur upon fireJoystickConnectedEvent/fireJoystickDisonnectedEvent

I would like to trigger the remapping of joysticks/gamepads in Lemur whenever a connect disconnect event happens. I saw that the InputMapper does have a protected mapper function for Joysticks, but bc it is protected and is called only in the initialize once I don’t see a good way to remap it. Does anybody have an idea how I could do that?

If I do not remapp it, I get tons Warnings that the Button has not mapping and I can’t use the new attached controller.

I was too quick with my question, I could solve it with reflections

    public void mapJoystickPublic(Joystick j) {
        try {
            Method mapJoystickMethod = InputMapper.class.getDeclaredMethod("mapJoystick", Joystick.class);
            mapJoystickMethod.setAccessible(true);
            mapJoystickMethod.invoke(inputMapper, j);
        } catch (Exception e) {
            e.printStackTrace(); // Handle the exception according to your needs
        }
    }

Sooooo cool, it works! At least it seams to work :smiley:

Nice. Yeah, I was going to suggest reflection as a short-term hack when I was reading the question.

It’s not really a good long-term solution. If JME provides a way to detect new joysticks then we should probably hook Lemur into that. Otherwise, making the refresh method public is probably not a bad idea.

1 Like

Just use JoystickConnectionListener and you are settled. The lwjgl3 does call that and ofc my SdlJoyInput does as well. I just hooked my first menu App State to this listener and then get all joystick and call mapJoystick for every new joystick. So in theories it is there you just have to hook your InputMapper into this Listener and call the mapper on every connect and disconnect.

Looking forward for an update of Lemur :wink:

1 Like

Me, too. I’m trying to get new versions of my packages out soon. Trying to get out from under some other things first and still need to wrap up some uncommitted changes to Lemur text component handling.

If you get bored and have the time, perhaps you can submit a PR for the joystick listener stuff?

2 Likes

Me too! How about checking my old PR Added missing buttons by Pesegato · Pull Request #101 · jMonkeyEngine-Contributions/Lemur · GitHub

  • adds some (needed) buttons to Button.java
  • allow me to tamper with FunctionListeners

I would gladly drop the requirement of a forked Lemur for BigBanana…

I’ll try to check it out.

I usually try to do a PR-clearing (or at least addressing) as part of my release prep.

Somehow I’m unable to upgrade the jme to 3.6.1-stable (currently it is 3.1.0-stable) in Lemur, it always tells me he doesn’t find it, but that I would need to make an auto-reload of joysticks on connect/disconnect events. It would be just a few lines of code :slight_smile:

1 Like

Alight. Well, thanks for trying… I’m hesitant to force all Lemur users to upgrade just for this but maybe I can make something pluggable.

1 Like

Or you could make an interface to remapp the joystick and the user decides when he wants to call it. Would be probably the simplest solution.

1 Like