use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.
the class TileSheetsConfig method exportSheets.
/**
* Export the defined sheets.
*
* @param nodeSheets Sheets node (must not be <code>null</code>).
* @param sheets Sheets defined (must not be <code>null</code>).
*/
private static void exportSheets(Xml nodeSheets, Collection<String> sheets) {
for (final String sheet : sheets) {
final Xml nodeSheet = nodeSheets.createChild(NODE_TILE_SHEET);
nodeSheet.setText(sheet);
}
}
use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.
the class CollisionCategoryConfig method imports.
/**
* Create the category data from node.
*
* @param root The root reference (must not be <code>null</code>).
* @param map The map reference (must not be <code>null</code>).
* @return The category node instance.
* @throws LionEngineException If unable to read node.
*/
public static CollisionCategory imports(Xml root, MapTileCollision map) {
Check.notNull(root);
Check.notNull(map);
final Collection<Xml> children = root.getChildren(TileGroupsConfig.NODE_GROUP);
final Collection<CollisionGroup> groups = new ArrayList<>(children.size());
for (final Xml groupNode : children) {
final String groupName = groupNode.getText();
final CollisionGroup group = map.getCollisionGroup(groupName);
groups.add(group);
}
final String axisName = root.readString(ATT_AXIS);
final Axis axis;
try {
axis = Axis.valueOf(axisName);
} catch (final IllegalArgumentException exception) {
throw new LionEngineException(exception, ERROR_AXIS + axisName);
}
final int x = root.readInteger(ATT_X);
final int y = root.readInteger(ATT_Y);
final String name = root.readString(ATT_NAME);
return new CollisionCategory(name, axis, x, y, groups);
}
use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.
the class CollisionCategoryConfig method imports.
/**
* Create the collision category data from node (should only be used to display names, as real content is
* <code>null</code>, mainly UI specific to not have dependency on {@link MapTileCollision}).
*
* @param root The node root reference (must not be <code>null</code>).
* @return The collisions category data.
* @throws LionEngineException If unable to read node.
*/
public static Collection<CollisionCategory> imports(Xml root) {
Check.notNull(root);
final Collection<Xml> childrenCategory = root.getChildren(NODE_CATEGORY);
final Collection<CollisionCategory> categories = new ArrayList<>(childrenCategory.size());
for (final Xml node : childrenCategory) {
final Collection<Xml> childrenGroup = node.getChildren(TileGroupsConfig.NODE_GROUP);
final Collection<CollisionGroup> groups = new ArrayList<>(childrenGroup.size());
for (final Xml group : childrenGroup) {
final String name = group.getText();
groups.add(new CollisionGroup(name, new ArrayList<CollisionFormula>(0)));
}
final String name = node.readString(ATT_NAME);
final Axis axis = Axis.valueOf(node.readString(ATT_AXIS));
final int x = node.readInteger(ATT_X);
final int y = node.readInteger(ATT_Y);
final CollisionCategory category = new CollisionCategory(name, axis, x, y, groups);
categories.add(category);
}
return categories;
}
use of com.b3dgs.lionengine.io.Xml 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(Xml root, String formula) {
Check.notNull(root);
Check.notNull(formula);
for (final Xml node : root.getChildren(NODE_FORMULA)) {
if (node.readString(ATT_NAME).equals(formula)) {
return true;
}
}
return false;
}
use of com.b3dgs.lionengine.io.Xml 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(Xml root, String group) {
Check.notNull(root);
Check.notNull(group);
for (final Xml node : root.getChildren(NODE_COLLISION)) {
if (node.readString(ATT_GROUP).equals(group)) {
return true;
}
}
return false;
}
Aggregations