Search in sources :

Example 26 with Setup

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

the class MapTileFogTest method testFog.

/**
 * Test the fog.
 */
@Test
void testFog() {
    final MapTile map = UtilMap.createMap(5);
    services.add(map);
    final FovableModel fovable = new FovableModel(services, setup);
    final FeaturableModel object = new FeaturableModel(services, setup);
    final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.teleport(3, 3);
    fovable.prepare(object);
    fovable.setFov(1);
    final MapTileFog fog = new MapTileFog();
    Medias.setLoadFromJar(MapTileFog.class);
    fog.create(map.getFeature(MapTileSurface.class), Medias.create("fog.xml"), null);
    Medias.setLoadFromJar(null);
    final AtomicInteger rtx = new AtomicInteger();
    final AtomicInteger rty = new AtomicInteger();
    final AtomicInteger count = new AtomicInteger();
    final RevealedListener listener = (tx, ty) -> {
        rtx.set(tx);
        rty.set(ty);
        count.incrementAndGet();
    };
    fog.addListener(listener);
    assertEquals(16, fog.getTile(2, 3).getNumber());
    assertEquals(16, fog.getTile(3, 3).getNumber());
    assertEquals(16, fog.getTile(4, 3).getNumber());
    fog.updateFov(fovable);
    assertEquals(10, fog.getTile(2, 2).getNumber());
    assertEquals(1, fog.getTile(3, 2).getNumber());
    assertEquals(11, fog.getTile(4, 2).getNumber());
    assertEquals(2, fog.getTile(2, 3).getNumber());
    assertEquals(17, fog.getTile(3, 3).getNumber());
    assertEquals(3, fog.getTile(4, 3).getNumber());
    assertEquals(8, fog.getTile(2, 4).getNumber());
    assertEquals(0, fog.getTile(3, 4).getNumber());
    assertEquals(9, fog.getTile(4, 4).getNumber());
    assertEquals(1, count.get());
    assertEquals(3, rtx.get());
    assertEquals(3, rty.get());
    fog.reset(fovable);
    fog.removeListener(listener);
    count.set(0);
    assertEquals(16, fog.getTile(2, 3).getNumber());
    assertEquals(16, fog.getTile(3, 3).getNumber());
    assertEquals(16, fog.getTile(4, 3).getNumber());
    fog.updateFov(fovable);
    assertEquals(0, count.get());
}
Also used : Medias(com.b3dgs.lionengine.Medias) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) UtilMap(com.b3dgs.lionengine.game.feature.tile.map.UtilMap) Services(com.b3dgs.lionengine.game.feature.Services) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) MapTileSurface(com.b3dgs.lionengine.game.feature.tile.map.MapTileSurface) UtilMapTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.UtilMapTransition) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapTileSurface(com.b3dgs.lionengine.game.feature.tile.map.MapTileSurface) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 27 with Setup

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

