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);
}
}
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());
}
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());
}
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());
}
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);
}
Aggregations