diff --git a/core/src/main/java/com/zigythebird/playeranimcore/animation/Animation.java b/core/src/main/java/com/zigythebird/playeranimcore/animation/Animation.java index 12411667..b93786fc 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/animation/Animation.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/animation/Animation.java @@ -30,7 +30,6 @@ import com.zigythebird.playeranimcore.animation.keyframe.event.data.CustomInstructionKeyframeData; import com.zigythebird.playeranimcore.animation.keyframe.event.data.ParticleKeyframeData; import com.zigythebird.playeranimcore.animation.keyframe.event.data.SoundKeyframeData; -import com.zigythebird.playeranimcore.enums.AnimationStage; import com.zigythebird.playeranimcore.loading.UniversalAnimLoader; import com.zigythebird.playeranimcore.math.Vec3f; import org.jetbrains.annotations.NotNull; @@ -54,7 +53,7 @@ public int hashCode() { } static Animation generateWaitAnimation(float length) { - return new Animation(new ExtraAnimationData(ExtraAnimationData.NAME_KEY, AnimationStage.WAIT.name()), length, LoopType.PLAY_ONCE, + return new Animation(new ExtraAnimationData(ExtraAnimationData.NAME_KEY, "internal.wait"), length, LoopType.PLAY_ONCE, Collections.emptyMap(), UniversalAnimLoader.NO_KEYFRAMES, new HashMap<>(), new HashMap<>()); } diff --git a/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java b/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java index 9f3caa34..9102ca26 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/animation/AnimationController.java @@ -40,7 +40,6 @@ import com.zigythebird.playeranimcore.api.firstPerson.FirstPersonMode; import com.zigythebird.playeranimcore.bones.*; import com.zigythebird.playeranimcore.easing.EasingType; -import com.zigythebird.playeranimcore.enums.AnimationStage; import com.zigythebird.playeranimcore.enums.PlayState; import com.zigythebird.playeranimcore.enums.State; import com.zigythebird.playeranimcore.enums.TransformType; @@ -363,13 +362,7 @@ protected void setAnimation(RawAnimation rawAnimation) { protected Queue getQueuedAnimations(RawAnimation rawAnimation) { LinkedList animations = new LinkedList<>(); for (RawAnimation.Stage stage : rawAnimation.getAnimationStages()) { - Animation animation; - if (stage.stage() == AnimationStage.WAIT) { // This is intentional. Do not change this or T̶s̶l̶a̶t̶ I will be unhappy!!! - animation = Animation.generateWaitAnimation(stage.additionalTicks()); - } else { - animation = stage.animation(); - } - + Animation animation = stage.animation(); if (animation != null) animations.add(new QueuedAnimation(animation, stage.loopType())); } return animations; diff --git a/core/src/main/java/com/zigythebird/playeranimcore/animation/RawAnimation.java b/core/src/main/java/com/zigythebird/playeranimcore/animation/RawAnimation.java index 3879df4e..0d789232 100644 --- a/core/src/main/java/com/zigythebird/playeranimcore/animation/RawAnimation.java +++ b/core/src/main/java/com/zigythebird/playeranimcore/animation/RawAnimation.java @@ -9,10 +9,10 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,17 +24,14 @@ package com.zigythebird.playeranimcore.animation; -import com.zigythebird.playeranimcore.enums.AnimationStage; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** - * A builder class for a raw/unbaked animation. These are constructed to pass to the - * {@link AnimationController} to build into full-fledged animations for usage - *

* Animations added to this builder are added in order of insertion - the animations will play in the order that you define them *

* RawAnimation instances should be cached statically where possible to reduce overheads and improve efficiency @@ -43,10 +40,17 @@ *

{@code RawAnimation.begin().thenPlay(openBox).thenLoop(stayOpen)}
*/ public final class RawAnimation { - private final List animationList = new ObjectArrayList<>(); + private final List animationList; // Private constructor to force usage of factory for logical operations - private RawAnimation() {} + private RawAnimation() { + this(new ObjectArrayList<>()); + } + + // Private constructor to force usage of factory for logical operations + private RawAnimation(List animationList) { + this.animationList = animationList; + } /** * Start a new RawAnimation instance. This is the start point for creating an animation chain @@ -84,7 +88,7 @@ public RawAnimation thenLoop(Animation animation) { * @param ticks The number of ticks to 'wait' for */ public RawAnimation thenWait(int ticks) { - this.animationList.add(new Stage(AnimationStage.WAIT, null, Animation.LoopType.PLAY_ONCE, ticks)); + this.animationList.add(new Stage(Animation.generateWaitAnimation(ticks), Animation.LoopType.PLAY_ONCE)); return this; } @@ -103,7 +107,7 @@ public RawAnimation thenPlayAndHold(Animation animation) { * Append an animation to the animation chain, playing the named animation playCount times, * then stopping or progressing to the next chained animation depending on the loop type set in the animation json * - * @param animation The animation to play X times + * @param animation The animation to play X times * @param playCount The number of times to repeat the animation before proceeding */ public RawAnimation thenPlayXTimes(Animation animation, int playCount) { @@ -146,6 +150,18 @@ public static RawAnimation copyOf(RawAnimation other) { return newInstance; } + @Override + public String toString() { + return "RawAnimation{" + this.animationList.stream().map(Stage::toString).collect(Collectors.joining(" -> ")) + "}"; + } + + /** + * Get the number of animation stages this RawAnimation contains + */ + public int getStageCount() { + return this.animationList.size(); + } + @Override public boolean equals(Object obj) { if (this == obj) @@ -167,15 +183,7 @@ public int hashCode() { *

* This is an entry object representing a single animation stage of the final compiled animation. */ - public record Stage(AnimationStage stage, @Nullable Animation animation, Animation.LoopType loopType, int additionalTicks) { - public Stage(AnimationStage stage, Animation animation, Animation.LoopType loopType) { - this(stage, animation, loopType, 0); - } - - public Stage(Animation animation, Animation.LoopType loopType) { - this(AnimationStage.ANIMATION, animation, loopType); - } - + public record Stage(@Nullable Animation animation, Animation.LoopType loopType) { @Override public boolean equals(Object obj) { if (this == obj) @@ -187,9 +195,14 @@ public boolean equals(Object obj) { return hashCode() == obj.hashCode(); } + @Override + public String toString() { + return animation == null ? "Invalid animation stage." : this.animation.toString(); + } + @Override public int hashCode() { - return Objects.hash(this.stage, this.animation, this.loopType); + return Objects.hash(this.animation, this.loopType); } } } diff --git a/core/src/main/java/com/zigythebird/playeranimcore/enums/AnimationStage.java b/core/src/main/java/com/zigythebird/playeranimcore/enums/AnimationStage.java deleted file mode 100644 index 96283aff..00000000 --- a/core/src/main/java/com/zigythebird/playeranimcore/enums/AnimationStage.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.zigythebird.playeranimcore.enums; - -public enum AnimationStage { - WAIT, - ANIMATION -}