use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.
the class TileSheetsConfig method importSheets.
/**
* Import the defined sheets.
*
* @param nodeSheets The sheets node (must not be <code>null</code>).
* @return The sheets filename.
*/
private static Collection<String> importSheets(Xml nodeSheets) {
final Collection<Xml> children = nodeSheets.getChildren(NODE_TILE_SHEET);
final Collection<String> sheets = new ArrayList<>(children.size());
for (final Xml nodeSheet : children) {
final String sheetFilename = nodeSheet.getText();
sheets.add(sheetFilename);
}
return sheets;
}
use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.
the class TileSheetsConfig method exports.
/**
* Export the sheets configuration.
*
* @param configSheets The export media (must not be <code>null</code>).
* @param tileWidth The tile width.
* @param tileHeight The tile height.
* @param sheets The sheets filename (must not be <code>null</code>).
* @throws LionEngineException If error on writing.
*/
public static void exports(Media configSheets, int tileWidth, int tileHeight, Collection<String> sheets) {
Check.notNull(configSheets);
Check.notNull(sheets);
final Xml nodeSheets = new Xml(NODE_TILE_SHEETS);
nodeSheets.writeString(Constant.XML_HEADER, Constant.ENGINE_WEBSITE);
final Xml tileSize = nodeSheets.createChild(NODE_TILE_SIZE);
tileSize.writeString(ATT_TILE_WIDTH, String.valueOf(tileWidth));
tileSize.writeString(ATT_TILE_HEIGHT, String.valueOf(tileHeight));
exportSheets(nodeSheets, sheets);
nodeSheets.save(configSheets);
}
use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.
the class CollisionConstraintConfig method imports.
/**
* Create the collision constraint data from node.
*
* @param node The node reference (must not be <code>null</code>).
* @return The collision constraint data.
* @throws LionEngineException If error when reading node.
*/
public static CollisionConstraint imports(Xml node) {
Check.notNull(node);
final CollisionConstraint constraint = new CollisionConstraint();
if (node.hasChild(NODE_CONSTRAINT)) {
for (final Xml current : node.getChildren(NODE_CONSTRAINT)) {
final Orientation orientation = Orientation.valueOf(current.readString(ATT_ORIENTATION));
final String group = current.readString(ATT_GROUP);
constraint.add(orientation, group);
}
}
return constraint;
}
use of com.b3dgs.lionengine.io.Xml 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(Xml parent) {
Check.notNull(parent);
final Xml node = parent.getChild(FUNCTION);
final String name = node.readString(TYPE);
try {
final CollisionFunctionType type = CollisionFunctionType.valueOf(name);
switch(type) {
case LINEAR:
return new CollisionFunctionLinear(node.readDouble(A), node.readDouble(B));
default:
throw new LionEngineException(ERROR_TYPE + name);
}
} catch (final IllegalArgumentException exception) {
throw new LionEngineException(exception, ERROR_TYPE + name);
}
}
use of com.b3dgs.lionengine.io.Xml 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(Xml root, MapTileCollision map) {
Check.notNull(root);
Check.notNull(map);
final Collection<Xml> childrenCollision = root.getChildren(NODE_COLLISION);
final Map<String, CollisionGroup> groups = new HashMap<>(childrenCollision.size());
for (final Xml node : childrenCollision) {
final Collection<Xml> childrenFormula = node.getChildren(CollisionFormulaConfig.NODE_FORMULA);
final Collection<CollisionFormula> formulas = new ArrayList<>(childrenFormula.size());
for (final Xml formula : childrenFormula) {
final String formulaName = formula.getText();
formulas.add(map.getCollisionFormula(formulaName));
}
final String groupName = node.readString(ATT_GROUP);
final CollisionGroup collision = new CollisionGroup(groupName, formulas);
groups.put(groupName, collision);
}
return new CollisionGroupConfig(groups);
}
Aggregations