use of com.b3dgs.lionengine.io.DeviceMapper 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.DeviceMapper in project lionengine by b3dgs.
the class DeviceControllerConfig method readFire.
/**
* Read fire data from node.
*
* @param mapping The mapping type.
* @param node The node parent.
* @return The fire data.
*/
private static Map<Integer, Set<Integer>> readFire(Class<Enum<? extends DeviceMapper>> mapping, XmlReader node) {
final Map<Integer, Set<Integer>> fire = new HashMap<>();
for (final XmlReader nodeFire : node.getChildren(NODE_FIRE)) {
final DeviceMapper mapper = findEnum(mapping, nodeFire.getString(ATT_INDEX));
final Integer index = mapper.getIndex();
final Integer positive = Integer.valueOf(nodeFire.getInteger(ATT_POSITIVE));
Set<Integer> codes = fire.get(index);
if (codes == null) {
codes = new HashSet<>();
fire.put(index, codes);
}
codes.add(positive);
}
return fire;
}
Aggregations