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