Search in sources :

Example 1 with KeyCommand

use of com.chrisali.javaflightsim.simulation.setup.KeyCommand 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)

Example 2 with KeyCommand

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

the class KeyboardVisitor method handleDeviceInput.

@Override
public void handleDeviceInput(Controller device) {
    if (!device.poll())
        return;
    for (Component component : device.getComponents()) {
        String componentName = component.getIdentifier().getName().toUpperCase();
        KeyCommand command = keyboardAssignments.get(componentName);
        if (command != null)
            actuator.handleParameterChange(command, component.getPollData());
        continue;
    }
}
Also used : Component(net.java.games.input.Component) KeyCommand(com.chrisali.javaflightsim.simulation.setup.KeyCommand)

Aggregations

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