Make multi-animateatlas characters use a getAnimateAtlas function instead of making a new FunkinSprite
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user