Search in sources :

Example 6 with Xml

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

the class TileGroupsConfig method exportGroup.

/**
 * Export the group data as a node.
 *
 * @param nodeGroups The root node (must not be <code>null</code>).
 * @param group The group to export (must not be <code>null</code>).
 */
private static void exportGroup(Xml nodeGroups, TileGroup group) {
    final Xml nodeGroup = nodeGroups.createChild(NODE_GROUP);
    nodeGroup.writeString(ATT_GROUP_NAME, group.getName());
    nodeGroup.writeEnum(ATT_GROUP_TYPE, group.getType());
    for (final Integer tile : group.getTiles()) {
        final Xml nodeTileRef = TileConfig.exports(tile.intValue());
        nodeGroup.add(nodeTileRef);
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 7 with Xml

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

the class TileSheetsConfig method exports.

/**
 * Export the sheets configuration.
 *
 * @param configSheets The export media (must not be <code>null</code>).
 * @param tileWidth The tile width.
 * @param tileHeight The tile height.
 * @param sheets The sheets filename (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Media configSheets, int tileWidth, int tileHeight, List<String> sheets) {
    Check.notNull(configSheets);
    Check.notNull(sheets);
    final Xml nodeSheets = new Xml(NODE_TILE_SHEETS);
    nodeSheets.writeString(Constant.XML_HEADER, Constant.ENGINE_WEBSITE);
    final Xml tileSize = nodeSheets.createChild(NODE_TILE_SIZE);
    tileSize.writeString(ATT_TILE_WIDTH, String.valueOf(tileWidth));
    tileSize.writeString(ATT_TILE_HEIGHT, String.valueOf(tileHeight));
    exportSheets(nodeSheets, sheets);
    nodeSheets.save(configSheets);
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 8 with Xml

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

the class TileSheetsConfig method exportSheets.

/**
 * Export the defined sheets.
 *
 * @param nodeSheets Sheets node (must not be <code>null</code>).
 * @param sheets Sheets defined (must not be <code>null</code>).
 */
private static void exportSheets(Xml nodeSheets, List<String> sheets) {
    for (final String sheet : sheets) {
        final Xml nodeSheet = nodeSheets.createChild(NODE_TILE_SHEET);
        nodeSheet.setText(sheet);
    }
}
Also used : Xml(com.b3dgs.lionengine.Xml)

Example 9 with Xml

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

the class FeaturableModelTest method testAddFeatures.

/**
 * Test the add features.
 */
@Test
void testAddFeatures() {
    final Media media = Medias.create("Features.xml");
    final Xml root = new Xml(FeaturableConfig.NODE_FEATURABLE);
    final Xml unknown = root.createChild(FeaturableConfig.NODE_FEATURE);
    unknown.setText(MyFeature.class.getName());
    root.save(media);
    Featurable featurable = new FeaturableModel(new Services(), new Setup(media));
    featurable.checkListener(featurable);
    assertEquals(media, featurable.getMedia());
    for (final Feature next : featurable.getFeatures()) {
        assertTrue(MyFeature.class.equals(next.getClass()) || Identifiable.class.isAssignableFrom(next.getClass()) || Recycler.class.isAssignableFrom(next.getClass()), next.getClass().getName());
    }
    featurable = new FeaturableModel(new Services(), new Setup(media));
    UtilFile.deleteFile(media.getFile());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Feature(com.b3dgs.lionengine.game.Feature) Test(org.junit.jupiter.api.Test)

Example 10 with Xml

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

the class ActionConfigTest method testExportsImports.

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

Xml (com.b3dgs.lionengine.Xml)133 Test (org.junit.jupiter.api.Test)73 Media (com.b3dgs.lionengine.Media)63 Configurer (com.b3dgs.lionengine.game.Configurer)25 Setup (com.b3dgs.lionengine.game.feature.Setup)11 HashMap (java.util.HashMap)9 Collection (java.util.Collection)8 Animation (com.b3dgs.lionengine.Animation)4 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)4 Feature (com.b3dgs.lionengine.game.Feature)3 Force (com.b3dgs.lionengine.game.Force)3 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)3 Services (com.b3dgs.lionengine.game.feature.Services)3 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)3 Map (java.util.Map)3 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 Origin (com.b3dgs.lionengine.Origin)1 UtilAssert.assertThrows (com.b3dgs.lionengine.UtilAssert.assertThrows)1 XmlReader (com.b3dgs.lionengine.XmlReader)1 Orientation (com.b3dgs.lionengine.game.Orientation)1