Search in sources :

Example 26 with Xml

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

Example 27 with Xml

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

Example 28 with Xml

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

Example 29 with Xml

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

Example 30 with Xml

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

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