Search in sources :

Example 6 with ImageBufferMock

use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.

the class MapTileRasteredModelTest method testRastered.

/**
 * Test the viewer functions.
 */
@Test
void testRastered() {
    map.loadSheets(Arrays.asList(Drawable.loadSpriteTiled(new ImageBufferMock(80, 80), 40, 40)));
    map.create(40, 40, 2, 2);
    map.setTile(0, 0, 0);
    map.setTile(1, 1, 1);
    assertFalse(mapRastered.loadSheets());
    mapRastered.setRaster(Medias.create("tiles.png"), 2, 0);
    assertTrue(mapRastered.loadSheets());
    mapViewer.addRenderer(mapRastered);
    mapViewer.render(g);
    assertEquals(RasterImage.MAX_RASTERS - 1, mapRastered.getRasterIndex(RasterImage.MAX_RASTERS * 2));
    assertTrue(mapRastered.loadSheets());
    mapViewer.render(g);
    assertEquals(RasterImage.MAX_RASTERS / RasterImage.LINES_PER_RASTER, mapRastered.getRasterIndex(RasterImage.MAX_RASTERS));
}
Also used : ImageBufferMock(com.b3dgs.lionengine.graphic.ImageBufferMock) Test(org.junit.jupiter.api.Test)

Example 7 with ImageBufferMock

use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.

the class RasterImageTest method testSmoothDefault.

/**
 * Test smooth default.
 */
@Test
public void testSmoothDefault() {
    final RasterImage raster = new RasterImage(new ImageBufferMock(100, 200), mediaRaster, 100, true);
    raster.loadRasters(50);
    Assert.assertEquals(30, raster.getRasters().size());
    Assert.assertEquals(mediaRaster, raster.getFile());
    Assert.assertEquals(100, raster.getHeight());
    Assert.assertTrue(raster.hasSmooth());
    Assert.assertEquals(100, raster.getRaster(0).getWidth());
    Assert.assertEquals(200, raster.getRaster(0).getHeight());
}
Also used : ImageBufferMock(com.b3dgs.lionengine.graphic.ImageBufferMock) Test(org.junit.Test)

Example 8 with ImageBufferMock

use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.

the class RasterImageTest method testNoSmoothSave.

/**
 * Test no smooth save.
 */
@Test
public void testNoSmoothSave() {
    final RasterImage raster = new RasterImage(new ImageBufferMock(100, 200), mediaRaster, 100, false);
    raster.loadRasters(50, true, "prefix");
    Assert.assertEquals(15, raster.getRasters().size());
    Assert.assertEquals(mediaRaster, raster.getFile());
    Assert.assertEquals(100, raster.getHeight());
    Assert.assertFalse(raster.hasSmooth());
    Assert.assertEquals(100, raster.getRaster(0).getWidth());
    Assert.assertEquals(200, raster.getRaster(0).getHeight());
    final Media folder = Medias.create("prefix_raster");
    Assert.assertTrue(folder.getFile().getAbsolutePath(), folder.exists());
    try {
        for (int i = 1; i <= 15; i++) {
            final Media file = Medias.create("prefix_raster", i + Constant.DOT + ImageFormat.PNG);
            Assert.assertTrue(file.getFile().getAbsolutePath(), file.exists());
        }
    } finally {
        UtilFolder.deleteDirectory(folder.getFile());
    }
}
Also used : ImageBufferMock(com.b3dgs.lionengine.graphic.ImageBufferMock) Media(com.b3dgs.lionengine.Media) Test(org.junit.Test)

Example 9 with ImageBufferMock

use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.

the class RasterImageTest method testDefaultPalette.

/**
 * Test default with palette.
 */
@Test
void testDefaultPalette() {
    final Media mediaRaster = Medias.create("raster.png");
    final int rastersNumber = ImageInfo.get(mediaRaster).getHeight() - 1;
    final RasterImage raster = new RasterImage(new ImageBufferMock(128, 64), mediaRaster, 16);
    raster.loadRasters(false, Constant.EMPTY_STRING);
    assertEquals(rastersNumber, raster.getRasters().size());
    assertEquals(mediaRaster, raster.getFile());
    assertEquals(16, raster.getHeight());
    assertEquals(128, raster.getRaster(0).getWidth());
    assertEquals(64, raster.getRaster(0).getHeight());
}
Also used : ImageBufferMock(com.b3dgs.lionengine.graphic.ImageBufferMock) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Example 10 with ImageBufferMock

use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.

the class RasterImageTest method testSavePalette.

/**
 * Test save.
 */
@Test
void testSavePalette() {
    final Media mediaRaster = Medias.create("raster.png");
    final int rastersNumber = ImageInfo.get(mediaRaster).getHeight() - 1;
    final RasterImage raster = new RasterImage(new ImageBufferMock(128, 64), mediaRaster, 16);
    raster.loadRasters(true, "save");
    assertEquals(rastersNumber, raster.getRasters().size());
    assertEquals(mediaRaster, raster.getFile());
    assertEquals(16, raster.getHeight());
    assertEquals(128, raster.getRaster(0).getWidth());
    assertEquals(64, raster.getRaster(0).getHeight());
    final Media folder = Medias.create("raster_save");
    assertTrue(folder.exists(), folder.getFile().getAbsolutePath());
    try {
        for (int i = 0; i < rastersNumber; i++) {
            final Media file = Medias.create("raster_save", i + Constant.DOT + ImageFormat.PNG);
            assertTrue(file.exists(), file.getFile().getAbsolutePath());
        }
    } finally {
        UtilFolder.deleteDirectory(folder.getFile());
    }
}
Also used : ImageBufferMock(com.b3dgs.lionengine.graphic.ImageBufferMock) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Aggregations

ImageBufferMock (com.b3dgs.lionengine.graphic.ImageBufferMock)11 Media (com.b3dgs.lionengine.Media)7 Test (org.junit.jupiter.api.Test)7 Test (org.junit.Test)4 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 Medias (com.b3dgs.lionengine.Medias)1 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)1 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)1 Camera (com.b3dgs.lionengine.game.feature.Camera)1 Services (com.b3dgs.lionengine.game.feature.Services)1 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)1 MapTileRenderer (com.b3dgs.lionengine.game.feature.tile.map.MapTileRenderer)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1 Graphic (com.b3dgs.lionengine.graphic.Graphic)1 GraphicMock (com.b3dgs.lionengine.graphic.GraphicMock)1 Drawable (com.b3dgs.lionengine.graphic.drawable.Drawable)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AfterAll (org.junit.jupiter.api.AfterAll)1