use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class BindsSubsystem method registerRealAxisBinds.
private void registerRealAxisBinds(ModuleEnvironment environment) {
Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterRealBindAxis.class);
for (Class<?> registerBindClass : classes) {
RegisterRealBindAxis info = registerBindClass.getAnnotation(RegisterRealBindAxis.class);
Name moduleId = environment.getModuleProviding(registerBindClass);
SimpleUri id = new SimpleUri(moduleId, info.id());
if (BindAxisEvent.class.isAssignableFrom(registerBindClass)) {
try {
BindAxisEvent instance = (BindAxisEvent) registerBindClass.newInstance();
BindableAxis bindAxis = registerRealBindAxis(id.toString(), instance);
bindAxis.setSendEventMode(info.eventMode());
for (Input input : bindsConfiguration.getBinds(id)) {
linkAxisToInput(input, id);
}
logger.debug("Registered axis bind: {}", id);
} catch (InstantiationException | IllegalAccessException e) {
logger.error("Failed to register axis bind \"{}\"", id, e);
}
} else {
logger.error("Failed to register axis bind \"{}\", does not extend BindAxisEvent", id);
}
}
}
use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class BindCommands method bindKey.
@Command(shortDescription = "Maps a key to a function", requiredPermission = PermissionManager.NO_PERMISSION)
public String bindKey(@CommandParam("key") String key, @CommandParam("function") String bind) {
Input keyInput = Keyboard.Key.find(key);
if (keyInput != null) {
bindsManager.linkBindButtonToKey(keyInput.getId(), new SimpleUri(bind));
StringBuilder builder = new StringBuilder();
builder.append("Mapped ").append(keyInput.getDisplayName()).append(" to action ");
builder.append(bind);
return builder.toString();
}
throw new IllegalArgumentException("Unknown key: " + key);
}
use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class BindsConfig method setBinds.
/**
* Sets the inputs for a given bind, replacing any previous inputs
*/
public void setBinds(SimpleUri bindUri, Iterable<Input> inputs) {
Set<Input> uniqueInputs = Sets.newLinkedHashSet(inputs);
// Clear existing usages of the given inputs
Iterator<Input> iterator = uriBoundInputs.values().iterator();
while (iterator.hasNext()) {
Input i = iterator.next();
if (uniqueInputs.contains(i)) {
iterator.remove();
}
}
uriBoundInputs.replaceValues(bindUri, uniqueInputs);
}
use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class LocalPlayerSystem method stopAutoMove.
/**
* Auto move is disabled when the associated key is pressed again.
* This cancels the simulated repeated key stroke for the forward input button.
*/
private void stopAutoMove() {
List<Input> inputs = bindsManager.getBindsConfig().getBinds(new SimpleUri("engine:forwards"));
Input forwardKey = getValidKey(inputs);
if (forwardKey != null) {
inputSystem.cancelSimulatedKeyStroke(forwardKey);
isAutoMove = false;
}
}
Aggregations