Search in sources :

Example 16 with MapTileGame

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

the class MapTilePersisterModelTest method testConstructor.

/**
 * Test the constructor with services with map.
 */
@Test
void testConstructor() {
    final MapTile map = new MapTileGame();
    final MapTilePersister mapPersister = new MapTilePersisterModel();
    assertNotNull(mapPersister);
    mapPersister.prepare(map);
}
Also used : MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 17 with MapTileGame

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

the class MapTilePersisterModelTest method testSaveLoadWithConfig.

/**
 * Test the save and load map from file with sheet config.
 *
 * @throws IOException If error.
 */
@Test
void testSaveLoadWithConfig() throws IOException {
    final Media config = Medias.create("config.xml");
    TileSheetsConfig.exports(config, 16, 32, new ArrayList<String>());
    final MapTileGame map = new MapTileGame();
    map.addFeature(new MapTilePersisterModel());
    map.create(16, 32, 3, 3);
    map.loadSheets(config);
    final Media level = Medias.create("level");
    UtilMapTilePersister.saveMap(map, level);
    final MapTileGame mapLoaded = UtilMapTilePersister.loadMap(level);
    mapLoaded.loadSheets(config);
    assertEquals(config, mapLoaded.getMedia());
    assertTrue(config.getFile().delete());
    assertTrue(level.getFile().delete());
}
Also used : MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Example 18 with MapTileGame

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

the class MapTilePersisterModelTest method testListener.

/**
 * Test load listener.
 *
 * @throws IOException If error.
 */
@Test
void testListener() throws IOException {
    final MapTileGame map = new MapTileGame();
    final MapTilePersister mapPersister = map.addFeatureAndGet(new MapTilePersisterModel());
    final Media level = Medias.create("level");
    map.create(16, 32, 3, 3);
    UtilMapTilePersister.saveMap(map, level);
    final AtomicBoolean load = new AtomicBoolean();
    final MapTilePersisterListener listener = new MapTilePersisterListener() {

        @Override
        public void notifyMapLoadStart() {
            load.set(false);
        }

        @Override
        public void notifyMapLoaded() {
            load.set(true);
        }
    };
    mapPersister.addListener(listener);
    try (FileReading input = new FileReading(level)) {
        mapPersister.load(input);
    }
    assertTrue(load.get());
    load.set(false);
    mapPersister.removeListener(listener);
    try (FileReading input = new FileReading(level)) {
        mapPersister.load(input);
    }
    assertFalse(load.get());
    assertTrue(level.getFile().delete());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) FileReading(com.b3dgs.lionengine.io.FileReading) Test(org.junit.jupiter.api.Test)

Example 19 with MapTileGame

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

the class MapTileRasteredModelTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new Camera());
    viewer = services.add(new ViewerMock());
    viewer.set(-20, -20);
    map = services.add(new MapTileGame());
    mapViewer = new MapTileViewerModel(services);
    mapViewer.prepare(map);
    mapRastered = new MapTileRasteredModel();
    mapRastered.prepare(map);
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Camera(com.b3dgs.lionengine.game.feature.Camera) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with MapTileGame

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

the class MapTileViewerModelTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new Camera());
    viewer = services.add(new ViewerMock());
    viewer.set(-20, -20);
    map = services.add(new MapTileGame());
    mapViewer = new MapTileViewerModel(services);
    mapViewer.prepare(map);
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Camera(com.b3dgs.lionengine.game.feature.Camera) BeforeEach(org.junit.jupiter.api.BeforeEach)

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