Funkin/source/funkin/util/assets/DataAssets.hx

32 lines
771 B
Haxe
Raw Normal View History

package funkin.util.assets;
class DataAssets
{
static function buildDataPath(path:String):String
{
return 'default:assets/data/${path}';
}
2022-09-13 01:09:30 -04:00
public static function listDataFilesInPath(path:String, ?suffix:String = '.json'):Array<String>
{
var textAssets = openfl.utils.Assets.list();
var queryPath = buildDataPath(path);
var results:Array<String> = [];
for (textPath in textAssets)
{
2022-09-13 01:09:30 -04:00
if (textPath.startsWith(queryPath) && textPath.endsWith(suffix))
{
2022-09-13 01:09:30 -04:00
var pathNoSuffix = textPath.substring(0, textPath.length - suffix.length);
var pathNoPrefix = pathNoSuffix.substring(queryPath.length);
// No duplicates! Why does this happen?
if (!results.contains(pathNoPrefix))
results.push(pathNoPrefix);
}
}
return results;
}
}