From 227b9846654a023714285c6fac7d74c48224e8e0 Mon Sep 17 00:00:00 2001 From: yusshu Date: Mon, 9 Oct 2023 16:15:25 -0500 Subject: [PATCH] refactor: rename Frame to BoneFrame, move inside timeline package --- .../controller/NormalAnimationController.java | 34 +++++++++---------- .../{Frame.java => timeline/BoneFrame.java} | 16 ++++----- .../animation/timeline/BoneTimeline.java | 5 ++- 3 files changed, 27 insertions(+), 28 deletions(-) rename api/src/main/java/team/unnamed/hephaestus/animation/{Frame.java => timeline/BoneFrame.java} (87%) diff --git a/api/src/main/java/team/unnamed/hephaestus/animation/controller/NormalAnimationController.java b/api/src/main/java/team/unnamed/hephaestus/animation/controller/NormalAnimationController.java index 0117aaab..0b1bb71b 100644 --- a/api/src/main/java/team/unnamed/hephaestus/animation/controller/NormalAnimationController.java +++ b/api/src/main/java/team/unnamed/hephaestus/animation/controller/NormalAnimationController.java @@ -27,7 +27,7 @@ import team.unnamed.creative.base.Vector3Float; import team.unnamed.hephaestus.Bone; import team.unnamed.hephaestus.animation.Animation; -import team.unnamed.hephaestus.animation.Frame; +import team.unnamed.hephaestus.animation.timeline.BoneFrame; import team.unnamed.hephaestus.animation.timeline.BoneTimeline; import team.unnamed.hephaestus.util.Quaternion; import team.unnamed.hephaestus.util.Vectors; @@ -46,7 +46,7 @@ class NormalAnimationController implements AnimationController { private final Map iterators = new HashMap<>(); - private final Map lastFrames = new HashMap<>(); + private final Map lastFrames = new HashMap<>(); // Reference to the animation currently being played private @Nullable Animation currentAnimation; @@ -69,11 +69,11 @@ public synchronized void queue(Animation animation, int transitionTicks) { Map boneTimelines = new HashMap<>(); Animation transitionAnimation = Animation.animation("$transition", transitionTicks, Animation.LoopMode.HOLD, boneTimelines); - lastFrames.forEach((boneName, frame) -> { + lastFrames.forEach((boneName, boneFrame) -> { BoneTimeline timeline = BoneTimeline.create(); - timeline.positions().put(0, frame.position()); - timeline.rotations().put(0, frame.rotation()); - timeline.scales().put(0, frame.scale()); + timeline.positions().put(0, boneFrame.position()); + timeline.rotations().put(0, boneFrame.rotation()); + timeline.scales().put(0, boneFrame.scale()); boneTimelines.put(boneName, timeline); }); @@ -103,9 +103,9 @@ private void tickBone( BaseBoneView boneView = view.bone(bone.name()); assert boneView != null; - Frame frame = nextFrame(bone.name()); - Vector3Float framePosition = frame.position(); - Vector3Float frameRotation = frame.rotation(); + BoneFrame boneFrame = nextFrame(bone.name()); + Vector3Float framePosition = boneFrame.position(); + Vector3Float frameRotation = boneFrame.rotation(); Vector3Float defaultPosition = bone.position(); Vector3Float defaultRotation = bone.rotation(); @@ -159,7 +159,7 @@ private void createIterators(Animation animation) { animation.timelines().forEach((name, list) -> iterators.put(name, list.iterator())); } - private Frame nextFrame(String boneName) { + private BoneFrame nextFrame(String boneName) { if (currentAnimation == null) { // if no animation currently being played, @@ -175,8 +175,8 @@ private Frame nextFrame(String boneName) { BoneTimeline.StateIterator iterator = iterators.get(boneName); if (iterator != null) { - Frame frame = iterator.next(); - lastFrames.put(boneName, frame); + BoneFrame boneFrame = iterator.next(); + lastFrames.put(boneName, boneFrame); if (iterator.tick() >= currentAnimation.length()) { // animation ended! @@ -186,13 +186,13 @@ private Frame nextFrame(String boneName) { // animation ended, lastFrames are removed // so that next calls will return INITIAL lastFrames.remove(boneName); - return frame; + return boneFrame; case LOOP: createIterators(currentAnimation); - return frame; + return boneFrame; case HOLD: nextAnimation(); - return frame; + return boneFrame; } } } @@ -200,8 +200,8 @@ private Frame nextFrame(String boneName) { return fallback(boneName); } - private Frame fallback(String boneName) { - return lastFrames.getOrDefault(boneName, Frame.INITIAL); + private BoneFrame fallback(String boneName) { + return lastFrames.getOrDefault(boneName, BoneFrame.INITIAL); } } \ No newline at end of file diff --git a/api/src/main/java/team/unnamed/hephaestus/animation/Frame.java b/api/src/main/java/team/unnamed/hephaestus/animation/timeline/BoneFrame.java similarity index 87% rename from api/src/main/java/team/unnamed/hephaestus/animation/Frame.java rename to api/src/main/java/team/unnamed/hephaestus/animation/timeline/BoneFrame.java index adce2a15..722ad37b 100644 --- a/api/src/main/java/team/unnamed/hephaestus/animation/Frame.java +++ b/api/src/main/java/team/unnamed/hephaestus/animation/timeline/BoneFrame.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package team.unnamed.hephaestus.animation; +package team.unnamed.hephaestus.animation.timeline; import net.kyori.examination.Examinable; import net.kyori.examination.ExaminableProperty; @@ -32,9 +32,9 @@ import java.util.Objects; import java.util.stream.Stream; -public final class Frame implements Examinable { +public final class BoneFrame implements Examinable { - public static final Frame INITIAL = new Frame( + public static final BoneFrame INITIAL = new BoneFrame( Vector3Float.ZERO, Vector3Float.ZERO, Vector3Float.ONE @@ -44,7 +44,7 @@ public final class Frame implements Examinable { private final Vector3Float rotation; private final Vector3Float scale; - public Frame( + public BoneFrame( Vector3Float position, Vector3Float rotation, Vector3Float scale @@ -79,10 +79,10 @@ public Vector3Float scale() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Frame frame = (Frame) o; - return position.equals(frame.position) - && rotation.equals(frame.rotation) - && scale.equals(frame.scale); + BoneFrame boneFrame = (BoneFrame) o; + return position.equals(boneFrame.position) + && rotation.equals(boneFrame.rotation) + && scale.equals(boneFrame.scale); } @Override diff --git a/api/src/main/java/team/unnamed/hephaestus/animation/timeline/BoneTimeline.java b/api/src/main/java/team/unnamed/hephaestus/animation/timeline/BoneTimeline.java index 9b024873..3b098e87 100644 --- a/api/src/main/java/team/unnamed/hephaestus/animation/timeline/BoneTimeline.java +++ b/api/src/main/java/team/unnamed/hephaestus/animation/timeline/BoneTimeline.java @@ -24,7 +24,6 @@ package team.unnamed.hephaestus.animation.timeline; import team.unnamed.creative.base.Vector3Float; -import team.unnamed.hephaestus.animation.Frame; /** * @@ -75,9 +74,9 @@ public int tick() { return tick; } - public Frame next() { + public BoneFrame next() { tick++; - return new Frame( + return new BoneFrame( positions.next(), rotations.next(), scales.next()