use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class StateHandlerTest method testClear.
/**
* Test the state clear transition.
*/
@Test
void testClear() {
Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
final Media config = UtilTransformable.createMedia(StateHandlerTest.class);
try {
final Setup setup = new Setup(config);
final StateHandler handler = new StateHandler(services, setup);
handler.changeState(StateClear.class);
handler.update(1.0);
assertFalse(handler.isState(StateClear.class));
handler.postUpdate();
assertTrue(handler.isState(StateClear.class));
assertTrue(config.getFile().delete());
} finally {
Medias.setResourcesDirectory(null);
}
}
use of com.b3dgs.lionengine.game.feature.Setup 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.Setup 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.Setup in project lionengine by b3dgs.
the class ExtractorModelTest method testConfig.
/**
* Test the extractor config.
*/
@Test
void testConfig() {
final ObjectExtractor object = new ObjectExtractor(services, setup, true, true);
object.addFeature(new TransformableModel(services, setup));
final Media media = UtilSetup.createConfig(ExtractorModelTest.class);
final Xml xml = new Xml(media);
xml.add(ExtractorConfig.exports(new ExtractorConfig(1.0, 2.0, 5)));
xml.save(media);
final ExtractorModel extractor = new ExtractorModel(services, new Setup(media));
extractor.recycle();
assertEquals(5, extractor.getExtractionCapacity());
assertEquals(1.0, extractor.getExtractionSpeed());
assertEquals(2.0, extractor.getDropOffSpeed());
extractor.prepare(object);
assertEquals(5, extractor.getExtractionCapacity());
assertEquals(1.0, extractor.getExtractionSpeed());
assertEquals(2.0, extractor.getDropOffSpeed());
object.getFeature(Identifiable.class).notifyDestroyed();
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.Setup 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