Skip to content

Commit

Permalink
waypoint color converter
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed May 29, 2024
1 parent b60e3d5 commit 58182ce
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
55 changes: 55 additions & 0 deletions src/main/java/com/github/rfresh2/ColorHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.rfresh2;

import java.awt.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ColorHelper {
/**
* Color indexes:
* 0 = black
* 1 = dark blue
* 2 = dark green
* 3 = dark aqua
* 4 = dark red
* 5 = dark purple
* 6 = gold
* 7 = gray
* 8 = dark gray
* 9 = blue
* 10 = green
* 11 = aqua
* 12 = red
* 13 = light purple
* 14 = yellow
* 15 = white
*/
public static List<Color> xaeroColors = Stream.of(-16777216, -16777046, -16733696, -16733526, -5636096, -5635926, -22016, -5592406, -11184811, -11184641, -11141291, -11141121, -65536, -43521, -171, -1)
.map(Color::new)
.collect(Collectors.toList());

public static int nearestXaeroColorIndex(Color jmColor) {
int minIndex = 0;
double min = Double.MAX_VALUE;
for (int i = 0; i < xaeroColors.size(); i++) {
Color xaeroColor = xaeroColors.get(i);
double d = colorDistance(xaeroColor, jmColor);
if (d < min) {
minIndex = i;
min = d;
}
}
return minIndex;
}

public static double colorDistance(Color c1, Color c2) {
int red1 = c1.getRed();
int red2 = c2.getRed();
int rmean = (red1 + red2) >> 1;
int r = red1 - red2;
int g = c1.getGreen() - c2.getGreen();
int b = c1.getBlue() - c2.getBlue();
return Math.sqrt((((512+rmean)*r*r)>>8) + 4*g*g + (((767-rmean)*b*b)>>8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
Expand All @@ -22,7 +23,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.stream.Collectors;

public class JourneyMapWaypointsToXaero {
Expand All @@ -37,7 +37,6 @@ public class JourneyMapWaypointsToXaero {
// we want to try modern, and if it fails, try legacy
objectMapper.coercionConfigFor(LogicalType.Textual).setCoercion(CoercionInputShape.Integer, CoercionAction.Fail);
}
static final Random random = new Random();
static final Logger LOG = LoggerFactory.getLogger("JMWaypointsToXaero");

public static void main(final String[] args) {
Expand All @@ -47,7 +46,6 @@ public static void main(final String[] args) {
}
String input = args[0];
String output = args[1];

Path folderIn = new File(String.format("%s/waypoints/", input)).toPath();
LOG.info("Reading JM waypoints from path: {}", folderIn.toAbsolutePath());
List<XaeroWaypoint> xaeroWaypoints = convertWaypoints(folderIn);
Expand Down Expand Up @@ -128,7 +126,7 @@ public static XaeroWaypoint convertWaypoint(final IJMWaypoint jmWaypoint) {
(dimension == -1 ? jmWaypoint.getX() / 8 : jmWaypoint.getX()), // jm stores all wp in ow coords
jmWaypoint.getY(),
(dimension == -1 ? jmWaypoint.getZ() / 8 : jmWaypoint.getZ()),
random.nextInt(16), // todo: convert JM rgb to some equivalent Xaero color
ColorHelper.nearestXaeroColorIndex(new Color(jmWaypoint.getR(), jmWaypoint.getG(), jmWaypoint.getB())),
!jmWaypoint.isEnabled(),
0,
"gui.xaero_default",
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/github/rfresh2/model/XaeroWaypoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ public class XaeroWaypoint {
public int x;
public int y;
public int z;
/**
* Color index
*/
public int color;
public boolean disabled;
public int type;
Expand Down

0 comments on commit 58182ce

Please sign in to comment.