use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollidableFramedConfig method imports.
/**
* Create the collision data from node.
*
* @param root The node reference (must not be <code>null</code>).
* @return The collisions data.
* @throws LionEngineException If unable to read node.
*/
public static CollidableFramedConfig imports(XmlReader root) {
Check.notNull(root);
final Map<Integer, Collection<Collision>> collisions = new HashMap<>(0);
if (root.hasNode(AnimationConfig.NODE_ANIMATIONS)) {
final Collection<XmlReader> children = root.getChild(AnimationConfig.NODE_ANIMATIONS).getChildren(AnimationConfig.NODE_ANIMATION);
for (final XmlReader node : children) {
final int start = node.getInteger(AnimationConfig.ANIMATION_START);
for (final XmlReader framed : node.getChildren(NODE_COLLISION_FRAMED)) {
importFrame(node, framed, start, collisions);
}
}
children.clear();
}
return new CollidableFramedConfig(collisions);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollidableFramedConfig method importFrame.
/**
* Import frame collision data.
*
* @param node The node root reference.
* @param framed The framed node reference.
* @param start The collision start number.
* @param collisions The imported collisions.
*/
private static void importFrame(XmlReader node, XmlReader framed, int start, Map<Integer, Collection<Collision>> collisions) {
final String name = getFrameName(node, framed);
if (framed.hasAttribute(ATT_NUMBER)) {
final int number = start + framed.getInteger(ATT_NUMBER);
final Collision collision = createCollision(name, framed, number - start);
final Integer key = Integer.valueOf(number - 1);
collisions.computeIfAbsent(key, k -> new ArrayList<>()).add(collision);
} else {
final int end = node.getInteger(AnimationConfig.ANIMATION_END);
for (int number = start; number <= end; number++) {
final Collision collision = createCollision(name, framed, number - start + 1);
final Integer key = Integer.valueOf(number);
collisions.computeIfAbsent(key, k -> new ArrayList<>()).add(collision);
}
}
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class FeaturableConfig method getFeatures.
/**
* Get all available features.
* Default constructor of each feature must be available or with {@link Setup} as single parameter.
*
* @param loader The class loader reference.
* @param services The services reference.
* @param setup The setup reference.
* @param filter The type filter (can be <code>null</code> if none).
* @return The available features.
* @throws LionEngineException If invalid class.
*/
public static List<Feature> getFeatures(ClassLoader loader, Services services, Setup setup, Class<?> filter) {
final Collection<XmlReader> children;
final XmlReader root = setup.getRoot();
if (root.hasNode(NODE_FEATURES)) {
children = setup.getRoot().getChild(FeaturableConfig.NODE_FEATURES).getChildren(FeaturableConfig.NODE_FEATURE);
} else {
children = Collections.emptyList();
}
final List<Feature> features = new ArrayList<>(children.size());
for (final XmlReader featureNode : children) {
final String className = featureNode.getText();
try {
final Class<? extends Feature> clazz = getClass(loader, className);
if (filter == null || filter.isAssignableFrom(clazz)) {
final Feature feature = UtilReflection.createReduce(clazz, services, setup);
features.add(feature);
}
} catch (final NoSuchMethodException | LionEngineException exception) {
throw new LionEngineException(exception, setup.getMedia());
}
}
children.clear();
return features;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class ActionConfig method imports.
/**
* Import the action data from node.
*
* @param root The root node reference (must not be <code>null</code>).
* @return The action data.
* @throws LionEngineException If unable to read node.
*/
public static ActionConfig imports(XmlReader root) {
Check.notNull(root);
final XmlReader nodeAction = root.getChild(NODE_ACTION);
final String name = nodeAction.getString(ATT_NAME);
final String description = nodeAction.getString(ATT_DESCRIPTION);
final int x = nodeAction.getInteger(ATT_X);
final int y = nodeAction.getInteger(ATT_Y);
final int width = nodeAction.getInteger(ATT_WIDTH);
final int height = nodeAction.getInteger(ATT_HEIGHT);
return new ActionConfig(name, description, x, y, width, height);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class ForceConfig method imports.
/**
* Create the force data from node.
*
* @param root The root reference (must not be <code>null</code>).
* @return The force data.
* @throws LionEngineException If unable to read node.
*/
public static Force imports(XmlReader root) {
Check.notNull(root);
final XmlReader node = root.getChild(NODE_FORCE);
final Force force = new Force(node.getDouble(ATT_VX), node.getDouble(ATT_VY));
force.setVelocity(node.getDouble(0.0, ATT_VELOCITY));
force.setSensibility(node.getDouble(0.0, ATT_SENSIBILITY));
return force;
}
Aggregations