1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-05 22:34:36 +00:00
Funkin/source/funkin/play/song/SongMigrator.hx

80 lines
2.2 KiB
Haxe
Raw Normal View History

2022-09-13 05:09:30 +00:00
package funkin.play.song;
import funkin.play.song.SongData.SongChartData;
import funkin.play.song.SongData.SongMetadata;
import funkin.util.VersionUtil;
class SongMigrator
{
2023-01-23 00:55:30 +00:00
/**
* The current latest version string for the song data format.
* Handle breaking changes by incrementing this value
* and adding migration to the SongMigrator class.
*/
public static final CHART_VERSION:String = "2.0.0";
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
public static final CHART_VERSION_RULE:String = "2.0.x";
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
public static function migrateSongMetadata(jsonData:Dynamic, songId:String):SongMetadata
{
if (jsonData.version)
{
if (VersionUtil.validateVersion(jsonData.version, CHART_VERSION_RULE))
{
trace('Song (${songId}) metadata version (${jsonData.version}) is valid and up-to-date.');
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
var songMetadata:SongMetadata = cast jsonData;
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
return songMetadata;
}
else
{
trace('Song (${songId}) metadata version (${jsonData.version}) is outdated.');
switch (jsonData.version)
{
// TODO: Add migration functions as cases here.
default:
// Unknown version.
trace('Song (${songId}) unknown metadata version: ${jsonData.version}');
}
}
}
else
{
trace('Song metadata version is missing.');
}
return null;
}
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
public static function migrateSongChartData(jsonData:Dynamic, songId:String):SongChartData
{
if (jsonData.version)
{
if (VersionUtil.validateVersion(jsonData.version, CHART_VERSION_RULE))
{
trace('Song (${songId}) chart version (${jsonData.version}) is valid and up-to-date.');
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
var songChartData:SongChartData = cast jsonData;
2022-09-13 05:09:30 +00:00
2023-01-23 00:55:30 +00:00
return songChartData;
}
else
{
trace('Song (${songId}) chart version (${jsonData.version}) is outdated.');
switch (jsonData.version)
{
// TODO: Add migration functions as cases here.
default:
// Unknown version.
trace('Song (${songId}) unknown chart version: ${jsonData.version}');
}
}
}
else
{
trace('Song chart version is missing.');
}
return null;
}
2022-09-13 05:09:30 +00:00
}