Search in sources :

Example 1 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class AnimationConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
public 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));
    Assert.assertEquals(animation1, imported.getAnimation("anim1"));
    Assert.assertEquals(animation2, imported.getAnimation("anim2"));
    Assert.assertTrue(imported.getAnimations().containsAll(Arrays.asList(animation1, animation2)));
    Assert.assertFalse(imported.hasAnimation("anim"));
    Assert.assertTrue(imported.hasAnimation("anim1"));
    Assert.assertTrue(imported.hasAnimation("anim2"));
    Assert.assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Animation(com.b3dgs.lionengine.Animation) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.Test)

Example 2 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class UtilActionnable method createActionable.

/**
 * Create the actionable.
 *
 * @param media The media.
 * @param services The services.
 * @return The prepared actionable.
 */
public static ActionableModel createActionable(Media media, Services services) {
    final Setup setup = new Setup(media);
    final Featurable featurable = new FeaturableModel();
    featurable.addFeature(new IdentifiableModel());
    final ActionableModel actionable = new ActionableModel(services, setup);
    actionable.prepare(featurable);
    return actionable;
}
Also used : ActionableModel(com.b3dgs.lionengine.game.feature.ActionableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) IdentifiableModel(com.b3dgs.lionengine.game.feature.IdentifiableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 3 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class CollidableConfigTest method testExport.

/**
 * Test export.
 */
@Test
public void testExport() {
    final Media media = Medias.create("object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    final Services services = new Services();
    services.add(new ViewerMock());
    final Collidable collidable = new CollidableModel(services, new Setup(media));
    collidable.setGroup(1);
    CollidableConfig.exports(root, collidable);
    root.save(media);
    Assert.assertEquals(Integer.valueOf(1), CollidableConfig.imports(new Configurer(media)));
    Assert.assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.Test)

Example 4 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class ComponentCollisionTest method prepare.

/**
 * Prepare test.
 */
@Before
public void prepare() {
    services.add(new Camera());
    featurable1 = new ObjectSelf();
    transformable1 = featurable1.addFeatureAndGet(new TransformableModel(setup));
    collidable1 = featurable1.addFeatureAndGet(new CollidableModel(services, setup));
    collidable1.setGroup(1);
    collidable1.addAccept(0);
    final Collision collision1 = new Collision("test1", 0, 0, 3, 3, false);
    collidable1.addCollision(collision1);
    featurable2 = CollidableModelTest.createFeaturable(config, services);
    transformable2 = featurable2.getFeature(Transformable.class);
    collidable2 = featurable2.getFeature(Collidable.class);
    collidable2.addAccept(1);
    collidable2.setGroup(0);
    final Collision collision2 = new Collision("test2", 0, 0, 3, 3, true);
    collidable2.addCollision(collision2);
    featurable3 = new ObjectSelf();
    transformable3 = featurable3.addFeatureAndGet(new TransformableModel(setup));
    collidable3 = featurable3.addFeatureAndGet(new CollidableModel(services, setup));
    collidable3.setGroup(0);
    final ComponentCollision component = new ComponentCollision();
    handler.addComponent(component);
    handler.add(featurable1);
    handler.add(featurable2);
    handler.add(featurable3);
    handler.add(nonCollidable);
    final CollidableListener listener = collidable -> collide.set(collidable);
    collidable2.addListener(listener);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Graphics(com.b3dgs.lionengine.graphic.Graphics) Services(com.b3dgs.lionengine.game.feature.Services) Medias(com.b3dgs.lionengine.core.Medias) Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Assert(org.junit.Assert) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Before(org.junit.Before) Camera(com.b3dgs.lionengine.game.feature.Camera) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Camera(com.b3dgs.lionengine.game.feature.Camera) Before(org.junit.Before)

Example 5 with Setup

use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.

the class LauncherModelTest method testLauncherException.

/**
 * Test the launcher failure.
 *
 * @throws InterruptedException If error.
 */
@Test(expected = LionEngineException.class)
public void testLauncherException() throws InterruptedException {
    final Media launchableMedia = UtilSetup.createMedia(LaunchableObjectException.class);
    final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia);
    final Setup setup = new Setup(launcherMedia);
    final Launcher launcher = UtilLaunchable.createLauncher(services, setup, featurable);
    try {
        while (!launcher.fire()) {
            continue;
        }
        Assert.fail();
    } finally {
        final Handler handler = services.get(Handler.class);
        handler.removeAll();
        handler.update(1.0);
        Assert.assertEquals(0, handler.size());
        Assert.assertTrue(launchableMedia.getFile().delete());
    }
}
Also used : Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.Test)

Aggregations

Setup (com.b3dgs.lionengine.game.feature.Setup)21 Test (org.junit.Test)15 Media (com.b3dgs.lionengine.Media)12 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)12 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)10 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)9 Transformable (com.b3dgs.lionengine.game.feature.Transformable)8 Featurable (com.b3dgs.lionengine.game.feature.Featurable)5 Handler (com.b3dgs.lionengine.game.feature.Handler)4 Services (com.b3dgs.lionengine.game.feature.Services)4 Xml (com.b3dgs.lionengine.io.Xml)4 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)3 Configurer (com.b3dgs.lionengine.game.Configurer)2 ActionableModel (com.b3dgs.lionengine.game.feature.ActionableModel)2 IdentifiableModel (com.b3dgs.lionengine.game.feature.IdentifiableModel)2 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Animation (com.b3dgs.lionengine.Animation)1 ViewerMock (com.b3dgs.lionengine.ViewerMock)1 Medias (com.b3dgs.lionengine.core.Medias)1