Implement BlueMapAPI 1.5.0

This commit is contained in:
Blue (Lukas Rieger) 2021-03-23 00:02:20 +01:00
parent 658ff7007d
commit 412e607e09
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
9 changed files with 747 additions and 41 deletions

@ -1 +1 @@
Subproject commit ea8d237925e4efb1e1fb17d9ec622ea9aa80b43c
Subproject commit 6bdbdb150db6ae0b2b4bf10fc9632e03367b310f

@ -1 +1 @@
Subproject commit 2a5a65fff8b2d2643ec588a6775da589e6d37b04
Subproject commit 99017af1ff3d4ed640e931f79d198680453a52fc

View File

@ -0,0 +1,241 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.common.api.marker;
import com.flowpowered.math.vector.Vector2d;
import com.flowpowered.math.vector.Vector3d;
import com.google.common.base.Preconditions;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.marker.ExtrudeMarker;
import de.bluecolored.bluemap.api.marker.Shape;
import ninja.leaping.configurate.ConfigurationNode;
import java.awt.*;
import java.util.List;
public class ExtrudeMarkerImpl extends ObjectMarkerImpl implements ExtrudeMarker {
public static final String MARKER_TYPE = "extrude";
private Shape shape;
private float shapeMinY;
private float shapeMaxY;
private boolean depthTest;
private int lineWidth;
private Color lineColor, fillColor;
private boolean hasUnsavedChanges;
public ExtrudeMarkerImpl(String id, BlueMapMap map, Vector3d position, Shape shape, float shapeMinY, float shapeMaxY) {
super(id, map, position);
Preconditions.checkNotNull(shape);
this.shape = shape;
this.shapeMinY = shapeMinY;
this.shapeMaxY = shapeMaxY;
this.lineWidth = 2;
this.lineColor = new Color(255, 0, 0, 200);
this.fillColor = new Color(200, 0, 0, 100);
this.hasUnsavedChanges = true;
}
@Override
public String getType() {
return MARKER_TYPE;
}
@Override
public Shape getShape() {
return this.shape;
}
@Override
public float getShapeMinY() {
return shapeMinY;
}
@Override
public float getShapeMaxY() {
return shapeMaxY;
}
@Override
public synchronized void setShape(Shape shape, float shapeMinY, float shapeMaxY) {
Preconditions.checkNotNull(shape);
this.shape = shape;
this.shapeMinY = shapeMinY;
this.shapeMaxY = shapeMaxY;
this.hasUnsavedChanges = true;
}
@Override
public boolean isDepthTestEnabled() {
return this.depthTest;
}
@Override
public void setDepthTestEnabled(boolean enabled) {
this.depthTest = enabled;
this.hasUnsavedChanges = true;
}
@Override
public int getLineWidth() {
return lineWidth;
}
@Override
public void setLineWidth(int lineWidth) {
this.lineWidth = lineWidth;
this.hasUnsavedChanges = true;
}
@Override
public Color getLineColor() {
return this.lineColor;
}
@Override
public synchronized void setLineColor(Color color) {
Preconditions.checkNotNull(color);
this.lineColor = color;
this.hasUnsavedChanges = true;
}
@Override
public Color getFillColor() {
return this.fillColor;
}
@Override
public synchronized void setFillColor(Color color) {
Preconditions.checkNotNull(color);
this.fillColor = color;
this.hasUnsavedChanges = true;
}
@Override
public void load(BlueMapAPI api, ConfigurationNode markerNode, boolean overwriteChanges) throws MarkerFileFormatException {
super.load(api, markerNode, overwriteChanges);
if (!overwriteChanges && hasUnsavedChanges) return;
this.hasUnsavedChanges = false;
this.shape = readShape(markerNode.getNode("shape"));
this.shapeMinY = markerNode.getNode("shapeMinY").getFloat(0);
this.shapeMaxY = markerNode.getNode("shapeMaxY").getFloat(255);
this.depthTest = markerNode.getNode("depthTest").getBoolean(true);
this.lineWidth = markerNode.getNode("lineWidth").getInt(2);
this.lineColor = readColor(markerNode.getNode("lineColor"));
this.fillColor = readColor(markerNode.getNode("fillColor"));
}
@Override
public void save(ConfigurationNode markerNode) {
super.save(markerNode);
writeShape(markerNode.getNode("shape"), this.shape);
markerNode.getNode("shapeMinY").setValue(Math.round(shapeMinY * 1000f) / 1000f);
markerNode.getNode("shapeMaxY").setValue(Math.round(shapeMaxY * 1000f) / 1000f);
markerNode.getNode("depthTest").setValue(this.depthTest);
markerNode.getNode("lineWidth").setValue(this.lineWidth);
writeColor(markerNode.getNode("lineColor"), this.lineColor);
writeColor(markerNode.getNode("fillColor"), this.fillColor);
hasUnsavedChanges = false;
}
private Shape readShape(ConfigurationNode node) throws MarkerFileFormatException {
List<? extends ConfigurationNode> posNodes = node.getChildrenList();
if (posNodes.size() < 3) throw new MarkerFileFormatException("Failed to read shape: point-list has fewer than 3 entries!");
Vector2d[] positions = new Vector2d[posNodes.size()];
for (int i = 0; i < positions.length; i++) {
positions[i] = readShapePos(posNodes.get(i));
}
return new Shape(positions);
}
private static Vector2d readShapePos(ConfigurationNode node) throws MarkerFileFormatException {
ConfigurationNode nx, nz;
nx = node.getNode("x");
nz = node.getNode("z");
if (nx.isVirtual() || nz.isVirtual()) throw new MarkerFileFormatException("Failed to read shape position: Node x or z is not set!");
return new Vector2d(
nx.getDouble(),
nz.getDouble()
);
}
private static Color readColor(ConfigurationNode node) throws MarkerFileFormatException {
ConfigurationNode nr, ng, nb, na;
nr = node.getNode("r");
ng = node.getNode("g");
nb = node.getNode("b");
na = node.getNode("a");
if (nr.isVirtual() || ng.isVirtual() || nb.isVirtual()) throw new MarkerFileFormatException("Failed to read color: Node r,g or b is not set!");
float alpha = na.getFloat(1);
if (alpha < 0 || alpha > 1) throw new MarkerFileFormatException("Failed to read color: alpha value out of range (0-1)!");
try {
return new Color(nr.getInt(), ng.getInt(), nb.getInt(), (int)(alpha * 255));
} catch (IllegalArgumentException ex) {
throw new MarkerFileFormatException("Failed to read color: " + ex.getMessage(), ex);
}
}
private static void writeShape(ConfigurationNode node, Shape shape) {
for (int i = 0; i < shape.getPointCount(); i++) {
ConfigurationNode pointNode = node.appendListNode();
Vector2d point = shape.getPoint(i);
pointNode.getNode("x").setValue(Math.round(point.getX() * 1000d) / 1000d);
pointNode.getNode("z").setValue(Math.round(point.getY() * 1000d) / 1000d);
}
}
private static void writeColor(ConfigurationNode node, Color color) {
int r = color.getRed();
int g = color.getGreen();
int b = color.getBlue();
float a = color.getAlpha() / 255f;
node.getNode("r").setValue(r);
node.getNode("g").setValue(g);
node.getNode("b").setValue(b);
node.getNode("a").setValue(a);
}
}

