Search in sources :

Example 1 with DeviceAxis

use of com.b3dgs.lionengine.io.DeviceAxis 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 2 with DeviceAxis

use of com.b3dgs.lionengine.io.DeviceAxis 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)2 DeviceAxis (com.b3dgs.lionengine.io.DeviceAxis)2 ArrayList (java.util.ArrayList)2 LionEngineException (com.b3dgs.lionengine.LionEngineException)1 Configurer (com.b3dgs.lionengine.game.Configurer)1 DeviceMapper (com.b3dgs.lionengine.io.DeviceMapper)1 DevicePush (com.b3dgs.lionengine.io.DevicePush)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1