Search in sources :

Example 6 with FileReading

use of com.b3dgs.lionengine.io.FileReading 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)

Aggregations

FileReading (com.b3dgs.lionengine.io.FileReading)6 Media (com.b3dgs.lionengine.Media)5 Test (org.junit.jupiter.api.Test)5 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)4 FileWriting (com.b3dgs.lionengine.io.FileWriting)4 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1