Added HighlightTileRenderer (thanks in part to rockNme2349)

This commit is contained in:
FrozenCow 2011-04-07 15:46:50 +02:00
parent eb276dd59d
commit d53b3bc340
4 changed files with 119 additions and 4 deletions

View File

@ -43,6 +43,14 @@ worlds:
prefix: t
maximumheight: 127
colorscheme: default
#- class: org.dynmap.kzedmap.HighlightTileRenderer
# prefix: ht
# maximumheight: 127
# colorscheme: default
# highlight: # For highlighting multiple block-types.
# - 56 # Highlight diamond-ore
# - 66 # Highlight minecart track
# highlight: 56 # For highlighting a single block-type.
- class: org.dynmap.kzedmap.CaveTileRenderer
prefix: ct
maximumheight: 127
@ -101,6 +109,10 @@ web:
title: Surface
name: surface
prefix: t
#- type: KzedMapType
# title: Highlighted Map
# name: highlight
# prefix: ht
- type: KzedMapType
title: Cave
name: cave

View File

@ -5,6 +5,7 @@ import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import javax.imageio.ImageIO;
@ -15,9 +16,12 @@ import org.dynmap.debug.Debug;
public class DefaultTileRenderer implements MapTileRenderer {
protected static final Color translucent = new Color(0, 0, 0, 0);
private String name;
protected String name;
protected int maximumHeight = 127;
private ColorScheme colorScheme;
protected ColorScheme colorScheme;
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
protected Color highlightColor = new Color(255, 0, 0);
@Override
public String getName() {
@ -135,6 +139,9 @@ public class DefaultTileRenderer implements MapTileRenderer {
seq = (seq + 1) & 3;
if (id != 0) {
if (highlightBlocks.contains(id)) {
return highlightColor;
}
Color[] colors = colorScheme.colors.get(id);
if (colors != null) {
Color c = colors[seq];

View File

@ -0,0 +1,93 @@
package org.dynmap.kzedmap;
import java.awt.Color;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.bukkit.World;
public class HighlightTileRenderer extends DefaultTileRenderer {
protected HashSet<Integer> highlightBlocks = new HashSet<Integer>();
public HighlightTileRenderer(Map<String, Object> configuration) {
super(configuration);
Object highlightObj = configuration.get("highlight");
if (highlightObj instanceof List<?>) {
for(Object o : (List<?>)highlightObj) {
highlightBlocks.add((Integer)o);
}
} else if (highlightObj instanceof Integer) {
highlightBlocks.add((Integer)highlightObj);
}
}
@Override
protected Color scan(World world, int x, int y, int z, int seq) {
Color result = translucent;
for (;;) {
if (y < 0) {
break;
}
int id = world.getBlockTypeIdAt(x, y, z);
switch (seq) {
case 0:
x--;
break;
case 1:
y--;
break;
case 2:
z++;
break;
case 3:
y--;
break;
}
seq = (seq + 1) & 3;
if (id != 0) {
Color[] colors = colorScheme.colors.get(id);
if (colors != null) {
Color c = colors[seq];
if (highlightBlocks.contains(id)) {
return c;
}
if (c.getAlpha() > 0) {
/* we found something that isn't transparent! */
/*
* if (c.getAlpha() == 255) { return c; }
*/
/* this block is transparent, so recurse */
// No need to blend if result is opaque.
if (result.getAlpha() < 255) {
Color bg = c;
c = result;
int cr = c.getRed();
int cg = c.getGreen();
int cb = c.getBlue();
int ca = c.getAlpha();
cr *= ca;
cg *= ca;
cb *= ca;
int na = 255 - ca;
result = new Color((bg.getRed() * na + cr) >> 8, (bg.getGreen() * na + cg) >> 8, (bg.getBlue() * na + cb) >> 8,
Math.min(255, bg.getAlpha()+c.getAlpha()) // Not really correct, but gets the job done without recursion while still looking ok.
);
}
}
}
}
}
return result;
}
}

View File

@ -282,8 +282,11 @@ DynMap.prototype = {
$.each(me.options.components, function(index, configuration) {
loadjs('js/' + configuration.type + '.js', function() {
var componentconstructor = componentconstructors[configuration.type];
me.components.push(new componentconstructor(me, configuration));
if (componentconstructor) {
me.components.push(new componentconstructor(me, configuration));
} else {
// Could not load component. We'll ignore this for the moment.
}
componentstoload--;
if (componentstoload == 0) {
// Actually start updating once all components are loaded.