Search in sources :

Example 26 with Configurer

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

the class FovableConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Xml root = new Xml("test");
    root.add(FovableConfig.exports(1));
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(1, FovableConfig.imports(new Xml(media)));
    assertEquals(1, 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)

Example 27 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.
 * @param standard <code>true</code> for standard setup, <code>false</code> else.
 * @return The setup instance.
 */
@SuppressWarnings("unchecked")
private Setup createSetup(Media media, boolean standard) {
    final Configurer configurer = new Configurer(media);
    try {
        final FeaturableConfig config = FeaturableConfig.imports(configurer);
        final String setup = config.getSetupName();
        final Class<? extends Setup> setupClass;
        if (standard) {
            setupClass = Setup.class;
        } else 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, media, ERROR_SETUP_CLASS);
    } catch (final NoSuchMethodException exception) {
        throw new LionEngineException(exception, ERROR_CONSTRUCTOR_MISSING + media.getPath());
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Constructor(java.lang.reflect.Constructor) Configurer(com.b3dgs.lionengine.game.Configurer)

Example 28 with Configurer

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

the class ActionsConfigTest method testCancelOnRef.

/**
 * Test cancel flag is not used on child reference.
 */
@Test
void testCancelOnRef() {
    final ActionRef ref = new ActionRef("ref", true, new ArrayList<ActionRef>());
    final Collection<ActionRef> refs = Arrays.asList(new ActionRef("test", false, Arrays.asList(ref)));
    final Xml root = new Xml("test");
    root.add(ActionsConfig.exports(refs));
    final Media media = Medias.create("producer.xml");
    root.save(media);
    assertNotEquals(refs, ActionsConfig.imports(new Xml(media), null));
    assertNotEquals(refs, ActionsConfig.imports(new Configurer(media), null));
    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 29 with Configurer

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

the class ExtractableConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final ExtractableConfig config = new ExtractableConfig("gold", 1);
    final Xml root = new Xml("test");
    root.add(ExtractableConfig.exports(config));
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(config, ExtractableConfig.imports(new Xml(media)));
    assertEquals(config, ExtractableConfig.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)

Example 30 with Configurer

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

the class ExtractorConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final ExtractorConfig config = new ExtractorConfig(1.0, 2.0, 3);
    final Xml root = new Xml("test");
    root.add(ExtractorConfig.exports(config));
    final Media media = Medias.create("Object.xml");
    root.save(media);
    assertEquals(config, ExtractorConfig.imports(new Xml(media)));
    assertEquals(config, ExtractorConfig.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