Add Position JsonAdapter for [x,y,z] format

Also add serializers for existing JsonAdapters
This commit is contained in:
AnimeGitB
2022-11-25 00:29:26 +10:30
parent ad502a8568
commit da3981089d
3 changed files with 70 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package emu.grasscutter.utils;
import java.io.Serializable;
import java.util.List;
import com.google.gson.annotations.SerializedName;
import com.github.davidmoten.rtreemulti.geometry.Point;
@@ -22,9 +23,7 @@ public class Position implements Serializable {
@SerializedName(value="z", alternate={"_z", "Z"})
@Getter @Setter private float z;
public Position() {
}
public Position() {}
public Position(float x, float y) {
set(x, y);
@@ -34,6 +33,20 @@ public class Position implements Serializable {
set(x, y, z);
}
public Position(List<Float> xyz) {
switch (xyz.size()) {
default: // Might want to error on excess elements, but maybe we want to extend to 3+3 representation later.
case 3:
this.z = xyz.get(2); // Fall-through
case 2:
this.y = xyz.get(1); // Fall-through
case 1:
this.y = xyz.get(0); // pointless fall-through
case 0:
break;
}
}
public Position(String p) {
String[] split = p.split(",");
if (split.length >= 2) {