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;
|
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
|
|
|
|
{
|
2024-03-16 04:55:57 +00:00
|
|
|
static var currentLevel:Null<String> = null;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2024-06-20 20:17:53 +00:00
|
|
|
public static function setCurrentLevel(name:Null<String>):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-06-20 20:17:53 +00:00
|
|
|
if (name == null)
|
|
|
|
{
|
|
|
|
currentLevel = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentLevel = name.toLowerCase();
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 01:56:41 +00:00
|
|
|
public static function stripLibrary(path:String):String
|
|
|
|
{
|
2024-03-17 02:20:22 +00:00
|
|
|
var parts:Array<String> = path.split(':');
|
2024-02-23 01:56:41 +00:00
|
|
|
if (parts.length < 2) return path;
|
|
|
|
return parts[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getLibrary(path:String):String
|
|
|
|
{
|
2024-03-17 02:20:22 +00:00
|
|
|
var parts:Array<String> = path.split(':');
|
|
|
|
if (parts.length < 2) return 'preload';
|
2024-02-23 01:56:41 +00:00
|
|
|
return parts[0];
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
static function getPath(file:String, type:AssetType, library:Null<String>):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
if (library != null) return getLibraryPath(file, library);
|
|
|
|
|
|
|
|
if (currentLevel != null)
|
|
|
|
{
|
2024-03-17 02:20:22 +00:00
|
|
|
var levelPath:String = getLibraryPathForce(file, currentLevel);
|
2024-09-18 09:04:32 +00:00
|
|
|
if (Assets.exists(levelPath, type)) return levelPath;
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
var levelPath:String = getLibraryPathForce(file, 'shared');
|
2024-09-18 09:04:32 +00:00
|
|
|
if (Assets.exists(levelPath, type)) return levelPath;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
return getPreloadPath(file);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function getLibraryPath(file:String, library = 'preload'):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-03-17 02:20:22 +00:00
|
|
|
return if (library == 'preload' || library == 'default') getPreloadPath(file); else getLibraryPathForce(file, library);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
static inline function getLibraryPathForce(file:String, library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return '$library:assets/$library/$file';
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
static inline function getPreloadPath(file:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return 'assets/$file';
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function file(file:String, type:AssetType = TEXT, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return getPath(file, type, library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function animateAtlas(path:String, ?library:String):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
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function txt(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return getPath('data/$key.txt', TEXT, library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function frag(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return getPath('shaders/$key.frag', TEXT, library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function vert(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return getPath('shaders/$key.vert', TEXT, library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function xml(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return getPath('data/$key.xml', TEXT, library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function json(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return getPath('data/$key.json', TEXT, library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function sound(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function soundRandom(key:String, min:Int, max:Int, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return sound(key + FlxG.random.int(min, max), library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function music(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function videos(key:String, ?library:String):String
|
2023-07-02 20:46:40 +00:00
|
|
|
{
|
2024-04-05 05:24:03 +00:00
|
|
|
return getPath('videos/$key.${Constants.EXT_VIDEO}', BINARY, library ?? 'videos');
|
2023-07-02 20:46:40 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function voices(song:String, ?suffix:String = ''):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-03-17 02:20:22 +00:00
|
|
|
if (suffix == null) suffix = ''; // no suffix, for a sorta backwards compatibility with older-ish voice files
|
2023-01-23 03:25:45 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-04-19 00:23:03 +00:00
|
|
|
/**
|
|
|
|
* Gets the path to an `Inst.mp3/ogg` song instrumental from songs:assets/songs/`song`/
|
|
|
|
* @param song name of the song to get instrumental for
|
|
|
|
* @param suffix any suffix to add to end of song name, used for `-erect` variants usually
|
|
|
|
* @param withExtension if it should return with the audio file extension `.mp3` or `.ogg`.
|
|
|
|
* @return String
|
|
|
|
*/
|
|
|
|
public static function inst(song:String, ?suffix:String = '', ?withExtension:Bool = true):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2024-04-19 00:23:03 +00:00
|
|
|
var ext:String = withExtension ? '.${Constants.EXT_SOUND}' : '';
|
|
|
|
return 'songs:assets/songs/${song.toLowerCase()}/Inst$suffix$ext';
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function image(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return getPath('images/$key.png', IMAGE, library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function font(key:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return 'assets/fonts/$key';
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function ui(key:String, ?library:String):String
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return xml('ui/$key', library);
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function getSparrowAtlas(key:String, ?library:String):FlxAtlasFrames
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return FlxAtlasFrames.fromSparrow(image(key, library), file('images/$key.xml', library));
|
|
|
|
}
|
|
|
|
|
2024-03-17 02:20:22 +00:00
|
|
|
public static function getPackerAtlas(key:String, ?library:String):FlxAtlasFrames
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
return FlxAtlasFrames.fromSpriteSheetPacker(image(key, library), file('images/$key.txt', library));
|
|
|
|
}
|
2021-03-02 04:00:02 +00:00
|
|
|
}
|
2024-04-19 00:23:03 +00:00
|
|
|
|
|
|
|
enum abstract PathsFunction(String)
|
|
|
|
{
|
|
|
|
var MUSIC;
|
|
|
|
var INST;
|
|
|
|
var VOICES;
|
|
|
|
var SOUND;
|
|
|
|
}
|