Search in sources :

Example 26 with XmlReader

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

Example 27 with XmlReader

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

Example 28 with XmlReader

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

Example 29 with XmlReader

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

Example 30 with XmlReader

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

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