use of com.b3dgs.lionengine.io.DevicePointer in project lionengine by b3dgs.
the class DeviceControllerConfig method create.
/**
* Create device controller from configuration.
*
* @param services The services reference (must not be <code>null</code>).
* @param media The media configuration (must not be <code>null</code>).
* @return The created controller.
* @throws LionEngineException If unable to read node.
*/
public static DeviceController create(Services services, Media media) {
final Context context = services.get(Context.class);
final DeviceController controller = new DeviceControllerModel();
final Collection<DeviceControllerConfig> configs = DeviceControllerConfig.imports(services, media);
for (final DeviceControllerConfig config : configs) {
final InputDevice device = context.getInputDevice(config.getDevice());
if (device instanceof DevicePush) {
final DevicePush push = (DevicePush) device;
config.getHorizontal().forEach(h -> controller.addHorizontal(push, new DeviceActionModel(h, push)));
config.getVertical().forEach(v -> controller.addVertical(push, new DeviceActionModel(v, push)));
config.getFire().entrySet().forEach(e -> e.getValue().forEach(c -> controller.addFire(device, e.getKey(), new DeviceActionModel(c, push))));
}
if (device instanceof DevicePointer) {
final DevicePointer pointer = (DevicePointer) device;
controller.addHorizontal(pointer, () -> pointer.getMoveX());
controller.addVertical(pointer, () -> -pointer.getMoveY());
}
if (config.isDisabled()) {
controller.setDisabled(device.getName(), true, true);
}
}
return controller;
}
Aggregations