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