Class Keymap

java.lang.Object
com.csse3200.game.input.Keymap

public class Keymap extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Keymap should never be instantiated
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Removes all actions and associated keybinds from the map.
    static int
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Keymap

      public Keymap()
      Keymap should never be instantiated
  • Method Details

    • registerAction

      public static boolean registerAction(String actionName, int keyCode, boolean display)
      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

      public static boolean setActionKeyCode(String actionName, int keyCode)
      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

      public static int getActionKeyCode(String actionName)
      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

      public static Map<String,Integer> 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.