Search in sources :

Example 41 with XmlReader

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;
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 42 with XmlReader

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;
}
Also used : XmlReader(com.b3dgs.lionengine.XmlReader) HashSet(java.util.HashSet)

Example 43 with XmlReader

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;
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 44 with XmlReader

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;
}
Also used : HashMap(java.util.HashMap) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 45 with XmlReader

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;
}
Also used : XmlReader(com.b3dgs.lionengine.XmlReader) HashSet(java.util.HashSet)

Aggregations

XmlReader (com.b3dgs.lionengine.XmlReader)45 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)12 LionEngineException (com.b3dgs.lionengine.LionEngineException)6 HashSet (java.util.HashSet)6 Collection (java.util.Collection)4 Xml (com.b3dgs.lionengine.Xml)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 DeviceAxis (com.b3dgs.lionengine.io.DeviceAxis)2 DeviceMapper (com.b3dgs.lionengine.io.DeviceMapper)2 Set (java.util.Set)2 Animation (com.b3dgs.lionengine.Animation)1 Check (com.b3dgs.lionengine.Check)1 Constant (com.b3dgs.lionengine.Constant)1 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)1 Feature (com.b3dgs.lionengine.game.Feature)1 Orientation (com.b3dgs.lionengine.game.Orientation)1 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)1 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1