Skip to content

Commit

Permalink
maps improvement + world coords option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 22, 2017
1 parent 0b06dbc commit a924a00
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
Expand Up @@ -63,9 +63,10 @@ public MapScriptContainer(YamlConfiguration configurationSection, String scriptC
// # Specify a cursor - {RED|GREEN|WHITE|BLUE)_POINTER, WHITE_CROSS, WHITE_CIRCLE, RED_MARKER, SMALL_WHITE_CIRCLE,
// # MANSION, TEMPLE
// cursor: red_marker
// # Supported on all objects: x/y positions.
// # Supported on all objects: x/y positions, and whether to use worldly or map coordinates.
// x: 5
// y: 5
// world_coordinates: false
// </code>
//
// -->
Expand Down Expand Up @@ -98,6 +99,7 @@ public void applyTo(MapView mapView) {
String x = objectSection.getString("X", "0");
String y = objectSection.getString("Y", "0");
String visible = objectSection.getString("VISIBLE", "true");
boolean worldC = objectSection.contains("WORLD_COORDINATES") && aH.getBooleanFrom(objectSection.getString("WORLD_COORDINATES", "false"));
if (type.equals("IMAGE")) {
if (!objectSection.contains("IMAGE")) {
dB.echoError("Map script '" + getName() + "'s image '" + objectKey
Expand Down Expand Up @@ -141,6 +143,12 @@ else if (type.equals("DOT")) {
renderer.addObject(new MapDot(x, y, visible, debug, objectSection.getString("RADIUS", "1"),
objectSection.getString("COLOR", "black")));
}
else {
dB.echoError("Weird map data!");
}
if (worldC && renderer.mapObjects.size() > 0) {
renderer.mapObjects.get(renderer.mapObjects.size() - 1).worldCoordinates = true;
}
}
}
DenizenMapManager.setMap(mapView, renderer);
Expand Down
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import net.aufdemrand.denizencore.utilities.NaturalOrderComparator;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -74,7 +75,8 @@ public static void reloadMaps() {
String xTag = objectsData.getString(objectKey + ".x");
String yTag = objectsData.getString(objectKey + ".y");
String visibilityTag = objectsData.getString(objectKey + ".visibility");
boolean debug = objectsData.getBoolean(objectKey + ".debug");
boolean debug = aH.getBooleanFrom(objectsData.getString(objectKey + ".debug", "false"));
boolean worldC = aH.getBooleanFrom(objectsData.getString(objectKey + ".world_coordinates", "false"));
MapObject object = null;
if (type.equals("CURSOR")) {
object = new MapCursor(xTag, yTag, visibilityTag, debug,
Expand All @@ -97,6 +99,7 @@ else if (type.equals("TEXT")) {
objectsData.getString(objectKey + ".text"));
}
if (object != null) {
object.worldCoordinates = worldC;
renderer.addObject(object);
}
}
Expand Down
Expand Up @@ -12,7 +12,7 @@

public class DenizenMapRenderer extends MapRenderer {

private List<MapObject> mapObjects = new ArrayList<MapObject>();
public List<MapObject> mapObjects = new ArrayList<MapObject>();
private List<MapRenderer> oldMapRenderers;
private boolean autoUpdate;

Expand Down Expand Up @@ -92,6 +92,7 @@ public void render(MapView mapView, MapCanvas mapCanvas, Player player) {
dPlayer p = dPlayer.mirrorBukkitPlayer(player);
for (MapObject object : mapObjects) {
if (autoUpdate) {
object.lastMap = mapView;
object.update(p, uuid);
}
if (object.isVisibleTo(p, uuid)) {
Expand Down
Expand Up @@ -21,6 +21,10 @@ public abstract class MapObject {
protected Map<UUID, Boolean> currentVisibility = new HashMap<UUID, Boolean>();
protected boolean debug;

public MapView lastMap;

public boolean worldCoordinates = false;

public MapObject(String xTag, String yTag, String visibilityTag, boolean debug) {
this.xTag = xTag;
this.yTag = yTag;
Expand All @@ -29,25 +33,37 @@ public MapObject(String xTag, String yTag, String visibilityTag, boolean debug)
}

public void update(dPlayer player, UUID uuid) {
currentX.put(uuid, (int) aH.getDoubleFrom(tag(xTag, player)));
currentY.put(uuid, (int) aH.getDoubleFrom(tag(yTag, player)));
currentX.put(uuid, getX(player, uuid));
currentY.put(uuid, getY(player, uuid));
currentVisibility.put(uuid, aH.getBooleanFrom(tag(visibilityTag, player)));
}

public int getX(dPlayer player, UUID uuid) {
if (!currentX.containsKey(uuid)) {
//if (!currentX.containsKey(uuid)) {
int x = (int) aH.getDoubleFrom(tag(xTag, player));
currentX.put(uuid, x);
//}
int tx = x;
if (worldCoordinates && lastMap != null) {
float f = (float) (tx - lastMap.getCenterX()) / (1 << (lastMap.getScale().getValue()));
byte bx = (byte) ((int) ((f * 2.0F) + 0.5D));
return bx;
}
return currentX.get(uuid);
return tx;
}

public int getY(dPlayer player, UUID uuid) {
if (!currentY.containsKey(uuid)) {
//if (!currentY.containsKey(uuid)) {
int y = (int) aH.getDoubleFrom(tag(yTag, player));
currentY.put(uuid, y);
//}
int ty = y;
if (worldCoordinates && lastMap != null) {
float f1 = (float) (ty - lastMap.getCenterZ()) / (1 << (lastMap.getScale().getValue()));
byte by = (byte) ((int) ((f1 * 2.0F) + 0.5D));
return by;
}
return currentY.get(uuid);
return ty;
}

public boolean isVisibleTo(dPlayer player, UUID uuid) {
Expand All @@ -68,6 +84,7 @@ public Map<String, Object> getSaveData() {
data.put("y", yTag);
data.put("visibility", visibilityTag);
data.put("debug", debug ? "true" : "false");
data.put("world_coordinates", worldCoordinates ? "true" : "false");
return data;
}

Expand Down

0 comments on commit a924a00

Please sign in to comment.