Search in sources :

Example 56 with Xml

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

the class TransitionsConfig method exports.

/**
 * Export all transitions to media.
 *
 * @param media The export media output (must not be <code>null</code>).
 * @param transitions The transitions reference (must not be <code>null</code>).
 * @throws LionEngineException If error on export.
 */
public static void exports(Media media, Map<Transition, Collection<Integer>> transitions) {
    Check.notNull(media);
    Check.notNull(transitions);
    final Xml nodeTransitions = new Xml(NODE_TRANSITIONS);
    for (final Map.Entry<Transition, Collection<Integer>> entry : transitions.entrySet()) {
        final Transition transition = entry.getKey();
        final Xml nodeTransition = nodeTransitions.createChild(NODE_TRANSITION);
        nodeTransition.writeEnum(ATTRIBUTE_TRANSITION_TYPE, transition.getType());
        nodeTransition.writeString(ATTRIBUTE_GROUP_IN, transition.getIn());
        nodeTransition.writeString(ATTRIBUTE_GROUP_OUT, transition.getOut());
        exportTiles(nodeTransition, entry.getValue());
    }
    nodeTransitions.save(media);
}
Also used : Xml(com.b3dgs.lionengine.Xml) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with Xml

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

the class CircuitsConfig method exports.

/**
 * Export all circuits to an XML file.
 *
 * @param media The export output (must not be <code>null</code>).
 * @param circuits The circuits reference (must not be <code>null</code>).
 * @throws LionEngineException If error on export.
 */
public static void exports(Media media, Map<Circuit, Collection<Integer>> circuits) {
    Check.notNull(media);
    Check.notNull(circuits);
    final Xml nodeCircuits = new Xml(NODE_CIRCUITS);
    for (final Map.Entry<Circuit, Collection<Integer>> entry : circuits.entrySet()) {
        final Circuit circuit = entry.getKey();
        final Xml nodeCircuit = nodeCircuits.createChild(NODE_CIRCUIT);
        nodeCircuit.writeEnum(ATT_CIRCUIT_TYPE, circuit.getType());
        nodeCircuit.writeString(ATT_GROUP_IN, circuit.getIn());
        nodeCircuit.writeString(ATT_GROUP_OUT, circuit.getOut());
        exportTiles(nodeCircuit, entry.getValue());
    }
    nodeCircuits.save(media);
}
Also used : Xml(com.b3dgs.lionengine.Xml) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 58 with Xml

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

the class MapTileCollisionModel method saveCollisions.

@Override
public void saveCollisions() {
    final Media formulasConfig = loader.getFormulasConfig();
    if (formulasConfig != null) {
        final Xml formulasRoot = new Xml(CollisionFormulaConfig.NODE_FORMULAS);
        for (final CollisionFormula formula : getCollisionFormulas()) {
            CollisionFormulaConfig.exports(formulasRoot, formula);
        }
        formulasRoot.save(formulasConfig);
    }
    final Media groupsConfig = loader.getCollisionsConfig();
    if (groupsConfig != null) {
        final Xml groupsNode = new Xml(CollisionGroupConfig.NODE_COLLISIONS);
        for (final CollisionGroup group : getCollisionGroups()) {
            CollisionGroupConfig.exports(groupsNode, group);
        }
        groupsNode.save(groupsConfig);
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media)

Example 59 with Xml

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

the class MapTileCollisionLoader method loadCollisionGroups.

/**
 * Load the collision groups. All previous groups will be cleared.
 *
 * @param mapCollision The map tile collision owner.
 * @param groupsConfig The configuration collision groups file.
 */
private void loadCollisionGroups(MapTileCollision mapCollision, Media groupsConfig) {
    this.groupsConfig = groupsConfig;
    final Xml nodeGroups = new Xml(groupsConfig);
    final CollisionGroupConfig config = CollisionGroupConfig.imports(nodeGroups, mapCollision);
    loadCollisionGroups(config);
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 60 with Xml

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

the class PathfindableConfig method exportPathData.

/**
 * Create a path data from its node.
 *
 * @param data The path data (must not be <code>null</code>).
 * @return The path data node.
 */
public static Xml exportPathData(PathData data) {
    Check.notNull(data);
    final Xml node = new Xml(NODE_PATH);
    node.writeString(ATT_CATEGORY, data.getName());
    node.writeDouble(ATT_COST, data.getCost());
    node.writeBoolean(ATT_BLOCK, data.isBlocking());
    exportAllowedMovements(node, data.getAllowedMovements());
    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