use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class PathfindableConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final Map<String, PathData> map = new HashMap<>();
final PathData data = new PathData("category", 1.0, true, Arrays.asList(MovementTile.UP));
map.put(data.getName(), data);
final Xml root = new Xml("test");
root.add(PathfindableConfig.exports(map));
final Media media = Medias.create("pathfindable.xml");
root.save(media);
assertEquals(map, PathfindableConfig.imports(new Configurer(media)));
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class PathfindableConfigTest method testWrongMovement.
/**
* Test with wrong movement.
*/
@Test
void testWrongMovement() {
final PathData data = new PathData("category", 1.0, true, EnumSet.noneOf(MovementTile.class));
final Xml path = PathfindableConfig.exportPathData(data);
final Xml movement = path.createChild(PathfindableConfig.NODE_MOVEMENT);
movement.setText("VOID");
final Xml root = new Xml("test");
final Xml node = root.createChild(PathfindableConfig.NODE_PATHFINDABLE);
node.add(path);
final Media media = Medias.create("pathfindable.xml");
root.save(media);
assertCause(() -> PathfindableConfig.imports(new Configurer(media)), IllegalArgumentException.class);
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class CollisionCategoryConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final Media formulasConfig = UtilConfig.createFormulaConfig(formula);
final Media groupsConfig = UtilConfig.createGroupsConfig(group);
mapCollision.loadCollisions(formulasConfig, groupsConfig);
final Xml root = new Xml("categories");
CollisionCategoryConfig.exports(root, category);
final Media media = Medias.create("Object.xml");
root.save(media);
final Collection<CollisionCategory> imported = CollisionCategoryConfig.imports(new Configurer(media), mapCollision);
assertEquals(category, imported.iterator().next());
assertTrue(formulasConfig.getFile().delete());
assertTrue(groupsConfig.getFile().delete());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class Factory method createSetup.
/**
* Create a setup from its media.
*
* @param media The media reference.
* @return The setup instance.
*/
@SuppressWarnings("unchecked")
private Setup createSetup(Media media) {
final Configurer configurer = new Configurer(media);
try {
final FeaturableConfig config = FeaturableConfig.imports(configurer);
final String setup = config.getSetupName();
final Class<? extends Setup> setupClass;
if (setup.isEmpty()) {
final Class<?> clazz = classLoader.loadClass(config.getClassName());
final Constructor<?> constructor = UtilReflection.getCompatibleConstructorParent(clazz, new Class<?>[] { Services.class, Setup.class });
setupClass = (Class<? extends Setup>) constructor.getParameterTypes()[SETUP_INDEX];
} else {
setupClass = (Class<? extends Setup>) classLoader.loadClass(config.getSetupName());
}
return UtilReflection.create(setupClass, new Class<?>[] { Media.class }, media);
} catch (final ClassNotFoundException exception) {
throw new LionEngineException(exception, ERROR_SETUP_CLASS);
} catch (final NoSuchMethodException exception) {
throw new LionEngineException(exception, ERROR_CONSTRUCTOR_MISSING + media.getPath());
}
}
use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.
the class ProducerConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
public void testExportsImports() {
final ActionRef ref = new ActionRef("ref", false, new ArrayList<ActionRef>());
final ActionRef ref2 = new ActionRef("ref", false, Arrays.asList(ref));
final Collection<ActionRef> refs = Arrays.asList(new ActionRef("test", true, Arrays.asList(ref2)));
final Xml root = new Xml("test");
root.add(ActionsConfig.exports(refs));
final Media media = Medias.create("producer.xml");
root.save(media);
Assert.assertEquals(refs, ActionsConfig.imports(new Xml(media)));
Assert.assertEquals(refs, ActionsConfig.imports(new Configurer(media)));
Assert.assertTrue(media.getFile().delete());
}
Aggregations