Search in sources :

Example 21 with MapTileGame

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());
}
Also used : MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) Collection(java.util.Collection) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 22 with MapTileGame

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 !");
    }
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) FileWriting(com.b3dgs.lionengine.io.FileWriting) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) HandlerPersister(com.b3dgs.lionengine.game.feature.HandlerPersister) Factory(com.b3dgs.lionengine.game.feature.Factory) Handler(com.b3dgs.lionengine.game.feature.Handler) IOException(java.io.IOException)

Example 23 with MapTileGame

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);
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) HashSet(java.util.HashSet)

Example 24 with MapTileGame

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);
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition) Media(com.b3dgs.lionengine.Media) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileTransitionModel(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransitionModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) HashSet(java.util.HashSet)

Example 25 with MapTileGame

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;
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition) MapTileCircuit(com.b3dgs.lionengine.game.feature.tile.map.transition.circuit.MapTileCircuit) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileTransitionModel(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransitionModel) MapTileCircuitModel(com.b3dgs.lionengine.game.feature.tile.map.transition.circuit.MapTileCircuitModel)

Aggregations

MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)27 Media (com.b3dgs.lionengine.Media)11 MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)11 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)10 Test (org.junit.jupiter.api.Test)10 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Featurable (com.b3dgs.lionengine.game.feature.Featurable)4 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)4 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)4 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)4 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)4 FileReading (com.b3dgs.lionengine.io.FileReading)4 Collection (java.util.Collection)4 Camera (com.b3dgs.lionengine.game.feature.Camera)3 FileWriting (com.b3dgs.lionengine.io.FileWriting)3 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 Factory (com.b3dgs.lionengine.game.feature.Factory)2 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)2 Services (com.b3dgs.lionengine.game.feature.Services)2 MapTileTransitionModel (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransitionModel)2