86 lines
2.1 KiB
Haxe
86 lines
2.1 KiB
Haxe
package;
|
|
|
|
import flixel.FlxSprite;
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
|
#if MODS_ALLOWED
|
|
import sys.io.File;
|
|
import sys.FileSystem;
|
|
#end
|
|
import openfl.utils.Assets;
|
|
import haxe.Json;
|
|
import haxe.format.JsonParser;
|
|
|
|
typedef MenuCharacterFile = {
|
|
var image:String;
|
|
var scale:Float;
|
|
var position:Array<Int>;
|
|
var idle_anim:String;
|
|
var confirm_anim:String;
|
|
}
|
|
|
|
class MenuCharacter extends FlxSprite
|
|
{
|
|
public var character:String;
|
|
private static var DEFAULT_CHARACTER:String = 'bf';
|
|
|
|
public function new(x:Float, character:String = 'bf')
|
|
{
|
|
super(x);
|
|
|
|
changeCharacter(character);
|
|
}
|
|
|
|
public function changeCharacter(?character:String = 'bf') {
|
|
if(character == null) character = '';
|
|
if(character == this.character) return;
|
|
|
|
this.character = character;
|
|
antialiasing = ClientPrefs.globalAntialiasing;
|
|
visible = true;
|
|
|
|
var dontPlayAnim:Bool = false;
|
|
scale.set(1, 1);
|
|
updateHitbox();
|
|
|
|
switch(character) {
|
|
case '':
|
|
visible = false;
|
|
dontPlayAnim = true;
|
|
default:
|
|
var characterPath:String = 'images/menucharacters/' + character + '.json';
|
|
var rawJson = null;
|
|
|
|
#if MODS_ALLOWED
|
|
var path:String = Paths.modFolders(characterPath);
|
|
if (!FileSystem.exists(path)) {
|
|
path = Paths.getPreloadPath(characterPath);
|
|
}
|
|
|
|
if(!FileSystem.exists(path)) {
|
|
path = Paths.getPreloadPath('images/menucharacters/' + DEFAULT_CHARACTER + '.json');
|
|
}
|
|
rawJson = File.getContent(path);
|
|
|
|
#else
|
|
var path:String = Paths.getPreloadPath(characterPath);
|
|
if(!Assets.exists(path)) {
|
|
path = Paths.getPreloadPath('images/menucharacters/' + DEFAULT_CHARACTER + '.json');
|
|
}
|
|
rawJson = Assets.getText(path);
|
|
#end
|
|
|
|
var charFile:MenuCharacterFile = cast Json.parse(rawJson);
|
|
frames = Paths.getSparrowAtlas('menucharacters/' + charFile.image);
|
|
animation.addByPrefix('idle', charFile.idle_anim, 24);
|
|
animation.addByPrefix('confirm', charFile.confirm_anim, 24, false);
|
|
|
|
if(charFile.scale != 1) {
|
|
scale.set(charFile.scale, charFile.scale);
|
|
updateHitbox();
|
|
}
|
|
offset.set(charFile.position[0], charFile.position[1]);
|
|
animation.play('idle');
|
|
}
|
|
}
|
|
}
|