Search in sources :

Example 1 with Xml

use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.

the class CollisionCategoryConfig method exports.

/**
 * Export the collision category data as a node.
 *
 * @param root The node root (must not be <code>null</code>).
 * @param category The collision category to export (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Xml root, CollisionCategory category) {
    Check.notNull(root);
    Check.notNull(category);
    final Xml categories;
    if (root.hasNode(NODE_CATEGORIES)) {
        categories = root.getChildXml(NODE_CATEGORIES);
    } else {
        categories = root.createChild(NODE_CATEGORIES);
    }
    final Xml node = categories.createChild(NODE_CATEGORY);
    node.writeString(ATT_NAME, category.getName());
    node.writeEnum(ATT_AXIS, category.getAxis());
    node.writeInteger(ATT_X, category.getOffsetX());
    node.writeInteger(ATT_Y, category.getOffsetY());
    node.writeBoolean(ATT_GLUE, category.isGlue());
    for (final CollisionGroup group : category.getGroups()) {
        final Xml groupNode = node.createChild(TileGroupsConfig.NODE_GROUP);
        groupNode.setText(group.getName());
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 2 with Xml

use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.

the class CollisionConstraintConfig method exports.

/**
 * Export the collision constraint as a node.
 *
 * @param root The node root (must not be <code>null</code>).
 * @param constraint The collision constraint to export (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Xml root, CollisionConstraint constraint) {
    Check.notNull(root);
    Check.notNull(constraint);
    for (final Entry<Orientation, Collection<String>> entry : constraint.getConstraints().entrySet()) {
        final Orientation orientation = entry.getKey();
        for (final String group : entry.getValue()) {
            final Xml current = root.createChild(NODE_CONSTRAINT);
            current.writeEnum(ATT_ORIENTATION, orientation);
            current.writeString(ATT_GROUP, group);
        }
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml) Collection(java.util.Collection) Orientation(com.b3dgs.lionengine.game.Orientation)

Example 3 with Xml

use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.

the class CollisionFormulaConfig method remove.

/**
 * Remove the formula node.
 *
 * @param root The root node (must not be <code>null</code>).
 * @param formula The formula name to remove (must not be <code>null</code>).
 * @throws LionEngineException If invalid argument.
 */
public static void remove(Xml root, String formula) {
    Check.notNull(root);
    Check.notNull(formula);
    final Collection<Xml> children = root.getChildrenXml(NODE_FORMULA);
    for (final Xml node : children) {
        if (node.getString(ATT_NAME).equals(formula)) {
            root.removeChild(node);
        }
    }
    children.clear();
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 4 with Xml

use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.

the class CollisionFunctionConfig method exports.

/**
 * Export the collision function data as a node.
 *
 * @param root The node root (must not be <code>null</code>).
 * @param function The collision function to export (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Xml root, CollisionFunction function) {
    Check.notNull(root);
    Check.notNull(function);
    final Xml node = root.createChild(FUNCTION);
    if (function instanceof CollisionFunctionLinear) {
        final CollisionFunctionLinear linear = (CollisionFunctionLinear) function;
        node.writeEnum(TYPE, CollisionFunctionType.LINEAR);
        node.writeDouble(A, linear.getA());
        node.writeDouble(B, linear.getB());
    } else {
        node.writeEnum(TYPE, function.getType());
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 5 with Xml

use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.

the class CollisionGroupConfig method remove.

/**
 * Remove the group node.
 *
 * @param root The root node (must not be <code>null</code>).
 * @param group The group name to remove (must not be <code>null</code>).
 * @throws LionEngineException If invalid argument.
 */
public static void remove(Xml root, String group) {
    Check.notNull(root);
    Check.notNull(group);
    final Collection<Xml> children = root.getChildrenXml(NODE_COLLISION);
    for (final Xml node : children) {
        if (node.getString(ATT_GROUP).equals(group)) {
            root.removeChild(node);
        }
    }
    children.clear();
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Aggregations

Xml (com.b3dgs.lionengine.Xml)133 Test (org.junit.jupiter.api.Test)73 Media (com.b3dgs.lionengine.Media)63 Configurer (com.b3dgs.lionengine.game.Configurer)25 Setup (com.b3dgs.lionengine.game.feature.Setup)11 HashMap (java.util.HashMap)9 Collection (java.util.Collection)8 Animation (com.b3dgs.lionengine.Animation)4 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)4 Feature (com.b3dgs.lionengine.game.Feature)3 Force (com.b3dgs.lionengine.game.Force)3 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)3 Services (com.b3dgs.lionengine.game.feature.Services)3 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)3 Map (java.util.Map)3 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 Origin (com.b3dgs.lionengine.Origin)1 UtilAssert.assertThrows (com.b3dgs.lionengine.UtilAssert.assertThrows)1 XmlReader (com.b3dgs.lionengine.XmlReader)1 Orientation (com.b3dgs.lionengine.game.Orientation)1