@@ -6,6 +6,7 @@ import flixel.graphics.frames.FlxFramesCollection;
66import funkin .backend .assets .ModsFolder ;
77import funkin .backend .scripting .Script ;
88import haxe .io .Path ;
9+ import flixel .util .typeLimit .OneOfTwo ;
910import lime .utils .AssetLibrary ;
1011import openfl .utils .Assets as OpenFlAssets ;
1112import animate .FlxAnimateFrames ;
@@ -24,8 +25,29 @@ class Paths
2425 });
2526 }
2627
27- public static inline function getPath (file : String , ? library : String ) {
28+ public static inline function getPath (file : String , ? library : String , ? exts : OneOfTwo < String , Array < String >> ) {
2829 var returnedPath : String = library != null ? ' $library :assets/ $library / $file ' : ' assets/ $file ' ;
30+
31+ // ext path search
32+ if (exts != null ) {
33+ var sanitizedPath = Path .withoutExtension (returnedPath );
34+ if (Std .isOfType (exts , String ))
35+ returnedPath = returnedPath + ' . ${cast (exts , String )}' ;
36+ else {
37+ var extArray : Array <String > = cast exts ;
38+ for (extension in extArray ) {
39+ var extPath : String = sanitizedPath + ' . $extension ' ;
40+ if (OpenFlAssets .exists (extPath )) {
41+ trace (extPath , OpenFlAssets .exists (extPath ));
42+ returnedPath = extPath ;
43+ break ;
44+ }
45+ }
46+ if (returnedPath == sanitizedPath ) returnedPath = returnedPath + extArray [0 ];
47+ }
48+ }
49+
50+ // unix path search
2951 #if (sys && !windows)
3052 returnedPath = Path .normalize (returnedPath );
3153 if (OpenFlAssets .exists (returnedPath )) return returnedPath ;
@@ -45,11 +67,12 @@ class Paths
4567 }
4668 if (returnedPath .toLowerCase () == fixedPath .toLowerCase ()) returnedPath = fixedPath ;
4769 #end
70+
4871 return returnedPath ;
4972 }
5073
51- public static inline function video (key : String , ? ext : String )
52- return getPath (' videos/ $key . ${ ext != null ? ext : Flags .VIDEO_EXT } ' );
74+ public static inline function video (key : String , ? ext : OneOfTwo < String , Array < String >> )
75+ return getPath (' videos/ $key ' , null , ext != null ? ext : Flags .VIDEO_EXT );
5376
5477 public static inline function ndll (key : String )
5578 return getPath (' ndlls/ $key .ndll' );
@@ -81,38 +104,35 @@ class Paths
81104 public static inline function ps1 (key : String , ? library : String )
82105 return getPath (' data/ $key .ps1' , library );
83106
84- static public function sound (key : String , ? library : String , ? ext : String )
85- return getPath (' sounds/ $key . ${ ext != null ? ext : Flags .SOUND_EXT } ' , library );
107+ static public function sound (key : String , ? library : String , ? ext : OneOfTwo < String , Array < String >> )
108+ return getPath (' sounds/ $key ' , library , ext != null ? ext : Flags .SOUND_EXT );
86109
87110 public static inline function soundRandom (key : String , min : Int , max : Int , ? library : String )
88111 return sound (key + FlxG .random .int (min , max ), library );
89112
90- inline static public function music (key : String , ? library : String , ? ext : String )
91- return getPath (' music/ $key . ${ ext != null ? ext : Flags .SOUND_EXT } ' , library );
113+ inline static public function music (key : String , ? library : String , ? ext : OneOfTwo < String , Array < String >> )
114+ return getPath (' music/ $key ' , library , ext != null ? ext : Flags .SOUND_EXT );
92115
93- inline static public function voices (song : String , ? difficulty : String , ? suffix : String = " " , ? ext : String ) {
116+ inline static public function voices (song : String , ? difficulty : String , ? suffix : String = " " , ? ext : OneOfTwo < String , Array < String >> ) {
94117 if (difficulty == null ) difficulty = Flags .DEFAULT_DIFFICULTY ;
95- if (ext == null ) ext = Flags .SOUND_EXT ;
96- var diff = getPath (' songs/ $song /song/Voices $suffix - ${difficulty }. ${ext }' , null );
97- return OpenFlAssets .exists (diff ) ? diff : getPath (' songs/ $song /song/Voices $suffix . ${ext }' , null );
118+ var diff = getPath (' songs/ $song /song/Voices $suffix - ${difficulty }' , null , ext != null ? ext : Flags .SOUND_EXT );
119+ return OpenFlAssets .exists (diff ) ? diff : getPath (' songs/ $song /song/Voices $suffix ' , null , ext != null ? ext : Flags .SOUND_EXT );
98120 }
99121
100- inline static public function inst (song : String , ? difficulty : String , ? suffix : String = " " , ? ext : String ) {
122+ inline static public function inst (song : String , ? difficulty : String , ? suffix : String = " " , ? ext : OneOfTwo < String , Array < String >> ) {
101123 if (difficulty == null ) difficulty = Flags .DEFAULT_DIFFICULTY ;
102- if (ext == null ) ext = Flags .SOUND_EXT ;
103- var diff = getPath (' songs/ $song /song/Inst $suffix - ${difficulty }. ${ext }' , null );
104- return OpenFlAssets .exists (diff ) ? diff : getPath (' songs/ $song /song/Inst $suffix . ${ext }' , null );
124+ var diff = getPath (' songs/ $song /song/Inst $suffix - ${difficulty }' , null , ext != null ? ext : Flags .SOUND_EXT );
125+ return OpenFlAssets .exists (diff ) ? diff : getPath (' songs/ $song /song/Inst $suffix ' , null , ext != null ? ext : Flags .SOUND_EXT );
105126 }
106127
107- static public function image (key : String , ? library : String , checkForAtlas : Bool = false , ? ext : String ) {
108- if (ext == null ) ext = Flags .IMAGE_EXT ;
128+ static public function image (key : String , ? library : String , checkForAtlas : Bool = false , ? ext : OneOfTwo <String , Array <String >>) {
109129 if (checkForAtlas ) {
110- var atlasPath = getPath (' images/ $key /spritemap. $ ext ' , library );
111- var multiplePath = getPath (' images/ $key /1. $ ext ' , library );
130+ var atlasPath = getPath (' images/ $key /spritemap' , library , ext != null ? ext : Flags . IMAGE_EXT );
131+ var multiplePath = getPath (' images/ $key /1' , library , ext != null ? ext : Flags . IMAGE_EXT );
112132 if (atlasPath != null && OpenFlAssets .exists (atlasPath )) return atlasPath .substr (0 , atlasPath .length - 14 );
113133 if (multiplePath != null && OpenFlAssets .exists (multiplePath )) return multiplePath .substr (0 , multiplePath .length - 6 );
114134 }
115- return getPath (' images/ $key . $ ext ' , library );
135+ return getPath (' images/ $key ' , library , ext != null ? ext : Flags . IMAGE_EXT );
116136 }
117137
118138 public static inline function script (key : String , ? library : String , isAssetsPath : Bool = false ) {
@@ -172,25 +192,25 @@ class Paths
172192 return getPath (' models/ $key .awd' );
173193 }
174194
175- inline static public function getSparrowAtlas (key : String , ? library : String , ? ext : String )
195+ inline static public function getSparrowAtlas (key : String , ? library : String , ? ext : OneOfTwo < String , Array < String >> )
176196 return FlxAtlasFrames .fromSparrow (image (key , library , ext ), file (' images/ $key .xml' , library ));
177197
178198 inline static public function getAnimateAtlasAlt (key : String , ? settings : FlxAnimateSettings )
179199 return FlxAnimateFrames .fromAnimate (key , null , null , null , false , settings );
180200
181- inline static public function getSparrowAtlasAlt (key : String , ? ext : String )
201+ inline static public function getSparrowAtlasAlt (key : String , ? ext : OneOfTwo < String , Array < String >> )
182202 return FlxAtlasFrames .fromSparrow (' $key . ${ext != null ? ext : Flags .IMAGE_EXT }' , ' $key .xml' );
183203
184- inline static public function getPackerAtlas (key : String , ? library : String , ? ext : String )
204+ inline static public function getPackerAtlas (key : String , ? library : String , ? ext : OneOfTwo < String , Array < String >> )
185205 return FlxAtlasFrames .fromSpriteSheetPacker (image (key , library , ext ), file (' images/ $key .txt' , library ));
186206
187- inline static public function getPackerAtlasAlt (key : String , ? ext : String )
207+ inline static public function getPackerAtlasAlt (key : String , ? ext : OneOfTwo < String , Array < String >> )
188208 return FlxAtlasFrames .fromSpriteSheetPacker (' $key . ${ext != null ? ext : Flags .IMAGE_EXT }' , ' $key .txt' );
189209
190- inline static public function getAsepriteAtlas (key : String , ? library : String , ? ext : String )
210+ inline static public function getAsepriteAtlas (key : String , ? library : String , ? ext : OneOfTwo < String , Array < String >> )
191211 return FlxAtlasFrames .fromAseprite (image (key , library , ext ), file (' images/ $key .json' , library ));
192212
193- inline static public function getAsepriteAtlasAlt (key : String , ? ext : String )
213+ inline static public function getAsepriteAtlasAlt (key : String , ? ext : OneOfTwo < String , Array < String >> )
194214 return FlxAtlasFrames .fromAseprite (' $key . ${ext != null ? ext : Flags .IMAGE_EXT }' , ' $key .json' );
195215
196216 static public function getAssetsRoot (): String {
@@ -203,15 +223,15 @@ class Paths
203223 * @param key Path to the frames
204224 * @param library (Additional) library to load the frames from.
205225 */
206- public static function getFrames (key : String , assetsPath : Bool = false , ? library : String , ? ext : String = null , ? animateSettings : FlxAnimateSettings ) {
226+ public static function getFrames (key : String , assetsPath : Bool = false , ? library : String , ? ext : OneOfTwo < String , Array < String >> = null , ? animateSettings : FlxAnimateSettings ) {
207227 if (tempFramesCache .exists (key )) {
208228 var frames = tempFramesCache [key ];
209229 if (frames != null && frames .parent != null && frames .parent .bitmap != null && frames .parent .bitmap .readable )
210230 return frames ;
211231 else
212232 tempFramesCache .remove (key );
213233 }
214- return tempFramesCache [key ] = loadFrames (assetsPath ? key : Paths .image (key , library , true , ext ), false , null , false , ext , animateSettings );
234+ return tempFramesCache [key ] = loadFrames (assetsPath ? key : Paths .image (key , library , true , ext ), false , null , false , animateSettings );
215235 }
216236
217237 /**
@@ -246,17 +266,17 @@ class Paths
246266 * @param ext (Additional) Extension of the images.
247267 * @return FlxFramesCollection Frames
248268 */
249- public static function getMultiFrames (sheets : Array <String >, ? unique : Bool = true , ? key : String = null , ? ext : String = null , ? animateSettings : FlxAnimateSettings ): FlxFramesCollection {
269+ public static function getMultiFrames (sheets : Array <String >, ? unique : Bool = true , ? key : String = null , ? ext : OneOfTwo < String , Array < String >> = null , ? animateSettings : FlxAnimateSettings ): FlxFramesCollection {
250270 // TODO: cache properly
251- if (sheets .length == 1 ) return loadFrames (sheets [0 ], unique , key , false , false , ext , animateSettings );
271+ if (sheets .length == 1 ) return loadFrames (sheets [0 ], unique , key , false , false , animateSettings );
252272 if (key == null ) key = ' combo/' + sheets .join (' ,' );
253273 var graphic = FlxG .bitmap .add (" flixel/images/logo/default.png" , unique , key );
254274 var sprFrames : FlxAtlasFrames = new FlxAtlasFrames (graphic );
255275 try {
256276 for (x => path in sheets ) {
257277 var noExt = haxe.io. Path .withoutExtension (Paths .image (path , null , true , ext ));
258278 @:privateAccess
259- var newFrames = cast Paths .loadFrames (noExt , true , key + ' _ $path ' , false , false , ext , animateSettings );
279+ var newFrames = cast Paths .loadFrames (noExt , true , key + ' _ $path ' , false , false , animateSettings );
260280 if (newFrames == null ) {
261281 Logs .warn (' There is no Bitmap asset for " $noExt ". Skipping...' );
262282 continue ;
@@ -279,9 +299,9 @@ class Paths
279299 * @param Ext Extension of the image.
280300 * @return FlxFramesCollection Frames
281301 */
282- static function loadFrames (path : String , Unique : Bool = false , Key : String = null , SkipAtlasCheck : Bool = false , SkipMultiCheck : Bool = false , ? Ext : String = null , ? animateSettings : FlxAnimateSettings ): FlxFramesCollection {
302+ static function loadFrames (path : String , Unique : Bool = false , Key : String = null , SkipAtlasCheck : Bool = false , SkipMultiCheck : Bool = false , ? animateSettings : FlxAnimateSettings ): FlxFramesCollection {
283303 var noExt = Path .withoutExtension (path );
284- var ext = Ext != null ? Ext : Flags . IMAGE_EXT ;
304+ var ext = Path . extension ( path ) ;
285305
286306 if (! SkipMultiCheck && Assets .exists (' $noExt /1. ${ext }' )) {
287307 // MULTIPLE SPRITESHEETS!!
0 commit comments