1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-09-04 20:58:03 +00:00
Funkin/source/funkin/data/stickers/StickerRegistry.hx

95 lines
2.8 KiB
Haxe
Raw Permalink Normal View History

2025-01-15 22:41:17 +00:00
package funkin.data.stickers;
import funkin.data.stickers.StickerData;
import funkin.ui.transition.stickers.StickerPack;
import funkin.ui.transition.stickers.ScriptedStickerPack;
2025-01-15 22:41:17 +00:00
2025-05-03 00:03:56 +00:00
@:nullSafety
2025-08-11 21:07:20 +00:00
class StickerRegistry extends BaseRegistry<StickerPack, StickerData, StickerEntryParams>
2025-01-15 22:41:17 +00:00
{
/**
* The current version string for the sticker pack data format.
2025-01-15 22:41:17 +00:00
* Handle breaking changes by incrementing this value
* and adding migration to the `migrateStickerData()` function.
*/
public static final STICKER_DATA_VERSION:thx.semver.Version = '1.0.0';
public static final STICKER_DATA_VERSION_RULE:thx.semver.VersionRule = '1.0.x';
public static final instance:StickerRegistry = new StickerRegistry();
public function new()
{
super('STICKER', 'stickerpacks', STICKER_DATA_VERSION_RULE);
}
public function fetchDefault():StickerPack
{
2025-05-03 00:03:56 +00:00
var stickerPack:Null<StickerPack> = fetchEntry(Constants.DEFAULT_STICKER_PACK);
if (stickerPack == null) throw 'Default sticker pack was null! This should not happen!';
return stickerPack;
2025-01-15 22:41:17 +00:00
}
/**
* Read, parse, and validate the JSON data and produce the corresponding data object.
* @param id The ID of the entry to load.
* @return The parsed data object.
*/
public function parseEntryData(id:String):Null<StickerData>
{
// JsonParser does not take type parameters,
// otherwise this function would be in BaseRegistry.
var parser:json2object.JsonParser<StickerData> = new json2object.JsonParser<StickerData>();
parser.ignoreUnknownVariables = false;
switch (loadEntryFile(id))
{
case {fileName: fileName, contents: contents}:
parser.fromJson(contents, fileName);
default:
return null;
}
if (parser.errors.length > 0)
{
printErrors(parser.errors, id);
return null;
}
return parser.value;
}
/**
* Parse and validate the JSON data and produce the corresponding data object.
*
* NOTE: Must be implemented on the implementation class.
* @param contents The JSON as a string.
* @param fileName An optional file name for error reporting.
* @return The parsed data object.
*/
public function parseEntryDataRaw(contents:String, ?fileName:String):Null<StickerData>
{
var parser:json2object.JsonParser<StickerData> = new json2object.JsonParser<StickerData>();
parser.ignoreUnknownVariables = false;
parser.fromJson(contents, fileName);
if (parser.errors.length > 0)
{
printErrors(parser.errors, fileName);
return null;
}
return parser.value;
}
function createScriptedEntry(clsName:String):StickerPack
2025-01-15 22:41:17 +00:00
{
return ScriptedStickerPack.init(clsName, 'unknown');
2025-01-15 22:41:17 +00:00
}
function getScriptedClassNames():Array<String>
{
return ScriptedStickerPack.listScriptClasses();
2025-01-15 22:41:17 +00:00
}
}
2025-08-11 21:07:20 +00:00
typedef StickerEntryParams = {}