2022-03-08 08:13:53 +00:00
|
|
|
package funkin;
|
2021-02-08 21:34:48 +00:00
|
|
|
|
|
|
|
import flixel.graphics.frames.FlxAtlasFrames;
|
2021-03-02 04:00:02 +00:00
|
|
|
import openfl.utils.AssetType;
|
|
|
|
import openfl.utils.Assets as OpenFlAssets;
|
2021-02-08 21:34:48 +00:00
|
|
|
|
2023-11-07 09:04:22 +00:00
|
|
|
/**
|
|
|
|
* A core class which handles determining asset paths.
|
|
|
|
*/
|
2021-02-08 21:34:48 +00:00
|
|
|
class Paths
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
static var currentLevel:String;
|
|
|
|
|
|
|
|
static public function setCurrentLevel(name:String)
|
|
|
|
{
|
|
|
|
currentLevel = name.toLowerCase();
|
|
|
|
}
|
|
|
|
|
2024-02-23 01:56:41 +00:00
|
|
|
public static function stripLibrary(path:String):String
|
|
|
|
{
|
|
|
|
var parts = path.split(':');
|
|
|
|
if (parts.length < 2) return path;
|
|
|
|
return parts[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getLibrary(path:String):String
|
|
|
|
{
|
|
|
|
var parts = path.split(':');
|
|
|
|
if (parts.length < 2) return "preload";
|
|
|
|
return parts[0];
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
static function getPath(file:String, type:AssetType, library:Null<String>)
|
|
|
|
{
|
|
|
|
if (library != null) return getLibraryPath(file, library);
|
|
|
|
|
|
|
|
if (currentLevel != null)
|
|
|
|
{
|
|
|
|
var levelPath = getLibraryPathForce(file, currentLevel);
|
|
|
|
if (OpenFlAssets.exists(levelPath, type)) return levelPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
var levelPath = getLibraryPathForce(file, "shared");
|
|
|
|
if (OpenFlAssets.exists(levelPath, type)) return levelPath;
|
|
|
|
|
|
|
|
return getPreloadPath(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function getLibraryPath(file:String, library = "preload")
|
|
|
|
{
|
|
|
|
return if (library == "preload" || library == "default") getPreloadPath(file); else getLibraryPathForce(file, library);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static function getLibraryPathForce(file:String, library:String)
|
|
|
|
{
|
|
|
|
return '$library:assets/$library/$file';
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static function getPreloadPath(file:String)
|
|
|
|
{
|
|
|
|
return 'assets/$file';
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function file(file:String, type:AssetType = TEXT, ?library:String)
|
|
|
|
{
|
|
|
|
return getPath(file, type, library);
|
|
|
|
}
|
|
|
|
|
2023-08-07 02:20:18 +00:00
|
|
|
public static inline function animateAtlas(path:String, ?library:String)
|
2023-02-22 01:58:15 +00:00
|
|
|
{
|
2023-08-07 02:20:18 +00:00
|
|
|
return getLibraryPath('images/$path', library);
|
2023-02-22 01:58:15 +00:00
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
inline static public function txt(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return getPath('data/$key.txt', TEXT, library);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function frag(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return getPath('shaders/$key.frag', TEXT, library);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function vert(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return getPath('shaders/$key.vert', TEXT, library);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function xml(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return getPath('data/$key.xml', TEXT, library);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function json(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return getPath('data/$key.json', TEXT, library);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function sound(key:String, ?library:String)
|
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
return getPath('sounds/$key.${Constants.EXT_SOUND}', SOUND, library);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function soundRandom(key:String, min:Int, max:Int, ?library:String)
|
|
|
|
{
|
|
|
|
return sound(key + FlxG.random.int(min, max), library);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function music(key:String, ?library:String)
|
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
return getPath('music/$key.${Constants.EXT_SOUND}', MUSIC, library);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 20:46:40 +00:00
|
|
|
inline static public function videos(key:String, ?library:String)
|
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
return getPath('videos/$key.${Constants.EXT_VIDEO}', BINARY, library);
|
2023-07-02 20:46:40 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 20:17:25 +00:00
|
|
|
inline static public function voices(song:String, ?suffix:String = '')
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
if (suffix == null) suffix = ""; // no suffix, for a sorta backwards compatibility with older-ish voice files
|
|
|
|
|
2023-09-26 03:24:07 +00:00
|
|
|
return 'songs:assets/songs/${song.toLowerCase()}/Voices$suffix.${Constants.EXT_SOUND}';
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 20:17:25 +00:00
|
|
|
inline static public function inst(song:String, ?suffix:String = '')
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-09-26 03:24:07 +00:00
|
|
|
return 'songs:assets/songs/${song.toLowerCase()}/Inst$suffix.${Constants.EXT_SOUND}';
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function image(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return getPath('images/$key.png', IMAGE, library);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function font(key:String)
|
|
|
|
{
|
|
|
|
return 'assets/fonts/$key';
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function ui(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return xml('ui/$key', library);
|
|
|
|
}
|
|
|
|
|
|
|
|
static public function getSparrowAtlas(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return FlxAtlasFrames.fromSparrow(image(key, library), file('images/$key.xml', library));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static public function getPackerAtlas(key:String, ?library:String)
|
|
|
|
{
|
|
|
|
return FlxAtlasFrames.fromSpriteSheetPacker(image(key, library), file('images/$key.txt', library));
|
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
}
|