Search in sources :

Example 26 with Featurable

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

the class ComponentNetwork method handleIdentifiableCreate.

private void handleIdentifiableCreate(Packet packet) {
    packet.buffer().position(MessageAbstract.SIZE_MIN + UtilNetwork.INDEX_MODE);
    int dataId = packet.readInt();
    if (removePending(packet.getClientSourceId(), Integer.valueOf(dataId))) {
        final Featurable featurable = factory.create(packet.readMedia());
        final Networkable networkable = featurable.getFeature(Networkable.class);
        if (server != null) {
            dataId = featurable.getFeature(Identifiable.class).getId().intValue();
            send(new IdentifiableSet(UtilNetwork.SERVER_ID, packet.getClientSourceId(), packet.getDataId(), dataId), packet.getClientId());
        }
        setNetworkable(packet.getClientSourceId(), Integer.valueOf(dataId), networkable);
        networkable.setDataId(dataId);
        handler.add(featurable);
    }
}
Also used : Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable)

Example 27 with Featurable

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

the class ProducerModelTest method testPending.

/**
 * Test the production pending.
 */
@Test
void testPending() {
    producer.recycle();
    producer.setStepsSpeed(50.0);
    final AtomicReference<Featurable> start = new AtomicReference<>();
    final AtomicReference<Featurable> skip = new AtomicReference<>();
    producer.addListener(UtilProducible.createProducerListener(start, skip, skip, skip));
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    producer.addToProductionQueue(featurable);
    assertEquals(1, producer.getQueueLength());
    assertNull(start.get());
    producer.update(1.0);
    assertTrue(producer.iterator().hasNext());
    assertEquals(1, producer.getQueueLength());
    assertNotNull(start.get());
    start.set(null);
    producer.update(1.0);
    producer.update(1.0);
    producer.update(1.0);
    producer.update(1.0);
    assertEquals(0, producer.getQueueLength());
    assertNotNull(start.get());
    assertFalse(producer.iterator().hasNext());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 28 with Featurable

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

the class ProducerModelTest method testProducibleListener.

/**
 * Test the production listener.
 */
@Test
void testProducibleListener() {
    producer.recycle();
    producer.setStepsSpeed(50.0);
    final Featurable featurable = UtilProducible.createProducible(services);
    final AtomicBoolean start = new AtomicBoolean();
    final AtomicBoolean progress = new AtomicBoolean();
    final AtomicBoolean end = new AtomicBoolean();
    featurable.getFeature(Producible.class).addListener(UtilProducible.createProducibleListener(start, progress, end));
    producer.addToProductionQueue(featurable);
    assertFalse(start.get());
    assertFalse(progress.get());
    assertFalse(end.get());
    producer.update(1.0);
    assertTrue(start.get());
    assertFalse(progress.get());
    assertFalse(end.get());
    producer.update(1.0);
    assertTrue(progress.get());
    assertFalse(end.get());
    producer.update(1.0);
    assertTrue(end.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 29 with Featurable

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

the class ProducerModelTest method testProduction.

/**
 * Test the production.
 */
@Test
void testProduction() {
    producer.recycle();
    producer.setStepsSpeed(0.5);
    final AtomicReference<Featurable> start = new AtomicReference<>();
    final AtomicReference<Featurable> current = new AtomicReference<>();
    final AtomicReference<Featurable> done = new AtomicReference<>();
    final AtomicReference<Featurable> cant = new AtomicReference<>();
    producer.addListener(UtilProducible.createProducerListener(start, current, done, cant));
    producer.setChecker(object);
    producer.update(1.0);
    assertNull(producer.getProducingElement());
    assertEquals(-1.0, producer.getProgress());
    assertEquals(-1, producer.getProgressPercent());
    assertEquals(0, producer.getQueueLength());
    assertFalse(producer.isProducing());
    final Featurable featurable = UtilProducible.createProducible(services);
    final Producible producible = featurable.getFeature(Producible.class);
    producer.addToProductionQueue(featurable);
    assertEquals(0, producer.getQueueLength());
    assertNull(start.get());
    assertFalse(producer.isProducing());
    assertFalse(producible.isProduced());
    producer.update(1.0);
    assertEquals(0.0, producer.getProgress());
    assertEquals(0, producer.getProgressPercent());
    assertEquals(0, producer.getQueueLength());
    assertEquals(featurable, start.get());
    assertNull(current.get());
    assertTrue(producer.isProducing());
    assertEquals(featurable, producer.getProducingElement());
    producer.update(1.0);
    assertEquals(0.5, producer.getProgress());
    assertEquals(50, producer.getProgressPercent());
    assertEquals(featurable, current.get());
    assertNull(done.get());
    assertTrue(producer.isProducing());
    producer.update(1.0);
    assertEquals(1.0, producer.getProgress());
    assertEquals(100, producer.getProgressPercent());
    assertEquals(featurable, current.get());
    assertNull(done.get());
    assertFalse(producer.isProducing());
    assertFalse(producible.isProduced());
    producer.update(1.0);
    assertEquals(featurable, done.get());
    assertNull(cant.get());
    assertFalse(producer.isProducing());
    assertTrue(producible.isProduced());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 30 with Featurable

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

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