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

Looping of character sing and strumline confirm animations on hold notes #2894

Closed
Closed
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
49 changes: 41 additions & 8 deletions source/funkin/play/character/BaseCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ class BaseCharacter extends Bopper
}
}

/**
* Stored the direction of the last note that was hit by this player.
*/
var lastNoteDirection:Null<NoteDirection> = null;

/**
* Stores the time at which the player should stop looping the sing animation when pressing a hold note.
*/
var lastHoldFinish:Null<Float> = null;

public override function onUpdate(event:UpdateScriptEvent):Void
{
super.onUpdate(event);
Expand Down Expand Up @@ -388,6 +398,17 @@ class BaseCharacter extends Bopper

// Without this check here, the player character would only play the `sing` animation
// for one beat, as opposed to holding it as long as the player is holding the button.

// Repeat the sing animation when pressing a hold note just like in the old input system.
if ((this.characterType != BF || isHoldingNote())
&& this.animation.curAnim.curFrame >= 3
&& lastNoteDirection != null
&& (lastHoldFinish != null && lastHoldFinish >= Conductor.instance.songPosition))
{
this.playSingAnimation(lastNoteDirection, false);
holdTimer = 0;
}

var shouldStopSinging:Bool = (this.characterType == BF) ? !isHoldingNote() : true;

FlxG.watch.addQuick('singTimeSec-${characterId}', singTimeSec);
Expand Down Expand Up @@ -479,6 +500,15 @@ class BaseCharacter extends Bopper
return false;
}

/**
* Resets the hold data values to stop the animation from looping
*/
function stopHolding()
{
lastNoteDirection = null;
lastHoldFinish = null;
}

/**
* Every time a note is hit, check if the note is from the same strumline.
* If it is, then play the sing animation.
Expand All @@ -487,17 +517,16 @@ class BaseCharacter extends Bopper
{
super.onNoteHit(event);

if (event.note.noteData.getMustHitNote() && characterType == BF)
{
// If the note is from the same strumline, play the sing animation.
this.playSingAnimation(event.note.noteData.getDirection(), false);
holdTimer = 0;
}
else if (!event.note.noteData.getMustHitNote() && characterType == DAD)
var noteDirection:NoteDirection = event.note.noteData.getDirection();

if ((event.note.noteData.getMustHitNote() && characterType == BF) || (!event.note.noteData.getMustHitNote() && characterType == DAD))
{
// If the note is from the same strumline, play the sing animation.
this.playSingAnimation(event.note.noteData.getDirection(), false);
this.playSingAnimation(noteDirection, false);
holdTimer = 0;

lastNoteDirection = noteDirection;
if (event.note.noteData.isHoldNote) lastHoldFinish = event.note.strumTime + event.note.noteData.length;
}
}

Expand Down Expand Up @@ -540,6 +569,8 @@ class BaseCharacter extends Bopper
this.playAnimation(dropAnim, true, true);
}
}

stopHolding();
}

/**
Expand All @@ -561,6 +592,8 @@ class BaseCharacter extends Bopper
// trace('Playing ghost miss animation...');
this.playSingAnimation(event.dir, true);
}

stopHolding();
}

public override function onDestroy(event:ScriptEvent):Void
Expand Down
8 changes: 7 additions & 1 deletion source/funkin/play/notes/Strumline.hx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ class Strumline extends FlxSpriteGroup
else if (conductorInUse.songPosition > holdNote.strumTime && holdNote.hitNote)
{
// Hold note is currently being hit, clip it off.
holdConfirm(holdNote.noteDirection);
/* holdConfirm(holdNote.noteDirection); */
playConfirmHold(holdNote.noteDirection);
holdNote.visible = true;

holdNote.sustainLength = (holdNote.strumTime + holdNote.fullSustainLength) - conductorInUse.songPosition;
Expand Down Expand Up @@ -643,6 +644,11 @@ class Strumline extends FlxSpriteGroup
getByDirection(direction).playConfirm();
}

public function playConfirmHold(direction:NoteDirection):Void
{
getByDirection(direction).playConfirmHold();
}

public function holdConfirm(direction:NoteDirection):Void
{
getByDirection(direction).holdConfirm();
Expand Down
14 changes: 14 additions & 0 deletions source/funkin/play/notes/StrumlineNote.hx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ class StrumlineNote extends FlxSprite
this.playAnimation('confirm', true);
}

public function playConfirmHold():Void
{
if (getCurrentAnimationFrame() >= 3)
{
this.active = true;
this.playAnimation('confirm', true);
}
}

public function isConfirm():Bool
{
return getCurrentAnimation().startsWith('confirm');
Expand Down Expand Up @@ -138,6 +147,11 @@ class StrumlineNote extends FlxSprite
}
}

public function getCurrentAnimationFrame():Int
{
return this.animation.curAnim.curFrame;
}

/**
* Returns the name of the animation that is currently playing.
* If no animation is playing (usually this means the sprite is BROKEN!),
Expand Down