use of com.b3dgs.lionengine.XmlReader 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.XmlReader in project lionengine by b3dgs.
the class PathfindableConfig method importAllowedMovements.
/**
* Import the allowed movements.
*
* @param node The root node (must not be <code>null</code>).
* @return The allowed movements.
* @throws LionEngineException If malformed movement name.
*/
private static Collection<MovementTile> importAllowedMovements(XmlReader node) {
if (!node.hasNode(NODE_MOVEMENT)) {
return Collections.emptySet();
}
final Collection<MovementTile> movements = EnumSet.noneOf(MovementTile.class);
final Collection<XmlReader> children = node.getChildren(NODE_MOVEMENT);
for (final XmlReader movementNode : children) {
try {
movements.add(MovementTile.valueOf(movementNode.getText()));
} catch (final IllegalArgumentException exception) {
throw new LionEngineException(exception);
}
}
children.clear();
return movements;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class ExtractorConfig method imports.
/**
* Imports the config from node.
*
* @param root The root reference (must not be <code>null</code>).
* @return The extractor data.
* @throws LionEngineException If unable to read node.
*/
public static ExtractorConfig imports(XmlReader root) {
Check.notNull(root);
final XmlReader node = root.getChild(NODE_EXTRACTOR);
final double extract = node.getDouble(0.0, ATT_EXTRACT);
final double dropoff = node.getDouble(0.0, ATT_DROPOFF);
final int capacity = node.getInteger(0, ATT_CAPACITY);
return new ExtractorConfig(extract, dropoff, capacity);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class FramesConfig method imports.
/**
* Imports the frames config from node.
*
* @param root The root reference (must not be <code>null</code>).
* @return The frames data.
* @throws LionEngineException If unable to read node or invalid integer.
*/
public static FramesConfig imports(XmlReader root) {
Check.notNull(root);
if (root.hasNode(NODE_FRAMES)) {
final XmlReader node = root.getChild(NODE_FRAMES);
final int horizontals = node.getInteger(ATT_HORIZONTAL);
final int verticals = node.getInteger(ATT_VERTICAL);
final int offsetX = node.getInteger(0, ATT_OFFSET_X);
final int offsetY = node.getInteger(0, ATT_OFFSET_Y);
return new FramesConfig(horizontals, verticals, offsetX, offsetY);
}
return new FramesConfig(1, 1, 0, 0);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class AnimationConfig method imports.
/**
* Create the animation data from configurer.
*
* @param root The root reference (must not be <code>null</code>).
* @return The animations configuration instance.
* @throws LionEngineException If unable to read data.
*/
public static AnimationConfig imports(XmlReader root) {
Check.notNull(root);
final Map<String, Animation> animations = new HashMap<>(0);
if (root.hasNode(NODE_ANIMATIONS)) {
final Collection<XmlReader> children = root.getChild(NODE_ANIMATIONS).getChildren(NODE_ANIMATION);
for (final XmlReader node : children) {
final String anim = node.getString(ANIMATION_NAME);
final Animation animation = createAnimation(node);
animations.put(anim, animation);
}
children.clear();
}
return new AnimationConfig(animations);
}
Aggregations