use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class TransitionsConfig method imports.
/**
* Import all transitions from configuration.
*
* @param config The transitions media (must not be <code>null</code>).
* @return The transitions imported with associated tiles.
* @throws LionEngineException If unable to read data.
*/
public static Map<Transition, Collection<Integer>> imports(Media config) {
final XmlReader root = new XmlReader(config);
final Collection<XmlReader> nodesTransition = root.getChildren(NODE_TRANSITION);
final Map<Transition, Collection<Integer>> transitions = new HashMap<>(nodesTransition.size());
for (final XmlReader nodeTransition : nodesTransition) {
final String groupIn = nodeTransition.getString(ATTRIBUTE_GROUP_IN);
final String groupOut = nodeTransition.getString(ATTRIBUTE_GROUP_OUT);
final String transitionType = nodeTransition.getString(ATTRIBUTE_TRANSITION_TYPE);
final TransitionType type = TransitionType.from(transitionType);
final Transition transition = new Transition(type, groupIn, groupOut);
final Collection<XmlReader> nodesTile = nodeTransition.getChildren(TileConfig.NODE_TILE);
final Collection<Integer> tiles = importTiles(nodesTile);
nodesTile.clear();
transitions.put(transition, tiles);
}
nodesTransition.clear();
return transitions;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CircuitsConfig method importTiles.
/**
* Import all tiles from their nodes.
*
* @param nodesTile The tiles nodes (must not be <code>null</code>).
* @return The imported tiles.
*/
private static Collection<Integer> importTiles(Collection<XmlReader> nodesTile) {
final Collection<Integer> tiles = new HashSet<>(nodesTile.size());
for (final XmlReader nodeTile : nodesTile) {
final Integer tile = Integer.valueOf(TileConfig.imports(nodeTile));
tiles.add(tile);
}
return tiles;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class CircuitsConfig method imports.
/**
* Import all circuits from configuration.
*
* @param circuitsConfig The circuits configuration (must not be <code>null</code>).
* @return The circuits imported.
* @throws LionEngineException If unable to read data.
*/
public static Map<Circuit, Collection<Integer>> imports(Media circuitsConfig) {
Check.notNull(circuitsConfig);
final XmlReader root = new XmlReader(circuitsConfig);
final Collection<XmlReader> nodesCircuit = root.getChildren(NODE_CIRCUIT);
final Map<Circuit, Collection<Integer>> circuits = new HashMap<>(nodesCircuit.size());
for (final XmlReader nodeCircuit : nodesCircuit) {
final String groupIn = nodeCircuit.getString(ATT_GROUP_IN);
final String groupOut = nodeCircuit.getString(ATT_GROUP_OUT);
final String circuitType = nodeCircuit.getString(ATT_CIRCUIT_TYPE);
final CircuitType type = CircuitType.from(circuitType);
final Circuit circuit = new Circuit(type, groupIn, groupOut);
final Collection<XmlReader> nodesTile = nodeCircuit.getChildren(TileConfig.NODE_TILE);
final Collection<Integer> tiles = importTiles(nodesTile);
nodesTile.clear();
circuits.put(circuit, tiles);
}
nodesCircuit.clear();
return circuits;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class PathfindableConfig method imports.
/**
* Import the pathfindable data from node.
*
* @param configurer The configurer reference (must not be <code>null</code>).
* @return The pathfindable data.
* @throws LionEngineException If unable to read node.
*/
public static Map<String, PathData> imports(Configurer configurer) {
Check.notNull(configurer);
final XmlReader root = configurer.getRoot();
if (!root.hasNode(NODE_PATHFINDABLE)) {
return Collections.emptyMap();
}
final Map<String, PathData> categories = new HashMap<>(0);
final XmlReader nodePathfindable = root.getChild(NODE_PATHFINDABLE);
final Collection<XmlReader> children = nodePathfindable.getChildren(NODE_PATH);
for (final XmlReader nodePath : children) {
final PathData data = importPathData(nodePath);
categories.put(data.getName(), data);
}
children.clear();
return categories;
}
use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.
the class PathfindingConfig method imports.
/**
* Import the category data from configuration.
*
* @param configPathfinding The pathfinding descriptor (must not be <code>null</code>).
* @return The categories data.
* @throws LionEngineException If unable to read data.
*/
public static Collection<PathCategory> imports(Media configPathfinding) {
Check.notNull(configPathfinding);
final XmlReader nodeCategories = new XmlReader(configPathfinding);
final Collection<XmlReader> childrenTile = nodeCategories.getChildren(NODE_TILE_PATH);
final Collection<PathCategory> categories = new HashSet<>(childrenTile.size());
for (final XmlReader node : childrenTile) {
final String name = node.getString(ATT_CATEGORY);
final Collection<XmlReader> childrenGroup = node.getChildren(TileGroupsConfig.NODE_GROUP);
final Collection<String> groups = new HashSet<>(childrenGroup.size());
for (final XmlReader groupNode : childrenGroup) {
groups.add(groupNode.getText());
}
childrenGroup.clear();
final PathCategory category = new PathCategory(name, groups);
categories.add(category);
}
childrenTile.clear();
return categories;
}
Aggregations