View File

@ -0,0 +1,111 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.common.api.marker;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.marker.HtmlMarker;
import ninja.leaping.configurate.ConfigurationNode;
public class HtmlMarkerImpl extends MarkerImpl implements HtmlMarker {
public static final String MARKER_TYPE = "html";
private String html;
private Vector2i anchor;
private boolean hasUnsavedChanges;
public HtmlMarkerImpl(String id, BlueMapMap map, Vector3d position, String html) {
super(id, map, position);
this.html = html;
this.anchor = new Vector2i(25, 45);
this.hasUnsavedChanges = true;
}
@Override
public String getType() {
return MARKER_TYPE;
}
@Override
public Vector2i getAnchor() {
return anchor;
}
@Override
public void setAnchor(Vector2i anchor) {
this.anchor = anchor;
this.hasUnsavedChanges = true;
}
@Override
public String getHtml() {
return html;
}
@Override
public synchronized void setHtml(String html) {
this.html = html;
this.hasUnsavedChanges = true;
}
@Override
public synchronized void load(BlueMapAPI api, ConfigurationNode markerNode, boolean overwriteChanges) throws MarkerFileFormatException {
super.load(api, markerNode, overwriteChanges);
if (!overwriteChanges && hasUnsavedChanges) return;
this.hasUnsavedChanges = false;
this.html = markerNode.getNode("html").getString("");
this.anchor = readAnchor(markerNode.getNode("anchor"));
}
@Override
public synchronized void save(ConfigurationNode markerNode) {
super.save(markerNode);
markerNode.getNode("html").setValue(this.html);
writeAnchor(markerNode.getNode("anchor"), this.anchor);
hasUnsavedChanges = false;
}
private static Vector2i readAnchor(ConfigurationNode node) {
return new Vector2i(
node.getNode("x").getInt(0),
node.getNode("y").getInt(0)
);
}
private static void writeAnchor(ConfigurationNode node, Vector2i anchor) {
node.getNode("x").setValue(anchor.getX());
node.getNode("y").setValue(anchor.getY());
}
}

