11package funkin .objects ;
22
3+ import animate .FlxAnimate ;
4+ import animate .FlxAnimateFrames ;
35import flixel .group .FlxSpriteGroup .FlxTypedSpriteGroup ;
46import flixel .util .FlxSignal .FlxTypedSignal ;
5- import flxanimate .FlxAnimate ;
67import funkin .structures .ObjectStructure ;
78
89/**
910 * This is a sprite class that adds on to the already existing FlxSprite.
1011 */
11- class FunkinSprite extends FlxSprite
12+ class FunkinSprite extends FlxAnimate
1213{
1314 /**
1415 * Draws this `FunkinSprite`, but invisible.
1516 * This is basically visible/alpha, but it doesn't lag when you make it visible again.
1617 */
1718 public var doInvisibleDraw : Bool = false ;
1819
19- /**
20- * The Animate Atlas Object if the animation is one.
21- */
22- public var atlas : FlxAnimate ;
23-
2420 public function new (x : Float = 0 , y : Float = 0 )
2521 {
2622 super (x , y );
2723 }
2824
25+ override function initVars (): Void
26+ {
27+ super .initVars ();
28+ }
29+
2930 /**
3031 * Loads or creates a texture and applies it to this sprite.
3132 * @param path The asset path. (If `path` starts with a **#** then a color will be made instead and rectWidth + rectHeight will determine its size.)
@@ -57,58 +58,29 @@ class FunkinSprite extends FlxSprite
5758 */
5859 public function loadFrames (path : String , ? forcedType : Null <String >): FunkinSprite
5960 {
60- if (atlas != null )
61- {
62- atlas .destroy ();
63- atlas = null ;
64- }
65-
66- // TODO: make forcedType work, im too lazy
67-
6861 if (Paths .location .exists (path + ' .xml' ))
6962 {
7063 frames = Paths .content .sparrowAtlas (path );
7164 }
7265 else if (Paths .location .exists (path + ' /Animation.json' ))
7366 {
74- atlas = new FlxAnimate (0 , 0 , Paths .location .get (path ), {
75- ShowPivot : false
76- });
67+ frames = FlxAnimateFrames .fromAnimate (Paths .location .get (path ));
7768 }
7869
7970 return this ;
8071 }
8172
82- override public function destroy (): Void
83- {
84- if (atlas != null )
85- atlas .destroy ();
86-
87- super .destroy ();
88- }
89-
9073 override public function draw (): Void
9174 {
9275 var oldAlpha : Float = alpha ;
9376 if (doInvisibleDraw )
9477 alpha = 0.0001 ;
9578
96- if (atlas != null )
97- {
98- updateAtlasDummy ();
99- atlas .draw ();
100- }
101- else
102- {
103- super .draw ();
104- }
79+ super .draw ();
10580
10681 if (doInvisibleDraw )
10782 {
10883 alpha = oldAlpha ;
109-
110- if (atlas != null )
111- atlas .alpha = alpha ;
11284 }
11385 }
11486
@@ -122,37 +94,6 @@ class FunkinSprite extends FlxSprite
12294 }
12395 #end
12496
125- override public function update (elapsed : Float ): Void
126- {
127- if (atlas != null )
128- atlas .update (elapsed );
129-
130- super .update (elapsed );
131- }
132-
133- /**
134- * Updates the Atlas dummy's values, so it looks like it belongs to this sprite.
135- * @see The Original Code: https://github.com/CodenameCrew/CodenameEngine/blob/f6deda2c84984202effdfc5f6b577c2d956aa7b5/source/funkin/backend/FunkinSprite.hx#L209C2-L232C3
136- */
137- @:privateAccess
138- public function updateAtlasDummy (): Void
139- {
140- atlas .cameras = cameras ;
141- atlas .scrollFactor = scrollFactor ;
142- atlas .scale = scale ;
143- atlas .offset = offset ;
144- atlas .x = x ;
145- atlas .y = y ;
146- atlas .angle = angle ;
147- atlas .alpha = alpha ;
148- atlas .visible = visible ;
149- atlas .flipX = flipX ;
150- atlas .flipY = flipY ;
151- atlas .shader = shader ;
152- atlas .antialiasing = antialiasing ;
153- atlas .colorTransform = colorTransform ;
154- }
155-
15697 // ANIMATION BINDINGS
15798
15899 /**
@@ -174,11 +115,7 @@ class FunkinSprite extends FlxSprite
174115 if (animationStunned )
175116 return ;
176117
177- if (atlas != null )
178- atlas .anim .play (name , restart , reversed );
179- else
180- animation .play (name , restart , reversed );
181-
118+ animation .play (name , restart , reversed );
182119 animationStunned = stunAnimations ;
183120 currentAnim = name ;
184121 }
@@ -193,19 +130,27 @@ class FunkinSprite extends FlxSprite
193130 */
194131 public function addAnimation (name : String , anim : String , ? indices : Array <Int > = null , ? frameRate : Float = 24 , ? looped : Bool = true ): Void
195132 {
196- if (atlas != null )
133+ if (indices != null && indices . length > 0 )
197134 {
198- if (indices != null && indices .length > 0 )
199- atlas .anim .addBySymbolIndices (name , anim + ' \\ ' , indices , frameRate , looped );
135+ if (isAnimate )
136+ {
137+ this .anim .addBySymbolIndices (name , anim , indices , frameRate , looped );
138+ }
200139 else
201- atlas .anim .addBySymbol (name , anim + ' \\ ' , frameRate , looped );
140+ {
141+ animation .addByIndices (name , anim + ' 0' , indices , ' ' , frameRate , looped );
142+ }
202143 }
203144 else
204145 {
205- if (indices != null && indices .length > 0 )
206- animation .addByIndices (name , anim + ' 0' , indices , ' ' , frameRate , looped );
146+ if (isAnimate )
147+ {
148+ this .anim .addBySymbol (name , anim , frameRate , looped );
149+ }
207150 else
151+ {
208152 animation .addByPrefix (name , anim + ' 0' , frameRate , looped );
153+ }
209154 }
210155 }
211156
@@ -216,7 +161,7 @@ class FunkinSprite extends FlxSprite
216161
217162 function get_animationIsNull (): Bool
218163 {
219- return ( atlas != null ) ? atlas . anim . curSymbol == null : animation .curAnim == null ;
164+ return animation .curAnim == null ;
220165 }
221166
222167 /**
@@ -226,10 +171,7 @@ class FunkinSprite extends FlxSprite
226171
227172 function get_animFinished (): Bool
228173 {
229- if (animationIsNull )
230- return false ;
231-
232- return ((atlas != null ) ? atlas .anim .finished : animation .curAnim .finished ) ?? false ;
174+ return animation ?. curAnim ?. finished ?? false ;
233175 }
234176
235177 /**
@@ -240,10 +182,7 @@ class FunkinSprite extends FlxSprite
240182 if (animationIsNull )
241183 return ;
242184
243- if (atlas != null )
244- atlas .anim .curFrame = atlas .anim .length - 1 ;
245- else
246- animation .curAnim .finish ();
185+ animation .curAnim .finish ();
247186 }
248187
249188 /**
@@ -256,28 +195,18 @@ class FunkinSprite extends FlxSprite
256195 if (animationIsNull )
257196 return false ;
258197
259- return (( atlas != null ) ? atlas . anim . isPlaying : animation . curAnim .paused ) ?? false ;
198+ return animation ?. curAnim ? .paused ?? false ;
260199 }
261200
262201 function set_animPaused (value : Bool ): Bool
263202 {
264203 if (animationIsNull )
265204 return value ;
266205
267- if (atlas != null )
268- {
269- if (value )
270- atlas .anim .pause ();
271- else
272- atlas .anim .resume ();
273- }
206+ if (value )
207+ animation .curAnim .pause ();
274208 else
275- {
276- if (value )
277- animation .curAnim .pause ();
278- else
279- animation .curAnim .resume ();
280- }
209+ animation .curAnim .resume ();
281210
282211 return value ;
283212 }
@@ -290,10 +219,7 @@ class FunkinSprite extends FlxSprite
290219 @:privateAccess
291220 public function animationExists (name : String ): Bool
292221 {
293- if (atlas != null )
294- return atlas .anim .symbolDictionary .get (name ) != null ;
295- else
296- return animation ?. exists (name ) ?? false ;
222+ return animation ?. exists (name ) ?? false ;
297223 }
298224
299225 /**
@@ -309,20 +235,10 @@ class FunkinSprite extends FlxSprite
309235 {
310236 _onAnimFinished = new FlxTypedSignal <String -> Void >();
311237
312- if (atlas != null )
313- {
314- atlas .anim .onComplete .add (() ->
315- {
316- _onAnimFinished .dispatch (currentAnim );
317- });
318- }
319- else
238+ animation .onFinish .add ((_ ) ->
320239 {
321- animation .onFinish .add ((_ ) ->
322- {
323- _onAnimFinished .dispatch (currentAnim );
324- });
325- }
240+ _onAnimFinished .dispatch (currentAnim );
241+ });
326242 }
327243
328244 return _onAnimFinished ;
@@ -337,65 +253,11 @@ class FunkinSprite extends FlxSprite
337253 if (animationIsNull )
338254 return false ;
339255
340- if (atlas != null )
341- {
342- var animData = atlas .anim .symbolDictionary .get (id );
343- if (animData == null )
344- return false ;
345- return animData .length > 1 ;
346- }
347- else
348- {
349- var animData = animation .getByName (id );
350- if (animData == null )
351- return false ;
352- return animData .numFrames > 1 ;
353- }
354- }
355-
356- @:noCompletion
357- override function set_width (value : Float ): Float
358- {
359- if (atlas != null )
360- {
361- atlas .width = value ;
362- return atlas .width ;
363- }
364-
365- return super .set_width (value );
366- }
367-
368- @:noCompletion
369- override function get_width (): Float
370- {
371- if (atlas != null )
372- {
373- return atlas .width ;
374- }
375-
376- return super .get_width ();
377- }
378-
379- @:noCompletion
380- override function set_height (value : Float ): Float
381- {
382- if (atlas != null )
383- {
384- atlas .height = value ;
385- return atlas .height ;
386- }
387-
388- return super .set_height (value );
389- }
390-
391- override function get_height (): Float
392- {
393- if (atlas != null )
394- {
395- return atlas .height ;
396- }
256+ var animData = animation .getByName (id );
257+ if (animData == null )
258+ return false ;
397259
398- return super . get_height () ;
260+ return animData . numFrames > 1 ;
399261 }
400262}
401263
0 commit comments