mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-15 19:33:36 +00:00
119 lines
2.7 KiB
Haxe
119 lines
2.7 KiB
Haxe
package funkin.ui.freeplay.charselect;
|
|
|
|
import funkin.data.IRegistryEntry;
|
|
import funkin.data.freeplay.player.PlayerData;
|
|
import funkin.data.freeplay.player.PlayerRegistry;
|
|
|
|
/**
|
|
* An object used to retrieve data about a playable character (also known as "weeks").
|
|
* Can be scripted to override each function, for custom behavior.
|
|
*/
|
|
class PlayableCharacter implements IRegistryEntry<PlayerData>
|
|
{
|
|
/**
|
|
* The ID of the playable character.
|
|
*/
|
|
public final id:String;
|
|
|
|
/**
|
|
* Playable character data as parsed from the JSON file.
|
|
*/
|
|
public final _data:PlayerData;
|
|
|
|
/**
|
|
* @param id The ID of the JSON file to parse.
|
|
*/
|
|
public function new(id:String)
|
|
{
|
|
this.id = id;
|
|
_data = _fetchData(id);
|
|
|
|
if (_data == null)
|
|
{
|
|
throw 'Could not parse playable character data for id: $id';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retrieve the readable name of the playable character.
|
|
*/
|
|
public function getName():String
|
|
{
|
|
// TODO: Maybe add localization support?
|
|
return _data.name;
|
|
}
|
|
|
|
/**
|
|
* Retrieve the list of stage character IDs associated with this playable character.
|
|
* @return The list of associated character IDs
|
|
*/
|
|
public function getOwnedCharacterIds():Array<String>
|
|
{
|
|
return _data.ownedChars;
|
|
}
|
|
|
|
/**
|
|
* Return `true` if, when this character is selected in Freeplay,
|
|
* songs unassociated with a specific character should appear.
|
|
*/
|
|
public function shouldShowUnownedChars():Bool
|
|
{
|
|
return _data.showUnownedChars;
|
|
}
|
|
|
|
public function shouldShowCharacter(id:String):Bool
|
|
{
|
|
if (_data.ownedChars.contains(id))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (_data.showUnownedChars)
|
|
{
|
|
var result = !PlayerRegistry.instance.isCharacterOwned(id);
|
|
return result;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getFreeplayDJData():PlayerFreeplayDJData
|
|
{
|
|
return _data.freeplayDJ;
|
|
}
|
|
|
|
public function getFreeplayDJText(index:Int):String
|
|
{
|
|
return _data.freeplayDJ.getFreeplayDJText(index);
|
|
}
|
|
|
|
/**
|
|
* Returns whether this character is unlocked.
|
|
*/
|
|
public function isUnlocked():Bool
|
|
{
|
|
return _data.unlocked;
|
|
}
|
|
|
|
/**
|
|
* Called when the character is destroyed.
|
|
* TODO: Document when this gets called
|
|
*/
|
|
public function destroy():Void {}
|
|
|
|
public function toString():String
|
|
{
|
|
return 'PlayableCharacter($id)';
|
|
}
|
|
|
|
/**
|
|
* Retrieve and parse the JSON data for a playable character by ID.
|
|
* @param id The ID of the character
|
|
* @return The parsed player data, or null if not found or invalid
|
|
*/
|
|
static function _fetchData(id:String):Null<PlayerData>
|
|
{
|
|
return PlayerRegistry.instance.parseEntryDataWithMigration(id, PlayerRegistry.instance.fetchEntryVersion(id));
|
|
}
|
|
}
|