Search in sources :

Example 76 with Xml

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

the class CollidableFramedModelTest method beforeTests.

/**
 * Prepare test.
 */
@BeforeAll
public static void beforeTests() {
    Graphics.setFactoryGraphic(new FactoryGraphicMock());
    Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
    config = UtilSetup.createConfig(CollidableFramedModelTest.class);
    final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
    collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 0, 2, 2, false)));
    final Xml root = new Xml(config);
    AnimationConfig.exports(root, new Animation("anim", 1, 2, 1.0, false, false));
    final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
    CollidableFramedConfig.exports(framed, collisions);
    root.save(config);
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.Xml) Collision(com.b3dgs.lionengine.game.feature.collidable.Collision) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Collection(java.util.Collection) Animation(com.b3dgs.lionengine.Animation) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 77 with Xml

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

the class AttackerModelTest method testConfig.

/**
 * Test the config.
 */
@Test
void testConfig() {
    final int damagesMin = 1;
    final int damagesMax = 2;
    final int distanceMin = 1;
    final int distanceMax = 2;
    final int frame = 1;
    final int time = 100;
    final Media media = UtilTransformable.createMedia(AttackerModelTest.class);
    final Xml xml = new Xml(media);
    xml.add(AttackerConfig.exports(new AttackerConfig(time, distanceMin, distanceMax, damagesMin, damagesMax)));
    xml.save(media);
    final AttackerModel attacker = new AttackerModel(services, new Setup(media));
    attacker.setAttackFrame(frame);
    assertTrue(attacker.getAttackDamages() >= damagesMin);
    assertTrue(attacker.getAttackDamages() <= damagesMax);
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Example 78 with Xml

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

the class FeaturableConfigTest method testDefaultClass.

/**
 * Test with default class.
 */
@Test
void testDefaultClass() {
    final Xml root = new Xml("test");
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(new FeaturableConfig(FeaturableModel.class.getName(), ""), FeaturableConfig.imports(new Xml(media)));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Example 79 with Xml

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

the class FeaturableConfigTest method testGetFeaturesUnknown.

/**
 * Test with unknown feature class.
 */
@Test
void testGetFeaturesUnknown() {
    final Xml root = new Xml("test");
    root.createChild(FeaturableConfig.NODE_FEATURES).createChild(FeaturableConfig.NODE_FEATURE).setText(Feature.class.getName());
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertCause(() -> FeaturableConfig.getFeatures(ClassLoader.getSystemClassLoader(), new Services(), new Setup(media)), NoSuchMethodException.class);
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Feature(com.b3dgs.lionengine.game.Feature) Test(org.junit.jupiter.api.Test)

Example 80 with Xml

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

the class FeaturableConfigTest method testDefaultSetup.

/**
 * Test with default setup.
 */
@Test
void testDefaultSetup() {
    final Xml root = new Xml("test");
    root.add(FeaturableConfig.exportClass("clazz"));
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(new FeaturableConfig("clazz", ""), FeaturableConfig.imports(new Xml(media)));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) 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