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