View File

@ -0,0 +1,208 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.common.api.marker;
import com.flowpowered.math.vector.Vector3d;
import com.google.common.base.Preconditions;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.marker.Line;
import de.bluecolored.bluemap.api.marker.LineMarker;
import ninja.leaping.configurate.ConfigurationNode;
import java.awt.*;
import java.util.List;
public class LineMarkerImpl extends ObjectMarkerImpl implements LineMarker {
public static final String MARKER_TYPE = "line";
private Line line;
private boolean depthTest;
private int lineWidth;
private Color lineColor;
private boolean hasUnsavedChanges;
public LineMarkerImpl(String id, BlueMapMap map, Vector3d position, Line line) {
super(id, map, position);
Preconditions.checkNotNull(line);
this.line = line;
this.lineWidth = 2;
this.lineColor = new Color(255, 0, 0, 200);
this.hasUnsavedChanges = true;
}
@Override
public String getType() {
return MARKER_TYPE;
}
@Override
public Line getLine() {
return line;
}
@Override
public synchronized void setLine(Line line) {
Preconditions.checkNotNull(line);
this.line = line;
this.hasUnsavedChanges = true;
}
@Override
public boolean isDepthTestEnabled() {
return this.depthTest;
}
@Override
public void setDepthTestEnabled(boolean enabled) {
this.depthTest = enabled;
this.hasUnsavedChanges = true;
}
@Override
public int getLineWidth() {
return lineWidth;
}
@Override
public void setLineWidth(int lineWidth) {
this.lineWidth = lineWidth;
this.hasUnsavedChanges = true;
}
@Override
public Color getLineColor() {
return this.lineColor;
}
@Override
public synchronized void setLineColor(Color color) {
Preconditions.checkNotNull(color);
this.lineColor = color;
this.hasUnsavedChanges = true;
}
@Override
public void load(BlueMapAPI api, ConfigurationNode markerNode, boolean overwriteChanges) throws MarkerFileFormatException {
super.load(api, markerNode, overwriteChanges);
if (!overwriteChanges && hasUnsavedChanges) return;
this.hasUnsavedChanges = false;
this.line = readLine(markerNode.getNode("line"));
this.depthTest = markerNode.getNode("depthTest").getBoolean(true);
this.lineWidth = markerNode.getNode("lineWidth").getInt(2);
this.lineColor = readColor(markerNode.getNode("lineColor"));
}
@Override
public void save(ConfigurationNode markerNode) {
super.save(markerNode);
writeLine(markerNode.getNode("line"), this.line);
markerNode.getNode("depthTest").setValue(this.depthTest);
markerNode.getNode("lineWidth").setValue(this.lineWidth);
writeColor(markerNode.getNode("lineColor"), this.lineColor);
hasUnsavedChanges = false;
}
private Line readLine(ConfigurationNode node) throws MarkerFileFormatException {
List<? extends ConfigurationNode> posNodes = node.getChildrenList();
if (posNodes.size() < 3) throw new MarkerFileFormatException("Failed to read line: point-list has fewer than 2 entries!");
Vector3d[] positions = new Vector3d[posNodes.size()];
for (int i = 0; i < positions.length; i++) {
positions[i] = readLinePos(posNodes.get(i));
}
return new Line(positions);
}
private static Vector3d readLinePos(ConfigurationNode node) throws MarkerFileFormatException {
ConfigurationNode nx, ny, nz;
nx = node.getNode("x");
ny = node.getNode("y");
nz = node.getNode("z");
if (nx.isVirtual() || ny.isVirtual() || nz.isVirtual()) throw new MarkerFileFormatException("Failed to read line position: Node x, y or z is not set!");
return new Vector3d(
nx.getDouble(),
ny.getDouble(),
nz.getDouble()
);
}
private static Color readColor(ConfigurationNode node) throws MarkerFileFormatException {
ConfigurationNode nr, ng, nb, na;
nr = node.getNode("r");
ng = node.getNode("g");
nb = node.getNode("b");
na = node.getNode("a");
if (nr.isVirtual() || ng.isVirtual() || nb.isVirtual()) throw new MarkerFileFormatException("Failed to read color: Node r,g or b is not set!");
float alpha = na.getFloat(1);
if (alpha < 0 || alpha > 1) throw new MarkerFileFormatException("Failed to read color: alpha value out of range (0-1)!");
try {
return new Color(nr.getInt(), ng.getInt(), nb.getInt(), (int)(alpha * 255));
} catch (IllegalArgumentException ex) {
throw new MarkerFileFormatException("Failed to read color: " + ex.getMessage(), ex);
}
}
private static void writeLine(ConfigurationNode node, Line line) {
for (int i = 0; i < line.getPointCount(); i++) {
ConfigurationNode pointNode = node.appendListNode();
Vector3d point = line.getPoint(i);
pointNode.getNode("x").setValue(Math.round(point.getX() * 1000d) / 1000d);
pointNode.getNode("y").setValue(Math.round(point.getY() * 1000d) / 1000d);
pointNode.getNode("z").setValue(Math.round(point.getZ() * 1000d) / 1000d);
}
}
private static void writeColor(ConfigurationNode node, Color color) {
int r = color.getRed();
int g = color.getGreen();
int b = color.getBlue();
float a = color.getAlpha() / 255f;
node.getNode("r").setValue(r);
node.getNode("g").setValue(g);
node.getNode("b").setValue(b);
node.getNode("a").setValue(a);
}
}

