Search in sources :

Example 71 with Xml

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

the class ExtractorConfig method exports.

/**
 * Exports the node from config.
 *
 * @param config The config reference (must not be <code>null</code>).
 * @return The extractor node.
 * @throws LionEngineException If unable to read node.
 */
public static Xml exports(ExtractorConfig config) {
    Check.notNull(config);
    final Xml node = new Xml(NODE_EXTRACTOR);
    node.writeDouble(ATT_EXTRACT, config.getExtract());
    node.writeDouble(ATT_DROPOFF, config.getDropOff());
    node.writeInteger(ATT_CAPACITY, config.getCapacity());
    return node;
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 72 with Xml

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

the class PathfindableConfig method exports.

/**
 * Export the pathfindable data to node.
 *
 * @param pathData The pathfindable data (must not be <code>null</code>).
 * @return The path data node.
 * @throws LionEngineException If unable to read node.
 */
public static Xml exports(Map<String, PathData> pathData) {
    Check.notNull(pathData);
    final Xml node = new Xml(NODE_PATHFINDABLE);
    for (final PathData data : pathData.values()) {
        node.add(exportPathData(data));
    }
    return node;
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 73 with Xml

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

the class CollidableFramedConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
    collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 1, 2, 3, true)));
    final CollidableFramedConfig config = new CollidableFramedConfig(collisions);
    final Xml root = new Xml("test");
    final Animation animation = new Animation("anim", 1, 2, 3.0, false, true);
    AnimationConfig.exports(root, animation);
    final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
    CollidableFramedConfig.exports(framed, collisions);
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(config, CollidableFramedConfig.imports(new Configurer(media)));
    assertEquals(collisions.values().iterator().next(), config.getCollisions());
    assertEquals(collisions.get(Integer.valueOf(1)), config.getCollision(Integer.valueOf(1)));
    assertTrue(config.getCollision(Integer.valueOf(2)).isEmpty());
    assertTrue(media.getFile().delete());
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.Xml) Collision(com.b3dgs.lionengine.game.feature.collidable.Collision) Media(com.b3dgs.lionengine.Media) Collection(java.util.Collection) Animation(com.b3dgs.lionengine.Animation) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 74 with Xml

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

the class CollidableFramedConfigTest method testExportsImportsNumber.

/**
 * Test exports imports with number.
 */
@Test
void testExportsImportsNumber() {
    final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
    collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("coll%anim%1", 0, 1, 2, 3, true)));
    final Xml root = new Xml("test");
    final Animation animation = new Animation("anim", 1, 2, 3.0, false, true);
    AnimationConfig.exports(root, animation);
    final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
    CollidableFramedConfig.exports(framed, collisions);
    framed.getChildXml(CollidableFramedConfig.NODE_COLLISION_FRAMED).removeAttribute(CollidableFramedConfig.ATT_NUMBER);
    framed.getChildXml(CollidableFramedConfig.NODE_COLLISION_FRAMED).writeString(CollidableFramedConfig.ATT_PREFIX, "coll");
    final Media media = Medias.create("Object.xml");
    root.save(media);
    final CollidableFramedConfig imported = CollidableFramedConfig.imports(new Configurer(media));
    assertEquals(collisions.get(Integer.valueOf(1)), imported.getCollision(Integer.valueOf(1)));
    assertFalse(imported.getCollision(Integer.valueOf(2)).isEmpty());
    assertTrue(media.getFile().delete());
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.Xml) Collision(com.b3dgs.lionengine.game.feature.collidable.Collision) Media(com.b3dgs.lionengine.Media) Collection(java.util.Collection) Animation(com.b3dgs.lionengine.Animation) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 75 with Xml

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

the class CollidableFramedConfigTest method testNoNode.

/**
 * Test no node.
 */
@Test
void testNoNode() {
    final Xml root = new Xml("test");
    assertTrue(CollidableFramedConfig.imports(root).getCollisions().isEmpty());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Test(org.junit.jupiter.api.Test)

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