Search in sources :

Example 36 with Xml

use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.

the class ActionsConfig method imports.

/**
 * Create the action data from node.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The allowed actions.
 * @throws LionEngineException If unable to read node.
 */
public static List<ActionRef> imports(Xml root) {
    Check.notNull(root);
    if (!root.hasChild(NODE_ACTIONS)) {
        return Collections.emptyList();
    }
    final Xml node = root.getChild(NODE_ACTIONS);
    return getRefs(node);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 37 with Xml

use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.

the class ActionsConfig method getRefs.

/**
 * Get all actions and their references.
 *
 * @param node The current node to check (must not be <code>null</code>).
 * @return The actions found.
 */
private static List<ActionRef> getRefs(Xml node) {
    final Collection<Xml> children = node.getChildren(NODE_ACTION);
    final List<ActionRef> actions = new ArrayList<>(children.size());
    for (final Xml action : children) {
        final String path = action.readString(ATT_PATH);
        final boolean cancel = action.readBoolean(false, ATT_CANCEL);
        actions.add(new ActionRef(path, cancel, getRefs(action)));
    }
    return actions;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) ArrayList(java.util.ArrayList)

Example 38 with Xml

use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.

the class ForceConfig method imports.

/**
 * Create the force data from node.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The force data.
 * @throws LionEngineException If unable to read node.
 */
public static Force imports(Xml root) {
    Check.notNull(root);
    final Xml node = root.getChild(NODE_FORCE);
    final Force force = new Force(node.readDouble(ATT_VX), node.readDouble(ATT_VY));
    force.setVelocity(node.readDouble(0.0, ATT_VELOCITY));
    force.setSensibility(node.readDouble(0.0, ATT_SENSIBILITY));
    return force;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 39 with Xml

use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.

the class SurfaceConfig method imports.

/**
 * Create the surface data from node.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The surface data.
 * @throws LionEngineException If unable to read node.
 */
public static SurfaceConfig imports(Xml root) {
    Check.notNull(root);
    final Xml node = root.getChild(NODE_SURFACE);
    final String surface = node.readString(ATT_IMAGE);
    final String icon = node.readString(null, ATT_ICON);
    return new SurfaceConfig(surface, icon);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 40 with Xml

use of com.b3dgs.lionengine.io.Xml in project lionengine by b3dgs.

the class FeaturableModel method getFeatures.

/**
 * Get all available features.
 * Default constructor of each feature must be available or with {@link Setup} as single parameter.
 *
 * @param services The services reference.
 * @param setup The setup reference.
 * @return The available features.
 * @throws LionEngineException If invalid class.
 */
private static List<Feature> getFeatures(Services services, Setup setup) {
    final Collection<Xml> children = setup.getRoot().getChildren(FeaturableConfig.NODE_FEATURE);
    final List<Feature> features = new ArrayList<>(children.size());
    for (final Xml featureNode : children) {
        final String className = featureNode.getText();
        final Feature feature;
        try {
            final Class<? extends Feature> clazz = getClass(className);
            feature = UtilReflection.createReduce(clazz, services, setup);
        } catch (final NoSuchMethodException exception) {
            throw new LionEngineException(exception);
        }
        features.add(feature);
    }
    return features;
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Xml(com.b3dgs.lionengine.io.Xml) ArrayList(java.util.ArrayList)

Aggregations

Xml (com.b3dgs.lionengine.io.Xml)45 ArrayList (java.util.ArrayList)8 Media (com.b3dgs.lionengine.Media)6 HashMap (java.util.HashMap)6 TileRef (com.b3dgs.lionengine.game.feature.tile.TileRef)5 Test (org.junit.Test)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Animation (com.b3dgs.lionengine.Animation)2 ActionRef (com.b3dgs.lionengine.game.ActionRef)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 HashSet (java.util.HashSet)2 ActionConfig (com.b3dgs.lionengine.game.ActionConfig)1 Orientation (com.b3dgs.lionengine.game.Orientation)1 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1 BeforeClass (org.junit.BeforeClass)1