Class JoystickCompatibilityMappings

java.lang.Object
com.jme3.input.JoystickCompatibilityMappings

public class JoystickCompatibilityMappings extends Object
Provides compatibility mapping to different joysticks that both report their name in a unique way and require remapping to achieve a proper default layout.

All mappings MUST be defined before the joystick support has been initialized in the InputManager.

  • Method Details

    • getMappings

      protected static Map<String,String> getMappings(String joystickName, boolean create)
    • getButtonMappings

      protected static Map<String,String> getButtonMappings(String joystickName, boolean create)
      Obtains mappings specific to the joystick buttons
      Parameters:
      joystickName - - The name of the joystick type to obtain mappings for.
      create - - If there are no mappings present and this parameter is true, then a new entry for this joystick is created.
      Returns:
      The various button remappings for the requested joystick, or null of there are none.
    • remapAxisRange

      public static float remapAxisRange(JoystickAxis axis, float currentValue)
      This method will take a "raw" axis value from the system and rescale it based on what the remapper has specified. For example, if the remapper specified an axis to be scaled to [0.0,1.0], then a raw value of -0.5 would be converted to 0.25.
      Parameters:
      axis - - The axis to remap.
      currentValue - - The raw value the system is outputting, on a scale of -1.0 to 1.0.
      Returns:
      The new value that will be provided to listeners, on a scale specified by the remappings file.
    • remapAxis

      public static String remapAxis(String joystickName, String componentId)
      Takes the original name of an axis, specifically, and returns the new name it will function under.
      Parameters:
      joystickName - - The joystick type the axis comes from.
      componentId - - The system-provided name for the axis.
      Returns:
      The new name for the axis, or just componentId if no remapping was provided.
    • remapButton

      public static String remapButton(String joystickName, String componentId)
      Takes the original name of a button, specifically, and returns the new name it will function under.
      Parameters:
      joystickName - - The joystick type the axis comes from.
      componentId - - The system-provided name for the button.
      Returns:
      The new name for the button, or just componentId if no remapping was provided.
    • remapComponent

      public static String remapComponent(String joystickName, String componentId)
      Returns the remapped version of the axis/button name if there is a mapping for it otherwise it returns the original name.
      Parameters:
      joystickName - which joystick (not null)
      componentId - the unmapped axis/button name
      Returns:
      the resulting axis/button name
    • getJoystickButtonMappings

      public static Map<String,String> getJoystickButtonMappings(String joystickName)
      Returns a set of Joystick button name remappings if they exist otherwise it returns an empty map.
      Parameters:
      joystickName - which joystick (not null)
      Returns:
      an unmodifiable map
    • getJoystickMappings

      public static Map<String,String> getJoystickMappings(String joystickName)
      Returns a set of Joystick axis/button name remappings if they exist otherwise it returns an empty map.
      Parameters:
      joystickName - which joystick (not null)
      Returns:
      an unmodifiable map
    • addAxisMapping

      public static void addAxisMapping(String stickName, String sourceComponentId, String remapId)
      Adds a single Joystick axis or button remapping based on the joystick's name and axis/button name. The "remap" value will be used instead.
      Parameters:
      stickName - which joystick (not null)
      sourceComponentId - the name to be remapped
      remapId - the remapped name
    • addAxisMapping

      public static void addAxisMapping(String stickName, String sourceComponentId, String remapId, float[] range)
      Adds a single Joystick axis or button remapping based on the joystick's name and axis/button name. The "remap" value will be used instead.
      Parameters:
      stickName - which joystick (not null)
      sourceComponentId - the name to be remapped
      remapId - the remapped name
      range - the desired range (not null, exactly 2 elements)
    • addButtonMapping

      public static void addButtonMapping(String stickName, String sourceComponentId, String remapId)
      Adds a single Joystick axis or button remapping based on the joystick's name and axis/button name. The "remap" value will be used instead.
      Parameters:
      stickName - which joystick (not null)
      sourceComponentId - the name to be remapped
      remapId - the remapped name
    • addMapping

      public static void addMapping(String stickName, String sourceComponentId, String remapId)
      Adds a single Joystick axis or button remapping based on the joystick's name and axis/button name. The "remap" value will be used instead.
      Parameters:
      stickName - which joystick (not null)
      sourceComponentId - the name to be remapped
      remapId - the remapped name
    • addMappings

      public static void addMappings(Properties p)
      Adds a preconfigured set of mappings in Properties object form where the names are dot notation "axis"/"button"/"". "joystick"."axis/button name" and the values are the remapped component name. This calls addMapping(stickName, sourceComponent, remap) for every property that it is able to parse.
      Parameters:
      p - (not null)
    • addJoystickNameRegex

      public static void addJoystickNameRegex(String regex, String name)
      Maps a regular expression to a normalized name for that joystick.
      Parameters:
      regex - the regular expression to be matched
      name - the remapped name
    • getNormalizedName

      protected static String getNormalizedName(String name)
    • loadMappingProperties

      public static void loadMappingProperties(URL u) throws IOException
      Loads a set of compatibility mappings from the property file specified by the given URL.
      Parameters:
      u - the URL of the properties file (not null)
      Throws:
      IOException - if an I/O exception occurs
    • loadMappings

      protected static void loadMappings(ClassLoader cl, String path) throws IOException
      Throws:
      IOException
    • loadDefaultMappings

      protected static void loadDefaultMappings()
      Loads the default compatibility mappings by looking for joystick-mapping.properties files on the classpath.