Funkin/source/funkin/play/character/PackerCharacter.hx

80 lines
1.9 KiB
Haxe
Raw Normal View History

package funkin.play.character;
2022-03-23 01:18:23 -04:00
import flixel.graphics.frames.FlxFramesCollection;
import funkin.modding.events.ScriptEvent;
import funkin.play.character.CharacterData.CharacterRenderType;
2022-03-23 01:18:23 -04:00
import funkin.util.assets.FlxAnimationUtil;
/**
* A PackerCharacter is a Character which is rendered by
* displaying an animation derived from a Packer spritesheet file.
*/
class PackerCharacter extends BaseCharacter
{
2023-01-22 19:55:30 -05:00
public function new(id:String)
{
super(id, CharacterRenderType.Packer);
2023-01-22 19:55:30 -05:00
}
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
override function onCreate(event:ScriptEvent):Void
{
trace('Creating Packer character: ' + this.characterId);
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
loadSpritesheet();
loadAnimations();
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
super.onCreate(event);
}
2022-03-23 01:18:23 -04:00
function loadSpritesheet():Void
2023-01-22 19:55:30 -05:00
{
trace('[PACKERCHAR] Loading spritesheet ${_data.assetPath} for ${characterId}');
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
var tex:FlxFramesCollection = Paths.getPackerAtlas(_data.assetPath, 'shared');
if (tex == null)
{
trace('Could not load Packer sprite: ${_data.assetPath}');
return;
}
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
this.frames = tex;
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
if (_data.isPixel)
{
2023-06-15 00:29:18 -04:00
this.isPixel = true;
2023-01-22 19:55:30 -05:00
this.antialiasing = false;
2024-06-19 23:47:11 -04:00
pixelPerfectRender = true;
pixelPerfectPosition = true;
2023-01-22 19:55:30 -05:00
}
else
{
2023-06-15 00:29:18 -04:00
this.isPixel = false;
2023-01-22 19:55:30 -05:00
this.antialiasing = true;
}
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
this.setScale(_data.scale);
}
2022-03-23 01:18:23 -04:00
function loadAnimations():Void
2023-01-22 19:55:30 -05:00
{
trace('[PACKERCHAR] Loading ${_data.animations.length} animations for ${characterId}');
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
FlxAnimationUtil.addAtlasAnimations(this, _data.animations);
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
for (anim in _data.animations)
{
if (anim.offsets == null)
{
setAnimationOffsets(anim.name, 0, 0);
}
else
{
setAnimationOffsets(anim.name, anim.offsets[0], anim.offsets[1]);
}
}
2022-03-23 01:18:23 -04:00
2023-01-22 19:55:30 -05:00
var animNames = this.animation.getNameList();
trace('[PACKERCHAR] Successfully loaded ${animNames.length} animations for ${characterId}');
}
}