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
1 change: 1 addition & 0 deletions project.hxp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class Project extends HXProject
addHaxeFlag("--macro include('flixel', true, ['flixel.addons.editors.spine.*', 'flixel.addons.nape.*', 'flixel.system.macros.*', 'flixel.addons.tile.FlxRayCastTilemap'])");
addHaxeFlag("--macro addMetadata('@:build(funkin.util.macro.ZProperty.buildZProperty())', 'flixel.FlxBasic')");
addHaxeFlag("--macro addMetadata('@:build(funkin.util.macro.ZProperty.buildRearrangeFunction())', 'flixel.group.FlxTypedGroup')");
addHaxeFlag("--macro addMetadata('@:build(funkin.util.macro.AnimPriority.build())', 'flixel.animation.FlxAnimation')");
addHaxeFlag('--no-output', FUNKIN_DOX_GENERATION.isEnabled(this));
addHaxeFlag('-xml docs/dox/' + Std.string(target).toLowerCase() + '.xml', FUNKIN_DOX_GENERATION.isEnabled(this));
}
Expand Down
45 changes: 26 additions & 19 deletions src/funkin/FunkinSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -107,47 +107,54 @@ class FunkinSprite extends FlxAnimate
*/
public var currentAnim(default, null):String = '';

var animationStunned:Bool = false;

/**
* Plays an animation.
* @param name The name of the animation to play.
* @param id The id of the animation to play.
* @param restart Should the animation restart if it's already playing?
* @param stunAnimations Should the animations be "stunned" until this one is finished?
* @param reversed Should the animation be reversed?
*/
public function playAnimation(name:String, ?restart:Bool = false, ?stunAnimations:Bool = false, ?reversed:Bool = false):Void
public function playAnimation(id:String, ?restart:Bool = false, ?reversed:Bool = false):Void
{
if (animationStunned)
if (animation?.getByName(id)?.priority ?? 0 < animation?.curAnim?.priority ?? 0)
{
return;
}

animation.play(name, restart, reversed);
animationStunned = stunAnimations;
currentAnim = name;
animation.play(id, restart, reversed);
currentAnim = id;
}

/**
* Adds an Animation to the sprite.
* @param name The name of the animation to add.
* @param anim The actual animation name.
* @param id The id of the animation to add.
* @param anim The actual animation name to be used.
* @param indices The frame indices to use. (Optional)
* @param frameRate The Frame Rate of the animation. (Optional)
* @param looped Should the animation loop? (Optional)
* @param flipX Should the animation be flipped horizontally? (Optional)
* @param flipY Should the animation be flipped vertically? (Optional)
*/
public function addAnimation(name:String, anim:String, ?indices:Array<Int> = null, ?frameRate:Float = 24, ?looped:Bool = true):Void
public function addAnimation(id:String, anim:String, ?priority:Int = 0, ?indices:Array<Int> = null, ?frameRate:Float = 24, ?looped:Bool = true,
?flipX:Bool = false, ?flipY:Bool = false):Void
{
var atlasAnimList:Array<String> = super.getAnimateAnimations();

if (atlasAnimList.contains(anim))
{
super.addAnimateAtlasAnimation(name, anim, indices, frameRate, looped);
super.addAnimateAtlasAnimation(id, anim, priority, indices, frameRate, looped, flipX, flipY);
return;
}

if (indices != null && indices.length > 0)
animation.addByIndices(name, anim + '0', indices, '', frameRate, looped);
{
animation.addByIndices(id, anim + '0', indices, '', frameRate, looped, flipX, flipY);
}
else
animation.addByPrefix(name, anim + '0', frameRate, looped);
{
animation.addByPrefix(id, anim + '0', frameRate, looped, flipX, flipY);
}

animation.getByName(id).priority = priority;
}

