2022-10-07 04:37:21 +00:00
|
|
|
package funkin.play.song;
|
|
|
|
|
2023-09-08 21:46:44 +00:00
|
|
|
import funkin.data.song.SongData.SongChartData;
|
|
|
|
import funkin.data.song.SongData.SongMetadata;
|
2022-10-07 04:37:21 +00:00
|
|
|
import funkin.util.SerializerUtil;
|
2023-09-26 03:24:07 +00:00
|
|
|
import funkin.util.FileUtil;
|
2022-10-07 04:37:21 +00:00
|
|
|
import lime.utils.Bytes;
|
|
|
|
import openfl.events.Event;
|
|
|
|
import openfl.events.IOErrorEvent;
|
|
|
|
import openfl.net.FileReference;
|
|
|
|
|
|
|
|
/**
|
2023-09-26 03:24:07 +00:00
|
|
|
* TODO: Refactor and remove this.
|
2022-10-07 04:37:21 +00:00
|
|
|
*/
|
|
|
|
class SongSerializer
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Access a SongChartData JSON file from a specific path, then load it.
|
|
|
|
* @param path The file path to read from.
|
|
|
|
*/
|
|
|
|
public static function importSongChartDataSync(path:String):SongChartData
|
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
var fileData = FileUtil.readStringFromPath(path);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
if (fileData == null) return null;
|
|
|
|
|
|
|
|
var songChartData:SongChartData = fileData.parseJSON();
|
|
|
|
|
|
|
|
return songChartData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access a SongMetadata JSON file from a specific path, then load it.
|
|
|
|
* @param path The file path to read from.
|
|
|
|
*/
|
|
|
|
public static function importSongMetadataSync(path:String):SongMetadata
|
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
var fileData = FileUtil.readStringFromPath(path);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
if (fileData == null) return null;
|
|
|
|
|
|
|
|
var songMetadata:SongMetadata = fileData.parseJSON();
|
|
|
|
|
|
|
|
return songMetadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prompt the user to browse for a SongChartData JSON file path, then load it.
|
|
|
|
* @param callback The function to call when the file is loaded.
|
|
|
|
*/
|
|
|
|
public static function importSongChartDataAsync(callback:SongChartData->Void):Void
|
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
FileUtil.browseFileReference(function(fileReference:FileReference) {
|
2023-01-23 03:25:45 +00:00
|
|
|
var data = fileReference.data.toString();
|
|
|
|
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
var songChartData:SongChartData = data.parseJSON();
|
|
|
|
|
|
|
|
if (songChartData != null) callback(songChartData);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prompt the user to browse for a SongMetadata JSON file path, then load it.
|
|
|
|
* @param callback The function to call when the file is loaded.
|
|
|
|
*/
|
|
|
|
public static function importSongMetadataAsync(callback:SongMetadata->Void):Void
|
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
FileUtil.browseFileReference(function(fileReference:FileReference) {
|
2023-01-23 03:25:45 +00:00
|
|
|
var data = fileReference.data.toString();
|
|
|
|
|
|
|
|
if (data == null) return;
|
|
|
|
|
|
|
|
var songMetadata:SongMetadata = data.parseJSON();
|
|
|
|
|
|
|
|
if (songMetadata != null) callback(songMetadata);
|
|
|
|
});
|
|
|
|
}
|
2022-10-07 04:37:21 +00:00
|
|
|
}
|