Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add animation:isHolding() #218

Merged
merged 1 commit into from
May 21, 2024
Merged
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
15 changes: 13 additions & 2 deletions common/src/main/java/org/figuramc/figura/animation/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ public void tick() {
else if (inverted && time < offset - loopDelay)
time += length + loopDelay - offset;
}
case HOLD -> time = inverted ? Math.max(time, offset) : Math.min(time, length);
case HOLD -> {
time = inverted ? Math.max(time, offset) : Math.min(time, length);
if (time == length)
playState = PlayState.HOLDING;
}
}

this.lastTime = this.frameTime;
Expand Down Expand Up @@ -158,6 +162,12 @@ public boolean isStopped() {
return this.playState == PlayState.STOPPED;
}

@LuaWhitelist
@LuaMethodDoc("animation.is_holding")
public boolean isHolding() {
return this.playState == PlayState.HOLDING;
}

@LuaWhitelist
@LuaMethodDoc("animation.play")
public Animation play() {
Expand Down Expand Up @@ -598,7 +608,8 @@ public String toString() {
public enum PlayState {
STOPPED,
PAUSED,
PLAYING
PLAYING,
HOLDING
}

public enum LoopMode {
Expand Down
16 changes: 13 additions & 3 deletions common/src/main/java/org/figuramc/figura/lua/api/AnimationAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.figuramc.figura.avatar.Avatar;
import org.figuramc.figura.lua.LuaWhitelist;
import org.figuramc.figura.lua.docs.LuaMethodDoc;
import org.figuramc.figura.lua.docs.LuaMethodOverload;
import org.figuramc.figura.lua.docs.LuaTypeDoc;

import java.util.ArrayList;
Expand Down Expand Up @@ -51,11 +52,20 @@ public List<Animation> getAnimations() {
}

@LuaWhitelist
@LuaMethodDoc("animations.get_playing")
public List<Animation> getPlaying() {
@LuaMethodDoc(
overloads = {
@LuaMethodOverload,
@LuaMethodOverload(
argumentTypes = Boolean.class,
argumentNames = "hold"
)
},
value = "animations.get_playing"
)
public List<Animation> getPlaying(boolean hold) {
List<Animation> list = new ArrayList<>();
for (Animation animation : avatar.animations.values())
if (animation.playState == Animation.PlayState.PLAYING)
if (hold ? (animation.playState == Animation.PlayState.PLAYING || animation.playState == Animation.PlayState.HOLDING) : (animation.playState == Animation.PlayState.PLAYING))
list.add(animation);
return list;
}
Expand Down
9 changes: 5 additions & 4 deletions common/src/main/resources/assets/figura/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,14 @@
"figura.docs.wheel_action.set_toggled": "Sets the toggle state of the Action",
"figura.docs.animations": "A global API used for control of Blockbench Animations",
"figura.docs.animations.get_animations": "Returns a table with all animations",
"figura.docs.animations.get_playing": "Return a table with all playing animations",
"figura.docs.animations.get_playing": "Return a table with all playing animations\nIf true is passed in for hold animations in the HOLDING play state will be included",
"figura.docs.animations.stop_all": "Stops all playing (and paused) animations",
"figura.docs.animation": "A Blockbench animation",
"figura.docs.animation.name": "This animation's name",
"figura.docs.animation.animation.is_playing": "Checks if this animation is being played",
"figura.docs.animation.animation.is_paused": "Checks if this animation is paused",
"figura.docs.animation.animation.is_stopped": "Checks if this animation is stopped",
"figura.docs.animation.is_playing": "Checks if this animation is being played",
"figura.docs.animation.is_paused": "Checks if this animation is paused",
"figura.docs.animation.is_stopped": "Checks if this animation is stopped",
"figura.docs.animation.is_holding": "Checks if this animation is holding on its last frame",
"figura.docs.animation.play": "Initializes the animation\nResume the animation if it was paused",
"figura.docs.animation.pause": "Pause the animation's playback",
"figura.docs.animation.stop": "Stop the animation",
Expand Down
Loading