2022-03-17 01:40:08 -04:00
|
|
|
package funkin.play.character;
|
|
|
|
|
|
|
|
import flixel.util.typeLimit.OneOfTwo;
|
2022-03-21 00:19:05 -04:00
|
|
|
import funkin.modding.events.ScriptEvent;
|
|
|
|
import funkin.modding.events.ScriptEventDispatcher;
|
|
|
|
import funkin.play.character.BaseCharacter;
|
|
|
|
import funkin.play.character.MultiSparrowCharacter;
|
|
|
|
import funkin.play.character.PackerCharacter;
|
|
|
|
import funkin.play.character.ScriptedCharacter.ScriptedBaseCharacter;
|
|
|
|
import funkin.play.character.ScriptedCharacter.ScriptedMultiSparrowCharacter;
|
|
|
|
import funkin.play.character.ScriptedCharacter.ScriptedPackerCharacter;
|
|
|
|
import funkin.play.character.ScriptedCharacter.ScriptedSparrowCharacter;
|
2022-05-02 23:00:00 -04:00
|
|
|
import funkin.play.character.SparrowCharacter;
|
2022-03-21 00:19:05 -04:00
|
|
|
import funkin.util.VersionUtil;
|
2022-05-02 23:00:00 -04:00
|
|
|
import funkin.util.assets.DataAssets;
|
2022-03-21 00:19:05 -04:00
|
|
|
import haxe.Json;
|
|
|
|
import openfl.utils.Assets;
|
2022-03-17 01:40:08 -04:00
|
|
|
|
|
|
|
using StringTools;
|
|
|
|
|
|
|
|
class CharacterDataParser
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The current version string for the stage data format.
|
|
|
|
* Handle breaking changes by incrementing this value
|
|
|
|
* and adding migration to the `migrateStageData()` function.
|
|
|
|
*/
|
2022-03-21 00:19:05 -04:00
|
|
|
public static final CHARACTER_DATA_VERSION:String = "1.0.0";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current version rule check for the stage data format.
|
|
|
|
*/
|
|
|
|
public static final CHARACTER_DATA_VERSION_RULE:String = "1.0.x";
|
2022-03-17 01:40:08 -04:00
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
static final characterCache:Map<String, CharacterData> = new Map<String, CharacterData>();
|
|
|
|
static final characterScriptedClass:Map<String, String> = new Map<String, String>();
|
2022-03-17 01:40:08 -04:00
|
|
|
|
|
|
|
static final DEFAULT_CHAR_ID:String = 'UNKNOWN';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses and preloads the game's stage data and scripts when the game starts.
|
|
|
|
*
|
|
|
|
* If you want to force stages to be reloaded, you can just call this function again.
|
|
|
|
*/
|
|
|
|
public static function loadCharacterCache():Void
|
|
|
|
{
|
|
|
|
// Clear any stages that are cached if there were any.
|
|
|
|
clearCharacterCache();
|
|
|
|
trace("[CHARDATA] Loading character cache...");
|
|
|
|
|
|
|
|
//
|
2022-03-21 00:19:05 -04:00
|
|
|
// UNSCRIPTED CHARACTERS
|
2022-03-17 01:40:08 -04:00
|
|
|
//
|
|
|
|
var charIdList:Array<String> = DataAssets.listDataFilesInPath('characters/');
|
|
|
|
var unscriptedCharIds:Array<String> = charIdList.filter(function(charId:String):Bool
|
|
|
|
{
|
|
|
|
return !characterCache.exists(charId);
|
|
|
|
});
|
2022-03-21 00:19:05 -04:00
|
|
|
trace(' Fetching data for ${unscriptedCharIds.length} characters...');
|
2022-03-17 01:40:08 -04:00
|
|
|
for (charId in unscriptedCharIds)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var charData:CharacterData = parseCharacterData(charId);
|
|
|
|
if (charData != null)
|
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
trace(' Loaded character data: ${charId}');
|
|
|
|
characterCache.set(charId, charData);
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// Assume error was already logged.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
//
|
|
|
|
// SCRIPTED CHARACTERS
|
|
|
|
//
|
|
|
|
|
|
|
|
// Fuck I wish scripted classes supported static functions.
|
|
|
|
|
|
|
|
var scriptedCharClassNames1:Array<String> = ScriptedSparrowCharacter.listScriptClasses();
|
|
|
|
if (scriptedCharClassNames1.length > 0)
|
|
|
|
{
|
|
|
|
trace(' Instantiating ${scriptedCharClassNames1.length} (Sparrow) scripted characters...');
|
|
|
|
for (charCls in scriptedCharClassNames1)
|
|
|
|
{
|
|
|
|
var character = ScriptedSparrowCharacter.init(charCls, DEFAULT_CHAR_ID);
|
|
|
|
characterScriptedClass.set(character.characterId, charCls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var scriptedCharClassNames2:Array<String> = ScriptedPackerCharacter.listScriptClasses();
|
|
|
|
if (scriptedCharClassNames2.length > 0)
|
|
|
|
{
|
|
|
|
trace(' Instantiating ${scriptedCharClassNames2.length} (Packer) scripted characters...');
|
|
|
|
for (charCls in scriptedCharClassNames2)
|
|
|
|
{
|
|
|
|
var character = ScriptedPackerCharacter.init(charCls, DEFAULT_CHAR_ID);
|
|
|
|
characterScriptedClass.set(character.characterId, charCls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var scriptedCharClassNames3:Array<String> = ScriptedMultiSparrowCharacter.listScriptClasses();
|
2022-03-29 21:56:04 -04:00
|
|
|
if (scriptedCharClassNames3.length > 0)
|
2022-03-21 00:19:05 -04:00
|
|
|
{
|
2022-03-29 21:56:04 -04:00
|
|
|
trace(' Instantiating ${scriptedCharClassNames3.length} (Multi-Sparrow) scripted characters...');
|
|
|
|
for (charCls in scriptedCharClassNames3)
|
2022-03-21 00:19:05 -04:00
|
|
|
{
|
2022-03-29 21:56:04 -04:00
|
|
|
var character = ScriptedBaseCharacter.init(charCls, DEFAULT_CHAR_ID);
|
|
|
|
if (character == null)
|
|
|
|
{
|
|
|
|
trace(' Failed to instantiate scripted character: ${charCls}');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
characterScriptedClass.set(character.characterId, charCls);
|
2022-03-21 00:19:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: Only instantiate the ones not populated above.
|
|
|
|
// ScriptedBaseCharacter.listScriptClasses() will pick up scripts extending the other classes.
|
|
|
|
var scriptedCharClassNames:Array<String> = ScriptedBaseCharacter.listScriptClasses();
|
2022-03-29 21:56:04 -04:00
|
|
|
scriptedCharClassNames = scriptedCharClassNames.filter(function(charCls:String):Bool
|
2022-03-21 00:19:05 -04:00
|
|
|
{
|
2022-03-29 21:56:04 -04:00
|
|
|
return !(scriptedCharClassNames1.contains(charCls)
|
|
|
|
|| scriptedCharClassNames2.contains(charCls)
|
|
|
|
|| scriptedCharClassNames3.contains(charCls));
|
2022-03-21 00:19:05 -04:00
|
|
|
});
|
|
|
|
|
2022-03-29 21:56:04 -04:00
|
|
|
if (scriptedCharClassNames.length > 0)
|
2022-03-21 00:19:05 -04:00
|
|
|
{
|
2022-03-29 21:56:04 -04:00
|
|
|
trace(' Instantiating ${scriptedCharClassNames.length} (Base) scripted characters...');
|
|
|
|
for (charCls in scriptedCharClassNames)
|
2022-03-25 22:30:37 -04:00
|
|
|
{
|
2022-03-29 21:56:04 -04:00
|
|
|
var character = ScriptedBaseCharacter.init(charCls, DEFAULT_CHAR_ID);
|
|
|
|
if (character == null)
|
|
|
|
{
|
|
|
|
trace(' Failed to instantiate scripted character: ${charCls}');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace(' Successfully instantiated scripted character: ${charCls}');
|
|
|
|
characterScriptedClass.set(character.characterId, charCls);
|
|
|
|
}
|
2022-03-25 22:30:37 -04:00
|
|
|
}
|
2022-03-21 00:19:05 -04:00
|
|
|
}
|
|
|
|
|
2022-03-17 01:40:08 -04:00
|
|
|
trace(' Successfully loaded ${Lambda.count(characterCache)} stages.');
|
|
|
|
}
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
public static function fetchCharacter(charId:String):Null<BaseCharacter>
|
2022-03-17 01:40:08 -04:00
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
if (charId == null || charId == '')
|
|
|
|
{
|
|
|
|
// Gracefully handle songs that don't use this character.
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (characterCache.exists(charId))
|
2022-03-17 01:40:08 -04:00
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
var charData:CharacterData = characterCache.get(charId);
|
|
|
|
var charScriptClass:String = characterScriptedClass.get(charId);
|
2022-03-17 01:40:08 -04:00
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
var char:BaseCharacter;
|
|
|
|
|
|
|
|
if (charScriptClass != null)
|
|
|
|
{
|
|
|
|
switch (charData.renderType)
|
|
|
|
{
|
|
|
|
case CharacterRenderType.MULTISPARROW:
|
|
|
|
char = ScriptedMultiSparrowCharacter.init(charScriptClass, charId);
|
|
|
|
case CharacterRenderType.SPARROW:
|
|
|
|
char = ScriptedSparrowCharacter.init(charScriptClass, charId);
|
|
|
|
case CharacterRenderType.PACKER:
|
|
|
|
char = ScriptedPackerCharacter.init(charScriptClass, charId);
|
|
|
|
default:
|
|
|
|
// We're going to assume that the script class does the rendering.
|
|
|
|
char = ScriptedBaseCharacter.init(charScriptClass, charId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (charData.renderType)
|
|
|
|
{
|
|
|
|
case CharacterRenderType.MULTISPARROW:
|
|
|
|
char = new MultiSparrowCharacter(charId);
|
|
|
|
case CharacterRenderType.SPARROW:
|
|
|
|
char = new SparrowCharacter(charId);
|
|
|
|
case CharacterRenderType.PACKER:
|
|
|
|
char = new PackerCharacter(charId);
|
|
|
|
default:
|
|
|
|
trace('[WARN] Creating character with undefined renderType ${charData.renderType}');
|
|
|
|
char = new BaseCharacter(charId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trace('[CHARDATA] Successfully instantiated character: ${charId}');
|
|
|
|
|
|
|
|
// Call onCreate only in the fetchCharacter() function, not at application initialization.
|
|
|
|
ScriptEventDispatcher.callEvent(char, new ScriptEvent(ScriptEvent.CREATE));
|
|
|
|
|
|
|
|
return char;
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
trace('[CHARDATA] Failed to build character, not found in cache: ${charId}');
|
|
|
|
return null;
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
public static function fetchCharacterData(charId:String):Null<CharacterData>
|
2022-03-17 01:40:08 -04:00
|
|
|
{
|
|
|
|
if (characterCache.exists(charId))
|
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
return characterCache.get(charId);
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static function clearCharacterCache():Void
|
|
|
|
{
|
|
|
|
if (characterCache != null)
|
|
|
|
{
|
|
|
|
characterCache.clear();
|
|
|
|
}
|
2022-03-21 00:19:05 -04:00
|
|
|
if (characterScriptedClass != null)
|
|
|
|
{
|
|
|
|
characterScriptedClass.clear();
|
|
|
|
}
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a character's JSON file, parse its data, and return it.
|
|
|
|
*
|
|
|
|
* @param charId The character to load.
|
|
|
|
* @return The character data, or null if validation failed.
|
|
|
|
*/
|
|
|
|
public static function parseCharacterData(charId:String):Null<CharacterData>
|
|
|
|
{
|
|
|
|
var rawJson:String = loadCharacterFile(charId);
|
|
|
|
|
|
|
|
var charData:CharacterData = migrateCharacterData(rawJson, charId);
|
|
|
|
|
|
|
|
return validateCharacterData(charId, charData);
|
|
|
|
}
|
|
|
|
|
|
|
|
static function loadCharacterFile(charPath:String):String
|
|
|
|
{
|
|
|
|
var charFilePath:String = Paths.json('characters/${charPath}');
|
2022-03-21 00:19:05 -04:00
|
|
|
var rawJson = StringTools.trim(Assets.getText(charFilePath));
|
2022-03-17 01:40:08 -04:00
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
while (!StringTools.endsWith(rawJson, "}"))
|
2022-03-17 01:40:08 -04:00
|
|
|
{
|
|
|
|
rawJson = rawJson.substr(0, rawJson.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rawJson;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function migrateCharacterData(rawJson:String, charId:String)
|
|
|
|
{
|
|
|
|
// If you update the character data format in a breaking way,
|
|
|
|
// handle migration here by checking the `version` value.
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var charData:CharacterData = cast Json.parse(rawJson);
|
|
|
|
return charData;
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
trace(' Error parsing data for character: ${charId}');
|
|
|
|
trace(' ${e}');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
/**
|
|
|
|
* The default time the character should sing for, in beats.
|
|
|
|
* Values that are too low will cause the character to stop singing between notes.
|
|
|
|
* Originally, this value was set to 1, but it was changed to 2 because that became
|
|
|
|
* too low after some other code changes.
|
|
|
|
*/
|
|
|
|
static final DEFAULT_SINGTIME:Float = 2.0;
|
|
|
|
|
2022-03-17 01:40:08 -04:00
|
|
|
static final DEFAULT_DANCEEVERY:Int = 1;
|
|
|
|
static final DEFAULT_FLIPX:Bool = false;
|
|
|
|
static final DEFAULT_FLIPY:Bool = false;
|
2022-03-21 00:19:05 -04:00
|
|
|
static final DEFAULT_FRAMERATE:Int = 24;
|
|
|
|
static final DEFAULT_ISPIXEL:Bool = false;
|
2022-03-17 01:40:08 -04:00
|
|
|
static final DEFAULT_LOOP:Bool = false;
|
2022-03-21 00:19:05 -04:00
|
|
|
static final DEFAULT_NAME:String = "Untitled Character";
|
2022-03-26 22:18:26 -04:00
|
|
|
static final DEFAULT_OFFSETS:Array<Float> = [0, 0];
|
|
|
|
static final DEFAULT_HEALTHICON_OFFSETS:Array<Int> = [0, 25];
|
2022-03-21 00:19:05 -04:00
|
|
|
static final DEFAULT_RENDERTYPE:CharacterRenderType = CharacterRenderType.SPARROW;
|
|
|
|
static final DEFAULT_SCALE:Float = 1;
|
|
|
|
static final DEFAULT_SCROLL:Array<Float> = [0, 0];
|
|
|
|
static final DEFAULT_STARTINGANIM:String = "idle";
|
2022-03-17 01:40:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set unspecified parameters to their defaults.
|
|
|
|
* If the parameter is mandatory, print an error message.
|
|
|
|
* @param id
|
|
|
|
* @param input
|
|
|
|
* @return The validated character data
|
|
|
|
*/
|
|
|
|
static function validateCharacterData(id:String, input:CharacterData):Null<CharacterData>
|
|
|
|
{
|
|
|
|
if (input == null)
|
|
|
|
{
|
2022-03-25 22:30:37 -04:00
|
|
|
// trace('[CHARDATA] ERROR: Could not parse character data for "${id}".');
|
2022-03-17 01:40:08 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.version == null)
|
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
trace('[CHARDATA] WARN: No semantic version specified for character data file "$id", assuming ${CHARACTER_DATA_VERSION}');
|
|
|
|
input.version = CHARACTER_DATA_VERSION;
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
if (!VersionUtil.validateVersion(input.version, CHARACTER_DATA_VERSION_RULE))
|
2022-03-17 01:40:08 -04:00
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
trace('[CHARDATA] ERROR: Could not load character data for "$id": bad version (got ${input.version}, expected ${CHARACTER_DATA_VERSION_RULE})');
|
2022-03-17 01:40:08 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.name == null)
|
|
|
|
{
|
|
|
|
trace('[CHARDATA] WARN: Character data for "$id" missing name');
|
|
|
|
input.name = DEFAULT_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.renderType == null)
|
|
|
|
{
|
|
|
|
input.renderType = DEFAULT_RENDERTYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.assetPath == null)
|
|
|
|
{
|
|
|
|
trace('[CHARDATA] ERROR: Could not load character data for "$id": missing assetPath');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-26 22:18:26 -04:00
|
|
|
if (input.offsets == null)
|
|
|
|
{
|
|
|
|
input.offsets = DEFAULT_OFFSETS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.cameraOffsets == null)
|
|
|
|
{
|
|
|
|
input.cameraOffsets = DEFAULT_OFFSETS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.healthIcon == null)
|
|
|
|
{
|
|
|
|
input.healthIcon = {
|
|
|
|
id: null,
|
|
|
|
scale: null,
|
|
|
|
offsets: null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.healthIcon.id == null)
|
|
|
|
{
|
|
|
|
input.healthIcon.id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.healthIcon.scale == null)
|
|
|
|
{
|
|
|
|
input.healthIcon.scale = DEFAULT_SCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.healthIcon.offsets == null)
|
|
|
|
{
|
|
|
|
input.healthIcon.offsets = DEFAULT_OFFSETS;
|
|
|
|
}
|
|
|
|
|
2022-03-17 01:40:08 -04:00
|
|
|
if (input.startingAnimation == null)
|
|
|
|
{
|
|
|
|
input.startingAnimation = DEFAULT_STARTINGANIM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.scale == null)
|
|
|
|
{
|
|
|
|
input.scale = DEFAULT_SCALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.isPixel == null)
|
|
|
|
{
|
|
|
|
input.isPixel = DEFAULT_ISPIXEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.danceEvery == null)
|
|
|
|
{
|
|
|
|
input.danceEvery = DEFAULT_DANCEEVERY;
|
|
|
|
}
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
if (input.singTime == null)
|
|
|
|
{
|
|
|
|
input.singTime = DEFAULT_SINGTIME;
|
|
|
|
}
|
|
|
|
|
2022-03-17 01:40:08 -04:00
|
|
|
if (input.animations == null || input.animations.length == 0)
|
|
|
|
{
|
|
|
|
trace('[CHARDATA] ERROR: Could not load character data for "$id": missing animations');
|
|
|
|
input.animations = [];
|
|
|
|
}
|
|
|
|
|
2022-05-02 23:00:00 -04:00
|
|
|
if (input.flipX == null)
|
|
|
|
{
|
|
|
|
input.flipX = DEFAULT_FLIPX;
|
|
|
|
}
|
|
|
|
|
2022-03-17 01:40:08 -04:00
|
|
|
if (input.animations.length == 0 && input.startingAnimation != null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (inputAnimation in input.animations)
|
|
|
|
{
|
|
|
|
if (inputAnimation.name == null)
|
|
|
|
{
|
|
|
|
trace('[CHARDATA] ERROR: Could not load character data for "$id": missing animation name for prop "${input.name}"');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputAnimation.frameRate == null)
|
|
|
|
{
|
|
|
|
inputAnimation.frameRate = DEFAULT_FRAMERATE;
|
|
|
|
}
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
if (inputAnimation.offsets == null)
|
2022-03-17 01:40:08 -04:00
|
|
|
{
|
2022-03-21 00:19:05 -04:00
|
|
|
inputAnimation.offsets = DEFAULT_OFFSETS;
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inputAnimation.looped == null)
|
|
|
|
{
|
|
|
|
inputAnimation.looped = DEFAULT_LOOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputAnimation.flipX == null)
|
|
|
|
{
|
|
|
|
inputAnimation.flipX = DEFAULT_FLIPX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputAnimation.flipY == null)
|
|
|
|
{
|
|
|
|
inputAnimation.flipY = DEFAULT_FLIPY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// All good!
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum abstract CharacterRenderType(String) from String to String
|
|
|
|
{
|
|
|
|
var SPARROW = 'sparrow';
|
|
|
|
var PACKER = 'packer';
|
2022-03-21 00:19:05 -04:00
|
|
|
var MULTISPARROW = 'multisparrow';
|
|
|
|
// TODO: FlxSpine?
|
|
|
|
// https://api.haxeflixel.com/flixel/addons/editors/spine/FlxSpine.html
|
|
|
|
// TODO: Aseprite?
|
|
|
|
// https://lib.haxe.org/p/openfl-aseprite/
|
2022-03-17 01:40:08 -04:00
|
|
|
// TODO: Animate?
|
2022-03-21 00:19:05 -04:00
|
|
|
// https://lib.haxe.org/p/flxanimate
|
|
|
|
// TODO: REDACTED
|
2022-03-17 01:40:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef CharacterData =
|
|
|
|
{
|
|
|
|
/**
|
2022-03-21 00:19:05 -04:00
|
|
|
* The sematic version number of the character data JSON format.
|
2022-03-17 01:40:08 -04:00
|
|
|
*/
|
|
|
|
var version:String;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The readable name of the character.
|
|
|
|
*/
|
|
|
|
var name:String;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of rendering system to use for the character.
|
|
|
|
* @default sparrow
|
|
|
|
*/
|
|
|
|
var renderType:CharacterRenderType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Behavior varies by render type:
|
|
|
|
* - SPARROW: Path to retrieve both the spritesheet and the XML data from.
|
|
|
|
* - PACKER: Path to retrieve both the spritsheet and the TXT data from.
|
|
|
|
*/
|
|
|
|
var assetPath:String;
|
|
|
|
|
|
|
|
/**
|
2022-03-25 22:30:37 -04:00
|
|
|
* The scale of the graphic as a float.
|
2022-03-17 01:40:08 -04:00
|
|
|
* Pro tip: On pixel-art levels, save the sprites small and set this value to 6 or so to save memory.
|
|
|
|
* @default 1
|
|
|
|
*/
|
2022-03-25 22:30:37 -04:00
|
|
|
var scale:Null<Float>;
|
|
|
|
|
2022-03-26 22:18:26 -04:00
|
|
|
/**
|
|
|
|
* Optional data about the health icon for the character.
|
|
|
|
*/
|
|
|
|
var healthIcon:Null<HealthIconData>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The global offset to the character's position, in pixels.
|
|
|
|
* @default [0, 0]
|
|
|
|
*/
|
|
|
|
var offsets:Null<Array<Float>>;
|
|
|
|
|
2022-03-25 22:30:37 -04:00
|
|
|
/**
|
|
|
|
* The amount to offset the camera by while focusing on this character.
|
|
|
|
* Default value focuses on the character directly.
|
|
|
|
* @default [0, 0]
|
|
|
|
*/
|
2022-03-26 22:18:26 -04:00
|
|
|
var cameraOffsets:Array<Float>;
|
2022-03-17 01:40:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setting this to true disables anti-aliasing for the character.
|
|
|
|
* @default false
|
|
|
|
*/
|
|
|
|
var isPixel:Null<Bool>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The frequency at which the character will play its idle animation, in beats.
|
|
|
|
* Increasing this number will make the character dance less often.
|
|
|
|
*
|
|
|
|
* @default 1
|
|
|
|
*/
|
|
|
|
var danceEvery:Null<Int>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The minimum duration that a character will play a note animation for, in beats.
|
|
|
|
* If this number is too low, you may see the character start playing the idle animation between notes.
|
|
|
|
* If this number is too high, you may see the the character play the sing animation for too long after the notes are gone.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* - Daddy Dearest uses a value of `1.525`.
|
|
|
|
* @default 1.0
|
|
|
|
*/
|
|
|
|
var singTime:Null<Float>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An optional array of animations which the character can play.
|
|
|
|
*/
|
|
|
|
var animations:Array<AnimationData>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If animations are used, this is the name of the animation to play first.
|
|
|
|
* @default idle
|
|
|
|
*/
|
|
|
|
var startingAnimation:Null<String>;
|
2022-05-02 23:00:00 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the whole ass sprite is flipped by default.
|
|
|
|
* Useful for characters that could also be played (Pico)
|
|
|
|
*
|
|
|
|
* @default false
|
|
|
|
*/
|
|
|
|
var flipX:Null<Bool>;
|
2022-03-17 01:40:08 -04:00
|
|
|
};
|
2022-03-26 22:18:26 -04:00
|
|
|
|
|
|
|
typedef HealthIconData =
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The ID to use for the health icon.
|
|
|
|
* @default The character's ID
|
|
|
|
*/
|
|
|
|
var id:Null<String>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The scale of the health icon.
|
|
|
|
*/
|
|
|
|
var scale:Null<Float>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The offset of the health icon, in pixels.
|
|
|
|
* @default [0, 25]
|
|
|
|
*/
|
|
|
|
var offsets:Null<Array<Float>>;
|
|
|
|
}
|