View File

@ -28,6 +28,7 @@ import com.flowpowered.math.vector.Vector3d;
import com.google.common.collect.Sets;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.marker.Line;
import de.bluecolored.bluemap.api.marker.Marker;
import de.bluecolored.bluemap.api.marker.MarkerSet;
import de.bluecolored.bluemap.api.marker.Shape;
@ -43,9 +44,9 @@ public class MarkerSetImpl implements MarkerSet {
private String label;
private boolean toggleable;
private boolean isDefaultHidden;
private Map<String, MarkerImpl> markers;
private final Map<String, MarkerImpl> markers;
private Set<String> removedMarkers;
private final Set<String> removedMarkers;
private boolean hasUnsavedChanges;
@ -120,15 +121,45 @@ public class MarkerSetImpl implements MarkerSet {
}
@Override
public synchronized ShapeMarkerImpl createShapeMarker(String id, BlueMapMap map, Vector3d position, Shape shape, float height) {
public HtmlMarkerImpl createHtmlMarker(String id, BlueMapMap map, Vector3d position, String html) {
removeMarker(id);
HtmlMarkerImpl marker = new HtmlMarkerImpl(id, map, position, html);
markers.put(id, marker);
return marker;
}
@Override
public synchronized ShapeMarkerImpl createShapeMarker(String id, BlueMapMap map, Vector3d position, Shape shape, float y) {
removeMarker(id);
ShapeMarkerImpl marker = new ShapeMarkerImpl(id, map, position, shape, height);
ShapeMarkerImpl marker = new ShapeMarkerImpl(id, map, position, shape, y);
markers.put(id, marker);
return marker;
}
@Override
public ExtrudeMarkerImpl createExtrudeMarker(String id, BlueMapMap map, Vector3d position, Shape shape, float minY, float maxY) {
removeMarker(id);
ExtrudeMarkerImpl marker = new ExtrudeMarkerImpl(id, map, position, shape, minY, maxY);
markers.put(id, marker);
return marker;
}
@Override
public LineMarkerImpl createLineMarker(String id, BlueMapMap map, Vector3d position, Line line) {
removeMarker(id);
LineMarkerImpl marker = new LineMarkerImpl(id, map, position, line);
markers.put(id, marker);
return marker;
}
@Override
public synchronized boolean removeMarker(String id) {
if (markers.remove(id) != null) {
@ -141,6 +172,7 @@ public class MarkerSetImpl implements MarkerSet {
public synchronized void load(BlueMapAPI api, ConfigurationNode node, boolean overwriteChanges) throws MarkerFileFormatException {
BlueMapMap dummyMap = api.getMaps().iterator().next();
Shape dummyShape = Shape.createRect(0d, 0d, 1d, 1d);
Line dummyLine = new Line(Vector3d.ZERO, Vector3d.ONE);
Set<String> externallyRemovedMarkers = new HashSet<>(this.markers.keySet());
for (ConfigurationNode markerNode : node.getNode("marker").getChildrenList()) {
@ -160,22 +192,36 @@ public class MarkerSetImpl implements MarkerSet {
try {
if (marker == null || !marker.getType().equals(type)) {
switch (type) {
case POIMarkerImpl.MARKER_TYPE:
marker = new POIMarkerImpl(id, dummyMap, Vector3d.ZERO);
break;
case ShapeMarkerImpl.MARKER_TYPE:
marker = new ShapeMarkerImpl(id, dummyMap, Vector3d.ZERO, dummyShape, 0f);
break;
default:
Logger.global.logDebug("Marker-API: Failed to load marker '" + id + "' in the set '" + this.id + "': Unknown marker-type '" + type + "'!");
continue;
case HtmlMarkerImpl.MARKER_TYPE :
marker = new HtmlMarkerImpl(id, dummyMap, Vector3d.ZERO, "");
break;
case POIMarkerImpl.MARKER_TYPE:
marker = new POIMarkerImpl(id, dummyMap, Vector3d.ZERO);
break;
case ShapeMarkerImpl.MARKER_TYPE:
marker = new ShapeMarkerImpl(id, dummyMap, Vector3d.ZERO, dummyShape, 0f);
break;
case ExtrudeMarkerImpl.MARKER_TYPE:
marker = new ExtrudeMarkerImpl(id, dummyMap, Vector3d.ZERO, dummyShape, 0f, 1f);
break;
case LineMarkerImpl.MARKER_TYPE:
marker = new LineMarkerImpl(id, dummyMap, Vector3d.ZERO, dummyLine);
break;
default:
Logger.global.logDebug("Marker-API: Failed to load marker '" + id + "' in the set '" + this.id + "': Unknown marker-type '" + type + "'!");
continue;
}
marker.load(api, markerNode, true);
} else {
marker.load(api, markerNode, overwriteChanges);
}
markers.put(id, marker);
if (overwriteChanges) {
markers.put(id, marker);
} else {
markers.putIfAbsent(id, marker);
}
} catch (MarkerFileFormatException ex) {
Logger.global.logDebug("Marker-API: Failed to load marker '" + id + "' in the set '" + this.id + "': " + ex);
}

View File

@ -0,0 +1,78 @@
/*
* This file is part of BlueMap, licensed under the MIT License (MIT).
*
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package de.bluecolored.bluemap.common.api.marker;
import com.flowpowered.math.vector.Vector3d;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.marker.ObjectMarker;
import ninja.leaping.configurate.ConfigurationNode;
public abstract class ObjectMarkerImpl extends MarkerImpl implements ObjectMarker {
private String detail;
private boolean hasUnsavedChanges;
public ObjectMarkerImpl(String id, BlueMapMap map, Vector3d position) {
super(id, map, position);
this.detail = null;
this.hasUnsavedChanges = true;
}
@Override
public String getDetail() {
if (detail == null) return getLabel();
return detail;
}
@Override
public void setDetail(String detail) {
this.detail = detail;
this.hasUnsavedChanges = true;
}
@Override
public void load(BlueMapAPI api, ConfigurationNode markerNode, boolean overwriteChanges) throws MarkerFileFormatException {
super.load(api, markerNode, overwriteChanges);
if (!overwriteChanges && hasUnsavedChanges) return;
this.hasUnsavedChanges = false;
this.detail = markerNode.getNode("detail").getString();
}
@Override
public void save(ConfigurationNode markerNode) {
super.save(markerNode);
if (this.detail != null) markerNode.getNode("detail").setValue(this.detail);
hasUnsavedChanges = false;
}
}

View File

@ -60,7 +60,7 @@ public class POIMarkerImpl extends MarkerImpl implements POIMarker {
}
@Override
public Vector2i getIconAnchor() {
public Vector2i getAnchor() {
return anchor;
}
@ -79,7 +79,10 @@ public class POIMarkerImpl extends MarkerImpl implements POIMarker {
this.hasUnsavedChanges = false;
this.iconAddress = markerNode.getNode("icon").getString("assets/poi.svg");
this.anchor = readAnchor(markerNode.getNode("iconAnchor"));
ConfigurationNode anchorNode = markerNode.getNode("anchor");
if (anchorNode.isVirtual()) anchorNode = markerNode.getNode("iconAnchor"); //fallback to deprecated "iconAnchor"
this.anchor = readAnchor(anchorNode);
}
@Override
@ -87,7 +90,7 @@ public class POIMarkerImpl extends MarkerImpl implements POIMarker {
super.save(markerNode);
markerNode.getNode("icon").setValue(this.iconAddress);
writeAnchor(markerNode.getNode("iconAnchor"), this.anchor);
writeAnchor(markerNode.getNode("anchor"), this.anchor);
hasUnsavedChanges = false;
}

View File

@ -24,37 +24,38 @@
*/
package de.bluecolored.bluemap.common.api.marker;
import java.awt.Color;
import java.util.List;
import com.flowpowered.math.vector.Vector2d;
import com.flowpowered.math.vector.Vector3d;
import com.google.common.base.Preconditions;
import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.BlueMapMap;
import de.bluecolored.bluemap.api.marker.Shape;
import de.bluecolored.bluemap.api.marker.ShapeMarker;
import ninja.leaping.configurate.ConfigurationNode;
public class ShapeMarkerImpl extends MarkerImpl implements ShapeMarker {
import java.awt.*;
import java.util.List;
public class ShapeMarkerImpl extends ObjectMarkerImpl implements ShapeMarker {
public static final String MARKER_TYPE = "shape";
private Shape shape;
private float height;
private float shapeY;
private boolean depthTest;
private Color borderColor, fillColor;
private int lineWidth;
private Color lineColor, fillColor;
private boolean hasUnsavedChanges;
public ShapeMarkerImpl(String id, BlueMapMap map, Vector3d position, Shape shape, float height) {
public ShapeMarkerImpl(String id, BlueMapMap map, Vector3d position, Shape shape, float shapeY) {
super(id, map, position);
Preconditions.checkNotNull(shape);
this.shape = shape;
this.height = height;
this.borderColor = new Color(255, 0, 0, 200);
this.shapeY = shapeY;
this.lineWidth = 2;
this.lineColor = new Color(255, 0, 0, 200);
this.fillColor = new Color(200, 0, 0, 100);
this.hasUnsavedChanges = true;
@ -71,16 +72,16 @@ public class ShapeMarkerImpl extends MarkerImpl implements ShapeMarker {
}
@Override
public float getHeight() {
return this.height;
public float getShapeY() {
return this.shapeY;
}
@Override
public synchronized void setShape(Shape shape, float height) {
public synchronized void setShape(Shape shape, float shapeY) {
Preconditions.checkNotNull(shape);
this.shape = shape;
this.height = height;
this.shapeY = shapeY;
this.hasUnsavedChanges = true;
}
@ -92,18 +93,30 @@ public class ShapeMarkerImpl extends MarkerImpl implements ShapeMarker {
@Override
public void setDepthTestEnabled(boolean enabled) {
this.depthTest = enabled;
this.hasUnsavedChanges = true;
}
@Override
public Color getBorderColor() {
return this.borderColor;
public int getLineWidth() {
return lineWidth;
}
@Override
public synchronized void setBorderColor(Color color) {
public void setLineWidth(int lineWidth) {
this.lineWidth = lineWidth;
this.hasUnsavedChanges = true;
}
@Override
public Color getLineColor() {
return this.lineColor;
}
@Override
public synchronized void setLineColor(Color color) {
Preconditions.checkNotNull(color);
this.borderColor = color;
this.lineColor = color;
this.hasUnsavedChanges = true;
}
@ -128,9 +141,14 @@ public class ShapeMarkerImpl extends MarkerImpl implements ShapeMarker {
this.hasUnsavedChanges = false;
this.shape = readShape(markerNode.getNode("shape"));
this.height = markerNode.getNode("height").getFloat(64);
this.shapeY = markerNode.getNode("shapeY").getFloat(markerNode.getNode("height").getFloat(64)); // fallback to deprecated "height"
this.depthTest = markerNode.getNode("depthTest").getBoolean(true);
this.borderColor = readColor(markerNode.getNode("borderColor"));
this.lineWidth = markerNode.getNode("lineWidth").getInt(2);
ConfigurationNode lineColorNode = markerNode.getNode("lineColor");
if (lineColorNode.isVirtual()) lineColorNode = markerNode.getNode("borderColor"); // fallback to deprecated "borderColor"
this.lineColor = readColor(lineColorNode);
this.fillColor = readColor(markerNode.getNode("fillColor"));
}
@ -139,9 +157,10 @@ public class ShapeMarkerImpl extends MarkerImpl implements ShapeMarker {
super.save(markerNode);
writeShape(markerNode.getNode("shape"), this.shape);
markerNode.getNode("height").setValue(Math.round(height * 1000f) / 1000f);
markerNode.getNode("shapeY").setValue(Math.round(shapeY * 1000f) / 1000f);
markerNode.getNode("depthTest").setValue(this.depthTest);
writeColor(markerNode.getNode("borderColor"), this.borderColor);
markerNode.getNode("lineWidth").setValue(this.lineWidth);
writeColor(markerNode.getNode("lineColor"), this.lineColor);
writeColor(markerNode.getNode("fillColor"), this.fillColor);
hasUnsavedChanges = false;