use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollisionFormulaConfig method imports.
/**
* Create the formula data from node.
*
* @param config The collision formulas descriptor (must not be <code>null</code>).
* @return The collision formula data.
* @throws LionEngineException If error when reading data.
*/
public static CollisionFormulaConfig imports(Media config) {
final XmlReader root = new XmlReader(config);
final Map<String, CollisionFormula> collisions = new HashMap<>(0);
final Collection<XmlReader> children = root.getChildren(NODE_FORMULA);
for (final XmlReader node : children) {
final String name = node.getString(ATT_NAME);
final CollisionFormula collision = createCollision(node);
collisions.put(name, collision);
}
children.clear();
return new CollisionFormulaConfig(collisions);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CollisionGroupConfig method imports.
/**
* Create the collision group data from node (should only be used to display names, as real content is
* <code>null</code>, mainly UI specific to not have dependency on {@link MapTileCollision}).
*
* @param config The tile collision groups descriptor (must not be <code>null</code>).
* @return The collisions group data.
* @throws LionEngineException If unable to read node.
*/
public static CollisionGroupConfig imports(Media config) {
final Xml root = new Xml(config);
final Collection<XmlReader> childrenCollision = root.getChildren(NODE_COLLISION);
final Map<String, CollisionGroup> groups = new HashMap<>(childrenCollision.size());
for (final XmlReader node : childrenCollision) {
final Collection<XmlReader> childrenFormula = node.getChildren(CollisionFormulaConfig.NODE_FORMULA);
final Collection<CollisionFormula> formulas = new ArrayList<>(childrenFormula.size());
for (final XmlReader formula : childrenFormula) {
final String formulaName = formula.getText();
formulas.add(new CollisionFormula(formulaName, null, null, null));
}
childrenFormula.clear();
final String groupName = node.getString(ATT_GROUP);
final CollisionGroup collision = new CollisionGroup(groupName, formulas);
groups.put(groupName, collision);
}
childrenCollision.clear();
return new CollisionGroupConfig(groups);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class ExtractableConfig method imports.
/**
* Imports the config from node.
*
* @param root The root reference (must not be <code>null</code>).
* @return The extractable data.
* @throws LionEngineException If unable to read node.
*/
public static ExtractableConfig imports(XmlReader root) {
Check.notNull(root);
final XmlReader node = root.getChild(NODE_EXTRACTABLE);
final String type = node.getStringDefault(Constant.EMPTY_STRING, ATT_TYPE);
final int quantity = node.getInteger(0, ATT_QUANTITY);
return new ExtractableConfig(type, quantity);
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class DeviceControllerConfig method readFire.
/**
* Read fire data from node.
*
* @param mapping The mapping type.
* @param node The node parent.
* @return The fire data.
*/
private static Map<Integer, Set<Integer>> readFire(Class<Enum<? extends DeviceMapper>> mapping, XmlReader node) {
final Map<Integer, Set<Integer>> fire = new HashMap<>();
for (final XmlReader nodeFire : node.getChildren(NODE_FIRE)) {
final DeviceMapper mapper = findEnum(mapping, nodeFire.getString(ATT_INDEX));
final Integer index = mapper.getIndex();
final Integer positive = Integer.valueOf(nodeFire.getInteger(ATT_POSITIVE));
Set<Integer> codes = fire.get(index);
if (codes == null) {
codes = new HashSet<>();
fire.put(index, codes);
}
codes.add(positive);
}
return fire;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class DeviceControllerConfig method readAxis.
/**
* Read axis data.
*
* @param node The parent node.
* @param nodeAxis The axis node name.
* @return The axis data.
*/
private static List<DeviceAxis> readAxis(XmlReader node, String nodeAxis) {
final List<DeviceAxis> axis = new ArrayList<>();
final Collection<XmlReader> children = node.getChildren(nodeAxis);
for (final XmlReader child : children) {
final Integer positive = Integer.valueOf(child.getInteger(ATT_POSITIVE));
final Integer negative = Integer.valueOf(child.getInteger(ATT_NEGATIVE));
axis.add(new DeviceAxis(positive, negative));
}
return axis;
}
Aggregations