diff --git a/configuration.txt b/configuration.txt index a1733481..e2c581cd 100644 --- a/configuration.txt +++ b/configuration.txt @@ -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 diff --git a/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java b/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java index 766869b0..9fb8e2a7 100644 --- a/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java +++ b/src/main/java/org/dynmap/kzedmap/DefaultTileRenderer.java @@ -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 highlightBlocks = new HashSet(); + 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]; diff --git a/src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java b/src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java new file mode 100644 index 00000000..74209b3b --- /dev/null +++ b/src/main/java/org/dynmap/kzedmap/HighlightTileRenderer.java @@ -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 highlightBlocks = new HashSet(); + + public HighlightTileRenderer(Map 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; + } +} diff --git a/web/js/map.js b/web/js/map.js index 7585e629..3f3e57cf 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -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.