Gamepad mapping configurable

This commit is contained in:
Iwan Timmer
2014-01-19 13:59:02 +01:00
parent dd10c8940b
commit 78452d7b82
2 changed files with 50 additions and 4 deletions

View File

@@ -1,5 +1,12 @@
package com.limelight.input;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Properties;
/**
* Mapping between gamepad and gamestream input
* @author Iwan Timmer
@@ -32,4 +39,25 @@ public class GamepadMapping {
public short btn_dpad_left = EvdevConstants.BTN_DPAD_LEFT;
public short btn_dpad_right = EvdevConstants.BTN_DPAD_RIGHT;
public GamepadMapping(File file) throws IOException {
Properties props = new Properties();
props.load(new FileInputStream(file));
for (Map.Entry entry:props.entrySet()) {
try {
Field field = this.getClass().getField(entry.getKey().toString());
field.setShort(this, Short.parseShort(entry.getValue().toString()));
} catch (NoSuchFieldException e) {
System.err.println("No mapping found named " + entry.getKey());
} catch (NumberFormatException e) {
System.err.println("Not a number for " + entry.getKey());
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
System.err.println("Can't change mapping for " + entry.getKey());
}
}
}
public GamepadMapping() {
}
}