Search in sources :

Example 26 with Xml

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

the class BodyConfig method exports.

/**
 * Create an XML node from a body.
 *
 * @param root The node root (must not be <code>null</code>).
 * @param body The body reference (must not be <code>null</code>).
 * @throws LionEngineException If invalid argument.
 */
public static void exports(Xml root, Body body) {
    Check.notNull(root);
    Check.notNull(body);
    final Xml node = root.createChild(NODE_BODY);
    node.writeDouble(ATT_GRAVITY, body.getGravity());
    node.writeDouble(ATT_GRAVITY_MAX, body.getGravityMax());
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 27 with Xml

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

the class ProducibleConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final ProducibleConfig producible = new ProducibleConfig(1, 2, 3);
    final Xml root = new Xml("test");
    root.add(SizeConfig.exports(new SizeConfig(producible.getWidth(), producible.getHeight())));
    root.add(ProducibleConfig.exports(producible));
    final Media media = Medias.create("producible.xml");
    root.save(media);
    assertEquals(producible, ProducibleConfig.imports(new Xml(media)));
    assertEquals(producible, ProducibleConfig.imports(new Setup(media)));
    assertEquals(producible, ProducibleConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) SizeConfig(com.b3dgs.lionengine.game.SizeConfig) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 28 with Xml

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

the class AttackerConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final AttackerConfig config = new AttackerConfig(1, 2, 3, 4, 5);
    final Xml root = new Xml("test");
    root.add(AttackerConfig.exports(config));
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(config, AttackerConfig.imports(new Xml(media)));
    assertEquals(config, AttackerConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 29 with Xml

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

the class CollidableConfigTest method testEmptyAccepted.

/**
 * Test with empty accepted.
 */
@Test
void testEmptyAccepted() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    final Services services = new Services();
    services.add(new ViewerMock());
    final Collidable collidable = new CollidableModel(services, new Setup(media));
    collidable.setGroup(Integer.valueOf(1));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertTrue(config.getAccepted().isEmpty());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 30 with Xml

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

the class CollidableConfigTest method testExport.

/**
 * Test export.
 */
@Test
void testExport() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    final Services services = new Services();
    services.add(new ViewerMock());
    final Collidable collidable = new CollidableModel(services, new Setup(media));
    collidable.setGroup(Integer.valueOf(1));
    collidable.addAccept(Integer.valueOf(2));
    collidable.addAccept(Integer.valueOf(3));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertIterableEquals(Arrays.asList(Integer.valueOf(2), Integer.valueOf(3)), config.getAccepted());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) 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