use of org.terasology.engine.input.DefaultBinding in project Terasology by MovingBlocks.
the class BindingScraper method main.
/**
* @param args (ignored)
* @throws Exception if the module environment cannot be loaded
*/
public static void main(String[] args) throws Exception {
ModuleManager moduleManager = ModuleManagerFactory.create();
// Holds normal input mappings where there is only one key
Multimap<InputCategory, String> categories = ArrayListMultimap.create();
Multimap<String, Input> keys = ArrayListMultimap.create();
Map<String, String> desc = new HashMap<>();
for (Class<?> holdingType : moduleManager.getEnvironment().getTypesAnnotatedWith(InputCategory.class)) {
InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
categories.put(inputCategory, null);
for (String button : inputCategory.ordering()) {
categories.put(inputCategory, button);
}
}
for (Class<?> buttonEvent : moduleManager.getEnvironment().getTypesAnnotatedWith(RegisterBindButton.class)) {
DefaultBinding defBinding = buttonEvent.getAnnotation(DefaultBinding.class);
RegisterBindButton info = buttonEvent.getAnnotation(RegisterBindButton.class);
String cat = info.category();
String id = "engine:" + info.id();
desc.put(id, info.description());
if (cat.isEmpty()) {
InputCategory inputCategory = findEntry(categories, id);
if (inputCategory == null) {
System.out.println("Invalid category for: " + info.id());
}
} else {
InputCategory inputCategory = findCategory(categories, cat);
if (inputCategory != null) {
categories.put(inputCategory, id);
} else {
System.out.println("Invalid category for: " + info.id());
}
}
if (defBinding != null) {
// This handles bindings with just one key
Input input = defBinding.type().getInput(defBinding.id());
keys.put(id, input);
} else {
// See if there is a multi-mapping for this button
DefaultBindings multiBinding = buttonEvent.getAnnotation(DefaultBindings.class);
// Annotation math magic. We're expecting a DefaultBindings containing one DefaultBinding pair
if (multiBinding != null && multiBinding.value().length == 2) {
DefaultBinding[] bindings = multiBinding.value();
Input primary = bindings[0].type().getInput(bindings[0].id());
Input secondary = bindings[1].type().getInput(bindings[1].id());
keys.put(id, primary);
keys.put(id, secondary);
}
}
}
for (InputCategory row : categories.keySet()) {
System.out.println("# " + row.displayName());
categories.get(row).stream().filter(entry -> entry != null).forEach(entry -> System.out.println(desc.get(entry) + ": " + keys.get(entry)));
}
}
use of org.terasology.engine.input.DefaultBinding in project Terasology by MovingBlocks.
the class BindsSubsystem method fetchDefaultBindings.
private List<Input> fetchDefaultBindings(Class<?> event, BindsConfiguration config) {
List<Input> defaultInputs = Lists.newArrayList();
Collection<Input> boundInputs = config.getBoundInputs();
for (Annotation annotation : event.getAnnotationsByType(DefaultBinding.class)) {
DefaultBinding defaultBinding = (DefaultBinding) annotation;
Input defaultInput = defaultBinding.type().getInput(defaultBinding.id());
if (!boundInputs.contains(defaultInput)) {
defaultInputs.add(defaultInput);
} else {
logger.warn("Input {} is already registered, can not use it as default for event {}", defaultInput, event);
}
}
return defaultInputs;
}
Aggregations