2023-07-14 00:25:44 +00:00
|
|
|
package funkin.data.notestyle;
|
|
|
|
|
|
|
|
import funkin.play.notes.notestyle.NoteStyle;
|
|
|
|
import funkin.play.notes.notestyle.ScriptedNoteStyle;
|
|
|
|
import funkin.data.notestyle.NoteStyleData;
|
|
|
|
|
|
|
|
class NoteStyleRegistry extends BaseRegistry<NoteStyle, NoteStyleData>
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The current version string for the note style data format.
|
|
|
|
* Handle breaking changes by incrementing this value
|
|
|
|
* and adding migration to the `migrateNoteStyleData()` function.
|
|
|
|
*/
|
2023-08-22 08:27:30 +00:00
|
|
|
public static final NOTE_STYLE_DATA_VERSION:thx.semver.Version = "1.0.0";
|
|
|
|
|
|
|
|
public static final NOTE_STYLE_DATA_VERSION_RULE:thx.semver.VersionRule = "1.0.x";
|
2023-07-14 00:25:44 +00:00
|
|
|
|
2024-03-22 06:47:21 +00:00
|
|
|
public static var instance(get, never):NoteStyleRegistry;
|
|
|
|
static var _instance:Null<NoteStyleRegistry> = null;
|
|
|
|
|
|
|
|
static function get_instance():NoteStyleRegistry
|
|
|
|
{
|
|
|
|
if (_instance == null) _instance = new NoteStyleRegistry();
|
|
|
|
return _instance;
|
|
|
|
}
|
2023-07-14 00:25:44 +00:00
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
2023-08-22 08:27:30 +00:00
|
|
|
super('NOTESTYLE', 'notestyles', NOTE_STYLE_DATA_VERSION_RULE);
|
2023-07-14 00:25:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function fetchDefault():NoteStyle
|
|
|
|
{
|
2023-10-21 05:04:50 +00:00
|
|
|
return fetchEntry(Constants.DEFAULT_NOTE_STYLE);
|
2023-07-14 00:25:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read, parse, and validate the JSON data and produce the corresponding data object.
|
|
|
|
*/
|
|
|
|
public function parseEntryData(id:String):Null<NoteStyleData>
|
|
|
|
{
|
|
|
|
// JsonParser does not take type parameters,
|
|
|
|
// otherwise this function would be in BaseRegistry.
|
|
|
|
var parser = new json2object.JsonParser<NoteStyleData>();
|
2023-12-19 06:23:42 +00:00
|
|
|
parser.ignoreUnknownVariables = false;
|
2023-07-14 00:25:44 +00:00
|
|
|
|
2023-09-08 21:45:47 +00:00
|
|
|
switch (loadEntryFile(id))
|
|
|
|
{
|
|
|
|
case {fileName: fileName, contents: contents}:
|
|
|
|
parser.fromJson(contents, fileName);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2023-07-14 00:25:44 +00:00
|
|
|
|
|
|
|
if (parser.errors.length > 0)
|
|
|
|
{
|
2023-09-08 21:45:47 +00:00
|
|
|
printErrors(parser.errors, id);
|
2023-07-14 00:25:44 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return parser.value;
|
|
|
|
}
|
|
|
|
|
2023-09-26 03:24:07 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
public function parseEntryDataRaw(contents:String, ?fileName:String):Null<NoteStyleData>
|
|
|
|
{
|
|
|
|
var parser = new json2object.JsonParser<NoteStyleData>();
|
2023-12-19 06:23:42 +00:00
|
|
|
parser.ignoreUnknownVariables = false;
|
2023-09-26 03:24:07 +00:00
|
|
|
parser.fromJson(contents, fileName);
|
|
|
|
|
|
|
|
if (parser.errors.length > 0)
|
|
|
|
{
|
|
|
|
printErrors(parser.errors, fileName);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return parser.value;
|
|
|
|
}
|
|
|
|
|
2023-07-14 00:25:44 +00:00
|
|
|
function createScriptedEntry(clsName:String):NoteStyle
|
|
|
|
{
|
|
|
|
return ScriptedNoteStyle.init(clsName, "unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getScriptedClassNames():Array<String>
|
|
|
|
{
|
|
|
|
return ScriptedNoteStyle.listScriptClasses();
|
|
|
|
}
|
|
|
|
}
|