use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.
the class ExtractorConfig method exports.
/**
* Exports the node from config.
*
* @param config The config reference (must not be <code>null</code>).
* @return The extractor node.
* @throws LionEngineException If unable to read node.
*/
public static Xml exports(ExtractorConfig config) {
Check.notNull(config);
final Xml node = new Xml(NODE_EXTRACTOR);
node.writeDouble(ATT_EXTRACT, config.getExtract());
node.writeDouble(ATT_DROPOFF, config.getDropOff());
node.writeInteger(ATT_CAPACITY, config.getCapacity());
return node;
}
use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.
the class PathfindableConfig method exports.
/**
* Export the pathfindable data to node.
*
* @param pathData The pathfindable data (must not be <code>null</code>).
* @return The path data node.
* @throws LionEngineException If unable to read node.
*/
public static Xml exports(Map<String, PathData> pathData) {
Check.notNull(pathData);
final Xml node = new Xml(NODE_PATHFINDABLE);
for (final PathData data : pathData.values()) {
node.add(exportPathData(data));
}
return node;
}
use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.
the class CollidableFramedConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 1, 2, 3, true)));
final CollidableFramedConfig config = new CollidableFramedConfig(collisions);
final Xml root = new Xml("test");
final Animation animation = new Animation("anim", 1, 2, 3.0, false, true);
AnimationConfig.exports(root, animation);
final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
CollidableFramedConfig.exports(framed, collisions);
final Media media = Medias.create("Object.xml");
root.save(media);
assertEquals(config, CollidableFramedConfig.imports(new Configurer(media)));
assertEquals(collisions.values().iterator().next(), config.getCollisions());
assertEquals(collisions.get(Integer.valueOf(1)), config.getCollision(Integer.valueOf(1)));
assertTrue(config.getCollision(Integer.valueOf(2)).isEmpty());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.
the class CollidableFramedConfigTest method testExportsImportsNumber.
/**
* Test exports imports with number.
*/
@Test
void testExportsImportsNumber() {
final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("coll%anim%1", 0, 1, 2, 3, true)));
final Xml root = new Xml("test");
final Animation animation = new Animation("anim", 1, 2, 3.0, false, true);
AnimationConfig.exports(root, animation);
final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
CollidableFramedConfig.exports(framed, collisions);
framed.getChildXml(CollidableFramedConfig.NODE_COLLISION_FRAMED).removeAttribute(CollidableFramedConfig.ATT_NUMBER);
framed.getChildXml(CollidableFramedConfig.NODE_COLLISION_FRAMED).writeString(CollidableFramedConfig.ATT_PREFIX, "coll");
final Media media = Medias.create("Object.xml");
root.save(media);
final CollidableFramedConfig imported = CollidableFramedConfig.imports(new Configurer(media));
assertEquals(collisions.get(Integer.valueOf(1)), imported.getCollision(Integer.valueOf(1)));
assertFalse(imported.getCollision(Integer.valueOf(2)).isEmpty());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.Xml in project lionengine by b3dgs.
the class CollidableFramedConfigTest method testNoNode.
/**
* Test no node.
*/
@Test
void testNoNode() {
final Xml root = new Xml("test");
assertTrue(CollidableFramedConfig.imports(root).getCollisions().isEmpty());
}
Aggregations