use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.
the class LauncherModelTest method testLauncherException.
/**
* Test the launcher failure.
*/
@Test
void testLauncherException() {
final Media launchableMedia = UtilSetup.createMedia(LaunchableObjectException.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;
}
}, "Feature not found: " + Launchable.class.getName());
} 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 testLauncher.
/**
* Test the launcher.
*
* @throws InterruptedException If error.
*/
@Test
void testLauncher() 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());
final Transformable transformable = new TransformableModel(services, setup);
assertTimeout(1000L, () -> {
while (!launcher.fire(transformable)) {
launcher.update(1.0);
continue;
}
});
assertNotNull(firedLaunchable.get());
firedLaunchable.set(null);
handler.update(1.0);
assertEquals(2, handler.size());
final Localizable localizable = UtilLaunchable.createLocalizable();
assertTimeout(1000L, () -> {
while (!launcher.fire(localizable)) {
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());
}
use of com.b3dgs.lionengine.game.feature.Handler in project lionengine by b3dgs.
the class LauncherModelTest method testLauncherSelfListener.
/**
* Test the launcher with listener itself.
*
* @throws InterruptedException If error.
*/
@Test
void testLauncherSelfListener() throws InterruptedException {
final LaunchableObjectSelf object = new LaunchableObjectSelf(services, setup);
final Launcher launcher = UtilLaunchable.createLauncher(services, setup, object);
launcher.addListener((LauncherListener) object);
launcher.addListener((LaunchableListener) 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());
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 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());
}
Aggregations