Funkin/source/funkin/ui/PixelatedIcon.hx

92 lines
2.3 KiB
Haxe
Raw Normal View History

2024-07-02 21:26:16 -04:00
package funkin.ui;
import flixel.FlxSprite;
/**
* 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
*/
class PixelatedIcon extends FlxSprite
{
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/";
switch (char)
{
2024-08-28 05:43:01 -04:00
case "bf-christmas" | "bf-car" | "bf-pixel" | "bf-holding-gf":
charPath += "bfpixel";
case "monster-christmas":
charPath += "monsterpixel";
case "mom" | "mom-car":
charPath += "mommypixel";
case "pico-blazin" | "pico-playable" | "pico-speaker":
charPath += "picopixel";
case "gf-christmas" | "gf-car" | "gf-pixel" | "gf-tankmen":
charPath += "gfpixel";
case "dad":
charPath += "dadpixel";
case "darnell-blazin":
charPath += "darnellpixel";
case "senpai-angry":
charPath += "senpaipixel";
case "spooky-dark":
charPath += "spookypixel";
case "tankman-atlas":
charPath += "tankmanpixel";
2024-07-02 21:26:16 -04:00
default:
charPath += '${char}pixel';
}
if (!openfl.utils.Assets.exists(Paths.image(charPath)))
{
trace('[WARN] Character ${char} has no freeplay icon.');
return;
}
var isAnimated = openfl.utils.Assets.exists(Paths.file('images/$charPath.xml'));
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);
this.animation.finishCallback = function(name:String):Void {
trace('Finish pixel animation: ${name}');
if (name == 'confirm') this.animation.play('confirm-hold');
};
this.animation.play('idle');
}
}
}