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