1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-30 02:33:40 +00:00
Funkin/source/Paths.hx

118 lines
2.9 KiB
Haxe
Raw Normal View History

2021-02-08 21:34:48 +00:00
package;
import flixel.FlxG;
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-02-11 19:14:02 +00:00
levelPath = getLibraryPathForce(file, "shared");
2021-02-09 02:43:17 +00:00
if (OpenFlAssets.exists(levelPath, type))
return levelPath;
}
2021-03-02 04:00:02 +00:00
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-11 19:14:02 +00:00
return getPath('data/$key.txt', TEXT, library);
}
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-11 19:14:02 +00:00
return getPath('data/$key.xml', TEXT, library);
}
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-11 19:14:02 +00:00
return getPath('data/$key.json', TEXT, library);
}
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
inline static public function voices(song:String)
{
return 'songs:assets/songs/${song.toLowerCase()}/Voices.$SOUND_EXT';
}
2021-03-02 04:00:02 +00:00
inline static public function inst(song:String)
{
return 'songs:assets/songs/${song.toLowerCase()}/Inst.$SOUND_EXT';
}
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
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
}