diff --git a/source/funkin/Paths.hx b/source/funkin/Paths.hx index c3cac3630..8e8bf52e6 100644 --- a/source/funkin/Paths.hx +++ b/source/funkin/Paths.hx @@ -1,6 +1,8 @@ package funkin; import flixel.graphics.frames.FlxAtlasFrames; +import animate.FlxAnimateFrames; +import funkin.graphics.FunkinSprite.AtlasSpriteSettings; import openfl.utils.AssetType; import funkin.util.macro.ConsoleMacro; import haxe.io.Path; @@ -177,6 +179,49 @@ class Paths implements ConsoleClass return FlxAtlasFrames.fromSparrow(image(key, library), file('images/$key.xml', library)); } + public static function getAnimateAtlas(key:String, ?library:String, settings:AtlasSpriteSettings):FlxAnimateFrames + { + var assetLibrary:String = library ?? ""; + var graphicKey:String = ""; + + if (assetLibrary != "") + { + graphicKey = Paths.animateAtlas(key, assetLibrary); + } + else + { + graphicKey = Paths.animateAtlas(key); + } + + var validatedSettings:AtlasSpriteSettings = + { + swfMode: settings?.swfMode ?? false, + cacheOnLoad: settings?.cacheOnLoad ?? false, + filterQuality: settings?.filterQuality ?? MEDIUM, + spritemaps: settings?.spritemaps ?? null, + metadataJson: settings?.metadataJson ?? null, + cacheKey: settings?.cacheKey ?? null, + uniqueInCache: settings?.uniqueInCache ?? false, + onSymbolCreate: settings?.onSymbolCreate ?? null, + applyStageMatrix: settings?.applyStageMatrix ?? false, + useRenderTexture: settings?.useRenderTexture ?? false + }; + + // Validate asset path. + if (!Assets.exists('${graphicKey}/Animation.json')) + { + throw 'No Animation.json file exists at the specified path (${graphicKey})'; + } + + return FlxAnimateFrames.fromAnimate(graphicKey, validatedSettings.spritemaps, validatedSettings.metadataJson, validatedSettings.cacheKey, + validatedSettings.uniqueInCache, { + swfMode: validatedSettings.swfMode, + cacheOnLoad: validatedSettings.cacheOnLoad, + filterQuality: validatedSettings.filterQuality, + onSymbolCreate: validatedSettings.onSymbolCreate + }); + } + public static function getPackerAtlas(key:String, ?library:String):FlxAtlasFrames { return FlxAtlasFrames.fromSpriteSheetPacker(image(key, library), file('images/$key.txt', library)); diff --git a/source/funkin/graphics/FunkinSprite.hx b/source/funkin/graphics/FunkinSprite.hx index 35b4797c9..07243407f 100644 --- a/source/funkin/graphics/FunkinSprite.hx +++ b/source/funkin/graphics/FunkinSprite.hx @@ -330,48 +330,15 @@ class FunkinSprite extends FlxAnimate throw 'Null path specified for loadTextureAtlas()!'; } - var validatedSettings:AtlasSpriteSettings = - { - swfMode: settings?.swfMode ?? false, - cacheOnLoad: settings?.cacheOnLoad ?? false, - filterQuality: settings?.filterQuality ?? MEDIUM, - spritemaps: settings?.spritemaps ?? null, - metadataJson: settings?.metadataJson ?? null, - cacheKey: settings?.cacheKey ?? null, - uniqueInCache: settings?.uniqueInCache ?? false, - onSymbolCreate: settings?.onSymbolCreate ?? null, - applyStageMatrix: settings?.applyStageMatrix ?? false, - useRenderTexture: settings?.useRenderTexture ?? false - }; - - var assetLibrary:String = assetLibrary ?? ""; - var graphicKey:String = ""; - - if (assetLibrary != "") + if (settings == null) { - graphicKey = Paths.animateAtlas(key, assetLibrary); - } - else - { - graphicKey = Paths.animateAtlas(key); + settings = getDefaultAtlasSettings(); } - // Validate asset path. - if (!Assets.exists('${graphicKey}/Animation.json')) - { - throw 'No Animation.json file exists at the specified path (${graphicKey})'; - } + this.applyStageMatrix = settings.applyStageMatrix ?? false; + this.useRenderTexture = settings.useRenderTexture ?? false; - this.applyStageMatrix = validatedSettings.applyStageMatrix ?? false; - this.useRenderTexture = validatedSettings.useRenderTexture ?? false; - - frames = FlxAnimateFrames.fromAnimate(graphicKey, validatedSettings.spritemaps, validatedSettings.metadataJson, validatedSettings.cacheKey, - validatedSettings.uniqueInCache, { - swfMode: validatedSettings.swfMode, - cacheOnLoad: validatedSettings.cacheOnLoad, - filterQuality: validatedSettings.filterQuality, - onSymbolCreate: validatedSettings.onSymbolCreate - }); + frames = Paths.getAnimateAtlas(key, assetLibrary, settings); return this; } @@ -735,6 +702,26 @@ class FunkinSprite extends FlxAnimate elementMatrix.ty -= positionOffset; } + /** + * Gets the default settings for a texture atlas sprite. + * @return The default settings for a texture atlas sprite. + */ + public function getDefaultAtlasSettings():AtlasSpriteSettings + { + return { + swfMode: false, + cacheOnLoad: false, + filterQuality: MEDIUM, + spritemaps: null, + metadataJson: null, + cacheKey: null, + uniqueInCache: false, + onSymbolCreate: null, + applyStageMatrix: false, + useRenderTexture: false + }; + } + /** * Ensure scale is applied when cloning a sprite.R * The default `clone()` method acts kinda weird TBH. diff --git a/source/funkin/play/character/MultiAnimateAtlasCharacter.hx b/source/funkin/play/character/MultiAnimateAtlasCharacter.hx index 4b818915e..9dd30ebef 100644 --- a/source/funkin/play/character/MultiAnimateAtlasCharacter.hx +++ b/source/funkin/play/character/MultiAnimateAtlasCharacter.hx @@ -67,8 +67,7 @@ class MultiAnimateAtlasCharacter extends BaseCharacter var subAssetLibrary:String = Paths.getLibrary(asset); var subAssetPath:String = Paths.stripLibrary(asset); - var clone:FunkinSprite = FunkinSprite.createTextureAtlas(0, 0, subAssetPath, subAssetLibrary, cast _data.atlasSettings); - var subTexture:FlxAnimateFrames = clone.library; + var subTexture:FlxAnimateFrames = Paths.getAnimateAtlas(subAssetPath, subAssetLibrary, cast _data.atlasSettings); log('Concatenating texture atlas: ${asset}'); subTexture.parent.destroyOnNoUse = false;