@@ -3,6 +3,7 @@ package funkin.play.character;
33import funkin .graphics .FunkinSprite ;
44import funkin .util .assets .FlxAnimationUtil ;
55import animate .FlxAnimateFrames ;
6+ import flixel .graphics .frames .FlxAtlasFrames ;
67import funkin .modding .events .ScriptEvent ;
78import funkin .data .animation .AnimationData ;
89import funkin .data .character .CharacterData .CharacterRenderType ;
@@ -29,16 +30,9 @@ class MultiAnimateAtlasCharacter extends BaseCharacter
2930 cpp.vm.tracy. TracyProfiler .zoneScoped (' MultiAnimateAtlasCharacter.create( ${this .characterId })' );
3031 #end
3132
32- try
33- {
34- log (' Loading assets for Multi-Animate Atlas character " ${characterId }"' );
35- loadAtlases ();
36- loadAnimations ();
37- }
38- catch (e )
39- {
40- throw " Exception thrown while building sprite: " + e ;
41- }
33+ log (' Loading assets for Multi-Animate Atlas character " ${characterId }"' );
34+ loadAtlases ();
35+ loadAnimations ();
4236
4337 log (' Successfully loaded texture atlases for ${characterId } with ${_data .animations .length } animations.' );
4438 super .onCreate (event );
@@ -48,31 +42,58 @@ class MultiAnimateAtlasCharacter extends BaseCharacter
4842 {
4943 log (' Loading sprite atlases for ${characterId }.' );
5044
51- var assetList : Array <String > = [];
52- for (anim in _data .animations )
53- {
54- if (anim .assetPath != null && ! assetList .contains (anim .assetPath ))
55- {
56- assetList .push (anim .assetPath );
57- }
58- }
45+ var textureList : Array <FlxAtlasFrames > = [];
46+ var addedAssetPaths : Array <String > = [];
5947
6048 var baseAssetLibrary : String = Paths .getLibrary (_data .assetPath );
6149 var baseAssetPath : String = Paths .stripLibrary (_data .assetPath );
6250
6351 loadTextureAtlas (baseAssetPath , baseAssetLibrary , getAtlasSettings ());
6452
65- for (asset in assetList )
66- {
67- var subAssetLibrary : String = Paths .getLibrary (asset );
68- var subAssetPath : String = Paths .stripLibrary (asset );
53+ var mainTexture : FlxAtlasFrames = this .library ;
54+ textureList .push (mainTexture );
6955
70- var subTexture : FlxAnimateFrames = Paths .getAnimateAtlas (subAssetPath , subAssetLibrary , cast _data .atlasSettings );
56+ for (animation in _data .animations )
57+ {
58+ if (animation .assetPath == null ) continue ;
59+ if (addedAssetPaths .contains (animation .assetPath )) continue ;
7160
72- log (' Concatenating texture atlas: ${asset }' );
73- subTexture .parent .destroyOnNoUse = false ;
61+ switch (animation .renderType )
62+ {
63+ case " sparrow" :
64+ var subTexture : FlxAtlasFrames = Paths .getSparrowAtlas (animation .assetPath );
65+ // If we don't do this, the unused textures will be removed as soon as they're loaded.
66+
67+ if (subTexture == null )
68+ {
69+ log (' Multi-Animate atlas could not load subtexture: ${animation .assetPath }' );
70+ FlxG .log .error (' Multi-Animate atlas could not load subtexture: ${animation .assetPath }' );
71+ return ;
72+ }
73+ else
74+ {
75+ log (' Concatenating sparrow atlas: ${animation .assetPath }' );
76+ subTexture .parent .destroyOnNoUse = false ;
77+ // This breaks mix-and-match for some reason.
78+ // TODO: Re-enable this line once a proper fix is found.
79+ // - Abnormal
80+ // FunkinMemory.cacheTexture(Paths.image(animation.assetPath));
81+ }
82+
83+ textureList .push (subTexture );
84+ default :
85+ var subAssetLibrary : String = Paths .getLibrary (animation .assetPath );
86+ var subAssetPath : String = Paths .stripLibrary (animation .assetPath );
87+
88+ var subTexture : FlxAnimateFrames = Paths .getAnimateAtlas (subAssetPath , subAssetLibrary , cast animation .atlasSettings ?? _data .atlasSettings );
89+
90+ log (' Concatenating texture atlas: ${animation .assetPath }' );
91+ subTexture .parent .destroyOnNoUse = false ;
92+
93+ textureList .push (subTexture );
94+ }
7495
75- this . library . addAtlas ( subTexture );
96+ addedAssetPaths . push ( animation . assetPath );
7697 }
7798
7899 if (_data .isPixel )
@@ -86,17 +107,24 @@ class MultiAnimateAtlasCharacter extends BaseCharacter
86107 this .antialiasing = true ;
87108 }
88109
110+ this .frames = FlxAnimateFrames .combineAtlas (textureList );
89111 this .setScale (_data .scale );
90112 }
91113
92114 function loadAnimations (): Void
93115 {
94- log (' Loading ${_data .animations .length } animations for ${characterId }' );
95-
96- FlxAnimationUtil .addTextureAtlasAnimations (this , _data .animations );
116+ log (' [MULTIATLASCHAR] Loading ${_data .animations .length } animations for ${characterId }' );
97117
98118 for (anim in _data .animations )
99119 {
120+ switch (anim .renderType )
121+ {
122+ case " sparrow" :
123+ FlxAnimationUtil .addAtlasAnimation (this , anim );
124+ default :
125+ FlxAnimationUtil .addTextureAtlasAnimation (this , anim );
126+ }
127+
100128 if (anim .offsets == null )
101129 {
102130 setAnimationOffsets (anim .name , 0 , 0 );
@@ -107,8 +135,8 @@ class MultiAnimateAtlasCharacter extends BaseCharacter
107135 }
108136 }
109137
110- var animNames = this .anim .getNameList ();
111- log (' Successfully loaded ${animNames .length } animations for ${characterId }' );
138+ var animationNames : Array < String > = this .animation .getNameList ();
139+ log (' [MULTIATLASCHAR] Successfully loaded ${animationNames .length } animations for ${characterId }' );
112140 }
113141
114142 /**
0 commit comments