use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.
the class RasterImageTest method testNoSmoothDefault.
/**
* Test no smooth default.
*/
@Test
public void testNoSmoothDefault() {
final RasterImage raster = new RasterImage(new ImageBufferMock(100, 200), mediaRaster, 100, false);
raster.loadRasters(50);
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());
}
use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.
the class RasterImageTest method testNoSmoothCache.
/**
* Test no smooth cache.
*/
@Test
public void testNoSmoothCache() {
final RasterImage raster = new RasterImage(Medias.create("image.png"), mediaRaster, 100, false);
raster.loadRasters(50, true, "cache");
Assert.assertEquals(15, raster.getRasters().size());
Assert.assertEquals(mediaRaster, raster.getFile());
Assert.assertEquals(100, raster.getHeight());
Assert.assertFalse(raster.hasSmooth());
Assert.assertEquals(64, raster.getRaster(0).getWidth());
Assert.assertEquals(32, raster.getRaster(0).getHeight());
final Media folder = Medias.create("cache_raster");
Assert.assertTrue(folder.getFile().getAbsolutePath(), folder.exists());
try {
for (int i = 1; i <= 15; i++) {
final Media file = Medias.create("cache_raster", i + Constant.DOT + ImageFormat.PNG);
Assert.assertTrue(file.getFile().getAbsolutePath(), file.exists());
}
final RasterImage cache = new RasterImage(new ImageBufferMock(100, 200), mediaRaster, 100, false);
cache.loadRasters(50, false, "cache");
Assert.assertEquals(15, cache.getRasters().size());
Assert.assertEquals(mediaRaster, cache.getFile());
Assert.assertEquals(100, cache.getHeight());
Assert.assertFalse(cache.hasSmooth());
Assert.assertEquals(64, cache.getRaster(0).getWidth());
Assert.assertEquals(32, cache.getRaster(0).getHeight());
} finally {
UtilFolder.deleteDirectory(folder.getFile());
}
}
use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.
the class RasterImageTest method testSpecificPalette.
/**
* Test specific with palette.
*/
@Test
void testSpecificPalette() {
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, mediaRaster, Constant.EMPTY_STRING, Collections.emptyList());
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());
}
use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.
the class RasterImageTest method testCachePalette.
/**
* Test cache with palette.
*/
@Test
void testCachePalette() {
final Media mediaRaster = Medias.create("raster.png");
final int rastersNumber = ImageInfo.get(mediaRaster).getHeight() - 1;
final RasterImage raster = new RasterImage(Medias.create("image.png"), mediaRaster, 16);
raster.loadRasters(true, "cache");
assertEquals(rastersNumber, raster.getRasters().size());
assertEquals(mediaRaster, raster.getFile());
assertEquals(16, raster.getHeight());
assertEquals(64, raster.getRaster(0).getWidth());
assertEquals(32, raster.getRaster(0).getHeight());
final Media folder = Medias.create("raster_cache");
assertTrue(folder.exists(), folder.getFile().getAbsolutePath());
try {
for (int i = 0; i < rastersNumber; i++) {
final Media file = Medias.create("raster_cache", i + Constant.DOT + ImageFormat.PNG);
assertTrue(file.exists(), file.getFile().getAbsolutePath());
}
final RasterImage cache = new RasterImage(new ImageBufferMock(100, 200), mediaRaster, 100);
cache.loadRasters(false, "cache");
assertEquals(rastersNumber, cache.getRasters().size());
assertEquals(mediaRaster, cache.getFile());
assertEquals(100, cache.getHeight());
assertEquals(64, cache.getRaster(0).getWidth());
assertEquals(32, cache.getRaster(0).getHeight());
} finally {
UtilFolder.deleteDirectory(folder.getFile());
}
}
use of com.b3dgs.lionengine.graphic.ImageBufferMock in project lionengine by b3dgs.
the class MapTileViewerModelTest method testViewer.
/**
* Test the viewer functions.
*/
@Test
void testViewer() {
map.loadSheets(Arrays.asList(Drawable.loadSpriteTiled(new ImageBufferMock(80, 80), 40, 40)));
mapViewer.render(g);
map.create(40, 40, 2, 2);
map.setTile(0, 0, 0);
map.setTile(1, 1, 1);
final AtomicBoolean rendered = new AtomicBoolean();
final MapTileRenderer renderer = (g, tile, x, y) -> rendered.set(true);
mapViewer.render(g);
assertFalse(rendered.get());
mapViewer.addRenderer(renderer);
mapViewer.render(g);
assertTrue(rendered.get());
rendered.set(false);
mapViewer.removeRenderer(renderer);
mapViewer.render(g);
assertFalse(rendered.get());
mapViewer.addRenderer(renderer);
mapViewer.render(g);
assertTrue(rendered.get());
rendered.set(false);
mapViewer.clear();
mapViewer.render(g);
assertFalse(rendered.get());
map.clear();
mapViewer.render(g);
}
Aggregations