Search in sources :

Example 6 with Configurer

use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.

the class CollidableConfigTest method testEmptyAccepted.

/**
 * Test with empty accepted.
 */
@Test
void testEmptyAccepted() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    final Services services = new Services();
    services.add(new ViewerMock());
    final Collidable collidable = new CollidableModel(services, new Setup(media));
    collidable.setGroup(Integer.valueOf(1));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertTrue(config.getAccepted().isEmpty());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 7 with Configurer

use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.

the class CollidableConfigTest method testExport.

/**
 * Test export.
 */
@Test
void testExport() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    final Services services = new Services();
    services.add(new ViewerMock());
    final Collidable collidable = new CollidableModel(services, new Setup(media));
    collidable.setGroup(Integer.valueOf(1));
    collidable.addAccept(Integer.valueOf(2));
    collidable.addAccept(Integer.valueOf(3));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertIterableEquals(Arrays.asList(Integer.valueOf(2), Integer.valueOf(3)), config.getAccepted());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 8 with Configurer

use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.

the class LauncherConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final LaunchableConfig launchable = new LaunchableConfig("media", "sfx", 10, 1, 2, new Force(1.0, 2.0));
    final LauncherConfig launcher = new LauncherConfig(10, 10, true, Arrays.asList(launchable));
    final Xml root = new Xml("test");
    root.add(LauncherConfig.exports(launcher));
    final Media media = Medias.create("launcher.xml");
    root.save(media);
    assertEquals(launcher, LauncherConfig.imports(new Xml(media).getChild(LauncherConfig.NODE_LAUNCHER)));
    assertEquals(Arrays.asList(launcher), LauncherConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : Force(com.b3dgs.lionengine.game.Force) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 9 with Configurer

use of com.b3dgs.lionengine.game.Configurer 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 10 with Configurer

use of com.b3dgs.lionengine.game.Configurer in project lionengine by b3dgs.

the class FovableConfigTest method testExportsImportsNoNode.

/**
 * Test exports imports without node.
 */
@Test
void testExportsImportsNoNode() {
    final Xml root = new Xml("test");
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(0, FovableConfig.imports(new Xml(media)));
    assertEquals(0, FovableConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Aggregations

Configurer (com.b3dgs.lionengine.game.Configurer)30 Media (com.b3dgs.lionengine.Media)27 Xml (com.b3dgs.lionengine.Xml)25 Test (org.junit.jupiter.api.Test)25 HashMap (java.util.HashMap)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Setup (com.b3dgs.lionengine.game.feature.Setup)3 Animation (com.b3dgs.lionengine.Animation)2 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 ActionRef (com.b3dgs.lionengine.game.ActionRef)2 Services (com.b3dgs.lionengine.game.feature.Services)2 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)2 Xml (com.b3dgs.lionengine.io.Xml)2 Collection (java.util.Collection)2 Test (org.junit.Test)2 XmlReader (com.b3dgs.lionengine.XmlReader)1 Force (com.b3dgs.lionengine.game.Force)1 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)1 DeviceAxis (com.b3dgs.lionengine.io.DeviceAxis)1 DeviceMapper (com.b3dgs.lionengine.io.DeviceMapper)1