Search in sources :

Example 16 with Configurer

use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.

the class ProducerConfigTest method testCancelOnRef.

/**
 * Test cancel flag is not used on child reference.
 */
@Test
public void testCancelOnRef() {
    final ActionRef ref = new ActionRef("ref", true, new ArrayList<ActionRef>());
    final Collection<ActionRef> refs = Arrays.asList(new ActionRef("test", false, Arrays.asList(ref)));
    final Xml root = new Xml("test");
    root.add(ActionsConfig.exports(refs));
    final Media media = Medias.create("producer.xml");
    root.save(media);
    Assert.assertNotEquals(refs, ActionsConfig.imports(new Xml(media)));
    Assert.assertNotEquals(refs, ActionsConfig.imports(new Configurer(media)));
    Assert.assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) ActionRef(com.b3dgs.lionengine.game.ActionRef) Test(org.junit.Test)

Example 17 with Configurer

use of com.b3dgs.lionengine.game.Configurer 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 18 with Configurer

use of com.b3dgs.lionengine.game.Configurer 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 19 with Configurer

use of com.b3dgs.lionengine.game.Configurer 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 20 with Configurer

use of com.b3dgs.lionengine.game.Configurer 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)

Aggregations

Configurer (com.b3dgs.lionengine.game.Configurer)30 Media (com.b3dgs.lionengine.Media)27 Xml (com.b3dgs.lionengine.Xml)25 Test (org.junit.jupiter.api.Test)25 HashMap (java.util.HashMap)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Setup (com.b3dgs.lionengine.game.feature.Setup)3 Animation (com.b3dgs.lionengine.Animation)2 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 ActionRef (com.b3dgs.lionengine.game.ActionRef)2 Services (com.b3dgs.lionengine.game.feature.Services)2 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)2 Xml (com.b3dgs.lionengine.io.Xml)2 Collection (java.util.Collection)2 Test (org.junit.Test)2 XmlReader (com.b3dgs.lionengine.XmlReader)1 Force (com.b3dgs.lionengine.game.Force)1 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)1 DeviceAxis (com.b3dgs.lionengine.io.DeviceAxis)1 DeviceMapper (com.b3dgs.lionengine.io.DeviceMapper)1