Search in sources :

Example 21 with XmlReader

use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.

the class CollisionCategoryConfig method imports.

/**
 * Create the collision category 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 root The node root reference (must not be <code>null</code>).
 * @return The collisions category data.
 * @throws LionEngineException If unable to read node.
 */
public static Collection<CollisionCategory> imports(XmlReader root) {
    Check.notNull(root);
    final Collection<CollisionCategory> categories = new ArrayList<>();
    if (root.hasNode(NODE_CATEGORIES)) {
        final Collection<XmlReader> childrenCategory = root.getChild(NODE_CATEGORIES).getChildren(NODE_CATEGORY);
        for (final XmlReader node : childrenCategory) {
            final Collection<XmlReader> childrenGroup = node.getChildren(TileGroupsConfig.NODE_GROUP);
            final Collection<CollisionGroup> groups = new ArrayList<>(childrenGroup.size());
            for (final XmlReader group : childrenGroup) {
                final String name = group.getText();
                groups.add(new CollisionGroup(name, new ArrayList<>(0)));
            }
            childrenGroup.clear();
            final String name = node.getString(ATT_NAME);
            final Axis axis = node.getEnum(Axis.class, ATT_AXIS);
            final int x = node.getInteger(ATT_X);
            final int y = node.getInteger(ATT_Y);
            final boolean glue = node.getBoolean(true, ATT_GLUE);
            final CollisionCategory category = new CollisionCategory(name, axis, x, y, glue, groups);
            categories.add(category);
        }
        childrenCategory.clear();
    }
    return categories;
}
Also used : ArrayList(java.util.ArrayList) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 22 with XmlReader

use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.

the class MinimapConfig method imports.

/**
 * Create the minimap data from node.
 *
 * @param configMinimap The minimap configuration media (must not be <code>null</code>).
 * @return The minimap data.
 * @throws LionEngineException If unable to read data.
 */
public static Map<Integer, ColorRgba> imports(Media configMinimap) {
    Check.notNull(configMinimap);
    final Map<Integer, ColorRgba> colors = new HashMap<>();
    final XmlReader nodeMinimap = new XmlReader(configMinimap);
    final Collection<XmlReader> children = nodeMinimap.getChildren(NODE_COLOR);
    for (final XmlReader nodeColor : children) {
        final ColorRgba color = new ColorRgba(nodeColor.getInteger(ATT_COLOR_RED), nodeColor.getInteger(ATT_COLOR_GREEN), nodeColor.getInteger(ATT_COLOR_BLUE));
        for (final XmlReader nodeTile : nodeColor.getChildren(TileConfig.NODE_TILE)) {
            final Integer tile = Integer.valueOf(TileConfig.imports(nodeTile));
            colors.put(tile, color);
        }
    }
    children.clear();
    return colors;
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) HashMap(java.util.HashMap) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 23 with XmlReader

use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.

the class TileGroupsConfig method imports.

/**
 * Import the group data from configuration.
 *
 * @param groupsConfig The groups descriptor (must not be <code>null</code>).
 * @return The groups data.
 * @throws LionEngineException If unable to read data.
 */
public static Collection<TileGroup> imports(Media groupsConfig) {
    Check.notNull(groupsConfig);
    final XmlReader nodeGroups = new XmlReader(groupsConfig);
    final Collection<XmlReader> children = nodeGroups.getChildren(NODE_GROUP);
    final Collection<TileGroup> groups = new ArrayList<>(children.size());
    for (final XmlReader nodeGroup : children) {
        final TileGroup group = importGroup(nodeGroup);
        groups.add(group);
    }
    children.clear();
    return groups;
}
Also used : ArrayList(java.util.ArrayList) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 24 with XmlReader

use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.

the class CollisionCategoryConfig method imports.

/**
 * Create the category data from node.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @param map The map reference (must not be <code>null</code>).
 * @return The category node instance.
 * @throws LionEngineException If unable to read node.
 */
public static CollisionCategory imports(XmlReader root, MapTileCollision map) {
    Check.notNull(root);
    Check.notNull(map);
    final Collection<XmlReader> children = root.getChildren(TileGroupsConfig.NODE_GROUP);
    final Collection<CollisionGroup> groups = new ArrayList<>(children.size());
    for (final XmlReader groupNode : children) {
        final String groupName = groupNode.getText();
        map.getCollisionGroup(groupName).ifPresent(groups::add);
    }
    children.clear();
    final String axisName = root.getString(ATT_AXIS);
    final Axis axis;
    try {
        axis = Axis.valueOf(axisName);
    } catch (final IllegalArgumentException exception) {
        throw new LionEngineException(exception, ERROR_AXIS + axisName);
    }
    final int x = root.getInteger(ATT_X);
    final int y = root.getInteger(ATT_Y);
    final boolean glue = root.getBoolean(true, ATT_GLUE);
    final String name = root.getString(ATT_NAME);
    return new CollisionCategory(name, axis, x, y, glue, groups);
}
Also used : ArrayList(java.util.ArrayList) XmlReader(com.b3dgs.lionengine.XmlReader) LionEngineException(com.b3dgs.lionengine.LionEngineException)

Example 25 with XmlReader

use of com.b3dgs.lionengine.XmlReader in project lionengine by b3dgs.

the class CollisionConstraintConfig method imports.

/**
 * Create the collision constraint data from node.
 *
 * @param node The node reference (must not be <code>null</code>).
 * @return The collision constraint data.
 * @throws LionEngineException If error when reading node.
 */
public static CollisionConstraint imports(XmlReader node) {
    Check.notNull(node);
    final CollisionConstraint constraint = new CollisionConstraint();
    if (node.hasNode(NODE_CONSTRAINT)) {
        final Collection<XmlReader> children = node.getChildren(NODE_CONSTRAINT);
        for (final XmlReader current : children) {
            final Orientation orientation = current.getEnum(Orientation.class, ATT_ORIENTATION);
            final String group = current.getString(ATT_GROUP);
            constraint.add(orientation, group);
        }
        children.clear();
    }
    return constraint;
}
Also used : XmlReader(com.b3dgs.lionengine.XmlReader) Orientation(com.b3dgs.lionengine.game.Orientation)

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