Added ability to specify colorschemes per map/renderer.
This commit is contained in:
parent
803867fbc9
commit
090f417f32
9 changed files with 453 additions and 243 deletions
85
src/main/java/org/dynmap/ColorScheme.java
Normal file
85
src/main/java/org/dynmap/ColorScheme.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package org.dynmap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.dynmap.debug.Debug;
|
||||
|
||||
public class ColorScheme {
|
||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||
private static final HashMap<String, ColorScheme> cache = new HashMap<String, ColorScheme>();
|
||||
|
||||
public String name;
|
||||
public java.util.Map<Integer, Color[]> colors;
|
||||
|
||||
public ColorScheme(String name, java.util.Map<Integer, Color[]> colors) {
|
||||
this.name = name;
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
private static File getColorSchemeDirectory() {
|
||||
return new File(DynmapPlugin.dataDirectory, "colorschemes");
|
||||
}
|
||||
|
||||
public static ColorScheme getScheme(String name) {
|
||||
if (name == null)
|
||||
name = "default";
|
||||
ColorScheme scheme = cache.get(name);
|
||||
if (scheme == null) {
|
||||
scheme = loadScheme(name);
|
||||
cache.put(name, scheme);
|
||||
}
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public static ColorScheme loadScheme(String name) {
|
||||
File colorSchemeFile = new File(getColorSchemeDirectory(), name + ".txt");
|
||||
java.util.Map<Integer, Color[]> colors = new HashMap<Integer, Color[]>();
|
||||
InputStream stream;
|
||||
try {
|
||||
Debug.debug("Loading colors from '" + colorSchemeFile + "'...");
|
||||
stream = new FileInputStream(colorSchemeFile);
|
||||
|
||||
Scanner scanner = new Scanner(stream);
|
||||
int nc = 0;
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("#") || line.equals("")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] split = line.split("\t");
|
||||
if (split.length < 17) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer id = new Integer(split[0]);
|
||||
|
||||
Color[] c = new Color[4];
|
||||
|
||||
/* store colors by raycast sequence number */
|
||||
c[0] = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]), Integer.parseInt(split[4]));
|
||||
c[3] = new Color(Integer.parseInt(split[5]), Integer.parseInt(split[6]), Integer.parseInt(split[7]), Integer.parseInt(split[8]));
|
||||
c[1] = new Color(Integer.parseInt(split[9]), Integer.parseInt(split[10]), Integer.parseInt(split[11]), Integer.parseInt(split[12]));
|
||||
c[2] = new Color(Integer.parseInt(split[13]), Integer.parseInt(split[14]), Integer.parseInt(split[15]), Integer.parseInt(split[16]));
|
||||
|
||||
colors.put(id, c);
|
||||
nc += 1;
|
||||
}
|
||||
scanner.close();
|
||||
} catch (RuntimeException e) {
|
||||
log.log(Level.SEVERE, "Could not load colors '" + name + "' ('" + colorSchemeFile + "').", e);
|
||||
return null;
|
||||
} catch (FileNotFoundException e) {
|
||||
log.log(Level.SEVERE, "Could not load colors '" + name + "' ('" + colorSchemeFile + "'): File not found.", e);
|
||||
}
|
||||
return new ColorScheme(name, colors);
|
||||
}
|
||||
}
|
||||
|
|
@ -58,6 +58,7 @@ public class DynmapPlugin extends JavaPlugin {
|
|||
|
||||
public Timer timer;
|
||||
|
||||
public static File dataDirectory;
|
||||
public static File tilesDirectory;
|
||||
|
||||
public World getWorld() {
|
||||
|
|
@ -73,11 +74,13 @@ public class DynmapPlugin extends JavaPlugin {
|
|||
}
|
||||
|
||||
public void onEnable() {
|
||||
dataDirectory = this.getDataFolder();
|
||||
|
||||
configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
|
||||
configuration.load();
|
||||
|
||||
loadDebuggers();
|
||||
|
||||
|
||||
tilesDirectory = getFile(configuration.getString("tilespath", "web/tiles"));
|
||||
if (!tilesDirectory.isDirectory() && !tilesDirectory.mkdirs()) {
|
||||
log.warning("Could not create directory for tiles ('" + tilesDirectory + "').");
|
||||
|
|
|
|||
|
|
@ -11,15 +11,17 @@ import javax.imageio.ImageIO;
|
|||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.dynmap.ColorScheme;
|
||||
import org.dynmap.DynmapChunk;
|
||||
import org.dynmap.MapTile;
|
||||
import org.dynmap.MapType;
|
||||
import org.dynmap.debug.Debug;
|
||||
import org.dynmap.kzedmap.KzedMap;
|
||||
|
||||
public class FlatMap extends MapType {
|
||||
private ColorScheme colorScheme;
|
||||
|
||||
public FlatMap(Map<String, Object> configuration) {
|
||||
colorScheme = ColorScheme.getScheme((String)configuration.get("colorscheme"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -73,7 +75,7 @@ public class FlatMap extends MapType {
|
|||
int mz = y + t.y * t.size;
|
||||
int my = w.getHighestBlockYAt(mx, mz) - 1;
|
||||
int blockType = w.getBlockTypeIdAt(mx, my, mz);
|
||||
Color[] colors = KzedMap.colors.get(blockType);
|
||||
Color[] colors = colorScheme.colors.get(blockType);
|
||||
if (colors == null)
|
||||
continue;
|
||||
Color c = colors[0];
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ import java.util.Map;
|
|||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.dynmap.ColorScheme;
|
||||
import org.dynmap.debug.Debug;
|
||||
|
||||
public class DefaultTileRenderer implements MapTileRenderer {
|
||||
protected static Color translucent = new Color(0, 0, 0, 0);
|
||||
private String name;
|
||||
protected int maximumHeight = 127;
|
||||
private ColorScheme colorScheme;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
|
@ -30,6 +32,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
if (maximumHeight > 127)
|
||||
maximumHeight = 127;
|
||||
}
|
||||
colorScheme = ColorScheme.getScheme((String)configuration.get("colorscheme"));
|
||||
}
|
||||
|
||||
public boolean render(KzedMapTile tile, File outputFile) {
|
||||
|
|
@ -132,7 +135,7 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
seq = (seq + 1) & 3;
|
||||
|
||||
if (id != 0) {
|
||||
Color[] colors = KzedMap.colors.get(id);
|
||||
Color[] colors = colorScheme.colors.get(id);
|
||||
if (colors != null) {
|
||||
Color c = colors[seq];
|
||||
if (c.getAlpha() > 0) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,10 @@
|
|||
package org.dynmap.kzedmap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -40,15 +33,10 @@ public class KzedMap extends MapType {
|
|||
public static final int anchory = 127;
|
||||
public static final int anchorz = 0;
|
||||
|
||||
public static java.util.Map<Integer, Color[]> colors;
|
||||
MapTileRenderer[] renderers;
|
||||
ZoomedTileRenderer zoomrenderer;
|
||||
|
||||
public KzedMap(Map<String, Object> configuration) {
|
||||
if (colors == null) {
|
||||
colors = loadColorSet("colors.txt");
|
||||
}
|
||||
|
||||
renderers = loadRenderers(configuration);
|
||||
zoomrenderer = new ZoomedTileRenderer(configuration);
|
||||
}
|
||||
|
|
@ -225,56 +213,4 @@ public class KzedMap extends MapType {
|
|||
else
|
||||
return y - (y % zTileHeight);
|
||||
}
|
||||
|
||||
public java.util.Map<Integer, Color[]> loadColorSet(String colorsetpath) {
|
||||
java.util.Map<Integer, Color[]> colors = new HashMap<Integer, Color[]>();
|
||||
|
||||
InputStream stream;
|
||||
|
||||
try {
|
||||
/* load colorset */
|
||||
File cfile = new File(colorsetpath);
|
||||
if (cfile.isFile()) {
|
||||
Debug.debug("Loading colors from '" + colorsetpath + "'...");
|
||||
stream = new FileInputStream(cfile);
|
||||
} else {
|
||||
Debug.debug("Loading colors from jar...");
|
||||
stream = KzedMap.class.getResourceAsStream("/colors.txt");
|
||||
}
|
||||
|
||||
Scanner scanner = new Scanner(stream);
|
||||
int nc = 0;
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("#") || line.equals("")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] split = line.split("\t");
|
||||
if (split.length < 17) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer id = new Integer(split[0]);
|
||||
|
||||
Color[] c = new Color[4];
|
||||
|
||||
/* store colors by raycast sequence number */
|
||||
c[0] = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]), Integer.parseInt(split[4]));
|
||||
c[3] = new Color(Integer.parseInt(split[5]), Integer.parseInt(split[6]), Integer.parseInt(split[7]), Integer.parseInt(split[8]));
|
||||
c[1] = new Color(Integer.parseInt(split[9]), Integer.parseInt(split[10]), Integer.parseInt(split[11]), Integer.parseInt(split[12]));
|
||||
c[2] = new Color(Integer.parseInt(split[13]), Integer.parseInt(split[14]), Integer.parseInt(split[15]), Integer.parseInt(split[16]));
|
||||
|
||||
colors.put(id, c);
|
||||
nc += 1;
|
||||
}
|
||||
scanner.close();
|
||||
} catch (RuntimeException e) {
|
||||
log.log(Level.SEVERE, "Could not load colors", e);
|
||||
return null;
|
||||
} catch (FileNotFoundException e) {
|
||||
log.log(Level.SEVERE, "Could not load colors: file not found", e);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue