Search in sources :

Example 6 with Setup

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

the class StateHandlerTest method testNullArgument.

/**
 * Test is state with invalid parameter.
 */
@Test
void testNullArgument() {
    Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
    final Media config = UtilTransformable.createMedia(StateHandlerTest.class);
    try {
        final Setup setup = new Setup(config);
        final StateHandler handler = new StateHandler(services, setup);
        assertThrows(() -> handler.changeState(null), "Unexpected null argument !");
        assertTrue(config.getFile().delete());
    } finally {
        Medias.setResourcesDirectory(null);
    }
}
Also used : Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 7 with Setup

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

the class StateHandlerTest method testWithConfig.

/**
 * Test state with configuration.
 */
@Test
void testWithConfig() {
    Medias.setLoadFromJar(StateHandlerTest.class);
    try {
        final Setup setup = new Setup(Medias.create("Object.xml"));
        final Featurable featurable = new FeaturableModel(services, setup);
        final StateHandler handler;
        handler = featurable.addFeatureAndGet(new StateHandler(services, setup));
        handler.prepare(featurable);
        handler.changeState(StateIdle.class);
        handler.postUpdate();
        assertEquals(new Animation(StateIdle.class.getSimpleName(), 1, 1, 0.125, false, false), StateIdle.animation);
        assertNull(StateWalk.animation);
        assertTrue(handler.isState(StateIdle.class));
        handler.update(1.0);
        assertNull(StateWalk.animation);
        handler.postUpdate();
        assertEquals(new Animation(StateWalk.class.getSimpleName(), 2, 2, 0.125, false, false), StateWalk.animation);
        assertTrue(handler.isState(StateWalk.class));
        handler.update(1.0);
        handler.postUpdate();
        assertTrue(handler.isState(StateIdle.class));
    } finally {
        Medias.setLoadFromJar(null);
    }
}
Also used : Animation(com.b3dgs.lionengine.Animation) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 8 with Setup

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

the class StateHandlerTest method testLast.

/**
 * Test transition with last state.
 */
@Test
void testLast() {
    final AtomicReference<Class<? extends State>> old = new AtomicReference<>();
    final AtomicReference<Class<? extends State>> next = new AtomicReference<>();
    Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
    final Media config = UtilTransformable.createMedia(StateHandlerTest.class);
    try {
        final Setup setup = new Setup(config);
        final StateHandler handler = new StateHandler(services, setup);
        handler.addListener((o, n) -> {
            old.set(o);
            next.set(n);
        });
        handler.changeState(StateMock.class);
        handler.postUpdate();
        handler.postUpdate();
        assertNull(old.get());
        assertEquals(StateMock.class, next.get());
        old.set(null);
        next.set(null);
        handler.changeState(StateMock.class);
        handler.postUpdate();
        assertEquals(StateMock.class, old.get());
        assertEquals(StateMock.class, next.get());
        assertTrue(config.getFile().delete());
    } finally {
        Medias.setResourcesDirectory(null);
    }
}
Also used : Media(com.b3dgs.lionengine.Media) AtomicReference(java.util.concurrent.atomic.AtomicReference) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 9 with Setup

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

the class CollidableConfigTest method testEmptyAccepted.

/**
 * Test with empty accepted.
 */
@Test
void testEmptyAccepted() {
    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(Integer.valueOf(1));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertTrue(config.getAccepted().isEmpty());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 10 with Setup

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

the class CollidableConfigTest method testExport.

/**
 * Test export.
 */
@Test
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(Integer.valueOf(1));
    collidable.addAccept(Integer.valueOf(2));
    collidable.addAccept(Integer.valueOf(3));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertIterableEquals(Arrays.asList(Integer.valueOf(2), Integer.valueOf(3)), config.getAccepted());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) 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