package org.dynmap.hdmap; import static org.dynmap.JSONUtils.a; import static org.dynmap.JSONUtils.s; import java.io.File; import java.util.ArrayList; import java.util.List; import org.bukkit.Location; import org.dynmap.ConfigurationNode; import org.dynmap.DynmapChunk; import org.dynmap.DynmapWorld; import org.dynmap.Log; import org.dynmap.MapManager; import org.dynmap.MapTile; import org.dynmap.MapType; import org.dynmap.utils.MapChunkCache; import org.json.simple.JSONObject; public class HDMap extends MapType { private String name; private String prefix; private HDPerspective perspective; private HDShader shader; private HDLighting lighting; private ConfigurationNode configuration; public HDMap(ConfigurationNode configuration) { name = configuration.getString("name", null); if(name == null) { Log.severe("HDMap missing required attribute 'name' - disabled"); return; } String perspectiveid = configuration.getString("perspective", "default"); perspective = MapManager.mapman.hdmapman.perspectives.get(perspectiveid); if(perspective == null) { Log.severe("HDMap '"+name+"' loading invalid perspective '" + perspectiveid + "' - map disabled"); name = null; return; } String shaderid = configuration.getString("shader", "default"); shader = MapManager.mapman.hdmapman.shaders.get(shaderid); if(shader == null) { Log.severe("HDMap '"+name+"' loading invalid shader '" + shaderid + "' - map disabled"); name = null; return; } String lightingid = configuration.getString("lighting", "default"); lighting = MapManager.mapman.hdmapman.lightings.get(lightingid); if(lighting == null) { Log.severe("HDMap '"+name+"' loading invalid lighting '" + lighting + "' - map disabled"); name = null; return; } prefix = configuration.getString("prefix", name); this.configuration = configuration; } public HDShader getShader() { return shader; } public HDPerspective getPerspective() { return perspective; } public HDLighting getLighting() { return lighting; } @Override public MapTile[] getTiles(Location loc) { return perspective.getTiles(loc); } @Override public MapTile[] getAdjecentTiles(MapTile tile) { return perspective.getAdjecentTiles(tile); } @Override public List getRequiredChunks(MapTile tile) { return perspective.getRequiredChunks(tile); } @Override public boolean render(MapChunkCache cache, MapTile tile, File bogus) { if(tile instanceof HDMapTile) return perspective.render(cache, (HDMapTile)tile); else return false; } @Override public List baseZoomFilePrefixes() { ArrayList s = new ArrayList(); s.add(prefix); if(lighting.isNightAndDayEnabled()) s.add(prefix + "_day"); return s; } public int baseZoomFileStepSize() { return 1; } private static final int[] stepseq = { 3, 1, 2, 0 }; public MapStep zoomFileMapStep() { return MapStep.X_PLUS_Y_MINUS; } public int[] zoomFileStepSequence() { return stepseq; } /* How many bits of coordinate are shifted off to make big world directory name */ public int getBigWorldShift() { return 5; } /* Returns true if big world file structure is in effect for this map */ @Override public boolean isBigWorldMap(DynmapWorld w) { return true; } /* We always use it on these maps */ @Override public String getName() { return name; } public String getPrefix() { return prefix; } @Override public void buildClientConfiguration(JSONObject worldObject, DynmapWorld world) { ConfigurationNode c = configuration; JSONObject o = new JSONObject(); s(o, "type", "HDMapType"); s(o, "name", name); s(o, "title", c.getString("title")); s(o, "icon", c.getString("icon")); s(o, "prefix", prefix); s(o, "background", c.getString("background")); s(o, "backgroundday", c.getString("backgroundday")); s(o, "backgroundnight", c.getString("backgroundnight")); s(o, "bigmap", true); perspective.addClientConfiguration(o); shader.addClientConfiguration(o); lighting.addClientConfiguration(o); a(worldObject, "maps", o); } }