Skip to content

Commit

Permalink
Fixes issue with keybinds not working after loading the game (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaskelly authored Feb 5, 2021
1 parent 8d0e851 commit da6aceb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
6 changes: 5 additions & 1 deletion Dungeoneer/src/com/interrupt/dungeoneer/game/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Options() {
}
}

public static void SetInputOptions(GamepadDefinition defaultGamepad) {
public static void SetKeyboardBindings() {
Actions.keyBindings.put(Action.USE, Options.instance.key_use);
Actions.keyBindings.put(Action.ATTACK, Options.instance.key_attack);
Actions.keyBindings.put(Action.FORWARD, Options.instance.key_forward);
Expand All @@ -114,7 +114,9 @@ public static void SetInputOptions(GamepadDefinition defaultGamepad) {
Actions.keyBindings.put(Action.TURN_LEFT, Options.instance.key_turn_left);
Actions.keyBindings.put(Action.TURN_RIGHT, Options.instance.key_turn_right);
Actions.keyBindings.put(Action.JUMP, Options.instance.key_jump);
}

public static void SetGamepadBindings(GamepadDefinition defaultGamepad) {
SetGamepadAction(Action.USE, Options.instance.gamepad_use, defaultGamepad);
SetGamepadAction(Action.ATTACK, Options.instance.gamepad_attack, defaultGamepad);
SetGamepadAction(Action.FORWARD, Options.instance.gamepad_forward, defaultGamepad);
Expand Down Expand Up @@ -171,6 +173,8 @@ public static void loadOptions() {
JsonUtil.toJson(o, file);
return o;
});

SetKeyboardBindings();
}

/** Save options to file. */
Expand Down
39 changes: 23 additions & 16 deletions Dungeoneer/src/com/interrupt/dungeoneer/input/GamepadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,30 @@ public void init() {
Controller first = Controllers.getControllers().first();
if(first != null) mapController(first);
}

public void mapController(Controller controller) {
String controllerName = controller.getName().toLowerCase();
if (controllerName.contains("microsoft corporatio controller"))
controllerMapping.put(controller, new GamepadDefinition(new Xbox360OSXPad()));
else if (controllerName.contains("microsoft") || controllerName.contains("xbox") || controllerName.contains("360"))
controllerMapping.put(controller, new GamepadDefinition(new Xbox360Pad()));
else if (controllerName.contains("sony"))
controllerMapping.put(controller, new GamepadDefinition(new SonyPad()));
else if(controller.getName().equals(Ouya.ID))
controllerMapping.put(controller, new GamepadDefinition(new Ouya()));
else if (controllerName.contains("moga"))
controllerMapping.put(controller, new GamepadDefinition(new MogaProPad()));
else
controllerMapping.put(controller, new GamepadDefinition(new Xbox360Pad()));

Options.SetInputOptions(controllerMapping.get(controller));
String controllerName = controller.getName().toLowerCase();

if (controllerName.contains("microsoft corporatio controller")) {
controllerMapping.put(controller, new GamepadDefinition(new Xbox360OSXPad()));
}
else if (controllerName.contains("microsoft") || controllerName.contains("xbox") || controllerName.contains("360")) {
controllerMapping.put(controller, new GamepadDefinition(new Xbox360Pad()));
}
else if (controllerName.contains("sony")) {
controllerMapping.put(controller, new GamepadDefinition(new SonyPad()));
}
else if (controller.getName().equals(Ouya.ID)) {
controllerMapping.put(controller, new GamepadDefinition(new Ouya()));
}
else if (controllerName.contains("moga")) {
controllerMapping.put(controller, new GamepadDefinition(new MogaProPad()));
}
else {
controllerMapping.put(controller, new GamepadDefinition(new Xbox360Pad()));
}

Options.SetGamepadBindings(controllerMapping.get(controller));
}

public Vector2 applyDeadzone(Vector2 rawInput) {
Expand Down

0 comments on commit da6aceb

Please sign in to comment.