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