Search in sources :

Example 81 with Xml

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

the class FeaturableConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final String clazz = "class";
    final String setup = "setup";
    final FeaturableConfig config = new FeaturableConfig(clazz, setup);
    final Xml root = new Xml("test");
    root.add(FeaturableConfig.exportClass(clazz));
    root.add(FeaturableConfig.exportSetup(setup));
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(config, FeaturableConfig.imports(new Xml(media)));
    assertEquals(config, FeaturableConfig.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 82 with Xml

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

the class BodyConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    final Xml node = root.createChild(BodyConfig.NODE_BODY);
    node.writeDouble(BodyConfig.ATT_GRAVITY, 1.0);
    node.writeDouble(BodyConfig.ATT_GRAVITY_MAX, 2.0);
    root.save(media);
    final Body body = new BodyModel(new Services(), new Setup(media));
    BodyConfig.exports(root, body);
    final BodyConfig config = BodyConfig.imports(new Setup(media));
    assertEquals(1.0, config.getGravity());
    assertEquals(2.0, config.getGravityMax());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 83 with Xml

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

the class CollidableConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final int group = 1;
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    final Xml node = root.createChild(CollidableConfig.NODE_COLLIDABLE);
    node.writeInteger(CollidableConfig.ATT_GROUP, group);
    node.writeString(CollidableConfig.ATT_ACCEPTED, "1%2");
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(1, config.getGroup().intValue());
    assertIterableEquals(Arrays.asList(Integer.valueOf(1), Integer.valueOf(2)), config.getAccepted());
    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 84 with Xml

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

the class CollidableConfigTest method testDefaultGroup.

/**
 * Test with default group.
 */
@Test
void testDefaultGroup() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    assertEquals(CollidableConfig.DEFAULT_GROUP, CollidableConfig.imports(new Configurer(media)).getGroup());
    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 85 with Xml

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

the class CollidableConfigTest method testInvalidGroup.

/**
 * Test with invalid group.
 */
@Test
void testInvalidGroup() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    final Xml node = root.createChild(CollidableConfig.NODE_COLLIDABLE);
    node.writeString(CollidableConfig.ATT_GROUP, "a");
    root.save(media);
    assertCause(() -> CollidableConfig.imports(new Configurer(media)), NumberFormatException.class);
    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)

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