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
|
|
|
|
|
|
|
class Paths
|
|
|
|
{
|
|
|
|
inline public static var SOUND_EXT = #if web "mp3" #else "ogg" #end;
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-08 21:34:48 +00:00
|
|
|
static var currentLevel:String;
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-09 02:43:17 +00:00
|
|
|
static public function setCurrentLevel(name:String)
|
2021-02-08 21:34:48 +00:00
|
|
|
{
|
2021-02-09 02:43:17 +00:00
|
|
|
currentLevel = name.toLowerCase();
|
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
static function getPath(file:String, type:AssetType, library:Null<String>)
|
2021-02-09 02:43:17 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
if (library != null)
|
|
|
|
return getLibraryPath(file, library);
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-09 02:43:17 +00:00
|
|
|
if (currentLevel != null)
|
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
var levelPath = getLibraryPathForce(file, currentLevel);
|
2021-02-09 02:43:17 +00:00
|
|
|
if (OpenFlAssets.exists(levelPath, type))
|
|
|
|
return levelPath;
|
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-09-07 21:10:43 +00:00
|
|
|
var levelPath = getLibraryPathForce(file, "shared");
|
|
|
|
if (OpenFlAssets.exists(levelPath, type))
|
|
|
|
return levelPath;
|
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPreloadPath(file);
|
2021-02-09 02:43:17 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
static public function getLibraryPath(file:String, library = "preload")
|
2021-02-09 02:43:17 +00:00
|
|
|
{
|
2021-03-02 04:00:02 +00:00
|
|
|
return if (library == "preload" || library == "default") getPreloadPath(file); else getLibraryPathForce(file, library);
|
2021-02-11 19:14:02 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static function getLibraryPathForce(file:String, library:String)
|
|
|
|
{
|
2021-02-09 02:43:17 +00:00
|
|
|
return '$library:assets/$library/$file';
|
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static function getPreloadPath(file:String)
|
|
|
|
{
|
|
|
|
return 'assets/$file';
|
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function file(file:String, type:AssetType = TEXT, ?library:String)
|
2021-02-09 02:43:17 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPath(file, type, library);
|
2021-02-08 21:34:48 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function txt(key:String, ?library:String)
|
2021-02-10 20:18:14 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPath('data/$key.txt', TEXT, library);
|
2021-02-10 20:18:14 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function xml(key:String, ?library:String)
|
2021-02-10 20:18:14 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPath('data/$key.xml', TEXT, library);
|
2021-02-10 20:18:14 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function json(key:String, ?library:String)
|
2021-02-10 20:18:14 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPath('data/$key.json', TEXT, library);
|
2021-02-10 20:18:14 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
|
|
|
static public function sound(key:String, ?library:String)
|
2021-02-08 21:34:48 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPath('sounds/$key.$SOUND_EXT', SOUND, library);
|
2021-02-08 21:34:48 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function soundRandom(key:String, min:Int, max:Int, ?library:String)
|
2021-02-08 21:34:48 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return sound(key + FlxG.random.int(min, max), library);
|
2021-02-08 21:34:48 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function music(key:String, ?library:String)
|
2021-02-08 21:34:48 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPath('music/$key.$SOUND_EXT', MUSIC, library);
|
2021-02-08 21:34:48 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-09-20 15:32:35 +00:00
|
|
|
inline static public function voices(song:String, ?suffix:String)
|
2021-02-09 18:07:05 +00:00
|
|
|
{
|
2021-09-20 15:32:35 +00:00
|
|
|
if (suffix == null)
|
|
|
|
suffix = ""; // no suffix, for a sorta backwards compatibility with older-ish voice files
|
|
|
|
|
|
|
|
return 'songs:assets/songs/${song.toLowerCase()}/Voices$suffix.$SOUND_EXT';
|
2021-02-09 18:07:05 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-09 18:07:05 +00:00
|
|
|
inline static public function inst(song:String)
|
|
|
|
{
|
2021-02-10 20:18:14 +00:00
|
|
|
return 'songs:assets/songs/${song.toLowerCase()}/Inst.$SOUND_EXT';
|
2021-02-09 18:07:05 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function image(key:String, ?library:String)
|
2021-02-08 21:34:48 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return getPath('images/$key.png', IMAGE, library);
|
2021-02-08 21:34:48 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-10 20:18:14 +00:00
|
|
|
inline static public function font(key:String)
|
|
|
|
{
|
|
|
|
return 'assets/fonts/$key';
|
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function getSparrowAtlas(key:String, ?library:String)
|
2021-02-08 21:34:48 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return FlxAtlasFrames.fromSparrow(image(key, library), file('images/$key.xml', library));
|
2021-02-08 21:34:48 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
|
2021-02-11 19:14:02 +00:00
|
|
|
inline static public function getPackerAtlas(key:String, ?library:String)
|
2021-02-08 21:34:48 +00:00
|
|
|
{
|
2021-02-11 19:14:02 +00:00
|
|
|
return FlxAtlasFrames.fromSpriteSheetPacker(image(key, library), file('images/$key.txt', library));
|
2021-02-08 21:34:48 +00:00
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
}
|