/**
Expand Down Expand Up @@ -209,16 +216,16 @@ class FunkinSprite extends FlxAnimate

/**
* Checks if the animation specified exists.
* @param name The animation name to check for.
* @param id The animation id to check for.
* @return If the animation exists.
*/
public function animationExists(name:String):Bool
public function animationExists(id:String):Bool
{
var atlasAnimList:Array<String> = super.getAnimateAnimations();
if (atlasAnimList.contains(name))
if (atlasAnimList.contains(id))
return true;

return animation?.exists(name) ?? false;
return animation?.exists(id) ?? false;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/funkin/data/object/ObjectData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ typedef AnimationData =

typedef AnimationDataArray =
{
var name:String;
var id:String;

var prefix:String;

var priority:Int;

@:optional
var ?indices:Array<Int>;

Expand Down
12 changes: 7 additions & 5 deletions src/funkin/play/hud/HealthIcon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ class HealthIcon extends FunkinSprite
for (anim in metadata.animations)
{
if (metadata.resolution != null)
animation.add(anim.name, anim.indices, anim.framerate, anim.looped, anim.flipX, anim.flipY);
{
animation.add(anim.id, anim?.indices ?? [0], anim?.framerate ?? 24, anim?.looped ?? true, anim?.flipX ?? false, anim?.flipY ?? false);
animation.getByName(anim.id).priority = anim.priority;
}
else
{
if (anim.indices.length != 0)
animation.addByIndices(anim.name, anim.prefix, anim.indices, '', anim.framerate, anim.looped, anim.flipX, anim.flipY);
else
animation.addByPrefix(anim.name, anim.prefix, anim.framerate, anim.looped, anim.flipX, anim.flipY);
addAnimation(anim.id, anim.prefix, anim?.priority ?? 0, anim?.indices ?? [], anim?.framerate ?? 24, anim?.looped ?? true, anim?.flipX ?? false,
anim?.flipY ?? false);
}
}

Expand All @@ -151,7 +153,7 @@ class HealthIcon extends FunkinSprite
continue;

if (curHealth >= check.minimumHealth && curHealth <= check.maximumHealth)
animation.play(check.anim, true);
playAnimation(check.anim, true);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/funkin/play/hud/strumline/NoteHoldCover.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ class NoteHoldCover extends FunkinSprite
// TODO: make this softcoded
loadFrames('gameplay/hud/funkin/strumline/sustainCover');

addAnimation('start', 'sustain cover pre', null, 24, false);
addAnimation('loop', 'sustain cover', null, 24, true);
addAnimation('end', 'sustain cover end', null, 24, false);
addAnimation('start', 'sustain cover pre', 0, null, 24, false);
addAnimation('loop', 'sustain cover', 0, null, 24, true);
addAnimation('end', 'sustain cover end', 0, null, 24, false);

onAnimFinished.add(onAnimationFinished);
}

override public function playAnimation(name:String, ?restart:Bool = false, ?stunAnimations:Bool = false, ?reversed:Bool = false):Void
override public function playAnimation(name:String, ?restart:Bool = false, ?reversed:Bool = false):Void
{
super.playAnimation(name, restart, stunAnimations, reversed);
super.playAnimation(name, restart, reversed);
centerOffsets();

switch (name)
Expand Down
2 changes: 1 addition & 1 deletion src/funkin/play/hud/strumline/NoteSplash.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NoteSplash extends FunkinSprite
{
for (i in 0...2)
{
addAnimation('${direction}-$i', 'note impact ${i + 1} ${direction.color}', null, 24, false);
addAnimation('${direction}-$i', 'note impact ${i + 1} ${direction.color}', 0, null, 24, false);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/funkin/play/hud/strumline/StrumlineNote.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class StrumlineNote extends FunkinSprite
public var forceActive:Bool = false;

/**
* Hold cover over this strumline note.
* Hold cover over this strumline note.
* This is never used internally, but is used by Strumline to find it.
*/
// public var holdCover:NoteHoldCover;
Expand All @@ -34,10 +34,10 @@ class StrumlineNote extends FunkinSprite
setGraphicSize(Std.int(width * 0.7));
updateHitbox();

addAnimation('static', 'arrow ${direction.name}', null, 24, false);
addAnimation('press', '${direction.name} press', null, 24, false);
addAnimation('confirm', '${direction.name} confirm', null, 24, false);
addAnimation('confirm-hold', '${direction.name} confirm hold', null, 24, false);
addAnimation('static', 'arrow ${direction.name}', 0, null, 24, false);
addAnimation('press', '${direction.name} press', 0, null, 24, false);
addAnimation('confirm', '${direction.name} confirm', 0, null, 24, false);
addAnimation('confirm-hold', '${direction.name} confirm hold', 0, null, 24, false);
playAnimation('static');
onAnimFinished.add(onAnimationFinished);
}
Expand All @@ -52,10 +52,10 @@ class StrumlineNote extends FunkinSprite
}
}

override public function playAnimation(name:String, ?restart:Bool = false, ?stunAnimations:Bool = false, ?reversed:Bool = false):Void
override public function playAnimation(id:String, ?restart:Bool = false, ?reversed:Bool = false):Void
{
this.active = (forceActive || isAnimationDynamic(name));
super.playAnimation(name, restart, stunAnimations, reversed);
this.active = (forceActive || isAnimationDynamic(id));
super.playAnimation(id, restart, reversed);
centerOffsets();
centerOrigin();

Expand Down
6 changes: 3 additions & 3 deletions src/funkin/ui/freeplay/FreeplayCapsule.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class FreeplayCapsule extends FlxSpriteGroup
super();

capsule = new FunkinSprite().loadFrames('ui/freeplay/capsule/default');
capsule.addAnimation('selected', 'mp3 capsule w backing0', null, 24);
capsule.addAnimation('unselected', 'mp3 capsule w backing NOT SELECTED', null, 24);
capsule.addAnimation('selected', 'mp3 capsule w backing0', 0, null, 24);
capsule.addAnimation('unselected', 'mp3 capsule w backing NOT SELECTED', 0, null, 24);
capsule.scale.set(realScaled, realScaled);
add(capsule);

Expand Down Expand Up @@ -73,7 +73,7 @@ class FreeplayCapsule extends FlxSpriteGroup
capsuleText.alpha = selected ? 1 : 0.6;
capsuleText.textBlur.visible = selected ? true : false;
capsule.offset.x = selected ? 0 : -5;
capsule.animation.play(selected ? "selected" : "unselected");
capsule.playAnimation(selected ? "selected" : "unselected");

if (capsuleText.tooLong)
capsuleText.resetText();
Expand Down
10 changes: 5 additions & 5 deletions src/funkin/ui/freeplay/PixelIcon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class PixelIcon extends FunkinSprite
if (animated)
{
active = true;
addAnimation('idle', 'idle', null, 10, true);
addAnimation('confirm', 'confirm', null, 10, false);
addAnimation('confirm-hold', 'confirm-hold', null, 10, true);
addAnimation('idle', 'idle', 0, null, 10, true);
addAnimation('confirm', 'confirm', 0, null, 10, false);
addAnimation('confirm-hold', 'confirm-hold', 0, null, 10, true);

onAnimFinished.add((name:String) ->
onAnimFinished.add((id:String) ->
{
if (name == 'confirm')
if (id == 'confirm')
playAnimation('confirm-hold');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class BoyfriendBackingCard extends BackingCard
add(glow);

backingTextYeah = new FunkinSprite(640, 370).loadFrames('ui/freeplay/backingCard/backing-text-yeah');
backingTextYeah.addAnimation("anim", "BF back card confirm raw", 24, false);
backingTextYeah.addAnimation("anim", "BF back card confirm raw", 0, 24, false);
add(backingTextYeah);
}

Expand Down
6 changes: 3 additions & 3 deletions src/funkin/ui/freeplay/dj/FreeplayDJ.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class FreeplayDJ extends FunkinSprite
loadFrames('ui/freeplay/freeplay-boyfriend');
applyStageMatrix = true;

addAnimation('idle', 'Idle', 24, false);
addAnimation('confirm', 'Confirm', 24, false);
addAnimation('intro', 'Intro', 24, false);
addAnimation('idle', 'Idle', 0, 24, false);
addAnimation('confirm', 'Confirm', 0, 24, false);
addAnimation('intro', 'Intro', 0, 24, false);
}

onAnimFinished.add(onFinishAnim);
Expand Down
8 changes: 4 additions & 4 deletions src/funkin/ui/menu/MenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class MenuState extends FunkinState
{
var itemSpr:FunkinSprite = new FunkinSprite(0, top + (spacing * i));
itemSpr.loadFrames('ui/menu/items/' + item.id);
itemSpr.addAnimation('idle', item.id + ' idle', [], 30, true);
itemSpr.addAnimation('selected', item.id + ' selected', [], 30, true);
itemSpr.addAnimation('idle', item.id + ' idle', 0, [], 30, true);
itemSpr.addAnimation('selected', item.id + ' selected', 0, [], 30, true);
itemSpr.playAnimation('idle');
itemSpr.updateHitbox();
itemSpr.screenCenter(X);
Expand Down Expand Up @@ -259,10 +259,10 @@ class MenuState extends FunkinState
if (menuItemGroup.members.indexOf(item) == curSelected)
{
camFollow.setPosition(FlxG.width / 2, item.getGraphicMidpoint().y);
item.animation.play('selected', true);
item.playAnimation('selected', true);
}
else
item.animation.play('idle', true);
item.playAnimation('idle', true);

item.centerOffsets();
});
Expand Down
2 changes: 1 addition & 1 deletion src/funkin/ui/story/StoryModeState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class StoryModeState extends FunkinState
for (spr in grp.members)
{
if (spr.currentAnim != 'confirm')
spr.animation.play(getIdleAnimationForSprite(spr), false);
spr.playAnimation(getIdleAnimationForSprite(spr), false);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/funkin/ui/title/TitleState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,25 @@ class TitleState extends FunkinState
{
logoBumpin = new FunkinSprite(-150 + 116, -100 + 106);
logoBumpin.frames = Paths.content.sparrowAtlas('ui/title/logoBumpin');
logoBumpin.animation.addByPrefix('bump', 'logo bumpin', 24, false);
logoBumpin.animation.play('bump');
logoBumpin.addAnimation('bump', 'logo bumpin', 0, 24, false);
logoBumpin.playAnimation('bump');
logoBumpin.updateHitbox();
logoBumpin.visible = false;
add(logoBumpin);

gfDance = new FunkinSprite(FlxG.width * 0.4, FlxG.height * 0.07);
gfDance.loadFrames('ui/title/gfDanceTitle');
gfDance.addAnimation('danceLeft', 'gfDance', [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 24, false);
gfDance.addAnimation('danceRight', 'gfDance', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], 24, false);
gfDance.addAnimation('danceLeft', 'gfDance', 0, [30, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 24, false);
gfDance.addAnimation('danceRight', 'gfDance', 0, [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], 24, false);
gfDance.updateHitbox();
gfDance.visible = false;
add(gfDance);

enterSpr = new FunkinSprite(0, FlxG.height * 0.8);
enterSpr.loadFrames('ui/title/titleEnter');
enterSpr.animation.addByPrefix('idle', "Press Enter to Begin", 24);
enterSpr.animation.addByPrefix('press', "ENTER PRESSED", 24);
enterSpr.animation.play('idle');
enterSpr.addAnimation('idle', "Press Enter to Begin", 0, 24);
enterSpr.addAnimation('press', "ENTER PRESSED", 0, 24);
enterSpr.playAnimation('idle');
enterSpr.updateHitbox();
enterSpr.screenCenter(X);
enterSpr.visible = false;
Expand Down Expand Up @@ -406,12 +406,12 @@ class TitleState extends FunkinState

if (logoBumpin != null && logoBumpin.animation != null)
{
logoBumpin.animation.play('bump', true);
logoBumpin.playAnimation('bump', true);
}

if (gfDance != null && gfDance.animation != null)
{
gfDance.animation.play('${gfHasDancedLeft ? 'danceLeft' : 'danceRight'}', true);
gfDance.playAnimation('${gfHasDancedLeft ? 'danceLeft' : 'danceRight'}', true);
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/funkin/util/FlxAnimateUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ class FlxAnimateUtil
* Adds a Texture Atlas Animation to a sprite.
* Frame Labels and Symbols are supported.
* @param sprite The sprite to apply this animation to.
* @param name What this animation should be called (e.g. `"run"`).
* @param id What this animation should be called (e.g. `"run"`).
* @param prefix The name of the Texture Atlas animation internally.
* @param indices An array of numbers indicating what frames to play in what order (e.g. `[0, 1, 2]`).
* @param frameRate The speed in frames per second that the animation should play at (e.g. `40` fps), leave ``null`` to use the default framerate.
* @param looped Whether or not the animation is looped or just plays once.
* @param flipX Whether the frames should be flipped horizontally.
* @param flipY Whether the frames should be flipped vertically.
*/
public static function addAnimateAtlasAnimation(sprite:FlxAnimate, name:String, prefix:String, ?indices:Array<Int>, ?frameRate:Float, ?looped:Bool = true,
?flipX:Bool, ?flipY:Bool):Void
public static function addAnimateAtlasAnimation(sprite:FlxAnimate, id:String, prefix:String, ?priority:Int = 0, ?indices:Array<Int>, ?frameRate:Float,
?looped:Bool = true, ?flipX:Bool, ?flipY:Bool):Void
{
if (sprite.library == null)
return;
Expand All @@ -109,16 +109,19 @@ class FlxAnimateUtil
if (foundLabelFrames.length > 0)
{
if (indices != null)
sprite.anim.addByFrameLabelIndices(name, newPrefix, indices, frameRate, looped, flipX, flipY);
sprite.anim.addByFrameLabelIndices(id, newPrefix, indices, frameRate, looped, flipX, flipY);
else
sprite.anim.addByFrameLabel(name, newPrefix, frameRate, looped, flipX, flipY);
sprite.anim.addByFrameLabel(id, newPrefix, frameRate, looped, flipX, flipY);
}
else
{
if (indices != null)
sprite.anim.addBySymbolIndices(name, newPrefix, indices, frameRate, looped, flipX, flipY);
sprite.anim.addBySymbolIndices(id, newPrefix, indices, frameRate, looped, flipX, flipY);
else
sprite.anim.addBySymbol(name, newPrefix, frameRate, looped, flipX, flipY);
sprite.anim.addBySymbol(id, newPrefix, frameRate, looped, flipX, flipY);
}

// TODO: idk if this works but i guess we'll find out the hard way
sprite.anim.getByName(id).priority = priority;
}
}
Loading
Loading