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