use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class MapTileFogTest method testFog.
/**
* Test the fog.
*/
@Test
void testFog() {
final MapTile map = UtilMap.createMap(5);
services.add(map);
final FovableModel fovable = new FovableModel(services, setup);
final FeaturableModel object = new FeaturableModel(services, setup);
final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
transformable.teleport(3, 3);
fovable.prepare(object);
fovable.setFov(1);
final MapTileFog fog = new MapTileFog();
Medias.setLoadFromJar(MapTileFog.class);
fog.create(map.getFeature(MapTileSurface.class), Medias.create("fog.xml"), null);
Medias.setLoadFromJar(null);
final AtomicInteger rtx = new AtomicInteger();
final AtomicInteger rty = new AtomicInteger();
final AtomicInteger count = new AtomicInteger();
final RevealedListener listener = (tx, ty) -> {
rtx.set(tx);
rty.set(ty);
count.incrementAndGet();
};
fog.addListener(listener);
assertEquals(16, fog.getTile(2, 3).getNumber());
assertEquals(16, fog.getTile(3, 3).getNumber());
assertEquals(16, fog.getTile(4, 3).getNumber());
fog.updateFov(fovable);
assertEquals(10, fog.getTile(2, 2).getNumber());
assertEquals(1, fog.getTile(3, 2).getNumber());
assertEquals(11, fog.getTile(4, 2).getNumber());
assertEquals(2, fog.getTile(2, 3).getNumber());
assertEquals(17, fog.getTile(3, 3).getNumber());
assertEquals(3, fog.getTile(4, 3).getNumber());
assertEquals(8, fog.getTile(2, 4).getNumber());
assertEquals(0, fog.getTile(3, 4).getNumber());
assertEquals(9, fog.getTile(4, 4).getNumber());
assertEquals(1, count.get());
assertEquals(3, rtx.get());
assertEquals(3, rty.get());
fog.reset(fovable);
fog.removeListener(listener);
count.set(0);
assertEquals(16, fog.getTile(2, 3).getNumber());
assertEquals(16, fog.getTile(3, 3).getNumber());
assertEquals(16, fog.getTile(4, 3).getNumber());
fog.updateFov(fovable);
assertEquals(0, count.get());
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class FramesConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final FramesConfig config = new FramesConfig(1, 2, 3, 4);
final Xml root = new Xml("test");
root.add(FramesConfig.exports(config));
final Media media = Medias.create("Object.xml");
root.save(media);
assertEquals(config, FramesConfig.imports(new Xml(media)));
assertEquals(config, FramesConfig.imports(new Setup(media)));
assertEquals(config, FramesConfig.imports(new Configurer(media)));
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class OriginConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final Origin origin = Origin.MIDDLE;
final Xml root = new Xml("test");
root.add(OriginConfig.exports(origin));
final Media media = Medias.create("origin.xml");
root.save(media);
assertEquals(origin, OriginConfig.imports(new Xml(media)));
assertEquals(origin, OriginConfig.imports(new Setup(media)));
assertEquals(origin, OriginConfig.imports(new Configurer(media)));
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class LauncherModelTest method testLauncherFailure.
/**
* Test the launcher failure.
*/
@Test
void testLauncherFailure() {
final Media launchableMedia = UtilSetup.createMedia(Featurable.class);
final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia);
final Setup setup = new Setup(launcherMedia);
final Launcher launcher = UtilLaunchable.createLauncher(services, setup, featurable);
try {
assertThrowsTimeout(1000L, () -> {
while (!launcher.fire()) {
launcher.update(1.0);
continue;
}
}, "No recognized constructor found for: Featurable.xml");
} finally {
final Handler handler = services.get(Handler.class);
handler.removeAll();
handler.update(1.0);
assertEquals(0, handler.size());
assertTrue(launchableMedia.getFile().delete());
}
}
use of com.b3dgs.lionengine.game.feature.Setup in project lionengine by b3dgs.
the class LauncherModelTest method testCheckListener.
/**
* Test check listener conditions.
*/
@Test
void testCheckListener() {
final Media launchableMedia = UtilSetup.createMedia(LaunchableObjectException.class);
final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia);
final Setup setup = new Setup(launcherMedia);
services.add(new Factory(services));
services.add(new Handler(services));
final AtomicBoolean launchableListener = new AtomicBoolean();
final AtomicBoolean launcherListener = new AtomicBoolean();
final Launcher launcher = new LauncherModel(services, setup) {
@Override
public void addListener(LaunchableListener listener) {
launchableListener.set(true);
}
@Override
public void addListener(LauncherListener listener) {
launcherListener.set(true);
}
};
assertFalse(launchableListener.get());
assertFalse(launcherListener.get());
launcher.checkListener(launcher);
assertFalse(launchableListener.get());
assertFalse(launcherListener.get());
launcher.checkListener((LaunchableListener) l -> l.update(1.0));
assertTrue(launchableListener.get());
assertFalse(launcherListener.get());
launcher.checkListener((LauncherListener) () -> launcher.update(1.0));
launchableListener.set(false);
assertFalse(launchableListener.get());
assertTrue(launcherListener.get());
assertTrue(launchableMedia.getFile().delete());
}
Aggregations