use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollisionCategoryConfig method imports.
/**
* Create the categories data from nodes.
*
* @param configurer The configurer reference (must not be <code>null</code>).
* @param map The map reference (must not be <code>null</code>).
* @return The category collisions data.
* @throws LionEngineException If unable to read node.
*/
public static Collection<CollisionCategory> imports(Configurer configurer, MapTileCollision map) {
Check.notNull(configurer);
Check.notNull(map);
final Collection<XmlReader> children = configurer.getRoot().getChild(NODE_CATEGORIES).getChildren(NODE_CATEGORY);
final Collection<CollisionCategory> categories = new ArrayList<>(children.size());
for (final XmlReader node : children) {
final CollisionCategory category = imports(node, map);
categories.add(category);
}
children.clear();
return categories;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollisionFormulaConfig method has.
/**
* Check if node has formula node.
*
* @param root The root node (must not be <code>null</code>).
* @param formula The formula name to check (must not be <code>null</code>).
* @return <code>true</code> if has formula, <code>false</code> else.
* @throws LionEngineException If invalid argument.
*/
public static boolean has(XmlReader root, String formula) {
Check.notNull(root);
Check.notNull(formula);
final Collection<XmlReader> children = root.getChildren(NODE_FORMULA);
boolean has = false;
for (final XmlReader node : children) {
if (node.getString(ATT_NAME).equals(formula)) {
has = true;
break;
}
}
children.clear();
return has;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollisionFunctionConfig method imports.
/**
* Create the collision function from node.
*
* @param parent The parent reference (must not be <code>null</code>).
* @return The collision function data.
* @throws LionEngineException If error when reading node.
*/
public static CollisionFunction imports(XmlReader parent) {
Check.notNull(parent);
final XmlReader node = parent.getChild(FUNCTION);
final CollisionFunctionType type = node.getEnum(CollisionFunctionType.class, TYPE);
try {
switch(type) {
case LINEAR:
return new CollisionFunctionLinear(node.getDouble(A), node.getDouble(B));
// $CASES-OMITTED$
default:
throw new LionEngineException(type);
}
} catch (final IllegalArgumentException | NullPointerException exception) {
throw new LionEngineException(exception, ERROR_TYPE + type);
}
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollisionGroupConfig method imports.
/**
* Create the collision group data from node.
*
* @param root The node root reference (must not be <code>null</code>).
* @param map The map reference (must not be <code>null</code>).
* @return The collisions group data.
* @throws LionEngineException If unable to read node.
*/
public static CollisionGroupConfig imports(XmlReader root, MapTileCollision map) {
Check.notNull(root);
Check.notNull(map);
final Collection<XmlReader> childrenCollision = root.getChildren(NODE_COLLISION);
final Map<String, CollisionGroup> groups = new HashMap<>(childrenCollision.size());
for (final XmlReader node : childrenCollision) {
final Collection<XmlReader> childrenFormula = node.getChildren(CollisionFormulaConfig.NODE_FORMULA);
final Collection<CollisionFormula> formulas = new ArrayList<>(childrenFormula.size());
for (final XmlReader formula : childrenFormula) {
final String formulaName = formula.getText();
formulas.add(map.getCollisionFormula(formulaName));
}
childrenFormula.clear();
final String groupName = node.getString(ATT_GROUP);
final CollisionGroup collision = new CollisionGroup(groupName, formulas);
groups.put(groupName, collision);
}
childrenCollision.clear();
return new CollisionGroupConfig(groups);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollisionGroupConfig method has.
/**
* Check if node has group node.
*
* @param root The root node (must not be <code>null</code>).
* @param group The group name to check (must not be <code>null</code>).
* @return <code>true</code> if has group, <code>false</code> else.
* @throws LionEngineException If invalid argument.
*/
public static boolean has(XmlReader root, String group) {
Check.notNull(root);
Check.notNull(group);
final Collection<XmlReader> children = root.getChildren(NODE_COLLISION);
boolean has = false;
for (final XmlReader node : children) {
if (node.getString(ATT_GROUP).equals(group)) {
has = true;
break;
}
}
children.clear();
return has;
}
Aggregations