Skip to content

Commit

Permalink
Fixes to animation looping and holds
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteMasterEric committed Mar 3, 2024
1 parent 0294ea0 commit f7a3d43
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 34 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

"haxe.displayPort": "auto",
"haxe.enableCompilationServer": false,
"haxe.enableServerView": true,
"haxe.displayServer": {
"arguments": ["-v"]
},
Expand Down
2 changes: 1 addition & 1 deletion assets
6 changes: 4 additions & 2 deletions source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ class FlxAtlasSprite extends FlxAnimate
}

anim.callback = function(_, frame:Int) {
if (frame == (anim.getFrameLabel(id).duration - 1) + anim.getFrameLabel(id).index)
var offset = loop ? 0 : -1;

if (frame == (anim.getFrameLabel(id).duration + offset) + anim.getFrameLabel(id).index)
{
if (loop)
{
Expand Down Expand Up @@ -183,7 +185,7 @@ class FlxAtlasSprite extends FlxAnimate
public function cleanupAnimation(_:String):Void
{
canPlayOtherAnims = true;
this.currentAnimation = null;
// this.currentAnimation = null;
this.anim.pause();
}
}
27 changes: 23 additions & 4 deletions source/funkin/play/character/AnimateAtlasCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class AnimateAtlasCharacter extends BaseCharacter
var _skipTransformChildren:Bool = false;

var animations:Map<String, AnimateAtlasAnimation> = new Map<String, AnimateAtlasAnimation>();
var currentAnimation:String;
var currentAnimName:Null<String> = null;
var animFinished:Bool = false;

public function new(id:String)
{
Expand Down Expand Up @@ -88,22 +89,37 @@ class AnimateAtlasCharacter extends BaseCharacter
if ((!canPlayOtherAnims && !ignoreOther)) return;

var correctName = correctAnimationName(name);
if (correctName == null) return;
if (correctName == null)
{
trace('Could not find Atlas animation: ' + name);
return;
}

var animData = getAnimationData(correctName);
currentAnimation = correctName;
currentAnimName = correctName;
var prefix:String = animData.prefix;
if (prefix == null) prefix = correctName;
var loop:Bool = animData.looped;

this.mainSprite.playAnimation(prefix, restart, ignoreOther, loop);

animFinished = false;
}

public override function hasAnimation(name:String):Bool
{
return getAnimationData(name) != null;
}

/**
* Returns true if the animation has finished playing.
* Never true if animation is configured to loop.
*/
public override function isAnimationFinished():Bool
{
return animFinished;
}

function loadAtlasSprite():FlxAtlasSprite
{
trace('[ATLASCHAR] Loading sprite atlas for ${characterId}.');
Expand All @@ -128,6 +144,8 @@ class AnimateAtlasCharacter extends BaseCharacter
{
// Make the game hold on the last frame.
this.mainSprite.cleanupAnimation(prefix);
// currentAnimName = null;
animFinished = true;

// Fallback to idle!
// playAnimation('idle', true, false);
Expand Down Expand Up @@ -178,7 +196,8 @@ class AnimateAtlasCharacter extends BaseCharacter

public override function getCurrentAnimation():String
{
return this.mainSprite.getCurrentAnimation();
// return this.mainSprite.getCurrentAnimation();
return currentAnimName;
}

function getAnimationData(name:String = null):AnimateAtlasAnimation
Expand Down
46 changes: 35 additions & 11 deletions source/funkin/play/notes/NoteSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,53 @@ class NoteSprite extends FunkinSprite
var hsvShader:HSVShader;

/**
* The time at which the note should be hit, in milliseconds.
* The strum time at which the note should be hit, in milliseconds.
*/
public var strumTime(default, set):Float;
public var strumTime(get, set):Float;

function get_strumTime():Float
{
return this.noteData?.time ?? 0.0;
}

function set_strumTime(value:Float):Float
{
this.strumTime = value;
return this.strumTime;
if (this.noteData == null) return value;
return this.noteData.time = value;
}

/**
* The length for which the note should be held, in milliseconds.
* Defaults to 0 for single notes.
*/
public var length(get, set):Float;

function get_length():Float
{
return this.noteData?.length ?? 0.0;
}

function set_length(value:Float):Float
{
if (this.noteData == null) return value;
return this.noteData.length = value;
}

/**
* An extra attribute for the note.
* For example, whether the note is an "alt" note, or whether it has custom behavior on hit.
*/
public var kind(default, set):String;
public var kind(get, set):Null<String>;

function get_kind():Null<String>
{
return this.noteData?.kind;
}

function set_kind(value:String):String
{
this.kind = value;
return this.kind;
if (this.noteData == null) return value;
return this.noteData.kind = value;
}

/**
Expand Down Expand Up @@ -100,16 +127,13 @@ class NoteSprite extends FunkinSprite
*/
public var handledMiss:Bool;

public function new(noteStyle:NoteStyle, strumTime:Float = 0, direction:Int = 0)
public function new(noteStyle:NoteStyle, direction:Int = 0)
{
super(0, -9999);
this.strumTime = strumTime;
this.direction = direction;

this.hsvShader = new HSVShader();

if (this.strumTime < 0) this.strumTime = 0;

setupNoteGraphic(noteStyle);

// Disables the update() function for performance.
Expand Down
1 change: 0 additions & 1 deletion source/funkin/play/notes/Strumline.hx
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ class Strumline extends FlxSpriteGroup

if (noteSprite != null)
{
noteSprite.strumTime = note.time;
noteSprite.direction = note.getDirection();
noteSprite.noteData = note;

Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/debug/charting/ChartEditorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5308,7 +5308,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
var startTimestamp:Float = 0;
if (playtestStartTime) startTimestamp = scrollPositionInMs + playheadPositionInMs;

var playbackRate:Float = (menubarItemPlaybackSpeed.value.toFloat() * 2.0) / 100.0;
var playbackRate:Float = ((menubarItemPlaybackSpeed.value ?? 1.0) * 2.0) / 100.0;
playbackRate = Math.floor(playbackRate / 0.05) * 0.05; // Round to nearest 5%
playbackRate = Math.max(0.05, Math.min(2.0, playbackRate)); // Clamp to 5% to 200%

Expand Down
36 changes: 24 additions & 12 deletions source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,30 @@ class ChartEditorDropdowns
"ugh" => "Ugh (Week 7)",
"hehPrettyGood" => "Heh, Pretty Good (Week 7)",
// Weekend 1
"weekend-1-lightcan" => "Light Can (2hot)",
"weekend-1-kickcan" => "Kick Can (2hot)",
"weekend-1-kneecan" => "Knee Can (2hot)",
"weekend-1-cockgun" => "Cock Gun (2hot)",
"weekend-1-firegun" => "Fire Gun (2hot)",
"weekend-1-punchlow" => "Punch Low (Blazin)",
"weekend-1-punchhigh" => "Punch High (Blazin)",
"weekend-1-punchlowblocked" => "Punch Low Blocked (Blazin)",
"weekend-1-punchhighblocked" => "Punch High Blocked (Blazin)",
"weekend-1-dodgelow" => "Dodge Low (Blazin)",
"weekend-1-blockhigh" => "Block High (Blazin)",
"weekend-1-fakeout" => "Fakeout (Blazin)",
"weekend-1-punchhigh" => "Punch High (Blazin')",
"weekend-1-punchhighdodged" => "Punch High (Dodge) (Blazin')",
"weekend-1-punchhighblocked" => "Punch High (Block) (Blazin')",
"weekend-1-punchhighspin" => "Punch High (Spin) (Blazin')",
"weekend-1-punchlow" => "Punch Low (Blazin')",
"weekend-1-punchlowdodged" => "Punch Low (Dodge) (Blazin')",
"weekend-1-punchlowblocked" => "Punch Low (Block) (Blazin')",
"weekend-1-punchlowspin" => "Punch High (Spin) (Blazin')",
"weekend-1-picouppercutprep" => "Pico Uppercut (Prep) (Blazin')",
"weekend-1-picouppercut" => "Pico Uppercut (Blazin')",
"weekend-1-blockhigh" => "Block High (Blazin')",
"weekend-1-blocklow" => "Dodge High (Blazin')",
"weekend-1-blockspin" => "Block High (Spin) (Blazin')",
"weekend-1-dodgehigh" => "Block Low (Blazin')",
"weekend-1-dodgelow" => "Dodge Low (Blazin')",
"weekend-1-dodgespin" => "Dodge High (Spin) (Blazin')",
"weekend-1-hithigh" => "Hit High (Blazin')",
"weekend-1-hitlow" => "Hit Low (Blazin')",
"weekend-1-hitspin" => "Hit High (Spin) (Blazin')",
"weekend-1-darnelluppercutprep" => "Darnell Uppercut (Prep) (Blazin')",
"weekend-1-darnelluppercut" => "Darnell Uppercut (Blazin')",
"weekend-1-idle" => "Idle (Blazin')",
"weekend-1-fakeout" => "Fakeout (Blazin')",
"weekend-1-reversefakeout" => "Reverse Fakeout (Blazin')",
];

public static function populateDropdownWithNoteKinds(dropDown:DropDown, startingKindId:String):DropDownEntry
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/debug/latency/LatencyState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class LatencyState extends MusicBeatSubState

for (i in 0...32)
{
var note:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault(), Conductor.instance.beatLengthMs * i);
var note:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault());
noteGrp.add(note);
}

Expand Down
2 changes: 1 addition & 1 deletion source/funkin/ui/options/ColorsMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ColorsMenu extends Page

for (i in 0...4)
{
var note:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault(), 0, i);
var note:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault(), i);

note.x = (100 * i) + i;
note.screenCenter(Y);
Expand Down

0 comments on commit f7a3d43

Please sign in to comment.