1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-08-31 10:56:21 +00:00
Funkin/source/funkin/ui/PixelatedIcon.hx

89 lines
2 KiB
Haxe
Raw Permalink Normal View History

2024-07-03 01:26:16 +00:00
package funkin.ui;
2024-09-06 04:28:08 +00:00
import funkin.graphics.FlxFilteredSprite;
2024-07-03 01:26:16 +00:00
/**
* The icon that gets used for Freeplay capsules and char select
* NOT to be confused with the CharIcon class, which is for the in-game icons
*/
@:nullSafety
2024-09-06 04:28:08 +00:00
class PixelatedIcon extends FlxFilteredSprite
2024-07-03 01:26:16 +00:00
{
public function new(x:Float, y:Float)
{
super(x, y);
this.makeGraphic(32, 32, 0x00000000);
this.antialiasing = false;
this.active = false;
}
public function setCharacter(char:String):Void
{
var charPath:String = "freeplay/icons/";
final charIDParts:Array<String> = char.split("-");
var iconName:String = "";
2025-08-16 22:00:05 +00:00
var lastValidIconName:String = "";
for (i in 0...charIDParts.length)
2024-07-03 01:26:16 +00:00
{
iconName += charIDParts[i];
if (Assets.exists(Paths.image(charPath + '${iconName}pixel')))
{
2025-08-16 22:00:05 +00:00
lastValidIconName = iconName;
}
2025-08-16 22:00:05 +00:00
if (i < charIDParts.length - 1) iconName += '-';
2024-07-03 01:26:16 +00:00
}
2025-08-16 22:00:05 +00:00
charPath += '${lastValidIconName}pixel';
if (!Assets.exists(Paths.image(charPath)))
2024-07-03 01:26:16 +00:00
{
trace('[WARN] Character ${char} has no freeplay icon.');
this.visible = false;
2024-07-03 01:26:16 +00:00
return;
}
else
{
this.visible = true;
}
2024-07-03 01:26:16 +00:00
var isAnimated = Assets.exists(Paths.file('images/$charPath.xml'));
2024-07-03 01:26:16 +00:00
if (isAnimated)
{
this.frames = Paths.getSparrowAtlas(charPath);
}
else
{
this.loadGraphic(Paths.image(charPath));
}
this.scale.x = this.scale.y = 2;
switch (char)
{
case 'parents-christmas':
this.origin.x = 140;
default:
this.origin.x = 100;
}
if (isAnimated)
{
this.active = true;
this.animation.addByPrefix('idle', 'idle0', 10, true);
this.animation.addByPrefix('confirm', 'confirm0', 10, false);
this.animation.addByPrefix('confirm-hold', 'confirm-hold0', 10, true);
2025-05-28 23:19:08 +00:00
this.animation.onFinish.add(function(name:String):Void {
2024-07-03 01:26:16 +00:00
trace('Finish pixel animation: ${name}');
if (name == 'confirm') this.animation.play('confirm-hold');
2025-05-28 23:19:08 +00:00
});
2024-07-03 01:26:16 +00:00
this.animation.play('idle');
}
}
}