Search in sources :

Example 31 with Featurable

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

the class StateHandlerTest method testHandlerConverter.

/**
 * Test the state handling with custom converter.
 */
@Test
void testHandlerConverter() {
    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, Class::getName));
        handler.prepare(featurable);
        handler.changeState(StateIdle.class);
        assertCause(() -> handler.postUpdate(), "Animation not found: " + StateIdle.class.getName());
    } finally {
        Medias.setLoadFromJar(null);
    }
}
Also used : 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 32 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable 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 33 with Featurable

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

the class UtilExtractable method createExtractable.

/**
 * Create extractable.
 *
 * @param services The services reference (must not be <code>null</code>).
 * @param setup The setup reference (must not be <code>null</code>).
 * @return The extractable.
 */
public static Extractable createExtractable(Services services, Setup setup) {
    services.add(new MapTileGame());
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new TransformableModel(services, setup));
    final Extractable extractable = new ExtractableModel(services, setup);
    extractable.setResourcesQuantity(10);
    extractable.setResourcesType("wood");
    extractable.prepare(featurable);
    return extractable;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 34 with Featurable

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

the class ExtractableModelTest method testExtract.

/**
 * Test the extraction.
 */
@Test
void testExtract() {
    services.add(new MapTileGame());
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new TransformableModel(services, setup));
    final Extractable extractable = new ExtractableModel(services, setup);
    extractable.prepare(featurable);
    extractable.setResourcesQuantity(10);
    assertEquals(10, extractable.getResourceQuantity());
    extractable.extractResource(5);
    assertEquals(5, extractable.getResourceQuantity());
    extractable.getFeature(Identifiable.class).notifyDestroyed();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 35 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable 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

Featurable (com.b3dgs.lionengine.game.feature.Featurable)35 Test (org.junit.jupiter.api.Test)19 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Setup (com.b3dgs.lionengine.game.feature.Setup)8 Media (com.b3dgs.lionengine.Media)7 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)6 Transformable (com.b3dgs.lionengine.game.feature.Transformable)5 Services (com.b3dgs.lionengine.game.feature.Services)4 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)4 Animation (com.b3dgs.lionengine.Animation)3 Medias (com.b3dgs.lionengine.Medias)2 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)2 Camera (com.b3dgs.lionengine.game.feature.Camera)2 IdentifiableModel (com.b3dgs.lionengine.game.feature.IdentifiableModel)2 LayerableModel (com.b3dgs.lionengine.game.feature.LayerableModel)2 MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)2 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)2