use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.
the class MapTileHelper method importAndSave.
/**
* Import and save the level.
*
* @param levelrip The level rip.
* @param sheetsConfig The file that define the sheets configuration.
* @param out The output media.
* @param mapPersister The persister reference.
*/
public static void importAndSave(Media levelrip, Media sheetsConfig, Media out, MapTilePersister mapPersister) {
final Services services = new Services();
final MapTileGame map = services.create(MapTileGame.class);
map.create(levelrip, sheetsConfig);
map.addFeature(mapPersister);
services.add(new Factory(services));
services.add(new Handler(services));
final HandlerPersister persister = new HandlerPersister(services);
try (FileWriting output = new FileWriting(out)) {
mapPersister.save(output);
persister.save(output);
} catch (final IOException exception) {
Verbose.exception(exception, "Error on saving map !");
}
}
use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.
the class LauncherModelTest method testListenerAutoAdd.
/**
* Test the launcher with listener auto add.
*
* @throws InterruptedException If error.
*/
@Test
void testListenerAutoAdd() throws InterruptedException {
final LaunchableObjectSelf object = new LaunchableObjectSelf(services, setup);
final Launcher launcher = UtilLaunchable.createLauncher(services, setup, object);
launcher.checkListener(object);
assertFalse(object.fired.get());
assertNull(object.firedLaunchable.get());
assertTimeout(1000L, () -> {
while (!launcher.fire()) {
launcher.update(1.0);
continue;
}
});
final Handler handler = services.get(Handler.class);
handler.update(1.0);
assertTrue(object.fired.get());
assertNotNull(object.firedLaunchable.get());
launcher.removeListener(object);
object.fired.set(false);
object.firedLaunchable.set(null);
assertFalse(object.fired.get());
assertNull(object.firedLaunchable.get());
handler.update(1.0);
handler.removeAll();
handler.update(1.0);
assertEquals(0, handler.size());
}
use of com.b3dgs.lionengine.game.feature.Handler 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.Handler 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());
}
use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.
the class LauncherModelTest method testLauncherLevel.
/**
* Test the launcher level.
*
* @throws InterruptedException If error.
*/
@Test
void testLauncherLevel() throws InterruptedException {
final AtomicBoolean fired = new AtomicBoolean();
final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
launcher.addListener(UtilLaunchable.createListener(fired));
launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
assertTimeout(1000L, () -> {
while (!launcher.fire()) {
launcher.update(1.0);
continue;
}
});
assertTrue(fired.get());
assertNotNull(firedLaunchable.get());
firedLaunchable.set(null);
final Handler handler = services.get(Handler.class);
handler.update(1.0);
assertEquals(1, handler.size());
launcher.setLevel(1);
assertNull(firedLaunchable.get());
assertTimeout(1000L, () -> {
while (!launcher.fire()) {
launcher.update(1.0);
continue;
}
});
assertTimeout(1000L, () -> {
while (!launcher.fire()) {
launcher.update(1.0);
continue;
}
});
assertNotNull(firedLaunchable.get());
handler.update(1.0);
assertEquals(3, handler.size());
handler.removeAll();
handler.update(1.0);
assertEquals(0, handler.size());
}
Aggregations