Skip to content

Commit

Permalink
Fix shape using y instead of z coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
TBlueF committed Aug 2, 2022
1 parent 745192e commit 1838ebb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/java/de/bluecolored/bluemap/api/gson/MarkerGson.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Line read(JsonReader in) throws IOException {
}

static class ShapeAdapter extends TypeAdapter<Shape> {
private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter();
private static final Vector2dAdapter VEC2D_ADAPTER = new Vector2dAdapter(true);

@Override
public void write(JsonWriter out, Shape value) throws IOException {
Expand Down Expand Up @@ -217,6 +217,16 @@ public Color read(JsonReader in) throws IOException {

static class Vector2dAdapter extends TypeAdapter<Vector2d> {

private final boolean useZ;

public Vector2dAdapter() {
this.useZ = false;
}

public Vector2dAdapter(boolean useZ) {
this.useZ = useZ;
}

@Override
public void write(JsonWriter out, Vector2d value) throws IOException {
if (value == null) {
Expand All @@ -226,7 +236,7 @@ public void write(JsonWriter out, Vector2d value) throws IOException {

out.beginObject();
out.name("x"); out.value(value.getX());
out.name("y"); out.value(value.getY());
out.name(useZ ? "z" : "y"); out.value(value.getY());
out.endObject();
}

Expand All @@ -242,7 +252,8 @@ public Vector2d read(JsonReader in) throws IOException {
while (in.peek() != JsonToken.END_OBJECT) {
switch (in.nextName()) {
case "x" : x = in.nextDouble(); break;
case "y" : y = in.nextDouble(); break;
case "y" : if (!useZ) y = in.nextDouble(); else in.skipValue(); break;
case "z" : if (useZ) y = in.nextDouble(); else in.skipValue(); break;
default : in.skipValue(); break;
}
}
Expand Down

0 comments on commit 1838ebb

Please sign in to comment.