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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations