Search in sources :

Example 41 with Xml

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

the class LayerableConfig method imports.

/**
 * Imports the layerable config from node.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The layerable data.
 * @throws LionEngineException If unable to read node or invalid integer.
 */
public static LayerableConfig imports(Xml root) {
    Check.notNull(root);
    final Xml node = root.getChild(NODE_LAYERABLE);
    final int layerRefresh = node.readInteger(ATT_REFRESH);
    final int layerDisplay = node.readInteger(ATT_DISPLAY);
    return new LayerableConfig(layerRefresh, layerDisplay);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 42 with Xml

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

the class CollisionConfig method imports.

/**
 * Create the collision data from node.
 *
 * @param configurer The configurer reference (must not be <code>null</code>).
 * @return The collisions data.
 * @throws LionEngineException If unable to read node.
 */
public static CollisionConfig imports(Configurer configurer) {
    Check.notNull(configurer);
    final Map<String, Collision> collisions = new HashMap<>(0);
    for (final Xml node : configurer.getRoot().getChildren(NODE_COLLISION)) {
        final String coll = node.readString(ATT_NAME);
        final Collision collision = createCollision(node);
        collisions.put(coll, collision);
    }
    return new CollisionConfig(collisions);
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.io.Xml)

Example 43 with Xml

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

the class LauncherConfig method imports.

/**
 * Import the launcher data from node.
 *
 * @param node The node reference (must not be <code>null</code>).
 * @return The launcher data.
 * @throws LionEngineException If unable to read node.
 */
public static LauncherConfig imports(Xml node) {
    Check.notNull(node);
    final Collection<Xml> children = node.getChildren(LaunchableConfig.NODE_LAUNCHABLE);
    final Collection<LaunchableConfig> launchables = new ArrayList<>(children.size());
    for (final Xml launchable : children) {
        launchables.add(LaunchableConfig.imports(launchable));
    }
    final int level = node.readInteger(0, ATT_RATE);
    final int rate = node.readInteger(ATT_RATE);
    return new LauncherConfig(level, rate, launchables);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) ArrayList(java.util.ArrayList)

Example 44 with Xml

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

the class ProducerConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
public void testExportsImports() {
    final ActionRef ref = new ActionRef("ref", false, new ArrayList<ActionRef>());
    final ActionRef ref2 = new ActionRef("ref", false, Arrays.asList(ref));
    final Collection<ActionRef> refs = Arrays.asList(new ActionRef("test", true, Arrays.asList(ref2)));
    final Xml root = new Xml("test");
    root.add(ActionsConfig.exports(refs));
    final Media media = Medias.create("producer.xml");
    root.save(media);
    Assert.assertEquals(refs, ActionsConfig.imports(new Xml(media)));
    Assert.assertEquals(refs, ActionsConfig.imports(new Configurer(media)));
    Assert.assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) ActionRef(com.b3dgs.lionengine.game.ActionRef) Test(org.junit.Test)

Example 45 with Xml

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

the class ProducerConfigTest method testCancelOnRef.

/**
 * Test cancel flag is not used on child reference.
 */
@Test
public void testCancelOnRef() {
    final ActionRef ref = new ActionRef("ref", true, new ArrayList<ActionRef>());
    final Collection<ActionRef> refs = Arrays.asList(new ActionRef("test", false, Arrays.asList(ref)));
    final Xml root = new Xml("test");
    root.add(ActionsConfig.exports(refs));
    final Media media = Medias.create("producer.xml");
    root.save(media);
    Assert.assertNotEquals(refs, ActionsConfig.imports(new Xml(media)));
    Assert.assertNotEquals(refs, ActionsConfig.imports(new Configurer(media)));
    Assert.assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) ActionRef(com.b3dgs.lionengine.game.ActionRef) Test(org.junit.Test)

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