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);
}
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;
}
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());
}
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;
}
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);
}
Aggregations