mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-05 22:34:36 +00:00
33 lines
877 B
Haxe
33 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);
|
||
|
}
|
||
|
}
|