use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class UtilActionnable method createActionable.
/**
* Create the actionable.
*
* @param media The media.
* @param services The services.
* @return The prepared actionable.
*/
public static ActionableModel createActionable(Media media, Services services) {
final Setup setup = new Setup(media);
final Featurable featurable = new FeaturableModel();
featurable.addFeature(new IdentifiableModel());
final ActionableModel actionable = new ActionableModel(services, setup);
actionable.prepare(featurable);
return actionable;
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class UtilAssignable method createAssignable.
/**
* Create the assignable.
*
* @param services The services.
* @return The prepared assignable.
*/
public static AssignableModel createAssignable(Services services) {
final Featurable featurable = new FeaturableModel();
featurable.addFeature(new IdentifiableModel());
final AssignableModel assignable = new AssignableModel(services);
assignable.prepare(featurable);
return assignable;
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class SceneRasterable method load.
@Override
public void load() {
final SetupSurfaceRastered setup = new SetupSurfaceRastered(Medias.create("object.xml"), Medias.create("raster.xml"));
final SpriteAnimated surface = Drawable.loadSpriteAnimated(setup.getSurface(), 4, 4);
final Featurable featurable = new FeaturableModel();
featurable.addFeature(new MirrorableModel());
featurable.addFeature(new AnimatableModel(surface));
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel());
final Rasterable rasterable = new RasterableModel(services, setup);
rasterable.setOrigin(Origin.MIDDLE);
featurable.addFeature(rasterable);
featurable.addFeature(new RefreshableModel(extrp -> {
transformable.setLocationY(UtilMath.sin(count * 3) * 240);
surface.setLocation(camera, transformable);
rasterable.update(extrp);
surface.update(extrp);
}));
featurable.addFeature(new DisplayableModel(g -> rasterable.render(g)));
transformable.setLocationX(120);
handler.add(featurable);
camera.setView(0, 0, getWidth(), getHeight(), getHeight());
timing.start();
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class ProducerModelTest method testDefaultProduction.
/**
* Test the default production with default checker.
*/
@Test
public void testDefaultProduction() {
final ProducerModel producer = new ProducerModel(services);
producer.prepare(new FeaturableModel());
producer.setStepsPerSecond(25.0);
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.update(1.0);
Assert.assertNull(producer.getProducingElement());
Assert.assertEquals(-1.0, producer.getProgress(), UtilTests.PRECISION);
Assert.assertEquals(-1, producer.getProgressPercent());
Assert.assertEquals(0, producer.getQueueLength());
Assert.assertFalse(producer.isProducing());
final Featurable featurable = UtilProducible.createProducible(services);
producer.addToProductionQueue(featurable);
Assert.assertEquals(0, producer.getQueueLength());
Assert.assertNull(start.get());
Assert.assertFalse(producer.isProducing());
producer.update(1.0);
Assert.assertEquals(0.0, producer.getProgress(), UtilTests.PRECISION);
Assert.assertEquals(0, producer.getProgressPercent());
Assert.assertEquals(0, producer.getQueueLength());
Assert.assertEquals(featurable, start.get());
Assert.assertNull(current.get());
Assert.assertTrue(producer.isProducing());
Assert.assertEquals(featurable.getFeature(Producible.class).getMedia(), producer.getProducingElement());
producer.update(1.0);
Assert.assertEquals(0.5, producer.getProgress(), UtilTests.PRECISION);
Assert.assertEquals(50, producer.getProgressPercent());
Assert.assertEquals(featurable, current.get());
Assert.assertNull(done.get());
Assert.assertTrue(producer.isProducing());
producer.update(1.0);
Assert.assertEquals(1.0, producer.getProgress(), UtilTests.PRECISION);
Assert.assertEquals(100, producer.getProgressPercent());
Assert.assertEquals(featurable, current.get());
Assert.assertNull(done.get());
Assert.assertFalse(producer.isProducing());
producer.update(1.0);
Assert.assertEquals(featurable, done.get());
Assert.assertNull(cant.get());
Assert.assertFalse(producer.isProducing());
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class ProducibleModelTest method testProducible.
/**
* Test the producible.
*/
@Test
public void testProducible() {
final Media media = UtilProducible.createProducibleMedia();
final Setup setup = new Setup(media);
final Featurable featurable = new FeaturableModel();
featurable.addFeature(new IdentifiableModel());
final Producible producible = new ProducibleModel(setup);
final ProducibleListener listener = UtilProducible.createListener();
producible.setLocation(1.0, 2.0);
producible.prepare(featurable);
producible.addListener(listener);
Assert.assertEquals(media, producible.getMedia());
Assert.assertEquals(1, producible.getSteps());
Assert.assertEquals(2, producible.getWidth());
Assert.assertEquals(3, producible.getHeight());
Assert.assertEquals(1.0, producible.getX(), UtilTests.PRECISION);
Assert.assertEquals(2.0, producible.getY(), UtilTests.PRECISION);
Assert.assertTrue(producible.getListeners().contains(listener));
producible.getFeature(Identifiable.class).notifyDestroyed();
Assert.assertTrue(media.getFile().delete());
}
Aggregations