Search in sources :

Example 1 with XmlReader

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

Example 2 with XmlReader

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

Example 3 with XmlReader

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

Example 4 with XmlReader

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

Example 5 with XmlReader

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

Aggregations

XmlReader (com.b3dgs.lionengine.XmlReader)45 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)12 LionEngineException (com.b3dgs.lionengine.LionEngineException)6 HashSet (java.util.HashSet)6 Collection (java.util.Collection)4 Xml (com.b3dgs.lionengine.Xml)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 DeviceAxis (com.b3dgs.lionengine.io.DeviceAxis)2 DeviceMapper (com.b3dgs.lionengine.io.DeviceMapper)2 Set (java.util.Set)2 Animation (com.b3dgs.lionengine.Animation)1 Check (com.b3dgs.lionengine.Check)1 Constant (com.b3dgs.lionengine.Constant)1 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)1 Feature (com.b3dgs.lionengine.game.Feature)1 Orientation (com.b3dgs.lionengine.game.Orientation)1 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)1 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1