Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -363,13 +362,7 @@ protected void setAnimation(RawAnimation rawAnimation) {
protected Queue<QueuedAnimation> getQueuedAnimations(RawAnimation rawAnimation) {
LinkedList<QueuedAnimation> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
* <p>
* Animations added to this builder are added <u>in order of insertion</u> - the animations will play in the order that you define them
* <p>
* RawAnimation instances should be cached statically where possible to reduce overheads and improve efficiency
Expand All @@ -43,10 +40,17 @@
* <pre>{@code RawAnimation.begin().thenPlay(openBox).thenLoop(stayOpen)}</pre>
*/
public final class RawAnimation {
private final List<Stage> animationList = new ObjectArrayList<>();
private final List<Stage> 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<Stage> animationList) {
this.animationList = animationList;
}

/**
* Start a new RawAnimation instance. This is the start point for creating an animation chain
Expand Down Expand Up @@ -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;
}
Expand All @@ -103,7 +107,7 @@ public RawAnimation thenPlayAndHold(Animation animation) {
* Append an animation to the animation chain, playing the named animation <code>playCount</code> 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) {
Expand Down Expand Up @@ -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)
Expand All @@ -167,15 +183,7 @@ public int hashCode() {
* <p>
* 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)
Expand All @@ -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);
}
}
}

This file was deleted.