Search in sources :

Example 1 with TileGroup

use of com.b3dgs.lionengine.game.feature.tile.TileGroup in project lionengine by b3dgs.

the class UtilMap method setGroups.

/**
 * Set the map tile groups.
 *
 * @param map The map reference.
 */
public static void setGroups(MapTile map) {
    final Collection<TileGroup> groups = new ArrayList<>();
    groups.add(new TileGroup(WATER, TileGroupType.PLAIN, Arrays.asList(new TileRef(SHEET, TILE_WATER))));
    groups.add(new TileGroup(GROUND, TileGroupType.PLAIN, Arrays.asList(new TileRef(SHEET, TILE_GROUND))));
    groups.add(new TileGroup(TREE, TileGroupType.PLAIN, Arrays.asList(new TileRef(SHEET, TILE_TREE))));
    groups.add(new TileGroup(ROAD, TileGroupType.CIRCUIT, Arrays.asList(new TileRef(SHEET, TILE_ROAD))));
    groups.add(new TileGroup(TRANSITION, TileGroupType.TRANSITION, Arrays.asList(new TileRef(SHEET, TILE_TRANSITION))));
    groups.add(new TileGroup(TRANSITION2, TileGroupType.TRANSITION, Arrays.asList(new TileRef(SHEET, TILE_TRANSITION2))));
    final Media config = Medias.create("groups.xml");
    TileGroupsConfig.exports(config, groups);
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    mapGroup.loadGroups(config);
    Assert.assertTrue(config.getFile().delete());
}
Also used : ArrayList(java.util.ArrayList) Media(com.b3dgs.lionengine.Media) TileGroup(com.b3dgs.lionengine.game.feature.tile.TileGroup) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 2 with TileGroup

use of com.b3dgs.lionengine.game.feature.tile.TileGroup in project lionengine by b3dgs.

the class MapTileGroupModel method loadGroups.

/*
     * MapTileGroup
     */
@Override
public void loadGroups(Media groupsConfig) {
    this.groupsConfig = groupsConfig;
    groupTiles.clear();
    tilesGroup.clear();
    groupTypes.clear();
    for (final TileGroup group : TileGroupsConfig.imports(groupsConfig)) {
        final String name = group.getName();
        groupTiles.put(name, group.getTiles());
        groupTypes.put(name, group.getType());
        for (final TileRef tile : group.getTiles()) {
            tilesGroup.put(tile, name);
        }
    }
}
Also used : TileGroup(com.b3dgs.lionengine.game.feature.tile.TileGroup) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 3 with TileGroup

use of com.b3dgs.lionengine.game.feature.tile.TileGroup in project lionengine by b3dgs.

the class MapTileGroupModelTest method testLoadMedia.

/**
 * Test the map tile with loaded media.
 */
@Test
public void testLoadMedia() {
    final Media configGroups = Medias.create("groups.xml");
    final Collection<TileGroup> groups = new ArrayList<>();
    groups.add(new TileGroup("water", TileGroupType.PLAIN, Arrays.asList(new TileRef(0, 0))));
    TileGroupsConfig.exports(configGroups, groups);
    mapGroup.loadGroups(configGroups);
    Assert.assertEquals(new TileRef(tile), mapGroup.getGroup("water").iterator().next());
    Assert.assertEquals("water", mapGroup.getGroup(tile));
    Assert.assertEquals("water", mapGroup.getGroup(new TileRef(0, 0)));
    Assert.assertEquals("water", mapGroup.getGroup(Integer.valueOf(0), 0));
    Assert.assertTrue(mapGroup.getGroups().containsAll(Arrays.asList("water")));
    Assert.assertEquals(TileGroupType.PLAIN, mapGroup.getType("water"));
    Assert.assertEquals(TileGroupType.PLAIN, mapGroup.getType(tile));
}
Also used : Media(com.b3dgs.lionengine.Media) ArrayList(java.util.ArrayList) TileGroup(com.b3dgs.lionengine.game.feature.tile.TileGroup) MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef) Test(org.junit.Test)

Aggregations

TileGroup (com.b3dgs.lionengine.game.feature.tile.TileGroup)3 TileRef (com.b3dgs.lionengine.game.feature.tile.TileRef)3 Media (com.b3dgs.lionengine.Media)2 ArrayList (java.util.ArrayList)2 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)1 Test (org.junit.Test)1