Search in sources :

Example 1 with BindableAxis

use of org.terasology.engine.input.BindableAxis 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 2 with BindableAxis

use of org.terasology.engine.input.BindableAxis 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);
        }
    }
}
Also used : RegisterRealBindAxis(org.terasology.engine.input.RegisterRealBindAxis) ControllerInput(org.terasology.input.ControllerInput) Input(org.terasology.input.Input) MouseInput(org.terasology.input.MouseInput) SimpleUri(org.terasology.engine.core.SimpleUri) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) AbstractBindableAxis(org.terasology.engine.input.internal.AbstractBindableAxis) BindableAxis(org.terasology.engine.input.BindableAxis) Name(org.terasology.gestalt.naming.Name)

Aggregations

SimpleUri (org.terasology.engine.core.SimpleUri)2 BindableAxis (org.terasology.engine.input.BindableAxis)2 AbstractBindableAxis (org.terasology.engine.input.internal.AbstractBindableAxis)2 Name (org.terasology.gestalt.naming.Name)2 BindAxisEvent (org.terasology.engine.input.BindAxisEvent)1 BindableButton (org.terasology.engine.input.BindableButton)1 RegisterBindAxis (org.terasology.engine.input.RegisterBindAxis)1 RegisterRealBindAxis (org.terasology.engine.input.RegisterRealBindAxis)1 ControllerInput (org.terasology.input.ControllerInput)1 Input (org.terasology.input.Input)1 MouseInput (org.terasology.input.MouseInput)1