Search in sources :

Example 86 with Xml

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

the class CollisionConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Xml root = new Xml(Constant.XML_PREFIX + FeaturableConfig.NODE_FEATURABLE);
    final Collision collision = new Collision("test", 0, 1, 2, 3, true);
    CollisionConfig.exports(root, collision);
    final Media media = Medias.create("collision.xml");
    root.save(media);
    final CollisionConfig config = CollisionConfig.imports(new Configurer(media));
    final Collision imported = config.getCollision("test");
    assertEquals("test", imported.getName());
    assertEquals(0, imported.getOffsetX());
    assertEquals(1, imported.getOffsetY());
    assertEquals(2, imported.getWidth());
    assertEquals(3, imported.getHeight());
    assertTrue(imported.hasMirror());
    assertFalse(config.getCollisions().isEmpty());
    assertEquals(collision, config.getCollision("test"));
    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 87 with Xml

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

the class UtilSetup method createMedia.

/**
 * Create the object media.
 *
 * @param clazz The class type.
 * @return The object media.
 */
public static Media createMedia(Class<?> clazz) {
    final Xml root = new Xml("test");
    root.add(FeaturableConfig.exportClass(clazz.getName()));
    final Media media = Medias.create(clazz.getSimpleName() + ".xml");
    root.save(media);
    return media;
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media)

Example 88 with Xml

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

the class UtilTransformable method createMedia.

/**
 * Create the object media.
 *
 * @param caller The caller class.
 * @return The object media.
 */
public static Media createMedia(Class<?> caller) {
    final Xml root = new Xml("test");
    root.add(FeaturableConfig.exportClass(Featurable.class.getName()));
    root.add(SizeConfig.exports(new SizeConfig(16, 32)));
    final Media media = Medias.create("transformable_" + caller.getSimpleName() + Factory.FILE_DATA_DOT_EXTENSION);
    root.save(media);
    return media;
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) SizeConfig(com.b3dgs.lionengine.game.SizeConfig)

Example 89 with Xml

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

the class UtilSetup method createConfig.

/**
 * Create a test configuration.
 *
 * @param caller The caller reference.
 * @return The test configuration media.
 */
public static Media createConfig(Class<?> caller) {
    final Xml root = new Xml(Constant.XML_PREFIX + "featurable");
    final Media media = Medias.create("Object" + caller.getSimpleName() + Factory.FILE_DATA_DOT_EXTENSION);
    root.save(media);
    return media;
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media)

Example 90 with Xml

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

the class PathfindableConfigTest method testNoMovements.

/**
 * Test without movements.
 */
@Test
void testNoMovements() {
    final Map<String, PathData> map = new HashMap<>();
    final PathData data = new PathData("category", 1.0, true, EnumSet.noneOf(MovementTile.class));
    map.put(data.getName(), data);
    final Xml root = new Xml("test");
    root.add(PathfindableConfig.exports(map));
    final Media media = Medias.create("pathfindable.xml");
    root.save(media);
    final Map<String, PathData> imported = PathfindableConfig.imports(new Configurer(media));
    assertTrue(imported.get(data.getName()).getAllowedMovements().isEmpty());
    assertEquals(map, imported);
    assertTrue(media.getFile().delete());
}
Also used : HashMap(java.util.HashMap) 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