Search in sources :

Example 61 with Xml

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

the class PathfindableConfig method exportAllowedMovements.

/**
 * Export the allowed movements.
 *
 * @param root The root node (must not be <code>null</code>).
 * @param movements The movements node (must not be <code>null</code>).
 */
private static void exportAllowedMovements(Xml root, Collection<MovementTile> movements) {
    for (final MovementTile movement : movements) {
        final Xml node = root.createChild(NODE_MOVEMENT);
        node.setText(movement.name());
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 62 with Xml

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

the class FramesConfig method exports.

/**
 * Exports the frames node from config.
 *
 * @param config The config reference (must not be <code>null</code>).
 * @return The frames node.
 * @throws LionEngineException If unable to read node or invalid integer.
 */
public static Xml exports(FramesConfig config) {
    Check.notNull(config);
    final Xml node = new Xml(NODE_FRAMES);
    node.writeInteger(ATT_HORIZONTAL, config.getHorizontal());
    node.writeInteger(ATT_VERTICAL, config.getVertical());
    node.writeInteger(ATT_OFFSET_X, config.getOffsetX());
    node.writeInteger(ATT_OFFSET_Y, config.getOffsetY());
    return node;
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 63 with Xml

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

the class AnimationConfig method exports.

/**
 * Create an XML node from an animation.
 *
 * @param root The node root (must not be <code>null</code>).
 * @param animation The animation reference (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Xml root, Animation animation) {
    Check.notNull(root);
    Check.notNull(animation);
    final Xml animations;
    if (root.hasNode(NODE_ANIMATIONS)) {
        animations = root.getChildXml(NODE_ANIMATIONS);
    } else {
        animations = root.createChild(NODE_ANIMATIONS);
    }
    final Xml node = animations.createChild(NODE_ANIMATION);
    node.writeString(ANIMATION_NAME, animation.getName());
    node.writeInteger(ANIMATION_START, animation.getFirst());
    node.writeInteger(ANIMATION_END, animation.getLast());
    node.writeDouble(ANIMATION_SPEED, animation.getSpeed());
    node.writeBoolean(ANIMATION_REVERSED, animation.hasReverse());
    node.writeBoolean(ANIMATION_REPEAT, animation.hasRepeat());
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 64 with Xml

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

the class MinimapConfig method exports.

/**
 * Export tiles colors data to configuration media.
 *
 * @param configMinimap The configuration media output (must not be <code>null</code>).
 * @param tiles The tiles data (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Media configMinimap, Map<Integer, ColorRgba> tiles) {
    Check.notNull(configMinimap);
    Check.notNull(tiles);
    final Map<ColorRgba, Collection<Integer>> colors = convertToColorKey(tiles);
    final Xml nodeMinimap = new Xml(NODE_MINIMAP);
    for (final Map.Entry<ColorRgba, Collection<Integer>> entry : colors.entrySet()) {
        final ColorRgba color = entry.getKey();
        final Xml nodeColor = nodeMinimap.createChild(NODE_COLOR);
        nodeColor.writeInteger(ATT_COLOR_RED, color.getRed());
        nodeColor.writeInteger(ATT_COLOR_GREEN, color.getGreen());
        nodeColor.writeInteger(ATT_COLOR_BLUE, color.getBlue());
        for (final Integer number : entry.getValue()) {
            final Xml nodeTile = TileConfig.exports(number.intValue());
            nodeColor.add(nodeTile);
        }
    }
    nodeMinimap.save(configMinimap);
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Xml(com.b3dgs.lionengine.Xml) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 65 with Xml

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

the class TileGroupsConfig method exports.

/**
 * Export groups to configuration file.
 *
 * @param groupsConfig The export media (must not be <code>null</code>).
 * @param groups The groups to export (must not be <code>null</code>).
 * @throws LionEngineException If unable to write to media.
 */
public static void exports(Media groupsConfig, Iterable<TileGroup> groups) {
    Check.notNull(groupsConfig);
    Check.notNull(groups);
    final Xml nodeGroups = new Xml(NODE_GROUPS);
    nodeGroups.writeString(Constant.XML_HEADER, Constant.ENGINE_WEBSITE);
    for (final TileGroup group : groups) {
        exportGroup(nodeGroups, group);
    }
    nodeGroups.save(groupsConfig);
}
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