the class FramesConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final FramesConfig config = new FramesConfig(1, 2, 3, 4);
    final Xml root = new Xml("test");
    root.add(FramesConfig.exports(config));
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(config, FramesConfig.imports(new Xml(media)));
    assertEquals(config, FramesConfig.imports(new Setup(media)));
    assertEquals(config, FramesConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 28 with Setup

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

the class OriginConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Origin origin = Origin.MIDDLE;
    final Xml root = new Xml("test");
    root.add(OriginConfig.exports(origin));
    final Media media = Medias.create("origin.xml");
    root.save(media);
    assertEquals(origin, OriginConfig.imports(new Xml(media)));
    assertEquals(origin, OriginConfig.imports(new Setup(media)));
    assertEquals(origin, OriginConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : Origin(com.b3dgs.lionengine.Origin) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 29 with Setup

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

the class LauncherModelTest method testLauncherFailure.

/**
 * Test the launcher failure.
 */
@Test
void testLauncherFailure() {
    final Media launchableMedia = UtilSetup.createMedia(Featurable.class);
    final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia);
    final Setup setup = new Setup(launcherMedia);
    final Launcher launcher = UtilLaunchable.createLauncher(services, setup, featurable);
    try {
        assertThrowsTimeout(1000L, () -> {
            while (!launcher.fire()) {
                launcher.update(1.0);
                continue;
            }
        }, "No recognized constructor found for: Featurable.xml");
    } finally {
        final Handler handler = services.get(Handler.class);
        handler.removeAll();
        handler.update(1.0);
        assertEquals(0, handler.size());
        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.jupiter.api.Test)

Example 30 with Setup

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

the class LauncherModelTest method testCheckListener.

/**
 * Test check listener conditions.
 */
@Test
void testCheckListener() {
    final Media launchableMedia = UtilSetup.createMedia(LaunchableObjectException.class);
    final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia);
    final Setup setup = new Setup(launcherMedia);
    services.add(new Factory(services));
    services.add(new Handler(services));
    final AtomicBoolean launchableListener = new AtomicBoolean();
    final AtomicBoolean launcherListener = new AtomicBoolean();
    final Launcher launcher = new LauncherModel(services, setup) {

        @Override
        public void addListener(LaunchableListener listener) {
            launchableListener.set(true);
        }

        @Override
        public void addListener(LauncherListener listener) {
            launcherListener.set(true);
        }
    };
    assertFalse(launchableListener.get());
    assertFalse(launcherListener.get());
    launcher.checkListener(launcher);
    assertFalse(launchableListener.get());
    assertFalse(launcherListener.get());
    launcher.checkListener((LaunchableListener) l -> l.update(1.0));
    assertTrue(launchableListener.get());
    assertFalse(launcherListener.get());
    launcher.checkListener((LauncherListener) () -> launcher.update(1.0));
    launchableListener.set(false);
    assertFalse(launchableListener.get());
    assertTrue(launcherListener.get());
    assertTrue(launchableMedia.getFile().delete());
}
Also used : Medias(com.b3dgs.lionengine.Medias) BeforeEach(org.junit.jupiter.api.BeforeEach) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilAssert.assertTimeout(com.b3dgs.lionengine.UtilAssert.assertTimeout) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) UtilAssert.assertThrowsTimeout(com.b3dgs.lionengine.UtilAssert.assertThrowsTimeout) AfterAll(org.junit.jupiter.api.AfterAll) UtilAssert.assertNull(com.b3dgs.lionengine.UtilAssert.assertNull) Resolution(com.b3dgs.lionengine.Resolution) Services(com.b3dgs.lionengine.game.feature.Services) UtilAssert.assertNotNull(com.b3dgs.lionengine.UtilAssert.assertNotNull) BeforeAll(org.junit.jupiter.api.BeforeAll) Force(com.b3dgs.lionengine.game.Force) Handler(com.b3dgs.lionengine.game.feature.Handler) SourceResolutionDelegate(com.b3dgs.lionengine.graphic.engine.SourceResolutionDelegate) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) Factory(com.b3dgs.lionengine.game.feature.Factory) Localizable(com.b3dgs.lionengine.Localizable) Featurable(com.b3dgs.lionengine.game.feature.Featurable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Media(com.b3dgs.lionengine.Media) Factory(com.b3dgs.lionengine.game.feature.Factory) Handler(com.b3dgs.lionengine.game.feature.Handler) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Aggregations

Setup (com.b3dgs.lionengine.game.feature.Setup)42 Test (org.junit.jupiter.api.Test)34 Media (com.b3dgs.lionengine.Media)31 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)20 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)15 Xml (com.b3dgs.lionengine.Xml)11 Featurable (com.b3dgs.lionengine.game.feature.Featurable)11 Transformable (com.b3dgs.lionengine.game.feature.Transformable)11 Services (com.b3dgs.lionengine.game.feature.Services)10 Medias (com.b3dgs.lionengine.Medias)6 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)6 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)6 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)6 Handler (com.b3dgs.lionengine.game.feature.Handler)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 AfterAll (org.junit.jupiter.api.AfterAll)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)4