Search in sources :

Example 26 with FeaturableModel

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

the class SelectorRefresherTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new ContextMock());
    services.add(new Camera());
    services.add(new ViewerMock());
    cursor = services.create(Cursor.class);
    cursor.setSync(mouse);
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new LayerableModel(services, setup));
    featurable.addFeature(new TransformableModel(services, setup));
    featurable.addFeature(new CollidableModel(services, setup));
    refresher = new SelectorRefresher(services, model);
    refresher.addListener(listener);
    refresher.prepare(featurable);
}
Also used : CollidableModel(com.b3dgs.lionengine.game.feature.collidable.CollidableModel) ViewerMock(com.b3dgs.lionengine.ViewerMock) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Camera(com.b3dgs.lionengine.game.feature.Camera) ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor) Featurable(com.b3dgs.lionengine.game.feature.Featurable) SelectorRefresher(com.b3dgs.lionengine.game.feature.collidable.selector.SelectorRefresher) LayerableModel(com.b3dgs.lionengine.game.feature.LayerableModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with FeaturableModel

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

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

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

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

Aggregations

FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)33 Test (org.junit.jupiter.api.Test)20 Featurable (com.b3dgs.lionengine.game.feature.Featurable)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)18 Transformable (com.b3dgs.lionengine.game.feature.Transformable)16 Setup (com.b3dgs.lionengine.game.feature.Setup)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)7 Media (com.b3dgs.lionengine.Media)6 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)6 Services (com.b3dgs.lionengine.game.feature.Services)5 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)5 Medias (com.b3dgs.lionengine.Medias)4 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)4 Animation (com.b3dgs.lionengine.Animation)3 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)3 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)3 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)3