Search in sources :

Example 36 with Setup

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

the class StateHandlerTest method testClear.

/**
 * Test the state clear transition.
 */
@Test
void testClear() {
    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.changeState(StateClear.class);
        handler.update(1.0);
        assertFalse(handler.isState(StateClear.class));
        handler.postUpdate();
        assertTrue(handler.isState(StateClear.class));
        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 37 with Setup

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

the class StateHandlerTest method testListener.

/**
 * Test is state with listener.
 */
@Test
void testListener() {
    final AtomicReference<Class<? extends State>> old = new AtomicReference<>();
    final AtomicReference<Class<? extends State>> next = new AtomicReference<>();
    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);
        final StateTransitionListener listener = (o, n) -> {
            old.set(o);
            next.set(n);
        };
        handler.addListener(listener);
        handler.changeState(StateIdle.class);
        handler.postUpdate();
        assertNull(old.get());
        assertEquals(StateIdle.class, next.get());
        handler.changeState(StateWalk.class);
        handler.postUpdate();
        assertEquals(StateIdle.class, old.get());
        assertEquals(StateWalk.class, next.get());
        handler.removeListener(listener);
        old.set(null);
        next.set(null);
        handler.changeState(StateIdle.class);
        handler.postUpdate();
        assertNull(old.get());
        assertNull(next.get());
    } finally {
        Medias.setLoadFromJar(null);
    }
}
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) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) UtilAssert.assertCause(com.b3dgs.lionengine.UtilAssert.assertCause) Test(org.junit.jupiter.api.Test) Animation(com.b3dgs.lionengine.Animation) UtilAssert.assertNull(com.b3dgs.lionengine.UtilAssert.assertNull) Services(com.b3dgs.lionengine.game.feature.Services) UtilAssert.assertThrows(com.b3dgs.lionengine.UtilAssert.assertThrows) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) UtilReflection(com.b3dgs.lionengine.UtilReflection) Featurable(com.b3dgs.lionengine.game.feature.Featurable) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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 38 with Setup

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

the class MapTileCollisionModelComplexTest method createObject.

/**
 * Create object test.
 *
 * @return The object test.
 */
private Transformable createObject() {
    final Setup setup = new Setup(config);
    CollisionCategoryConfig.exports(setup.getRoot(), category);
    final FeaturableModel object = new FeaturableModel(services, setup);
    final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.setSize(1, 1);
    final TileCollidable collidable = object.addFeatureAndGet(new TileCollidableModel(services, setup));
    collidable.setEnabled(true);
    return transformable;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup)

Example 39 with Setup

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

the class ExtractorModelTest method testConfig.

/**
 * Test the extractor config.
 */
@Test
void testConfig() {
    final ObjectExtractor object = new ObjectExtractor(services, setup, true, true);
    object.addFeature(new TransformableModel(services, setup));
    final Media media = UtilSetup.createConfig(ExtractorModelTest.class);
    final Xml xml = new Xml(media);
    xml.add(ExtractorConfig.exports(new ExtractorConfig(1.0, 2.0, 5)));
    xml.save(media);
    final ExtractorModel extractor = new ExtractorModel(services, new Setup(media));
    extractor.recycle();
    assertEquals(5, extractor.getExtractionCapacity());
    assertEquals(1.0, extractor.getExtractionSpeed());
    assertEquals(2.0, extractor.getDropOffSpeed());
    extractor.prepare(object);
    assertEquals(5, extractor.getExtractionCapacity());
    assertEquals(1.0, extractor.getExtractionSpeed());
    assertEquals(2.0, extractor.getDropOffSpeed());
    object.getFeature(Identifiable.class).notifyDestroyed();
    assertTrue(media.getFile().delete());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 40 with Setup

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

the class UtilProducible method createProducible.

/**
 * Create producible.
 *
 * @param services The services.
 * @return The producible.
 */
public static Featurable createProducible(Services services) {
    final Media media = createProducibleMedia();
    final Setup setup = new Setup(media);
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new TransformableModel(services, setup));
    featurable.addFeature(new ProducibleModel(services, setup));
    return featurable;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Media(com.b3dgs.lionengine.Media) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

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