Search in sources :

Example 11 with Configurer

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

the class PathfindableConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Map<String, PathData> map = new HashMap<>();
    final PathData data = new PathData("category", 1.0, true, Arrays.asList(MovementTile.UP));
    map.put(data.getName(), data);
    final Xml root = new Xml("test");
    root.add(PathfindableConfig.exports(map));
    final Media media = Medias.create("pathfindable.xml");
    root.save(media);
    assertEquals(map, PathfindableConfig.imports(new Configurer(media)));
    assertTrue(media.getFile().delete());
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 12 with Configurer

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

the class PathfindableConfigTest method testWrongMovement.

/**
 * Test with wrong movement.
 */
@Test
void testWrongMovement() {
    final PathData data = new PathData("category", 1.0, true, EnumSet.noneOf(MovementTile.class));
    final Xml path = PathfindableConfig.exportPathData(data);
    final Xml movement = path.createChild(PathfindableConfig.NODE_MOVEMENT);
    movement.setText("VOID");
    final Xml root = new Xml("test");
    final Xml node = root.createChild(PathfindableConfig.NODE_PATHFINDABLE);
    node.add(path);
    final Media media = Medias.create("pathfindable.xml");
    root.save(media);
    assertCause(() -> PathfindableConfig.imports(new Configurer(media)), IllegalArgumentException.class);
    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)

Example 13 with Configurer

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

the class CollisionCategoryConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Media formulasConfig = UtilConfig.createFormulaConfig(formula);
    final Media groupsConfig = UtilConfig.createGroupsConfig(group);
    mapCollision.loadCollisions(formulasConfig, groupsConfig);
    final Xml root = new Xml("categories");
    CollisionCategoryConfig.exports(root, category);
    final Media media = Medias.create("Object.xml");
    root.save(media);
    final Collection<CollisionCategory> imported = CollisionCategoryConfig.imports(new Configurer(media), mapCollision);
    assertEquals(category, imported.iterator().next());
    assertTrue(formulasConfig.getFile().delete());
    assertTrue(groupsConfig.getFile().delete());
    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)

Example 14 with Configurer

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

the class Factory method createSetup.

/**
 * Create a setup from its media.
 *
 * @param media The media reference.
 * @return The setup instance.
 */
@SuppressWarnings("unchecked")
private Setup createSetup(Media media) {
    final Configurer configurer = new Configurer(media);
    try {
        final FeaturableConfig config = FeaturableConfig.imports(configurer);
        final String setup = config.getSetupName();
        final Class<? extends Setup> setupClass;
        if (setup.isEmpty()) {
            final Class<?> clazz = classLoader.loadClass(config.getClassName());
            final Constructor<?> constructor = UtilReflection.getCompatibleConstructorParent(clazz, new Class<?>[] { Services.class, Setup.class });
            setupClass = (Class<? extends Setup>) constructor.getParameterTypes()[SETUP_INDEX];
        } else {
            setupClass = (Class<? extends Setup>) classLoader.loadClass(config.getSetupName());
        }
        return UtilReflection.create(setupClass, new Class<?>[] { Media.class }, media);
    } catch (final ClassNotFoundException exception) {
        throw new LionEngineException(exception, ERROR_SETUP_CLASS);
    } catch (final NoSuchMethodException exception) {
        throw new LionEngineException(exception, ERROR_CONSTRUCTOR_MISSING + media.getPath());
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Configurer(com.b3dgs.lionengine.game.Configurer)

Example 15 with Configurer

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

the class ProducerConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
public void testExportsImports() {
    final ActionRef ref = new ActionRef("ref", false, new ArrayList<ActionRef>());
    final ActionRef ref2 = new ActionRef("ref", false, Arrays.asList(ref));
    final Collection<ActionRef> refs = Arrays.asList(new ActionRef("test", true, Arrays.asList(ref2)));
    final Xml root = new Xml("test");
    root.add(ActionsConfig.exports(refs));
    final Media media = Medias.create("producer.xml");
    root.save(media);
    Assert.assertEquals(refs, ActionsConfig.imports(new Xml(media)));
    Assert.assertEquals(refs, ActionsConfig.imports(new Configurer(media)));
    Assert.assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Configurer(com.b3dgs.lionengine.game.Configurer) ActionRef(com.b3dgs.lionengine.game.ActionRef) Test(org.junit.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