Search in sources :

Example 11 with MapTileGame

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

the class ExtractableModelTest method testConfigWithNode.

/**
 * Test the extraction config with node.
 */
@Test
void testConfigWithNode() {
    final MapTile map = new MapTileGame();
    map.create(16, 16, 4, 4);
    services.add(map);
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeatureAndGet(new TransformableModel(services, setup)).teleport(16, 32);
    final Media media = UtilExtractable.createMedia();
    final Extractable extractable = new ExtractableModel(services, new Setup(media));
    extractable.prepare(featurable);
    assertEquals(10, extractable.getResourceQuantity());
    assertEquals("gold", extractable.getResourceType());
    assertEquals(1, extractable.getInTileX());
    assertEquals(2, extractable.getInTileY());
    assertEquals(1, extractable.getInTileWidth());
    assertEquals(2, extractable.getInTileHeight());
    extractable.getFeature(Identifiable.class).notifyDestroyed();
    assertTrue(media.getFile().delete());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 12 with MapTileGame

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

the class TransitionsConfigTest method testExportsImports.

/**
 * Test exports and imports.
 *
 * @throws IOException If error.
 */
@Test
void testExportsImports() throws IOException {
    final MapTile map = UtilMap.createMap(7);
    UtilMap.fill(map, UtilMap.TILE_WATER);
    UtilMap.fill(map, UtilMap.TILE_WATER, UtilMap.TILE_TRANSITION, 3);
    final MapTile map2 = UtilMap.createMap(7);
    UtilMap.fill(map, UtilMap.TILE_WATER);
    UtilMap.fill(map, UtilMap.TILE_GROUND, UtilMap.TILE_TRANSITION, 3);
    final MapTileGame map3 = new MapTileGame();
    map3.addFeature(new MapTileGroupModel());
    map3.create(1, 1, 3, 3);
    final TransitionsExtractor extractor = new TransitionsExtractorImpl();
    final Map<Transition, Collection<Integer>> transitions = extractor.getTransitions(Arrays.asList(map, map2, map3));
    final Media media = Medias.create("transition.xml");
    TransitionsConfig.exports(media, transitions);
    assertEquals(transitions, TransitionsConfig.imports(media));
    assertTrue(media.getFile().delete());
}
Also used : 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 13 with MapTileGame

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

the class TransformableModelTest method prepare.

/**
 * Prepare test.
 */
@Before
public void prepare() {
    services.add(new MapTileGame());
    featurable.addFeature(new IdentifiableModel());
    transformable.prepare(featurable);
}
Also used : MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Before(org.junit.Before)

Example 14 with MapTileGame

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

the class CircuitConfigTest method testExportsImports.

/**
 * Test exports imports.
 *
 * @throws IOException If error.
 */
@Test
public 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 MapTile map3 = new MapTileGame();
    map3.addFeature(new MapTileGroupModel());
    map3.create(1, 1, 3, 3);
    final CircuitsExtractor extractor = new CircuitsExtractorImpl();
    final Map<Circuit, Collection<TileRef>> circuits = extractor.getCircuits(Arrays.asList(map, map3));
    final Media media = Medias.create("circuit.xml");
    CircuitsConfig.exports(media, circuits);
    final Map<Circuit, Collection<TileRef>> imported = CircuitsConfig.imports(media);
    Assert.assertEquals(circuits, imported);
    Assert.assertTrue(media.getFile().delete());
    Assert.assertTrue(config.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.Test)

Example 15 with MapTileGame

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

the class HandlerPersisterTest method testWithMap.

/**
 * Test with map.
 *
 * @throws IOException If error.
 */
@Test
void testWithMap() throws IOException {
    services.add(new Camera());
    final MapTile map = services.add(new MapTileGame());
    map.create(16, 16, 5, 5);
    final Featurable featurable = factory.create(Medias.create("ObjectFeatures.xml"));
    featurable.getFeature(Transformable.class).teleport(16, 32);
    handler.add(featurable);
    handler.update(1.0);
    final HandlerPersister persister = new HandlerPersister(services);
    final Media media = Medias.create("persister.data");
    try (FileWriting writing = new FileWriting(media)) {
        persister.save(writing);
    }
    final Services services2 = new Services();
    services2.add(new Factory(services2));
    services2.add(map);
    final Handler handler2 = services2.add(new Handler(services2));
    final HandlerPersister persister2 = new HandlerPersister(services2);
    try (FileReading reading = new FileReading(media)) {
        persister2.load(reading);
    }
    handler2.update(1.0);
    final Featurable featurable2 = handler2.values().iterator().next();
    final Transformable transformable = featurable2.getFeature(Transformable.class);
    assertEquals(16.0, transformable.getX());
    assertEquals(32.0, transformable.getY());
    assertTrue(media.getFile().delete());
}
Also used : FileWriting(com.b3dgs.lionengine.io.FileWriting) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) FileReading(com.b3dgs.lionengine.io.FileReading) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

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