1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-09-03 20:28:04 +00:00
Funkin/source/funkin/play/notes/NoteHoldCover.hx

105 lines
2.4 KiB
Haxe
Raw Permalink Normal View History

2023-07-04 20:38:10 +00:00
package funkin.play.notes;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import flixel.graphics.frames.FlxFramesCollection;
2023-07-10 22:14:34 +00:00
import funkin.util.assets.FlxAnimationUtil;
2023-07-04 20:38:10 +00:00
import flixel.FlxSprite;
2025-03-12 01:06:28 +00:00
import funkin.play.notes.notestyle.NoteStyle;
2023-07-04 20:38:10 +00:00
class NoteHoldCover extends FlxTypedSpriteGroup<FlxSprite>
{
static final FRAMERATE_DEFAULT:Int = 24;
2023-07-06 02:11:58 +00:00
public var holdNote:SustainTrail;
2025-03-12 01:06:28 +00:00
public var glow:FlxSprite;
2023-07-04 20:38:10 +00:00
var sparks:FlxSprite;
2025-03-12 01:06:28 +00:00
public function new(noteStyle:NoteStyle)
2023-07-04 20:38:10 +00:00
{
super(0, 0);
2025-03-12 01:06:28 +00:00
setupHoldNoteCover(noteStyle);
2023-07-06 02:11:58 +00:00
}
2023-07-04 20:38:10 +00:00
/**
* Add ALL the animations to this sprite. We will recycle and reuse the FlxSprite multiple times.
*/
2025-03-12 01:06:28 +00:00
function setupHoldNoteCover(noteStyle:NoteStyle):Void
2023-07-04 20:38:10 +00:00
{
glow = new FlxSprite();
add(glow);
2025-03-12 01:06:28 +00:00
// TODO: null check here like how NoteSplash does
noteStyle.buildHoldCoverSprite(this);
2023-07-04 20:38:10 +00:00
2025-03-03 02:44:41 +00:00
glow.animation.onFinish.add(this.onAnimationFinished);
2023-07-04 20:38:10 +00:00
2023-07-10 22:14:34 +00:00
if (glow.animation.getAnimationList().length < 3 * 4)
2023-07-04 20:38:10 +00:00
{
trace('WARNING: NoteHoldCover failed to initialize all animations.');
}
}
2023-07-06 02:11:58 +00:00
public override function update(elapsed):Void
2023-07-04 20:38:10 +00:00
{
2023-07-06 02:11:58 +00:00
super.update(elapsed);
2023-07-04 20:38:10 +00:00
}
2023-07-06 02:11:58 +00:00
public function playStart():Void
2023-07-04 20:38:10 +00:00
{
2023-07-10 22:14:34 +00:00
var direction:NoteDirection = holdNote.noteDirection;
glow.animation.play('holdCoverStart${direction.colorName.toTitleCase()}');
2023-07-06 02:11:58 +00:00
}
public function playContinue():Void
{
2023-07-10 22:14:34 +00:00
var direction:NoteDirection = holdNote.noteDirection;
glow.animation.play('holdCover${direction.colorName.toTitleCase()}');
2023-07-04 20:38:10 +00:00
}
2023-07-06 02:11:58 +00:00
public function playEnd():Void
2023-07-04 20:38:10 +00:00
{
2023-07-10 22:14:34 +00:00
var direction:NoteDirection = holdNote.noteDirection;
glow.animation.play('holdCoverEnd${direction.colorName.toTitleCase()}');
2023-07-04 20:38:10 +00:00
}
public override function kill():Void
{
super.kill();
this.visible = false;
holdNote.cover = null;
if (glow != null) glow.visible = false;
if (sparks != null) sparks.visible = false;
}
public override function revive():Void
{
super.revive();
this.visible = true;
this.alpha = 1.0;
if (glow != null) glow.visible = true;
if (sparks != null) sparks.visible = true;
}
2023-07-04 20:38:10 +00:00
public function onAnimationFinished(animationName:String):Void
{
2023-07-06 02:11:58 +00:00
if (animationName.startsWith('holdCoverStart'))
{
playContinue();
}
2023-07-04 20:38:10 +00:00
if (animationName.startsWith('holdCoverEnd'))
{
// *lightning* *zap* *crackle*
2023-07-06 02:11:58 +00:00
this.visible = false;
2023-07-04 20:38:10 +00:00
this.kill();
}
}
}