Fix waypoint stringification logic

This commit is contained in:
Vftdan 2024-09-05 08:31:27 +02:00
parent 0e55d1cc37
commit d950e45e49
1 changed files with 15 additions and 4 deletions

View File

@ -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) {