mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-23 08:07:54 -05:00
32 lines
877 B
Haxe
32 lines
877 B
Haxe
package funkin.audio.waveform;
|
|
|
|
class WaveformDataParser
|
|
{
|
|
public static function parseWaveformData(path:String):Null<WaveformData>
|
|
{
|
|
var rawJson:String = openfl.Assets.getText(path).trim();
|
|
return parseWaveformDataString(rawJson, path);
|
|
}
|
|
|
|
public static function parseWaveformDataString(contents:String, ?fileName:String):Null<WaveformData>
|
|
{
|
|
var parser = new json2object.JsonParser<WaveformData>();
|
|
parser.ignoreUnknownVariables = false;
|
|
parser.fromJson(contents, fileName);
|
|
|
|
if (parser.errors.length > 0)
|
|
{
|
|
printErrors(parser.errors, fileName);
|
|
return null;
|
|
}
|
|
return parser.value;
|
|
}
|
|
|
|
static function printErrors(errors:Array<json2object.Error>, id:String = ''):Void
|
|
{
|
|
trace('[WAVEFORM] Failed to parse waveform data: ${id}');
|
|
|
|
for (error in errors)
|
|
funkin.data.DataError.printError(error);
|
|
}
|
|
}
|