use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class CollidableConfigTest method testEmptyAccepted.
/**
* Test with empty accepted.
*/
@Test
void testEmptyAccepted() {
final Media media = Medias.create("Object.xml");
final Xml root = new Xml("test");
root.save(media);
final Services services = new Services();
services.add(new ViewerMock());
final Collidable collidable = new CollidableModel(services, new Setup(media));
collidable.setGroup(Integer.valueOf(1));
CollidableConfig.exports(root, collidable);
root.save(media);
final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
assertEquals(Integer.valueOf(1), config.getGroup());
assertTrue(config.getAccepted().isEmpty());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class CollidableConfigTest method testExport.
/**
* Test export.
*/
@Test
void testExport() {
final Media media = Medias.create("Object.xml");
final Xml root = new Xml("test");
root.save(media);
final Services services = new Services();
services.add(new ViewerMock());
final Collidable collidable = new CollidableModel(services, new Setup(media));
collidable.setGroup(Integer.valueOf(1));
collidable.addAccept(Integer.valueOf(2));
collidable.addAccept(Integer.valueOf(3));
CollidableConfig.exports(root, collidable);
root.save(media);
final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
assertEquals(Integer.valueOf(1), config.getGroup());
assertIterableEquals(Arrays.asList(Integer.valueOf(2), Integer.valueOf(3)), config.getAccepted());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class LauncherConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final LaunchableConfig launchable = new LaunchableConfig("media", "sfx", 10, 1, 2, new Force(1.0, 2.0));
final LauncherConfig launcher = new LauncherConfig(10, 10, true, Arrays.asList(launchable));
final Xml root = new Xml("test");
root.add(LauncherConfig.exports(launcher));
final Media media = Medias.create("launcher.xml");
root.save(media);
assertEquals(launcher, LauncherConfig.imports(new Xml(media).getChild(LauncherConfig.NODE_LAUNCHER)));
assertEquals(Arrays.asList(launcher), LauncherConfig.imports(new Configurer(media)));
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class DeviceControllerConfig method imports.
/**
* Import the data from configurer.
*
* @param services The services reference (must not be <code>null</code>).
* @param media The media configuration (must not be <code>null</code>).
* @return The loaded input.
* @throws LionEngineException If unable to read node.
*/
@SuppressWarnings("unchecked")
public static Collection<DeviceControllerConfig> imports(Services services, Media media) {
Check.notNull(services);
Check.notNull(media);
final Collection<DeviceControllerConfig> configs = new ArrayList<>();
final ClassLoader loader = services.getOptional(ClassLoader.class).orElse(DeviceControllerConfig.class.getClassLoader());
final Configurer configurer = new Configurer(media);
try {
final Class<Enum<? extends DeviceMapper>> mapping;
mapping = (Class<Enum<? extends DeviceMapper>>) loader.loadClass(configurer.getString(ATT_MAPPING));
for (final XmlReader deviceNode : configurer.getChildren(NODE_DEVICE)) {
final Class<DevicePush> device = (Class<DevicePush>) loader.loadClass(deviceNode.getString(ATT_CLASS));
final boolean disabled = deviceNode.getBoolean(false, ATT_DISABLED);
final List<DeviceAxis> horizontal = readAxis(deviceNode, NODE_HORIZONTAL);
final List<DeviceAxis> vertical = readAxis(deviceNode, NODE_VERTICAL);
final Map<Integer, Set<Integer>> fire = readFire(mapping, deviceNode);
configs.add(new DeviceControllerConfig(device, disabled, horizontal, vertical, fire));
}
} catch (final ReflectiveOperationException exception) {
throw new LionEngineException(exception);
}
return configs;
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class FovableConfigTest method testExportsImportsNoNode.
/**
* Test exports imports without node.
*/
@Test
void testExportsImportsNoNode() {
final Xml root = new Xml("test");
final Media media = Medias.create("Object.xml");
root.save(media);
assertEquals(0, FovableConfig.imports(new Xml(media)));
assertEquals(0, FovableConfig.imports(new Configurer(media)));
assertTrue(media.getFile().delete());
}
Aggregations