Search in sources :

Example 1 with BindableButton

use of org.terasology.engine.input.BindableButton in project Terasology by MovingBlocks.

the class InputSystemTests method testKeyBinding.

@Test
public void testKeyBinding() {
    Map<Integer, BindableButton> keyBinds = new HashMap<>();
    // mock binding to the TestEventButton, this is done by the BindsManager over the annotations by default
    keyBinds.put(KeyId.T, new BindableButtonImpl(new SimpleUri("engine-tests", "testEvent"), "theTestEvent", new TestEventButton()));
    when(bindsManager.getKeyBinds()).thenReturn(keyBinds);
    pressKey(Key.T);
    inputSystem.update(1f);
    verify(clientEntity).send(Mockito.any(TestEventButton.class));
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) HashMap(java.util.HashMap) SimpleUri(org.terasology.engine.core.SimpleUri) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) Test(org.junit.jupiter.api.Test)

Example 2 with BindableButton

use of org.terasology.engine.input.BindableButton in project Terasology by MovingBlocks.

the class BindsSubsystem method registerButtonBinds.

private void registerButtonBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindButton.class);
    for (Class<?> registerBindClass : classes) {
        RegisterBindButton info = registerBindClass.getAnnotation(RegisterBindButton.class);
        SimpleUri bindUri = new SimpleUri(environment.getModuleProviding(registerBindClass), info.id());
        if (BindButtonEvent.class.isAssignableFrom(registerBindClass)) {
            try {
                BindableButton bindButton = registerBindButton(bindUri, info.description(), (BindButtonEvent) registerBindClass.newInstance());
                bindButton.setMode(info.mode());
                bindButton.setRepeating(info.repeating());
                bindsConfiguration.getBinds(bindUri).stream().filter(input -> input != null).forEach(input -> linkBindButtonToInput(input, bindUri));
                logger.debug("Registered button bind: {}", bindUri);
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register button bind \"{}\"", e);
            }
        } else {
            logger.error("Failed to register button bind \"{}\", does not extend BindButtonEvent", bindUri);
        }
    }
}
Also used : RegisterBindButton(org.terasology.engine.input.RegisterBindButton) BindsConfiguration(org.terasology.engine.config.facade.BindsConfiguration) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) ModuleManager(org.terasology.engine.core.module.ModuleManager) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) ControllerInput(org.terasology.input.ControllerInput) LoggerFactory(org.slf4j.LoggerFactory) BindsConfig(org.terasology.engine.config.BindsConfig) FromModule(org.terasology.gestalt.module.predicates.FromModule) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Lists(com.google.common.collect.Lists) DefaultBinding(org.terasology.engine.input.DefaultBinding) Map(java.util.Map) Input(org.terasology.input.Input) RegisterRealBindAxis(org.terasology.engine.input.RegisterRealBindAxis) AbstractBindableAxis(org.terasology.engine.input.internal.AbstractBindableAxis) MouseInput(org.terasology.input.MouseInput) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) InputType(org.terasology.input.InputType) Logger(org.slf4j.Logger) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Collection(java.util.Collection) AxisEvent(org.terasology.engine.input.events.AxisEvent) BindableAxisImpl(org.terasology.engine.input.internal.BindableAxisImpl) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) Maps(com.google.common.collect.Maps) BindableButton(org.terasology.engine.input.BindableButton) SimpleUri(org.terasology.engine.core.SimpleUri) EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) List(java.util.List) Context(org.terasology.engine.context.Context) Config(org.terasology.engine.config.Config) Annotation(java.lang.annotation.Annotation) BindableAxis(org.terasology.engine.input.BindableAxis) BindableRealAxis(org.terasology.engine.input.internal.BindableRealAxis) ButtonEvent(org.terasology.engine.input.events.ButtonEvent) Name(org.terasology.gestalt.naming.Name) BindableButton(org.terasology.engine.input.BindableButton) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) SimpleUri(org.terasology.engine.core.SimpleUri)

Example 3 with BindableButton

use of org.terasology.engine.input.BindableButton in project Terasology by MovingBlocks.

the class BindsSubsystem method registerAxisBinds.

private void registerAxisBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindAxis.class);
    for (Class<?> registerBindClass : classes) {
        RegisterBindAxis info = registerBindClass.getAnnotation(RegisterBindAxis.class);
        Name moduleId = environment.getModuleProviding(registerBindClass);
        SimpleUri id = new SimpleUri(moduleId, info.id());
        if (BindAxisEvent.class.isAssignableFrom(registerBindClass)) {
            BindableButton positiveButton = getBindButton(new SimpleUri(info.positiveButton()));
            BindableButton negativeButton = getBindButton(new SimpleUri(info.negativeButton()));
            if (positiveButton == null) {
                logger.warn("Failed to register axis \"{}\", missing positive button \"{}\"", id, info.positiveButton());
                continue;
            }
            if (negativeButton == null) {
                logger.warn("Failed to register axis \"{}\", missing negative button \"{}\"", id, info.negativeButton());
                continue;
            }
            try {
                BindableAxis bindAxis = registerBindAxis(id.toString(), (BindAxisEvent) registerBindClass.newInstance(), positiveButton, negativeButton);
                bindAxis.setSendEventMode(info.eventMode());
                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);
        }
    }
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) SimpleUri(org.terasology.engine.core.SimpleUri) AbstractBindableAxis(org.terasology.engine.input.internal.AbstractBindableAxis) BindableAxis(org.terasology.engine.input.BindableAxis) Name(org.terasology.gestalt.naming.Name)

Example 4 with BindableButton

use of org.terasology.engine.input.BindableButton in project Terasology by MovingBlocks.

the class BindsSubsystem method linkBindButtonToKey.

@Override
public void linkBindButtonToKey(int key, SimpleUri bindId) {
    BindableButton bindInfo = buttonLookup.get(bindId);
    keyBinds.put(key, bindInfo);
}
Also used : BindableButton(org.terasology.engine.input.BindableButton)

Example 5 with BindableButton

use of org.terasology.engine.input.BindableButton in project Terasology by MovingBlocks.

the class BindsSubsystem method linkBindButtonToController.

private void linkBindButtonToController(ControllerInput button, SimpleUri bindId) {
    BindableButton bindInfo = buttonLookup.get(bindId);
    controllerBinds.put(button, bindInfo);
}
Also used : BindableButton(org.terasology.engine.input.BindableButton)

Aggregations

BindableButton (org.terasology.engine.input.BindableButton)8 SimpleUri (org.terasology.engine.core.SimpleUri)5 BindableButtonImpl (org.terasology.engine.input.internal.BindableButtonImpl)3 Test (org.junit.jupiter.api.Test)2 BindButtonEvent (org.terasology.engine.input.BindButtonEvent)2 BindableAxis (org.terasology.engine.input.BindableAxis)2 RegisterBindAxis (org.terasology.engine.input.RegisterBindAxis)2 AbstractBindableAxis (org.terasology.engine.input.internal.AbstractBindableAxis)2 Name (org.terasology.gestalt.naming.Name)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Annotation (java.lang.annotation.Annotation)1 Collection (java.util.Collection)1 Collections.unmodifiableCollection (java.util.Collections.unmodifiableCollection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BindsConfig (org.terasology.engine.config.BindsConfig)1