use of com.b3dgs.lionengine.io.DeviceAxis in project lionengine by b3dgs.
the class DeviceControllerConfig method imports.
/**
* Import the data from configurer.
*
* @param services The services reference (must not be <code>null</code>).
* @param media The media configuration (must not be <code>null</code>).
* @return The loaded input.
* @throws LionEngineException If unable to read node.
*/
@SuppressWarnings("unchecked")
public static Collection<DeviceControllerConfig> imports(Services services, Media media) {
Check.notNull(services);
Check.notNull(media);
final Collection<DeviceControllerConfig> configs = new ArrayList<>();
final ClassLoader loader = services.getOptional(ClassLoader.class).orElse(DeviceControllerConfig.class.getClassLoader());
final Configurer configurer = new Configurer(media);
try {
final Class<Enum<? extends DeviceMapper>> mapping;
mapping = (Class<Enum<? extends DeviceMapper>>) loader.loadClass(configurer.getString(ATT_MAPPING));
for (final XmlReader deviceNode : configurer.getChildren(NODE_DEVICE)) {
final Class<DevicePush> device = (Class<DevicePush>) loader.loadClass(deviceNode.getString(ATT_CLASS));
final boolean disabled = deviceNode.getBoolean(false, ATT_DISABLED);
final List<DeviceAxis> horizontal = readAxis(deviceNode, NODE_HORIZONTAL);
final List<DeviceAxis> vertical = readAxis(deviceNode, NODE_VERTICAL);
final Map<Integer, Set<Integer>> fire = readFire(mapping, deviceNode);
configs.add(new DeviceControllerConfig(device, disabled, horizontal, vertical, fire));
}
} catch (final ReflectiveOperationException exception) {
throw new LionEngineException(exception);
}
return configs;
}
use of com.b3dgs.lionengine.io.DeviceAxis in project lionengine by b3dgs.
the class DeviceControllerConfig method readAxis.
/**
* Read axis data.
*
* @param node The parent node.
* @param nodeAxis The axis node name.
* @return The axis data.
*/
private static List<DeviceAxis> readAxis(XmlReader node, String nodeAxis) {
final List<DeviceAxis> axis = new ArrayList<>();
final Collection<XmlReader> children = node.getChildren(nodeAxis);
for (final XmlReader child : children) {
final Integer positive = Integer.valueOf(child.getInteger(ATT_POSITIVE));
final Integer negative = Integer.valueOf(child.getInteger(ATT_NEGATIVE));
axis.add(new DeviceAxis(positive, negative));
}
return axis;
}
Aggregations