Add option to configure marker-sets in the map-configs

This commit is contained in:
Lukas Rieger (Blue) 2022-07-30 13:24:07 +02:00
parent 2d57b1a32a
commit ca1d5cb50b
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
7 changed files with 152 additions and 78 deletions

@ -1 +1 @@
Subproject commit 92c438e0996bd3f0a034d4cf90b192f2d7017eac
Subproject commit 29e84ed198a024e2e5a6a7dd4a5c62999cac4fb4

View File

@ -24,6 +24,14 @@
*/
package de.bluecolored.bluemap.common;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.api.markers.MarkerGson;
import de.bluecolored.bluemap.api.markers.MarkerSet;
import de.bluecolored.bluemap.common.config.ConfigurationException;
import de.bluecolored.bluemap.common.config.MapConfig;
import de.bluecolored.bluemap.common.config.storage.StorageConfig;
@ -31,7 +39,6 @@
import de.bluecolored.bluemap.common.serverinterface.ServerInterface;
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
import de.bluecolored.bluemap.core.MinecraftVersion;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.core.debug.StateDumper;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.map.BmMap;
@ -41,8 +48,12 @@
import de.bluecolored.bluemap.core.util.AtomicFileHelper;
import de.bluecolored.bluemap.core.world.World;
import org.apache.commons.io.FileUtils;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
import org.spongepowered.configurate.loader.HeaderMode;
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
@ -206,11 +217,32 @@ private synchronized void loadWorldsAndMaps() throws ConfigurationException, Int
getResourcePack(),
mapConfig
);
maps.put(id, map);
// load marker-config by converting it first from hocon to json and then loading it with MarkerGson
if (!mapConfig.getMarkerSets().empty()) {
String markerJson = GsonConfigurationLoader.builder()
.headerMode(HeaderMode.NONE)
.lenient(false)
.indent(0)
.buildAndSaveString(mapConfig.getMarkerSets());
Gson gson = MarkerGson.addAdapters(new GsonBuilder())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES)
.create();
Type markerSetType = new TypeToken<Map<String, MarkerSet>>() {}.getType();
Map<String, MarkerSet> markerSets = gson.fromJson(markerJson, markerSetType);
map.getMarkerSets().putAll(markerSets);
}
} catch (ConfigurateException | JsonParseException ex) {
throw new ConfigurationException("Failed to load map '" + id + "': \n" +
"Failed to create the markers for this map!\n" +
"Make sure your marker-configuration for this map is valid.",
ex);
} catch (IOException ex) {
throw new ConfigurationException("Failed to load map '" + id + "'!", ex);
}
}
worlds = Collections.unmodifiableMap(worlds);

View File

