Search in sources :

Example 21 with Xml

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

the class ProducerConfigTest method testImportNoNode.

/**
 * Test import without node.
 */
@Test
public void testImportNoNode() {
    final Media media = Medias.create("producer.xml");
    final Xml root = new Xml("test");
    root.save(media);
    Assert.assertTrue(ActionsConfig.imports(new Xml(media)).isEmpty());
    Assert.assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media) Test(org.junit.Test)

Example 22 with Xml

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

the class RasterData method load.

/**
 * Load raster data from node.
 *
 * @param root The raster node.
 * @param color The raster color name.
 * @return The raster data.
 */
public static RasterData load(Xml root, String color) {
    final Xml node = root.getChild(color);
    final int start = Integer.decode(node.readString(ATT_START)).intValue();
    final int step = Integer.decode(node.readString(ATT_STEP)).intValue();
    final int force = node.readInteger(ATT_FORCE);
    final int amplitude = node.readInteger(ATT_AMPLITUDE);
    final int offset = node.readInteger(ATT_OFFSET);
    final int type = node.readInteger(ATT_TYPE);
    return new RasterData(start, step, force, amplitude, offset, type);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml)

Example 23 with Xml

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

the class StateAnimationBasedTest method setUp.

/**
 * Prepare test.
 */
@BeforeClass
public static void setUp() {
    Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
    media = Medias.create("animations.xml");
    final Xml root = new Xml("test");
    final Animation idle = new Animation("idle", 1, 2, 3.0, false, true);
    AnimationConfig.exports(root, idle);
    final Animation walk = new Animation("walk", 1, 2, 3.0, false, true);
    AnimationConfig.exports(root, walk);
    final Animation jump = new Animation("jump", 1, 2, 3.0, false, true);
    AnimationConfig.exports(root, jump);
    root.save(media);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) Animation(com.b3dgs.lionengine.Animation) BeforeClass(org.junit.BeforeClass)

Example 24 with Xml

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

the class UtilActionnable method createAction.

/**
 * Create a default action.
 *
 * @param description The description.
 * @param rectangle The button.
 * @return The temp media.
 */
public static Media createAction(String description, Rectangle rectangle) {
    final Media media = Medias.create("action.xml");
    final String name = "name";
    final ActionConfig action = new ActionConfig(name, description, (int) rectangle.getX(), (int) rectangle.getY(), rectangle.getWidth(), rectangle.getHeight());
    final Xml root = new Xml("test");
    root.add(ActionConfig.exports(action));
    root.save(media);
    return media;
}
Also used : ActionConfig(com.b3dgs.lionengine.game.ActionConfig) Xml(com.b3dgs.lionengine.io.Xml) Media(com.b3dgs.lionengine.Media)

Example 25 with Xml

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

the class TileGroupsConfig method importGroup.

/**
 * Import the group from its node.
 *
 * @param nodeGroup The group node (must not be <code>null</code>).
 * @return The imported group.
 */
private static TileGroup importGroup(Xml nodeGroup) {
    final Collection<Xml> children = nodeGroup.getChildren(TileConfig.NODE_TILE);
    final Collection<TileRef> tiles = new ArrayList<>(children.size());
    for (final Xml nodeTileRef : children) {
        final TileRef tileRef = TileConfig.imports(nodeTileRef);
        tiles.add(tileRef);
    }
    final String groupName = nodeGroup.readString(ATT_GROUP_NAME);
    final TileGroupType groupType = TileGroupType.from(nodeGroup.readString(TileGroupType.NONE.name(), ATT_GROUP_TYPE));
    return new TileGroup(groupName, groupType, tiles);
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) ArrayList(java.util.ArrayList)

Aggregations

Xml (com.b3dgs.lionengine.io.Xml)45 ArrayList (java.util.ArrayList)8 Media (com.b3dgs.lionengine.Media)6 HashMap (java.util.HashMap)6 TileRef (com.b3dgs.lionengine.game.feature.tile.TileRef)5 Test (org.junit.Test)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Animation (com.b3dgs.lionengine.Animation)2 ActionRef (com.b3dgs.lionengine.game.ActionRef)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 HashSet (java.util.HashSet)2 ActionConfig (com.b3dgs.lionengine.game.ActionConfig)1 Orientation (com.b3dgs.lionengine.game.Orientation)1 SizeConfig (com.b3dgs.lionengine.game.SizeConfig)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1 BeforeClass (org.junit.BeforeClass)1