use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGame in project lionengine by b3dgs.
the class CircuitsConfigTest method testExportsImports.
/**
* Test exports imports.
*
* @throws IOException If error.
*/
@Test
void testExportsImports() throws IOException {
final Media config = UtilMapTransition.createTransitions();
final MapTile map = UtilMap.createMap(7);
map.getFeature(MapTileTransition.class).loadTransitions(config);
UtilMap.fill(map, UtilMap.TILE_GROUND);
UtilMap.fill(map, UtilMap.TILE_ROAD, UtilMap.TILE_ROAD, 3);
final MapTileGame map3 = new MapTileGame();
map3.addFeature(new MapTileGroupModel());
map3.create(1, 1, 3, 3);
final CircuitsExtractor extractor = new CircuitsExtractorImpl();
final Map<Circuit, Collection<Integer>> circuits = extractor.getCircuits(Arrays.asList(map, map3));
final Media media = Medias.create("circuit.xml");
CircuitsConfig.exports(media, circuits);
final Map<Circuit, Collection<Integer>> imported = CircuitsConfig.imports(media);
assertEquals(circuits, imported);
assertTrue(media.getFile().delete());
assertTrue(config.getFile().delete());
final Media sheets = Medias.create("sheets.xml");
TileSheetsConfig.exports(sheets, 1, 1, Arrays.asList("sheet.png"));
final Media groups = Medias.create("groups.xml");
TileGroupsConfig.exports(groups, Collections.emptyList());
CircuitsConfig.exports(media, Arrays.asList(Medias.create("level.png")), sheets, groups);
assertTrue(sheets.getFile().delete());
assertTrue(groups.getFile().delete());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGame in project lionengine by b3dgs.
the class MapTileHelper method importAndSave.
/**
* Import and save the level.
*
* @param levelrip The level rip.
* @param sheetsConfig The file that define the sheets configuration.
* @param out The output media.
* @param mapPersister The persister reference.
*/
public static void importAndSave(Media levelrip, Media sheetsConfig, Media out, MapTilePersister mapPersister) {
final Services services = new Services();
final MapTileGame map = services.create(MapTileGame.class);
map.create(levelrip, sheetsConfig);
map.addFeature(mapPersister);
services.add(new Factory(services));
services.add(new Handler(services));
final HandlerPersister persister = new HandlerPersister(services);
try (FileWriting output = new FileWriting(out)) {
mapPersister.save(output);
persister.save(output);
} catch (final IOException exception) {
Verbose.exception(exception, "Error on saving map !");
}
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGame in project lionengine by b3dgs.
the class TransitionsExtractorImpl method getTransitions.
/*
* TransitionsExtractor
*/
@Override
public Map<Transition, Collection<Integer>> getTransitions(Collection<Media> levels, Media sheetsConfig, Media groupsConfig) {
final Collection<MapTile> mapsSet = new HashSet<>(levels.size());
for (final Media level : levels) {
final MapTileGame map = new MapTileGame();
map.create(level, sheetsConfig);
final MapTileGroup mapGroup = new MapTileGroupModel();
mapGroup.loadGroups(groupsConfig);
map.addFeature(mapGroup);
mapsSet.add(map);
}
return getTransitions(mapsSet);
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGame in project lionengine by b3dgs.
the class CircuitsExtractorImpl method getCircuits.
/*
* CircuitsExtractor
*/
@Override
public Map<Circuit, Collection<Integer>> getCircuits(Collection<Media> levels, Media sheetsConfig, Media groupsConfig) {
final Collection<MapTile> mapsSet = new HashSet<>(levels.size());
for (final Media level : levels) {
final MapTileGame map = new MapTileGame();
map.create(level, sheetsConfig);
final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
final MapTileTransition mapTransition = map.addFeatureAndGet(new MapTileTransitionModel());
mapGroup.loadGroups(groupsConfig);
mapTransition.loadTransitions(levels, sheetsConfig, groupsConfig);
mapsSet.add(map);
}
return getCircuits(mapsSet);
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGame in project lionengine by b3dgs.
the class MapGeneratorImpl method generateMap.
/*
* MapGenerator
*/
@Override
public MapTile generateMap(GeneratorParameter parameters, Collection<Media> levels, Media sheetsConfig, Media groupsConfig) {
final MapTileGame map = new MapTileGame();
map.loadSheets(sheetsConfig);
final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
final MapTileTransition mapTransition = map.addFeatureAndGet(new MapTileTransitionModel());
final MapTileCircuit mapCircuit = map.addFeatureAndGet(new MapTileCircuitModel());
mapGroup.loadGroups(groupsConfig);
mapTransition.loadTransitions(levels, sheetsConfig, groupsConfig);
mapCircuit.loadCircuits(levels, sheetsConfig, groupsConfig);
parameters.apply(map);
return map;
}
Aggregations