use of com.b3dgs.lionengine.game.feature.TransformableModel 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.TransformableModel in project lionengine by b3dgs.
the class ExtractorModelTest method testExtractorExtractable.
/**
* Test the extractor with extractable.
*/
@Test
void testExtractorExtractable() {
final ObjectExtractorSelf object = new ObjectExtractorSelf(services, setup);
object.addFeature(new TransformableModel(services, setup));
final Extractor extractor = new ExtractorModel(services, setup);
extractor.setCapacity(2);
extractor.setExtractionSpeed(25.0);
extractor.setDropOffSpeed(100.0);
extractor.prepare(object);
extractor.addListener(object);
assertNull(extractor.getResourceLocation());
assertNull(extractor.getResourceType());
final Extractable extractable = UtilExtractable.createExtractable(services, setup);
extractor.setResource(extractable);
assertFalse(extractor.isExtracting());
extractor.startExtraction();
assertFalse(extractor.isExtracting());
assertEquals(1, object.flag.get());
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals(2, object.flag.get());
extractor.update(1.0);
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals(5, object.flag.get());
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
assertFalse(extractor.isExtracting());
assertEquals(6, object.flag.get());
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals(2, object.flag.get());
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals(2, object.flag.get());
object.getFeature(Identifiable.class).notifyDestroyed();
extractable.getFeature(Identifiable.class).notifyDestroyed();
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class ExtractorModelTest method testCannotCarry.
/**
* Test the extractor cannot carry.
*/
@Test
void testCannotCarry() {
final ObjectExtractor object = new ObjectExtractor(services, setup, true, false);
object.addFeature(new TransformableModel(services, setup));
final Extractor extractor = new ExtractorModel(services, setup);
extractor.setCapacity(1);
extractor.setExtractionSpeed(50.0);
extractor.setDropOffSpeed(50.0);
extractor.prepare(object);
final AtomicReference<String> drop = new AtomicReference<>();
final AtomicReference<String> skip = new AtomicReference<>();
extractor.addListener(UtilExtractable.createListener(skip, skip, skip, skip, drop, skip));
extractor.setResource("wood", 1, 2, 1, 1);
extractor.startExtraction();
extractor.update(1.0);
assertTrue(extractor.isExtracting());
extractor.update(1.0);
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertNull(drop.get());
object.getFeature(Identifiable.class).notifyDestroyed();
}
use of com.b3dgs.lionengine.game.feature.TransformableModel 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.TransformableModel 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();
}
Aggregations