Package com.csse3200.game.input
Class Keymap
java.lang.Object
com.csse3200.game.input.Keymap
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Removes all actions and associated keybinds from the map.static int
getActionKeyCode
(String actionName) Returns the keycode associated with an action.Getter method that returns a display-friendly version of the keybinding map.static boolean
registerAction
(String actionName, int keyCode, boolean display) Registers a new action into the keymap with a given key code.static boolean
setActionKeyCode
(String actionName, int keyCode) Updates an existing action in the keymap with a given key code.static void
Attempts to register and set key codes for all actions in the game.
-
Constructor Details
-
Keymap
public Keymap()Keymap should never be instantiated
-
-
Method Details
-
registerAction
Registers a new action into the keymap with a given key code. Returns false if the action is already in the keymap, or if the key code is already in use.- Parameters:
actionName
- The name of the action to be added to the map.keyCode
- The key code to be assigned to the action.- Returns:
- Boolean for if the action and key were registered/set correctly (true) or not (false).
-
setActionKeyCode
Updates an existing action in the keymap with a given key code. Returns false if the action is not in the keymap, or if the key code is already in use by a different action. Does not affect the display flag.- Parameters:
actionName
- The name of the action to be added to the map.keyCode
- The key code to be assigned to the action.- Returns:
- Boolean for if the action and key were registered/set correctly (true) or not (false).
-
getActionKeyCode
Returns the keycode associated with an action.- Parameters:
actionName
- The name of the action whose key code is being fetched.- Returns:
- The key code of the associated action. -1 if action does not exist or key code is not set for action.
-
setKeyMapDefaults
public static void setKeyMapDefaults()Attempts to register and set key codes for all actions in the game. Any actions that require a keybind in the game should be set here with there default key codes. -
clearKeyMap
public static void clearKeyMap()Removes all actions and associated keybinds from the map. -
getKeyMap
Getter method that returns a display-friendly version of the keybinding map. Entries whose display flag is set as false are ignored.- Returns:
- The hash map with actions mapped to their keycodes.
-