Search in sources :

Example 1 with JoystickAxis

use of com.chrisali.javaflightsim.simulation.setup.JoystickAxis in project j6dof-flight-sim by chris-ali.

the class JoystickVisitor method handleDeviceInput.

@Override
public void handleDeviceInput(Controller device) {
    if (!canHandleDevice(device))
        return;
    JoystickAssignments assignments = joystickAssignments.get(device.getName());
    Map<String, JoystickAxis> axisAssignments = assignments.getAxisAssignments();
    Map<String, KeyCommand> buttonAssignments = assignments.getButtonAssignments();
    Map<Float, KeyCommand> hatAssignments = assignments.getHatAssignments();
    if (device.poll()) {
        Event event = new Event();
        while (device.getEventQueue().getNextEvent(event)) {
            Component component = event.getComponent();
            Identifier componentIdentifier = component.getIdentifier();
            String componentName = componentIdentifier.getName();
            float pollValue = component.getPollData();
            // Buttons
            if (buttonAssignments != null && componentIdentifier.getName().matches("^[0-9]*$")) {
                // If the component name contains only numbers, it is a button
                KeyCommand command = buttonAssignments.get(componentName);
                if (command != null)
                    actuator.handleParameterChange(command, pollValue);
                continue;
            }
            // Hat Switch
            if (hatAssignments != null && componentIdentifier == Axis.POV) {
                KeyCommand command = hatAssignments.get(pollValue);
                if (command != null)
                    actuator.handleParameterChange(command, pollValue);
                continue;
            }
            // Joystick Axes
            if (axisAssignments != null) {
                JoystickAxis axis = axisAssignments.get(componentName);
                if (axis != null)
                    actuator.handleParameterChange(axis.getAxisAssignment(), pollValue);
                continue;
            }
        }
    }
}
Also used : Identifier(net.java.games.input.Component.Identifier) Event(net.java.games.input.Event) JoystickAssignments(com.chrisali.javaflightsim.simulation.setup.ControlsConfiguration.JoystickAssignments) JoystickAxis(com.chrisali.javaflightsim.simulation.setup.JoystickAxis) KeyCommand(com.chrisali.javaflightsim.simulation.setup.KeyCommand) Component(net.java.games.input.Component)

Aggregations

JoystickAssignments (com.chrisali.javaflightsim.simulation.setup.ControlsConfiguration.JoystickAssignments)1 JoystickAxis (com.chrisali.javaflightsim.simulation.setup.JoystickAxis)1 KeyCommand (com.chrisali.javaflightsim.simulation.setup.KeyCommand)1 Component (net.java.games.input.Component)1 Identifier (net.java.games.input.Component.Identifier)1 Event (net.java.games.input.Event)1