Search in sources :

Example 16 with XmlReader

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

the class DeviceControllerConfig method imports.

/**
 * Import the data from configurer.
 *
 * @param services The services reference (must not be <code>null</code>).
 * @param media The media configuration (must not be <code>null</code>).
 * @return The loaded input.
 * @throws LionEngineException If unable to read node.
 */
@SuppressWarnings("unchecked")
public static Collection<DeviceControllerConfig> imports(Services services, Media media) {
    Check.notNull(services);
    Check.notNull(media);
    final Collection<DeviceControllerConfig> configs = new ArrayList<>();
    final ClassLoader loader = services.getOptional(ClassLoader.class).orElse(DeviceControllerConfig.class.getClassLoader());
    final Configurer configurer = new Configurer(media);
    try {
        final Class<Enum<? extends DeviceMapper>> mapping;
        mapping = (Class<Enum<? extends DeviceMapper>>) loader.loadClass(configurer.getString(ATT_MAPPING));
        for (final XmlReader deviceNode : configurer.getChildren(NODE_DEVICE)) {
            final Class<DevicePush> device = (Class<DevicePush>) loader.loadClass(deviceNode.getString(ATT_CLASS));
            final boolean disabled = deviceNode.getBoolean(false, ATT_DISABLED);
            final List<DeviceAxis> horizontal = readAxis(deviceNode, NODE_HORIZONTAL);
            final List<DeviceAxis> vertical = readAxis(deviceNode, NODE_VERTICAL);
            final Map<Integer, Set<Integer>> fire = readFire(mapping, deviceNode);
            configs.add(new DeviceControllerConfig(device, disabled, horizontal, vertical, fire));
        }
    } catch (final ReflectiveOperationException exception) {
        throw new LionEngineException(exception);
    }
    return configs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DeviceMapper(com.b3dgs.lionengine.io.DeviceMapper) ArrayList(java.util.ArrayList) XmlReader(com.b3dgs.lionengine.XmlReader) DeviceAxis(com.b3dgs.lionengine.io.DeviceAxis) DevicePush(com.b3dgs.lionengine.io.DevicePush) LionEngineException(com.b3dgs.lionengine.LionEngineException) Configurer(com.b3dgs.lionengine.game.Configurer)

Example 17 with XmlReader

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

the class PathfindableConfig method importAllowedMovements.

/**
 * Import the allowed movements.
 *
 * @param node The root node (must not be <code>null</code>).
 * @return The allowed movements.
 * @throws LionEngineException If malformed movement name.
 */
private static Collection<MovementTile> importAllowedMovements(XmlReader node) {
    if (!node.hasNode(NODE_MOVEMENT)) {
        return Collections.emptySet();
    }
    final Collection<MovementTile> movements = EnumSet.noneOf(MovementTile.class);
    final Collection<XmlReader> children = node.getChildren(NODE_MOVEMENT);
    for (final XmlReader movementNode : children) {
        try {
            movements.add(MovementTile.valueOf(movementNode.getText()));
        } catch (final IllegalArgumentException exception) {
            throw new LionEngineException(exception);
        }
    }
    children.clear();
    return movements;
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 18 with XmlReader

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

the class ExtractorConfig method imports.

/**
 * Imports the config from node.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The extractor data.
 * @throws LionEngineException If unable to read node.
 */
public static ExtractorConfig imports(XmlReader root) {
    Check.notNull(root);
    final XmlReader node = root.getChild(NODE_EXTRACTOR);
    final double extract = node.getDouble(0.0, ATT_EXTRACT);
    final double dropoff = node.getDouble(0.0, ATT_DROPOFF);
    final int capacity = node.getInteger(0, ATT_CAPACITY);
    return new ExtractorConfig(extract, dropoff, capacity);
}
Also used : XmlReader(com.b3dgs.lionengine.XmlReader)

Example 19 with XmlReader

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

the class FramesConfig method imports.

/**
 * Imports the frames config from node.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The frames data.
 * @throws LionEngineException If unable to read node or invalid integer.
 */
public static FramesConfig imports(XmlReader root) {
    Check.notNull(root);
    if (root.hasNode(NODE_FRAMES)) {
        final XmlReader node = root.getChild(NODE_FRAMES);
        final int horizontals = node.getInteger(ATT_HORIZONTAL);
        final int verticals = node.getInteger(ATT_VERTICAL);
        final int offsetX = node.getInteger(0, ATT_OFFSET_X);
        final int offsetY = node.getInteger(0, ATT_OFFSET_Y);
        return new FramesConfig(horizontals, verticals, offsetX, offsetY);
    }
    return new FramesConfig(1, 1, 0, 0);
}
Also used : XmlReader(com.b3dgs.lionengine.XmlReader)

Example 20 with XmlReader

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

the class AnimationConfig method imports.

/**
 * Create the animation data from configurer.
 *
 * @param root The root reference (must not be <code>null</code>).
 * @return The animations configuration instance.
 * @throws LionEngineException If unable to read data.
 */
public static AnimationConfig imports(XmlReader root) {
    Check.notNull(root);
    final Map<String, Animation> animations = new HashMap<>(0);
    if (root.hasNode(NODE_ANIMATIONS)) {
        final Collection<XmlReader> children = root.getChild(NODE_ANIMATIONS).getChildren(NODE_ANIMATION);
        for (final XmlReader node : children) {
            final String anim = node.getString(ANIMATION_NAME);
            final Animation animation = createAnimation(node);
            animations.put(anim, animation);
        }
        children.clear();
    }
    return new AnimationConfig(animations);
}
Also used : HashMap(java.util.HashMap) Animation(com.b3dgs.lionengine.Animation) XmlReader(com.b3dgs.lionengine.XmlReader)

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