Search in sources :

Example 31 with Xml

use of com.b3dgs.lionengine.io.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<TileRef>> transitions) {
    Check.notNull(media);
    Check.notNull(transitions);
    final Xml nodeTransitions = new Xml(NODE_TRANSITIONS);
    for (final Map.Entry<Transition, Collection<TileRef>> entry : transitions.entrySet()) {
        final Transition transition = entry.getKey();
        final Xml nodeTransition = nodeTransitions.createChild(NODE_TRANSITION);
        nodeTransition.writeString(ATTRIBUTE_TRANSITION_TYPE, transition.getType().name());
        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.io.Xml) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with Xml

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

the class CircuitsConfig method exportTiles.

/**
 * Export all tiles for the circuit.
 *
 * @param nodeCircuit The circuit node (must not be <code>null</code>).
 * @param tilesRef The circuit tiles ref.
 */
private static void exportTiles(Xml nodeCircuit, Collection<TileRef> tilesRef) {
    for (final TileRef tileRef : tilesRef) {
        final Xml nodeTileRef = TileConfig.exports(tileRef);
        nodeCircuit.add(nodeTileRef);
    }
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 33 with Xml

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

the class ActionConfig method exports.

/**
 * Export the action node from data.
 *
 * @param config The config reference (must not be <code>null</code>).
 * @return The action node.
 * @throws LionEngineException If unable to save.
 */
public static Xml exports(ActionConfig config) {
    Check.notNull(config);
    final Xml nodeAction = new Xml(NODE_ACTION);
    nodeAction.writeString(ATT_NAME, config.getName());
    nodeAction.writeString(ATT_DESCRIPTION, config.getDescription());
    nodeAction.writeInteger(ATT_X, config.getX());
    nodeAction.writeInteger(ATT_Y, config.getY());
    nodeAction.writeInteger(ATT_WIDTH, config.getWidth());
    nodeAction.writeInteger(ATT_HEIGHT, config.getHeight());
    return nodeAction;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 34 with Xml

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

the class ActionConfig method imports.

/**
 * Import the action data from node.
 *
 * @param root The root node reference (must not be <code>null</code>).
 * @return The action data.
 * @throws LionEngineException If unable to read node.
 */
public static ActionConfig imports(Xml root) {
    Check.notNull(root);
    final Xml nodeAction = root.getChild(NODE_ACTION);
    final String name = nodeAction.readString(ATT_NAME);
    final String description = nodeAction.readString(ATT_DESCRIPTION);
    final int x = nodeAction.readInteger(ATT_X);
    final int y = nodeAction.readInteger(ATT_Y);
    final int width = nodeAction.readInteger(ATT_WIDTH);
    final int height = nodeAction.readInteger(ATT_HEIGHT);
    return new ActionConfig(name, description, x, y, width, height);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 35 with Xml

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

the class ActionsConfig method exports.

/**
 * Export the action node from config.
 *
 * @param actions The allowed actions (must not be <code>null</code>).
 * @return The actions node.
 * @throws LionEngineException If unable to write node.
 */
public static Xml exports(Collection<ActionRef> actions) {
    Check.notNull(actions);
    final Xml node = new Xml(NODE_ACTIONS);
    for (final ActionRef action : actions) {
        final Xml nodeAction = node.createChild(NODE_ACTION);
        nodeAction.writeString(ATT_PATH, action.getPath());
        if (action.hasCancel()) {
            nodeAction.writeBoolean(ATT_CANCEL, true);
        }
        for (final ActionRef ref : action.getRefs()) {
            exports(nodeAction, ref);
        }
    }
    return node;
}
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