changes
This commit is contained in:
parent
cdbc51f232
commit
11be158abe
102
source/Paths.hx
102
source/Paths.hx
|
@ -3,18 +3,26 @@ package;
|
|||
import flixel.FlxG;
|
||||
import flixel.graphics.FlxGraphic;
|
||||
import flixel.graphics.frames.FlxAtlasFrames;
|
||||
import openfl.utils.AssetType;
|
||||
import openfl.media.Sound;
|
||||
import openfl.utils.Assets;
|
||||
|
||||
using StringTools;
|
||||
|
||||
class Paths
|
||||
{
|
||||
inline public static var SOUND_EXT = #if web "mp3" #else "ogg" #end;
|
||||
|
||||
public static var currentTrackedAssets:Map<String, FlxGraphic> = [];
|
||||
public static var currentTrackedSounds:Map<String, Sound> = [];
|
||||
|
||||
public static var localTrackedAssets:Array<String> = [];
|
||||
|
||||
static var currentLevel:String;
|
||||
|
||||
static public function setCurrentLevel(name:String)
|
||||
{
|
||||
currentLevel = name.toLowerCase();
|
||||
}
|
||||
|
||||
public static function clearUnusedMemory()
|
||||
{
|
||||
for (key in currentTrackedAssets.keys())
|
||||
|
@ -85,29 +93,54 @@ class Paths
|
|||
localTrackedAssets = [];
|
||||
}
|
||||
|
||||
inline static public function txt(key:String):String
|
||||
return 'assets/$key.txt';
|
||||
static function getPath(file:String, type:AssetType, library:Null<String>)
|
||||
{
|
||||
if (library != null)
|
||||
return getLibraryPath(file, library);
|
||||
|
||||
inline static public function xml(key:String):String
|
||||
return 'assets/$key.xml';
|
||||
if (currentLevel != null)
|
||||
{
|
||||
var levelPath = getLibraryPathForce(file, currentLevel);
|
||||
if (Assets.exists(levelPath, type))
|
||||
return levelPath;
|
||||
|
||||
inline static public function json(key:String):String
|
||||
return 'assets/$key.json';
|
||||
levelPath = getLibraryPathForce(file, "shared");
|
||||
if (Assets.exists(levelPath, type))
|
||||
return levelPath;
|
||||
}
|
||||
|
||||
inline static public function video(key:String):String
|
||||
return 'assets/$key.mp4';
|
||||
return getPreloadPath(file);
|
||||
}
|
||||
|
||||
inline static public function font(key:String):String
|
||||
return 'assets/fonts/$key';
|
||||
static public function getLibraryPath(file:String, library = "preload")
|
||||
return if (library == "preload" || library == "default") getPreloadPath(file); else getLibraryPathForce(file, library);
|
||||
|
||||
static public function sound(key:String, ?cache:Bool = true):Sound
|
||||
return returnSound('sounds/$key', cache);
|
||||
|
||||
inline static public function soundRandom(key:String, min:Int, max:Int)
|
||||
inline static function getLibraryPathForce(file:String, library:String)
|
||||
return '$library:assets/$library/$file';
|
||||
|
||||
inline static function getPreloadPath(file:String)
|
||||
return 'assets/$file';
|
||||
|
||||
inline static public function file(file:String, type:AssetType = TEXT, ?library:String)
|
||||
return getPath(file, type, library);
|
||||
|
||||
inline static public function txt(key:String, ?library:String)
|
||||
return getPath('data/$key.txt', TEXT, library);
|
||||
|
||||
inline static public function xml(key:String, ?library:String)
|
||||
return getPath('data/$key.xml', TEXT, library);
|
||||
|
||||
inline static public function json(key:String, ?library:String)
|
||||
return getPath('data/$key.json', TEXT, library);
|
||||
|
||||
static public function sound(key:String, ?library:String, ?cache:Bool = true):Sound
|
||||
return returnSound('sounds/$key', SOUND, library, cache);
|
||||
|
||||
inline static public function soundRandom(key:String, min:Int, max:Int, ?library:String)
|
||||
return sound(key + FlxG.random.int(min, max), library);
|
||||
|
||||
inline static public function music(key:String, ?cache:Bool = true):Sound
|
||||
return returnSound('music/$key', cache);
|
||||
inline static public function music(key:String, ?library:String, ?cache:Bool = true):Sound
|
||||
return returnSound('music/$key', MUSIC, library, cache);
|
||||
|
||||
inline static public function voices(song:String, ?cache:Bool = true):Sound
|
||||
return returnSound('songs/' + ${song.toLowerCase()} + '/Voices', cache);
|
||||
|
@ -115,19 +148,22 @@ class Paths
|
|||
inline static public function inst(song:String, ?cache:Bool = true):Sound
|
||||
return returnSound('songs/' + ${song.toLowerCase()} + '/Inst', cache);
|
||||
|
||||
inline static public function image(key:String, ?cache:Bool = true):FlxGraphic
|
||||
return returnGraphic('images/$key', cache);
|
||||
inline static public function image(key:String, ?library:String, ?cache:Bool = true):FlxGraphic
|
||||
return returnGraphic('images/$key', IMAGE, library, cache);
|
||||
|
||||
inline static public function getSparrowAtlas(key:String, ?cache:Bool = true):FlxAtlasFrames
|
||||
inline static public function font(key:String)
|
||||
return 'assets/fonts/$key';
|
||||
|
||||
inline static public function getSparrowAtlas(key:String, ?library:String, ?cache:Bool = true)
|
||||
return FlxAtlasFrames.fromSparrow(returnGraphic('images/$key', cache), xml('images/$key'));
|
||||
|
||||
inline static public function getPackerAtlas(key:String, ?cache:Bool = true):FlxAtlasFrames
|
||||
inline static public function getPackerAtlas(key:String, ?library:String, ?cache:Bool = true)
|
||||
return FlxAtlasFrames.fromSpriteSheetPacker(returnGraphic('images/$key', cache), txt('images/$key'));
|
||||
|
||||
public static function returnGraphic(key:String, ?cache:Bool = true):FlxGraphic
|
||||
{
|
||||
var path:String = 'assets/$key.png';
|
||||
if (Assets.exists(path, IMAGE))
|
||||
if (Assets.exists(path, IMAGE, library))
|
||||
{
|
||||
if (!currentTrackedAssets.exists(path))
|
||||
{
|
||||
|
@ -146,29 +182,17 @@ class Paths
|
|||
|
||||
public static function returnSound(key:String, ?cache:Bool = true):Sound
|
||||
{
|
||||
#if web
|
||||
if (Assets.exists('assets/$key.mp3', SOUND))
|
||||
if (Assets.exists('assets/$key.$SOUND_EXT', SOUND, library))
|
||||
{
|
||||
var path:String = 'assets/$key.mp3';
|
||||
var path:String = 'assets/$key.$SOUND_EXT';
|
||||
if (!currentTrackedSounds.exists(path))
|
||||
currentTrackedSounds.set(path, Assets.getSound(path, cache));
|
||||
currentTrackedSounds.set(path, Assets.getSound(path, library, cache));
|
||||
|
||||
localTrackedAssets.push(path);
|
||||
return currentTrackedSounds.get(path);
|
||||
}
|
||||
#else
|
||||
if (Assets.exists('assets/$key.ogg', SOUND))
|
||||
{
|
||||
var path:String = 'assets/$key.ogg';
|
||||
if (!currentTrackedSounds.exists(path))
|
||||
currentTrackedSounds.set(path, Assets.getSound(path, cache));
|
||||
|
||||
localTrackedAssets.push(path);
|
||||
return currentTrackedSounds.get(path);
|
||||
}
|
||||
#end
|
||||
|
||||
trace('$key its null');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,8 @@ class ModCore
|
|||
'xml' => TEXT,
|
||||
'txt' => TEXT,
|
||||
'ttf' => FONT,
|
||||
'otf' => FONT
|
||||
'otf' => FONT,
|
||||
'mp4' => VIDEO
|
||||
];
|
||||
|
||||
public static var trackedMods:Array<ModMetadata> = [];
|
||||
|
|
Loading…
Reference in New Issue