Search in sources :

Example 66 with Xml

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

the class CollisionFormulaConfig method exports.

/**
 * Export the current formula data to the formula node.
 *
 * @param root The root node (must not be <code>null</code>).
 * @param formula The formula reference (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Xml root, CollisionFormula formula) {
    Check.notNull(root);
    Check.notNull(formula);
    final Xml node = root.createChild(NODE_FORMULA);
    node.writeString(ATT_NAME, formula.getName());
    CollisionRangeConfig.exports(node, formula.getRange());
    CollisionFunctionConfig.exports(node, formula.getFunction());
    CollisionConstraintConfig.exports(node, formula.getConstraint());
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 67 with Xml

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

the class CollisionGroupConfig method imports.

/**
 * Create the collision group 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 config The tile collision groups descriptor (must not be <code>null</code>).
 * @return The collisions group data.
 * @throws LionEngineException If unable to read node.
 */
public static CollisionGroupConfig imports(Media config) {
    final Xml root = new Xml(config);
    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(new CollisionFormula(formulaName, null, null, null));
        }
        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) Xml(com.b3dgs.lionengine.Xml) ArrayList(java.util.ArrayList) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 68 with Xml

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

the class CollisionGroupConfig method exports.

/**
 * Export the collision group data as a node.
 *
 * @param root The node root (must not be <code>null</code>).
 * @param group The collision group to export (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Xml root, CollisionGroup group) {
    Check.notNull(root);
    Check.notNull(group);
    final Xml node = root.createChild(NODE_COLLISION);
    node.writeString(ATT_GROUP, group.getName());
    for (final CollisionFormula formula : group.getFormulas()) {
        final Xml nodeFormula = node.createChild(CollisionFormulaConfig.NODE_FORMULA);
        nodeFormula.setText(formula.getName());
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 69 with Xml

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

the class CollisionRangeConfig method exports.

/**
 * Export the collision range as a node.
 *
 * @param root The node root (must not be <code>null</code>).
 * @param range The collision range to export (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Xml root, CollisionRange range) {
    Check.notNull(root);
    Check.notNull(range);
    final Xml node = root.createChild(NODE_RANGE);
    node.writeEnum(ATT_AXIS, range.getOutput());
    node.writeInteger(ATT_MIN_X, range.getMinX());
    node.writeInteger(ATT_MIN_Y, range.getMinY());
    node.writeInteger(ATT_MAX_X, range.getMaxX());
    node.writeInteger(ATT_MAX_Y, range.getMaxY());
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 70 with Xml

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

the class ExtractableConfig method exports.

/**
 * Exports the node from config.
 *
 * @param config The config reference (must not be <code>null</code>).
 * @return The extractable node.
 * @throws LionEngineException If unable to read node.
 */
public static Xml exports(ExtractableConfig config) {
    Check.notNull(config);
    final Xml node = new Xml(NODE_EXTRACTABLE);
    node.writeString(ATT_TYPE, config.getType());
    node.writeInteger(ATT_QUANTITY, config.getQuantity());
    return node;
}
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