Search in sources :

Example 1 with Xml

use of com.b3dgs.lionengine.io.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<TileRef>> circuits) {
    Check.notNull(media);
    Check.notNull(circuits);
    final Xml nodeCircuits = new Xml(NODE_CIRCUITS);
    for (final Map.Entry<Circuit, Collection<TileRef>> entry : circuits.entrySet()) {
        final Circuit circuit = entry.getKey();
        final Xml nodeCircuit = nodeCircuits.createChild(NODE_CIRCUIT);
        nodeCircuit.writeString(ATT_CIRCUIT_TYPE, circuit.getType().name());
        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.io.Xml) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Xml

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

the class CircuitsConfig method importTiles.

/**
 * Import all tiles from their nodes.
 *
 * @param nodesTileRef The tiles nodes (must not be <code>null</code>).
 * @return The imported tiles ref.
 */
private static Collection<TileRef> importTiles(Collection<Xml> nodesTileRef) {
    final Collection<TileRef> tilesRef = new HashSet<>(nodesTileRef.size());
    for (final Xml nodeTileRef : nodesTileRef) {
        final TileRef tileRef = TileConfig.imports(nodeTileRef);
        tilesRef.add(tileRef);
    }
    return tilesRef;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef) HashSet(java.util.HashSet)

Example 3 with Xml

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

the class ActionConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
public void testExportsImports() {
    final ActionConfig action = new ActionConfig("name", "description", 0, 1, 16, 32);
    final Xml root = new Xml("test");
    root.add(ActionConfig.exports(action));
    final Media media = Medias.create("action.xml");
    root.save(media);
    Assert.assertEquals(action, ActionConfig.imports(new Xml(media)));
    Assert.assertEquals(action, ActionConfig.imports(new Configurer(media)));
    Assert.assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Test(org.junit.Test)

Example 4 with Xml

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

the class UtilSetup method createConfig.

/**
 * Create a test configuration.
 *
 * @return The test configuration media.
 */
public static Media createConfig() {
    final Media media = Medias.create("object.xml");
    final Xml root = new Xml("test");
    root.add(FeaturableConfig.exportClass("class"));
    root.add(FeaturableConfig.exportSetup("setup"));
    root.save(media);
    return media;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media)

Example 5 with Xml

use of com.b3dgs.lionengine.io.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<TileRef, ColorRgba> tiles) {
    Check.notNull(configMinimap);
    Check.notNull(tiles);
    final Map<ColorRgba, Collection<TileRef>> colors = convertToColorKey(tiles);
    final Xml nodeMinimap = new Xml(NODE_MINIMAP);
    for (final Map.Entry<ColorRgba, Collection<TileRef>> 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 TileRef tileRef : entry.getValue()) {
            final Xml nodeTileRef = TileConfig.exports(tileRef);
            nodeColor.add(nodeTileRef);
        }
    }
    nodeMinimap.save(configMinimap);
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Xml(com.b3dgs.lionengine.io.Xml) Collection(java.util.Collection) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef) Map(java.util.Map) HashMap(java.util.HashMap)

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