Search in sources :

Example 11 with Xml

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

the class ActionsConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
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);
    assertEquals(refs, ActionsConfig.imports(new Xml(media), null));
    assertEquals(refs, ActionsConfig.imports(new Configurer(media), null));
    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 12 with Xml

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

the class FovableConfig method exports.

/**
 * Create the data from node.
 *
 * @param fov The field of view value.
 * @return The node data.
 * @throws LionEngineException If unable to write node.
 */
public static Xml exports(int fov) {
    final Xml node = new Xml(NODE_FOVABLE);
    node.writeInteger(ATT_FOV, fov);
    return node;
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 13 with Xml

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

the class AnimationConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Xml root = new Xml("test");
    final Animation animation1 = new Animation("anim1", 1, 2, 3.0, false, true);
    final Animation animation2 = new Animation("anim2", 4, 5, 6.0, true, false);
    AnimationConfig.exports(root, animation1);
    AnimationConfig.exports(root, animation2);
    final Media media = Medias.create("animations.xml");
    root.save(media);
    final AnimationConfig imported = AnimationConfig.imports(new Setup(media));
    assertEquals(animation1, imported.getAnimation("anim1"));
    assertEquals(animation2, imported.getAnimation("anim2"));
    assertTrue(imported.getAnimations().containsAll(Arrays.asList(animation1, animation2)));
    assertFalse(imported.hasAnimation("anim"));
    assertTrue(imported.hasAnimation("anim1"));
    assertTrue(imported.hasAnimation("anim2"));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Animation(com.b3dgs.lionengine.Animation) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 14 with Xml

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

the class AnimationConfigTest method testNoNode.

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

Example 15 with Xml

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

the class FeaturableConfigTest method testGetFeaturesCache.

/**
 * Test with cached feature class.
 */
@Test
void testGetFeaturesCache() {
    final Xml root = new Xml("test");
    root.createChild(FeaturableConfig.NODE_FEATURES).createChild(FeaturableConfig.NODE_FEATURE).setText(FeatureModel.class.getName());
    final Media media = Medias.create("Object.xml");
    root.save(media);
    final ClassLoader loader = ClassLoader.getSystemClassLoader();
    final Services services = new Services();
    final Setup setup = new Setup(media);
    final List<Feature> a = FeaturableConfig.getFeatures(loader, services, setup);
    final List<Feature> b = FeaturableConfig.getFeatures(loader, services, setup);
    assertNotEquals(a.get(0), b.get(0));
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Feature(com.b3dgs.lionengine.game.Feature) 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