Add tile data coloring (aka colored wool support), combine rendering
of default tiles and their zoomed counterparts (saves reloading the default tile, and keeps the scale levels of the map consistent during a fullrender and otherwise)
This commit is contained in:
parent
0a8f2a182a
commit
17644a5778
10 changed files with 241 additions and 106 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package org.dynmap.kzedmap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.File;
|
||||
|
|
@ -25,6 +27,25 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
|
||||
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
|
||||
protected Color highlightColor = new Color(255, 0, 0);
|
||||
|
||||
private static final Color[] woolshades = {
|
||||
Color.WHITE,
|
||||
Color.ORANGE,
|
||||
Color.MAGENTA,
|
||||
new Color(51,204,255),
|
||||
Color.YELLOW,
|
||||
new Color(102,255,102),
|
||||
Color.PINK,
|
||||
Color.GRAY,
|
||||
Color.LIGHT_GRAY,
|
||||
Color.CYAN,
|
||||
new Color(255,0,255),
|
||||
Color.BLUE,
|
||||
new Color(102,51,51),
|
||||
Color.GREEN,
|
||||
Color.RED,
|
||||
Color.BLACK
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
|
@ -111,27 +132,90 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
final File fname = outputFile;
|
||||
final KzedMapTile mtile = tile;
|
||||
final BufferedImage img = im;
|
||||
MapManager.mapman.enqueueImageWrite(new Runnable() {
|
||||
final KzedZoomedMapTile zmtile = new KzedZoomedMapTile(mtile.getWorld(),
|
||||
(KzedMap) mtile.getMap(), mtile);
|
||||
final File zoomFile = MapManager.mapman.getTileFile(zmtile);
|
||||
|
||||
MapManager.mapman.enqueueImageWrite(new Runnable() {
|
||||
public void run() {
|
||||
Debug.debug("saving image " + fname.getPath());
|
||||
try {
|
||||
ImageIO.write(img, "png", fname);
|
||||
} catch (IOException e) {
|
||||
Debug.error("Failed to save image: " + fname.getPath(), e);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
Debug.error("Failed to save image (NullPointerException): " + fname.getPath(), e);
|
||||
}
|
||||
img.flush();
|
||||
mtile.file = fname;
|
||||
((KzedMap)mtile.getMap()).invalidateTile(
|
||||
new KzedZoomedMapTile(mtile.getWorld(), (KzedMap) mtile.getMap(), mtile));
|
||||
MapManager.mapman.pushUpdate(mtile.getWorld(),
|
||||
new Client.Tile(mtile.getFilename()));
|
||||
doFileWrites(fname, mtile, img, zmtile, zoomFile);
|
||||
}
|
||||
});
|
||||
|
||||
return !isempty;
|
||||
}
|
||||
|
||||
private void doFileWrites(final File fname, final KzedMapTile mtile,
|
||||
final BufferedImage img, final KzedZoomedMapTile zmtile, final File zoomFile) {
|
||||
Debug.debug("saving image " + fname.getPath());
|
||||
try {
|
||||
ImageIO.write(img, "png", fname);
|
||||
} catch (IOException e) {
|
||||
Debug.error("Failed to save image: " + fname.getPath(), e);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
Debug.error("Failed to save image (NullPointerException): " + fname.getPath(), e);
|
||||
}
|
||||
mtile.file = fname;
|
||||
// Since we've already got the new tile, and we're on an async thread, just
|
||||
// make the zoomed tile here
|
||||
int px = mtile.px;
|
||||
int py = mtile.py;
|
||||
int zpx = zmtile.getTileX();
|
||||
int zpy = zmtile.getTileY();
|
||||
|
||||
/* scaled size */
|
||||
int scw = KzedMap.tileWidth / 2;
|
||||
int sch = KzedMap.tileHeight / 2;
|
||||
|
||||
/* origin in zoomed-out tile */
|
||||
int ox = 0;
|
||||
int oy = 0;
|
||||
|
||||
if (zpx != px)
|
||||
ox = scw;
|
||||
if (zpy != py)
|
||||
oy = sch;
|
||||
|
||||
BufferedImage zIm = null;
|
||||
try {
|
||||
zIm = ImageIO.read(zoomFile);
|
||||
} catch (IOException e) {
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
}
|
||||
|
||||
if (zIm == null) {
|
||||
/* create new one */
|
||||
zIm = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||
Debug.debug("New zoom-out tile created " + zmtile.getFilename());
|
||||
} else {
|
||||
Debug.debug("Loaded zoom-out tile from " + zmtile.getFilename());
|
||||
}
|
||||
|
||||
/* blit scaled rendered tile onto zoom-out tile */
|
||||
Graphics2D g2 = zIm.createGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g2.drawImage(img, ox, oy, scw, sch, null);
|
||||
|
||||
img.flush();
|
||||
|
||||
/* save zoom-out tile */
|
||||
|
||||
try {
|
||||
ImageIO.write(zIm, "png", zoomFile);
|
||||
Debug.debug("Saved zoom-out tile at " + zoomFile.getName());
|
||||
} catch (IOException e) {
|
||||
Debug.error("Failed to save zoom-out tile: " + zoomFile.getName(), e);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
Debug.error("Failed to save zoom-out tile (NullPointerException): " + zoomFile.getName(), e);
|
||||
}
|
||||
zIm.flush();
|
||||
/* Push updates for both files.*/
|
||||
MapManager.mapman.pushUpdate(mtile.getWorld(),
|
||||
new Client.Tile(mtile.getFilename()));
|
||||
MapManager.mapman.pushUpdate(zmtile.getWorld(),
|
||||
new Client.Tile(zmtile.getFilename()));
|
||||
}
|
||||
|
||||
|
||||
protected Color scan(World world, int x, int y, int z, int seq) {
|
||||
for (;;) {
|
||||
|
|
@ -139,7 +223,10 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
return translucent;
|
||||
|
||||
int id = world.getBlockTypeIdAt(x, y, z);
|
||||
|
||||
byte data = 0;
|
||||
if(colorScheme.datacolors[id] != null) { /* If data colored */
|
||||
data = world.getBlockAt(x, y, z).getData();
|
||||
}
|
||||
switch (seq) {
|
||||
case 0:
|
||||
x--;
|
||||
|
|
@ -161,7 +248,11 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
if (highlightBlocks.contains(id)) {
|
||||
return highlightColor;
|
||||
}
|
||||
Color[] colors = colorScheme.colors.get(id);
|
||||
Color[] colors;
|
||||
if(data != 0)
|
||||
colors = colorScheme.datacolors[id][data];
|
||||
else
|
||||
colors = colorScheme.colors[id];
|
||||
if (colors != null) {
|
||||
Color c = colors[seq];
|
||||
if (c.getAlpha() > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue