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;
}
}
}
}
Aggregations