[libgdx] Fixed data loader scale for transform constraint.

This commit is contained in:
Nathan Sweet 2025-04-08 14:10:12 -04:00
parent 8d5f6c593e
commit 7965da21b9

View File

@ -263,17 +263,34 @@ public class SkeletonJson extends SkeletonLoader {
boolean rotate = false, x = false, y = false, scaleX = false, scaleY = false, shearY = false; boolean rotate = false, x = false, y = false, scaleX = false, scaleY = false, shearY = false;
for (JsonValue fromEntry = constraintMap.getChild("properties"); fromEntry != null; fromEntry = fromEntry.next) { for (JsonValue fromEntry = constraintMap.getChild("properties"); fromEntry != null; fromEntry = fromEntry.next) {
FromProperty from = switch (fromEntry.name) { float fromScale = 1;
case "rotate" -> new FromRotate(); FromProperty from;
case "x" -> new FromX(); switch (fromEntry.name) {
case "y" -> new FromY(); case "rotate" -> {
case "scaleX" -> new FromScaleX(); from = new FromRotate();
case "scaleY" -> new FromScaleY(); }
case "shearY" -> new FromShearY(); case "x" -> {
from = new FromX();
fromScale = scale;
}
case "y" -> {
from = new FromY();
fromScale = scale;
}
case "scaleX" -> {
from = new FromScaleX();
}
case "scaleY" -> {
from = new FromScaleY();
}
case "shearY" -> {
from = new FromShearY();
}
default -> throw new SerializationException("Invalid transform constraint from property: " + fromEntry.name); default -> throw new SerializationException("Invalid transform constraint from property: " + fromEntry.name);
}; }
from.offset = fromEntry.getFloat("offset", 0) * scale; from.offset = fromEntry.getFloat("offset", 0) * fromScale;
for (JsonValue toEntry = fromEntry.getChild("to"); toEntry != null; toEntry = toEntry.next) { for (JsonValue toEntry = fromEntry.getChild("to"); toEntry != null; toEntry = toEntry.next) {
float toScale = 1;
ToProperty to; ToProperty to;
switch (toEntry.name) { switch (toEntry.name) {
case "rotate" -> { case "rotate" -> {
@ -283,10 +300,12 @@ public class SkeletonJson extends SkeletonLoader {
case "x" -> { case "x" -> {
x = true; x = true;
to = new ToX(); to = new ToX();
toScale = scale;
} }
case "y" -> { case "y" -> {
y = true; y = true;
to = new ToY(); to = new ToY();
toScale = scale;
} }
case "scaleX" -> { case "scaleX" -> {
scaleX = true; scaleX = true;
@ -302,9 +321,9 @@ public class SkeletonJson extends SkeletonLoader {
} }
default -> throw new SerializationException("Invalid transform constraint to property: " + toEntry.name); default -> throw new SerializationException("Invalid transform constraint to property: " + toEntry.name);
} }
to.offset = toEntry.getFloat("offset", 0) * scale; to.offset = toEntry.getFloat("offset", 0) * toScale;
to.max = toEntry.getFloat("max", 1) * scale; to.max = toEntry.getFloat("max", 1) * toScale;
to.scale = toEntry.getFloat("scale"); to.scale = toEntry.getFloat("scale") * toScale / fromScale;
from.to.add(to); from.to.add(to);
} }
if (from.to.notEmpty()) data.properties.add(from); if (from.to.notEmpty()) data.properties.add(from);