Search in sources :

Example 6 with Xml

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;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) ArrayList(java.util.ArrayList)

Example 7 with Xml

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);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 8 with Xml

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;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Orientation(com.b3dgs.lionengine.game.Orientation)

Example 9 with Xml

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);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Xml(com.b3dgs.lionengine.io.Xml)

Example 10 with Xml

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);
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.io.Xml) ArrayList(java.util.ArrayList)

Aggregations

Xml (com.b3dgs.lionengine.io.Xml)45 ArrayList (java.util.ArrayList)8 Media (com.b3dgs.lionengine.Media)6 HashMap (java.util.HashMap)6 TileRef (com.b3dgs.lionengine.game.feature.tile.TileRef)5 Test (org.junit.Test)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Animation (com.b3dgs.lionengine.Animation)2 ActionRef (com.b3dgs.lionengine.game.ActionRef)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 HashSet (java.util.HashSet)2 ActionConfig (com.b3dgs.lionengine.game.ActionConfig)1 Orientation (com.b3dgs.lionengine.game.Orientation)1 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1 BeforeClass (org.junit.BeforeClass)1