2023-05-16 22:09:53 -04:00
|
|
|
package funkin.data.level;
|
|
|
|
|
|
|
|
import funkin.ui.story.Level;
|
|
|
|
import funkin.data.level.LevelData;
|
|
|
|
import funkin.ui.story.ScriptedLevel;
|
|
|
|
|
|
|
|
class LevelRegistry extends BaseRegistry<Level, LevelData>
|
|
|
|
{
|
|
|
|
/**
|
2024-01-16 16:49:15 -05:00
|
|
|
* The current version string for the level data format.
|
2023-05-16 22:09:53 -04:00
|
|
|
* Handle breaking changes by incrementing this value
|
2024-01-16 16:49:15 -05:00
|
|
|
* and adding migration to the `migrateLevelData()` function.
|
2023-05-16 22:09:53 -04:00
|
|
|
*/
|
2023-08-22 04:27:30 -04:00
|
|
|
public static final LEVEL_DATA_VERSION:thx.semver.Version = "1.0.0";
|
|
|
|
|
|
|
|
public static final LEVEL_DATA_VERSION_RULE:thx.semver.VersionRule = "1.0.x";
|
2023-05-16 22:09:53 -04:00
|
|
|
|
|
|
|
public static final instance:LevelRegistry = new LevelRegistry();
|
|
|
|
|
|
|
|
public function new()
|
|
|
|
{
|
2023-08-22 04:27:30 -04:00
|
|
|
super('LEVEL', 'levels', LEVEL_DATA_VERSION_RULE);
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read, parse, and validate the JSON data and produce the corresponding data object.
|
|
|
|
*/
|
|
|
|
public function parseEntryData(id:String):Null<LevelData>
|
|
|
|
{
|
|
|
|
// JsonParser does not take type parameters,
|
|
|
|
// otherwise this function would be in BaseRegistry.
|
|
|
|
var parser = new json2object.JsonParser<LevelData>();
|
2023-12-19 01:23:42 -05:00
|
|
|
parser.ignoreUnknownVariables = false;
|
2023-05-16 22:09:53 -04:00
|
|
|
|
2023-09-08 17:45:47 -04:00
|
|
|
switch (loadEntryFile(id))
|
|
|
|
{
|
|
|
|
case {fileName: fileName, contents: contents}:
|
|
|
|
parser.fromJson(contents, fileName);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2023-05-16 22:09:53 -04:00
|
|
|
|
|
|
|
if (parser.errors.length > 0)
|
|
|
|
{
|
2023-09-08 17:45:47 -04:00
|
|
|
printErrors(parser.errors, id);
|
2023-05-16 22:09:53 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return parser.value;
|
|
|
|
}
|
|
|
|
|
2023-09-25 23:24:07 -04: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<LevelData>
|
|
|
|
{
|
|
|
|
var parser = new json2object.JsonParser<LevelData>();
|
2023-12-19 01:23:42 -05:00
|
|
|
parser.ignoreUnknownVariables = false;
|
2023-09-25 23:24:07 -04:00
|
|
|
parser.fromJson(contents, fileName);
|
|
|
|
|
|
|
|
if (parser.errors.length > 0)
|
|
|
|
{
|
|
|
|
printErrors(parser.errors, fileName);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return parser.value;
|
|
|
|
}
|
|
|
|
|
2023-05-16 22:09:53 -04:00
|
|
|
function createScriptedEntry(clsName:String):Level
|
|
|
|
{
|
|
|
|
return ScriptedLevel.init(clsName, "unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
function getScriptedClassNames():Array<String>
|
|
|
|
{
|
|
|
|
return ScriptedLevel.listScriptClasses();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-05-17 16:42:58 -04:00
|
|
|
* A list of all the story weeks from the base game, in order.
|
2023-05-16 22:09:53 -04:00
|
|
|
* TODO: Should this be hardcoded?
|
|
|
|
*/
|
2023-05-17 16:42:58 -04:00
|
|
|
public function listBaseGameLevelIds():Array<String>
|
2023-05-16 22:09:53 -04:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
"tutorial",
|
|
|
|
"week1",
|
|
|
|
"week2",
|
|
|
|
"week3",
|
|
|
|
"week4",
|
|
|
|
"week5",
|
|
|
|
"week6",
|
|
|
|
"week7",
|
|
|
|
"weekend1"
|
2023-05-17 16:42:58 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of all installed story weeks that are not from the base game.
|
|
|
|
*/
|
|
|
|
public function listModdedLevelIds():Array<String>
|
|
|
|
{
|
|
|
|
return listEntryIds().filter(function(id:String):Bool {
|
|
|
|
return listBaseGameLevelIds().indexOf(id) == -1;
|
|
|
|
});
|
2023-05-16 22:09:53 -04:00
|
|
|
}
|
|
|
|
}
|