@ -273,35 +273,6 @@ private synchronized Map<String, MapConfig> loadMapConfigs() throws Configuratio
return mapConfigs;
}
/*
private synchronized Map<String, Map<String, MarkerSet>> loadMarkerConfigs() throws ConfigurationException {
Map<String, Map<String, MarkerSet>> markerConfigs = new HashMap<>();
Path markerFolder = Paths.get("markers");
Path markerConfigFolder = configManager.getConfigRoot().resolve(markerFolder);
if (!Files.exists(markerConfigFolder)){
try {
Files.createDirectories(markerConfigFolder);
for (var mapConfigEntry : mapConfigs.entrySet()) {
Files.writeString(
markerConfigFolder.resolve(mapConfigEntry.getKey() + ".conf"),
configManager.loadConfigTemplate("/de/bluecolored/bluemap/config/markers/markers.conf")
.setVariable("map", mapConfig.getId())
.build(),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING
);
}
} catch (IOException | NullPointerException ex) {
throw new ConfigurationException("BlueMap failed to create default marker-configuration-files in\n" +
markerConfigFolder.toAbsolutePath().normalize() + "\n" +
"Check if BlueMap has the permission to create and read from this folder.",
ex);
}
}
}
*/
private synchronized Map<String, StorageConfig> loadStorageConfigs(Path defaultWebroot) throws ConfigurationException {
Map<String, StorageConfig> storageConfigs = new HashMap<>();

View File

@ -4,6 +4,7 @@
import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.core.map.MapSettings;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Required;
@ -50,6 +51,8 @@ public class MapConfig implements MapSettings {
private boolean ignoreMissingLightData = false;
private ConfigurationNode markerSets = null;
// hidden config fields
private int hiresTileSize = 32;
private int lowresPointsPerHiresTile = 4;
@ -113,6 +116,10 @@ public boolean isIgnoreMissingLightData() {
return ignoreMissingLightData;
}
public ConfigurationNode getMarkerSets() {
return markerSets;
}
public int getHiresTileSize() {
return hiresTileSize;
}

View File

@ -86,3 +86,112 @@ storage: "file"
# - Caves will always be rendered (ignoring the 'renderCaves' setting)
# Default is false
ignore-missing-light-data: false
# Here you can define any static marker-sets with markers that should be displayed on the map.
# If you need dynamic markers, you can use any plugin that integrates with BlueMap's API.
# Here is a list: https://bluemap.bluecolored.de/wiki/customization/3rdPartySupport.html
marker-sets: {
# Here is a marker-set with one of each type of marker as an example.
# Uncomment (remove the leading #'s) and adapt them to your purpose.
# See the wiki for more information: https://bluemap.bluecolored.de/wiki/customization/Markers.html
#example-marker-set: {
#
# label: "Example Marker Set"
# toggleable: true
# default-hidden: false
# markers: {
#
# example-poi-marker: {
# type: "poi"
# position: { x: 1, y: 64, z: -23 }
# label: "Example POI Marker"
# icon: "assets/poi.svg"
# anchor: { x: 25, y: 45 }
# min-distance: 10
# max-distance: 10000000
# }
#
# example-html-marker: {
# type: "html"
# position: { x: 1, y: 64, z: -23 }
# label: "Example HTML Marker"
# html: "<div style='line-height: 2em; font-size: 2em; color: white; transform: translate(-50%, -50%);'>Example HTML Marker</div>"
# anchor: { x: 0, y: 0 }
# min-distance: 10
# max-distance: 10000000
# }
#
# example-line-marker: {
# type: "line"
# position: { x: 1, y: 64, z: -25 }
# line: [
# { x: 1, y: 64, z: -23 }
# { x: 1, y: 64, z: -24 }
# { x: 1, y: 64, z: -25 }
# { x: 2, y: 64, z: -25 }
# { x: 3, y: 64, z: -25 }
# ]
# label: "Example Line Marker"
# detail: "This is a <b>line</b> marker"
# link: null
# new-tab: false
# depth-test: true
# line-width: 5
# line-color: { r: 255, g: 0, b: 0, a: 1.0 }
# min-distance: 10
# max-distance: 10000000
# }
#
# example-shape-marker: {
# type: "shape"
# position: { x: 1, y: 64, z: -23 }
# shape: [
# { x: 1, z: -23 }
# { x: 1, z: -24 }
# { x: 1, z: -25 }
# { x: 2, z: -25 }
# { x: 3, z: -25 }
# ]
# shape-y: 64
# label: "Example Shape Marker"
# detail: "This is a <b>shape</b> marker"
# link: null
# new-tab: false
# depth-test: true
# line-width: 5
# line-color: { r: 255, g: 0, b: 0, a: 1.0 }
# fill-color: { r: 200, g: 0, b: 0, a: 0.3 }
# min-distance: 10
# max-distance: 10000000
# }
#
# example-extrude-marker: {
# type: "extrude"
# position: { x: 1, y: 64, z: -23 }
# shape: [
# { x: 1, z: -23 }
# { x: 1, z: -24 }
# { x: 1, z: -25 }
# { x: 2, z: -25 }
# { x: 3, z: -25 }
# ]
# shape-min-y: 47
# shape-max-y: 72
# label: "Example Extrude Marker"
# detail: "This is a <b>extrude</b> marker"
# link: null
# new-tab: false
# depth-test: true
# line-width: 5
# line-color: { r: 255, g: 0, b: 0, a: 1.0 }
# fill-color: { r: 200, g: 0, b: 0, a: 0.3 }
# min-distance: 10
# max-distance: 10000000
# }
#
# }
#
#}
}

View File

@ -1,45 +0,0 @@
## ##
## BlueMap ##
## Marker-Config ##
## ##
exampleMarkerSet {
label: "Example Marker Set"
toggleable: true
defaultHidden: false
markers {
examplePoiMarker {
type: "poi"
position: { x: 13, y: 62, z: -37 }
label: "Example Poi Marker"
icon: "assets/poi.svg"
anchor: { x: 25, y: 45 }
minDistance: 10.0
maxDistance: 1000.0
}
exampleShapeMarker {
type: "shape"
position: { x: 13, y: 62, z: -37 }
label: "Example Shape Marker"
detail: "This is a detail text for the marker."
shape: [
{ x: 23, z: 33 }
{ x: -15, z: 33 }
{ x: -15, z: -10 }
{ x: 23, z: -10 }
]
shapeY: 64
depthTest: false
lineWidth: 2
lineColor: { r: 255, g: 0, b: 0, a: 1.0 }
fillColor: { r: 200, g: 0, b: 0, a: 0.3 }
minDistance: 100.0
maxDistance: 100000.0
}
}
}

View File

@ -64,7 +64,7 @@ public class BmMap {
private final HiresModelManager hiresModelManager;
private final LowresModelManager lowresModelManager;
private final Map<String, MarkerSet> markerSets;
private final ConcurrentHashMap<String, MarkerSet> markerSets;
private Predicate<Vector2i> tileFilter;