use of sun.reflect.generics.reflectiveObjects.NotImplementedException in project nhglib by VoidZombie.
the class ParameterTweaker method tweak.
/**
* Register class field for runtime tweaking.
* This also creates a static reference to passed object, so GC will not be able to free it.
*
* @param objInstance object instance that holds the field (usually "this" keyword can be used)
* @param fieldName name of class field
* @param step by how much should value change on key press
* @param min minimum value
* @param max maximum value
* @param decreaseKey ID of key used to decrease value
* @param increaseKey ID of key used to increase value
*/
public static void tweak(Object objInstance, String fieldName, float step, float min, float max, int decreaseKey, int increaseKey) {
Field field = null;
try {
field = objInstance.getClass().getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
if (!(field.getType().equals(Float.TYPE) || field.getType().equals(Integer.TYPE)))
throw new NotImplementedException();
field.setAccessible(true);
// add new tweak command to decrease key mapping
Array<Tweak> keyTweaks = tweakMap.get(decreaseKey, new Array<Tweak>(1));
keyTweaks.add(new Tweak(objInstance, field, -step, min, max));
tweakMap.put(decreaseKey, keyTweaks);
Gdx.app.log("ParameterTweaker", String.format("Key id %d set to change parameter %s by %+f between min=%f and max=%f", decreaseKey, fieldName, -step, min, max));
// add new tweak command to increase key mapping
keyTweaks = tweakMap.get(increaseKey, new Array<Tweak>(1));
keyTweaks.add(new Tweak(objInstance, field, +step, min, max));
tweakMap.put(increaseKey, keyTweaks);
Gdx.app.log("ParameterTweaker", String.format("Key id %d set to change parameter %s by %+f between min=%f and max=%f", increaseKey, fieldName, +step, min, max));
if (instance == null) {
instance = new ParameterTweaker();
Gdx.input.setInputProcessor(instance);
}
}
Aggregations