From d950e45e4946c0c070e00d693f48b4c0b5a22f9d Mon Sep 17 00:00:00 2001 From: Vftdan Date: Thu, 5 Sep 2024 08:31:27 +0200 Subject: [PATCH] Fix waypoint stringification logic --- .../ClipboardCopyWaypointAction.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/client/java/io/github/vftdan/xaeromapaddon/worldmap/waypointactions/ClipboardCopyWaypointAction.java b/src/client/java/io/github/vftdan/xaeromapaddon/worldmap/waypointactions/ClipboardCopyWaypointAction.java index e934633..605e071 100644 --- a/src/client/java/io/github/vftdan/xaeromapaddon/worldmap/waypointactions/ClipboardCopyWaypointAction.java +++ b/src/client/java/io/github/vftdan/xaeromapaddon/worldmap/waypointactions/ClipboardCopyWaypointAction.java @@ -9,6 +9,8 @@ import xaero.common.minimap.waypoints.WaypointWorld; import xaero.common.minimap.waypoints.WaypointWorldRootContainer; import xaero.map.mods.gui.Waypoint; import xaero.map.mods.SupportMods; +import static xaero.common.settings.ModSettings.COLORS; +import static io.github.vftdan.xaeromapaddon.VftdansXaerosMapAddon.LOGGER; public class ClipboardCopyWaypointAction implements WaypointAction { @Override @@ -26,6 +28,16 @@ public class ClipboardCopyWaypointAction implements WaypointAction { return "gui.vftdan.xaero_right_click_waypoint.copy_to_clipboard"; } + public static int reverseLookupColor(int rgba) { + for (int i = 0; i < COLORS.length; ++i) { + if (COLORS[i] == rgba) { + return i; + } + } + LOGGER.warn("Failed to reverse-lookup color " + rgba); + return 0; + } + public static String waypointToShareableString(Waypoint w) { WaypointWorld waypointWorld = SupportMods.xaeroMinimap.getWaypointWorld(); String dimInfo; @@ -45,7 +57,7 @@ public class ClipboardCopyWaypointAction implements WaypointAction { dim = "the_end"; } containerKeyElements[1] = dim; - internalInfo = String.join("/", Arrays.copyOfRange(containerKeyElements, 1, containerKeyElements.length)); + internalInfo = escapeWaypointComponent(String.join("/", Arrays.copyOfRange(containerKeyElements, 1, containerKeyElements.length))) + "_waypoints"; } dimInfo = "Internal_" + internalInfo; } else { @@ -57,11 +69,10 @@ public class ClipboardCopyWaypointAction implements WaypointAction { String x = w.getX() + ""; String y = w.isyIncluded() ? Integer.valueOf(w.getY()) + "" : "~"; String z = w.getZ() + ""; - String color = w.getColor() + ""; + String color = reverseLookupColor(w.getColor()) + ""; String isRotation = w.isRotation() + ""; String yaw = w.getYaw() + ""; - String dimInfoEscaped = escapeWaypointComponent(dimInfo); - return "xaero-waypoint:" + title + ":" + icon + ":" + x + ":" + y + ":" + z + ":" + color + ":" + isRotation + ":" + yaw + ":" + dimInfoEscaped; + return "xaero-waypoint:" + title + ":" + icon + ":" + x + ":" + y + ":" + z + ":" + color + ":" + isRotation + ":" + yaw + ":" + dimInfo; } public static String escapeWaypointComponent(String unsafe) {