Funkin/source/funkin/audio/waveform/WaveformDataParser.hx
2024-01-20 14:07:48 -05:00

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);
}
}