11package funkin .objects ;
22
3+ import animate .FlxAnimate ;
4+ import animate .FlxAnimateFrames ;
35import flixel .FlxCamera ;
46import flixel .group .FlxSpriteGroup .FlxTypedSpriteGroup ;
57import flixel .math .FlxPoint ;
68import flixel .util .FlxSignal .FlxTypedSignal ;
7- import flxanimate .FlxAnimate ;
89import funkin .structures .ObjectStructure ;
910
1011/**
1112 * This is a sprite class that adds on to the already existing FlxSprite.
1213 */
13- class FunkinSprite extends FlxSprite
14+ class FunkinSprite extends FlxAnimate
1415{
1516 /**
1617 * uh oh! the letters are ANGRY!!
17- * wont work on animate atlases :(
1818 */
1919 static var spritesAreAngy : Bool = FlxG .random .bool (0.9125 );
2020
@@ -24,16 +24,16 @@ class FunkinSprite extends FlxSprite
2424 */
2525 public var doInvisibleDraw : Bool = false ;
2626
27- /**
28- * The Animate Atlas Object if the animation is one.
29- */
30- public var atlas : FlxAnimate ;
31-
3227 public function new (x : Float = 0 , y : Float = 0 )
3328 {
3429 super (x , y );
3530 }
3631
32+ override function initVars (): Void
33+ {
34+ super .initVars ();
35+ }
36+
3737 /**
3838 * Loads or creates a texture and applies it to this sprite.
3939 * @param path The asset path. (If `path` starts with a **#** then a color will be made instead and rectWidth + rectHeight will determine its size.)
@@ -63,58 +63,29 @@ class FunkinSprite extends FlxSprite
6363 */
6464 public function loadFrames (path : String , ? forcedType : Null <String >): FunkinSprite
6565 {
66- if (atlas != null )
67- {
68- atlas .destroy ();
69- atlas = null ;
70- }
71-
72- // TODO: make forcedType work, im too lazy
73-
7466 if (Paths .location .exists (path + ' .xml' ))
7567 {
7668 frames = Paths .content .sparrowAtlas (path );
7769 }
7870 else if (Paths .location .exists (path + ' /Animation.json' ))
7971 {
80- atlas = new FlxAnimate (0 , 0 , Paths .location .get (path ), {
81- ShowPivot : false
82- });
72+ frames = FlxAnimateFrames .fromAnimate (Paths .location .get (path ));
8373 }
8474
8575 return this ;
8676 }
8777
88- override public function destroy (): Void
89- {
90- if (atlas != null )
91- atlas .destroy ();
92-
93- super .destroy ();
94- }
95-
9678 override public function draw (): Void
9779 {
9880 var oldAlpha : Float = alpha ;
9981 if (doInvisibleDraw )
10082 alpha = 0.0001 ;
10183
102- if (atlas != null )
103- {
104- updateAtlasDummy ();
105- atlas .draw ();
106- }
107- else
108- {
109- super .draw ();
110- }
84+ super .draw ();
11185
11286 if (doInvisibleDraw )
11387 {
11488 alpha = oldAlpha ;
115-
116- if (atlas != null )
117- atlas .alpha = alpha ;
11889 }
11990 }
12091
@@ -128,38 +99,6 @@ class FunkinSprite extends FlxSprite
12899 }
129100 #end
130101
131- override public function update (elapsed : Float ): Void
132- {
133- if (atlas != null )
134- atlas .update (elapsed );
135-
136- super .update (elapsed );
137- }
138-
139- /**
140- * Updates the Atlas dummy's values, so it looks like it belongs to this sprite.
141- * @see The Original Code: https://github.com/CodenameCrew/CodenameEngine/blob/f6deda2c84984202effdfc5f6b577c2d956aa7b5/source/funkin/backend/FunkinSprite.hx#L209C2-L232C3
142- */
143- @:privateAccess
144- public function updateAtlasDummy (): Void
145- {
146- atlas .cameras = cameras ;
147- atlas .scrollFactor = scrollFactor ;
148- atlas .scale = scale ;
149- atlas .offset = offset ;
150- atlas .x = x ;
151- atlas .y = y ;
152- atlas .angle = angle ;
153- atlas .alpha = alpha ;
154- atlas .visible = visible ;
155- atlas .flipX = flipX ;
156- atlas .flipY = flipY ;
157- atlas .shader = shader ;
158- atlas .antialiasing = antialiasing ;
159- atlas .colorTransform = colorTransform ;
160- }
161-
162- // crusher, do you FUCKING dare import these.
163102 override public function getScreenPosition (? result : FlxPoint , ? camera : FlxCamera ): FlxPoint
164103 {
165104 var point : FlxPoint = super .getScreenPosition (result , camera );
@@ -191,11 +130,7 @@ class FunkinSprite extends FlxSprite
191130 if (animationStunned )
192131 return ;
193132
194- if (atlas != null )
195- atlas .anim .play (name , restart , reversed );
196- else
197- animation .play (name , restart , reversed );
198-
133+ animation .play (name , restart , reversed );
199134 animationStunned = stunAnimations ;
200135 currentAnim = name ;
201136 }
@@ -210,19 +145,27 @@ class FunkinSprite extends FlxSprite
210145 */
211146 public function addAnimation (name : String , anim : String , ? indices : Array <Int > = null , ? frameRate : Float = 24 , ? looped : Bool = true ): Void
212147 {
213- if (atlas != null )
148+ if (indices != null && indices . length > 0 )
214149 {
215- if (indices != null && indices .length > 0 )
216- atlas .anim .addBySymbolIndices (name , anim + ' \\ ' , indices , frameRate , looped );
150+ if (isAnimate )
151+ {
152+ this .anim .addBySymbolIndices (name , anim , indices , frameRate , looped );
153+ }
217154 else
218- atlas .anim .addBySymbol (name , anim + ' \\ ' , frameRate , looped );
155+ {
156+ animation .addByIndices (name , anim + ' 0' , indices , ' ' , frameRate , looped );
157+ }
219158 }
220159 else
221160 {
222- if (indices != null && indices .length > 0 )
223- animation .addByIndices (name , anim + ' 0' , indices , ' ' , frameRate , looped );
161+ if (isAnimate )
162+ {
163+ this .anim .addBySymbol (name , anim , frameRate , looped );
164+ }
224165 else
166+ {
225167 animation .addByPrefix (name , anim + ' 0' , frameRate , looped );
168+ }
226169 }
227170 }
228171
@@ -233,7 +176,7 @@ class FunkinSprite extends FlxSprite
233176
234177 function get_animationIsNull (): Bool
235178 {
236- return ( atlas != null ) ? atlas . anim . curSymbol == null : animation .curAnim == null ;
179+ return animation .curAnim == null ;
237180 }
238181
239182 /**
@@ -243,10 +186,7 @@ class FunkinSprite extends FlxSprite
243186
244187 function get_animFinished (): Bool
245188 {
246- if (animationIsNull )
247- return false ;
248-
249- return ((atlas != null ) ? atlas .anim .finished : animation .curAnim .finished ) ?? false ;
189+ return animation ?. curAnim ?. finished ?? false ;
250190 }
251191
252192 /**
@@ -257,10 +197,7 @@ class FunkinSprite extends FlxSprite
257197 if (animationIsNull )
258198 return ;
259199
260- if (atlas != null )
261- atlas .anim .curFrame = atlas .anim .length - 1 ;
262- else
263- animation .curAnim .finish ();
200+ animation .curAnim .finish ();
264201 }
265202
266203 /**
@@ -273,28 +210,18 @@ class FunkinSprite extends FlxSprite
273210 if (animationIsNull )
274211 return false ;
275212
276- return (( atlas != null ) ? atlas . anim . isPlaying : animation . curAnim .paused ) ?? false ;
213+ return animation ?. curAnim ? .paused ?? false ;
277214 }
278215
279216 function set_animPaused (value : Bool ): Bool
280217 {
281218 if (animationIsNull )
282219 return value ;
283220
284- if (atlas != null )
285- {
286- if (value )
287- atlas .anim .pause ();
288- else
289- atlas .anim .resume ();
290- }
221+ if (value )
222+ animation .curAnim .pause ();
291223 else
292- {
293- if (value )
294- animation .curAnim .pause ();
295- else
296- animation .curAnim .resume ();
297- }
224+ animation .curAnim .resume ();
298225
299226 return value ;
300227 }
@@ -307,10 +234,7 @@ class FunkinSprite extends FlxSprite
307234 @:privateAccess
308235 public function animationExists (name : String ): Bool
309236 {
310- if (atlas != null )
311- return atlas .anim .symbolDictionary .get (name ) != null ;
312- else
313- return animation ?. exists (name ) ?? false ;
237+ return animation ?. exists (name ) ?? false ;
314238 }
315239
316240 /**
@@ -326,20 +250,10 @@ class FunkinSprite extends FlxSprite
326250 {
327251 _onAnimFinished = new FlxTypedSignal <String -> Void >();
328252
329- if (atlas != null )
330- {
331- atlas .anim .onComplete .add (() ->
332- {
333- _onAnimFinished .dispatch (currentAnim );
334- });
335- }
336- else
253+ animation .onFinish .add ((_ ) ->
337254 {
338- animation .onFinish .add ((_ ) ->
339- {
340- _onAnimFinished .dispatch (currentAnim );
341- });
342- }
255+ _onAnimFinished .dispatch (currentAnim );
256+ });
343257 }
344258
345259 return _onAnimFinished ;
@@ -354,65 +268,11 @@ class FunkinSprite extends FlxSprite
354268 if (animationIsNull )
355269 return false ;
356270
357- if (atlas != null )
358- {
359- var animData = atlas .anim .symbolDictionary .get (id );
360- if (animData == null )
361- return false ;
362- return animData .length > 1 ;
363- }
364- else
365- {
366- var animData = animation .getByName (id );
367- if (animData == null )
368- return false ;
369- return animData .numFrames > 1 ;
370- }
371- }
372-
373- @:noCompletion
374- override function set_width (value : Float ): Float
375- {
376- if (atlas != null )
377- {
378- atlas .width = value ;
379- return atlas .width ;
380- }
381-
382- return super .set_width (value );
383- }
384-
385- @:noCompletion
386- override function get_width (): Float
387- {
388- if (atlas != null )
389- {
390- return atlas .width ;
391- }
392-
393- return super .get_width ();
394- }
395-
396- @:noCompletion
397- override function set_height (value : Float ): Float
398- {
399- if (atlas != null )
400- {
401- atlas .height = value ;
402- return atlas .height ;
403- }
404-
405- return super .set_height (value );
406- }
407-
408- override function get_height (): Float
409- {
410- if (atlas != null )
411- {
412- return atlas .height ;
413- }
271+ var animData = animation .getByName (id );
272+ if (animData == null )
273+ return false ;
414274
415- return super . get_height () ;
275+ return animData . numFrames > 1 ;
416276 }
417277}
418278
0 commit comments