@@ -247,16 +247,7 @@ class FlxAnimationController implements IFlxDestroyable
247
247
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
248
248
{
249
249
var indices : Array <Int > = new Array <Int >();
250
- var l : Int = FrameNames .length ;
251
- for (i in 0 ... l )
252
- {
253
- var name : String = FrameNames [i ];
254
- if (_sprite .framesData .framesHash .exists (name ))
255
- {
256
- var frameToAdd : FlxFrame = _sprite .framesData .framesHash .get (name );
257
- indices .push (getFrameIndex (frameToAdd ));
258
- }
259
- }
250
+ byNamesHelper (indices , FrameNames ); // finds frames and appends them to the blank array
260
251
261
252
if (indices .length > 0 )
262
253
{
@@ -285,16 +276,7 @@ class FlxAnimationController implements IFlxDestroyable
285
276
286
277
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
287
278
{
288
- var l : Int = FrameNames .length ;
289
- for (i in 0 ... l )
290
- {
291
- var name : String = FrameNames [i ];
292
- if (_sprite .framesData .framesHash .exists (name ))
293
- {
294
- var frameToAdd : FlxFrame = _sprite .framesData .framesHash .get (name );
295
- anim ._frames .push (getFrameIndex (frameToAdd ));
296
- }
297
- }
279
+ byNamesHelper (anim ._frames , FrameNames ); // finds frames and appends them to the existing array
298
280
}
299
281
}
300
282
@@ -312,16 +294,7 @@ class FlxAnimationController implements IFlxDestroyable
312
294
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
313
295
{
314
296
var frameIndices : Array <Int > = new Array <Int >();
315
- var l : Int = Indices .length ;
316
- for (i in 0 ... l )
317
- {
318
- var name : String = Prefix + Indices [i ] + Postfix ;
319
- if (_sprite .framesData .framesHash .exists (name ))
320
- {
321
- var frameToAdd : FlxFrame = _sprite .framesData .framesHash .get (name );
322
- frameIndices .push (getFrameIndex (frameToAdd ));
323
- }
324
- }
297
+ byStringIndicesHelper (frameIndices , Prefix , Indices , Postfix ); // finds frames and appends them to the blank array
325
298
326
299
if (frameIndices .length > 0 )
327
300
{
@@ -352,16 +325,7 @@ class FlxAnimationController implements IFlxDestroyable
352
325
353
326
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
354
327
{
355
- var l : Int = Indices .length ;
356
- for (i in 0 ... l )
357
- {
358
- var name : String = Prefix + Indices [i ] + Postfix ;
359
- if (_sprite .framesData .framesHash .exists (name ))
360
- {
361
- var frameToAdd : FlxFrame = _sprite .framesData .framesHash .get (name );
362
- anim ._frames .push (getFrameIndex (frameToAdd ));
363
- }
364
- }
328
+ byStringIndicesHelper (anim ._frames , Prefix , Indices , Postfix ); // finds frames and appends them to the existing array
365
329
}
366
330
}
367
331
@@ -379,15 +343,7 @@ class FlxAnimationController implements IFlxDestroyable
379
343
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
380
344
{
381
345
var frameIndices : Array <Int > = new Array <Int >();
382
- var l : Int = Indices .length ;
383
- for (i in 0 ... l )
384
- {
385
- var indexToAdd : Int = findSpriteFrame (Prefix , Indices [i ], Postfix );
386
- if (indexToAdd != - 1 )
387
- {
388
- frameIndices .push (indexToAdd );
389
- }
390
- }
346
+ byIndicesHelper (frameIndices , Prefix , Indices , Postfix ); // finds frames and appends them to the blank array
391
347
392
348
if (frameIndices .length > 0 )
393
349
{
@@ -418,15 +374,7 @@ class FlxAnimationController implements IFlxDestroyable
418
374
419
375
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
420
376
{
421
- var l : Int = Indices .length ;
422
- for (i in 0 ... l )
423
- {
424
- var indexToAdd : Int = findSpriteFrame (Prefix , Indices [i ], Postfix );
425
- if (indexToAdd != - 1 )
426
- {
427
- anim ._frames .push (indexToAdd );
428
- }
429
- }
377
+ byIndicesHelper (anim ._frames , Prefix , Indices , Postfix ); // finds frames and appends them to the existing array
430
378
}
431
379
}
432
380
@@ -468,31 +416,12 @@ class FlxAnimationController implements IFlxDestroyable
468
416
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
469
417
{
470
418
var animFrames : Array <FlxFrame > = new Array <FlxFrame >();
471
- var l : Int = _sprite .framesData .frames .length ;
472
- for (i in 0 ... l )
473
- {
474
- if (StringTools .startsWith (_sprite .framesData .frames [i ].name , Prefix ))
475
- {
476
- animFrames .push (_sprite .framesData .frames [i ]);
477
- }
478
- }
419
+ findByPrefix (animFrames , Prefix ); // adds valid frames to animFrames
479
420
480
421
if (animFrames .length > 0 )
481
422
{
482
- var name : String = animFrames [0 ].name ;
483
- // check for potential postFix: ".png", ".gif", etc
484
- var postIndex : Int = name .indexOf (" ." , Prefix .length );
485
- var postFix : String = name .substring (postIndex == - 1 ? name .length : postIndex , name .length );
486
- FlxAnimationController .prefixLength = Prefix .length ;
487
- FlxAnimationController .postfixLength = postFix .length ;
488
- animFrames .sort (FlxAnimationController .frameSortFunction );
489
423
var frameIndices : Array <Int > = new Array <Int >();
490
-
491
- l = animFrames .length ;
492
- for (i in 0 ... l )
493
- {
494
- frameIndices .push (getFrameIndex (animFrames [i ]));
495
- }
424
+ byPrefixHelper (frameIndices , animFrames , Prefix ); // finds frames and appends them to the blank array
496
425
497
426
if (frameIndices .length > 0 )
498
427
{
@@ -523,29 +452,11 @@ class FlxAnimationController implements IFlxDestroyable
523
452
if (_sprite .cachedGraphics != null && _sprite .cachedGraphics .data != null )
524
453
{
525
454
var animFrames : Array <FlxFrame > = new Array <FlxFrame >();
526
- var l : Int = _sprite .framesData .frames .length ;
527
- for (i in 0 ... l )
528
- {
529
- if (StringTools .startsWith (_sprite .framesData .frames [i ].name , Prefix ))
530
- {
531
- animFrames .push (_sprite .framesData .frames [i ]);
532
- }
533
- }
455
+ findByPrefix (animFrames , Prefix ); // adds valid frames to animFrames
534
456
535
457
if (animFrames .length > 0 )
536
458
{
537
- var name : String = animFrames [0 ].name ;
538
- var postIndex : Int = name .indexOf (" ." , Prefix .length );
539
- var postFix : String = name .substring (postIndex == - 1 ? name .length : postIndex , name .length );
540
- FlxAnimationController .prefixLength = Prefix .length ;
541
- FlxAnimationController .postfixLength = postFix .length ;
542
- animFrames .sort (FlxAnimationController .frameSortFunction );
543
-
544
- l = animFrames .length ;
545
- for (i in 0 ... l )
546
- {
547
- anim ._frames .push (getFrameIndex (animFrames [i ]));
548
- }
459
+ byPrefixHelper (anim ._frames , animFrames , Prefix ); // finds frames and appends them to the existing array
549
460
}
550
461
}
551
462
}
@@ -626,6 +537,90 @@ class FlxAnimationController implements IFlxDestroyable
626
537
frameIndex = FlxRandom .intRanged (0 , frames - 1 );
627
538
}
628
539
540
+ /**
541
+ * Private helper method for add- and appendByNames. Gets frames and appends them to AddTo.
542
+ */
543
+ private function byNamesHelper (AddTo : Array <Int >, FrameNames : Array <String >): Void
544
+ {
545
+ var l : Int = FrameNames .length ;
546
+ for (i in 0 ... l )
547
+ {
548
+ var name : String = FrameNames [i ];
549
+ if (_sprite .framesData .framesHash .exists (name ))
550
+ {
551
+ var frameToAdd : FlxFrame = _sprite .framesData .framesHash .get (name );
552
+ AddTo .push (getFrameIndex (frameToAdd ));
553
+ }
554
+ }
555
+ }
556
+
557
+ /**
558
+ * Private helper method for add- and appendByStringIndices. Gets frames and appends them to AddTo.
559
+ */
560
+ private function byStringIndicesHelper (AddTo : Array <Int >, Prefix : String , Indices : Array <String >, Postfix : String ): Void
561
+ {
562
+ var l : Int = Indices .length ;
563
+ for (i in 0 ... l )
564
+ {
565
+ var name : String = Prefix + Indices [i ] + Postfix ;
566
+ if (_sprite .framesData .framesHash .exists (name ))
567
+ {
568
+ var frameToAdd : FlxFrame = _sprite .framesData .framesHash .get (name );
569
+ AddTo .push (getFrameIndex (frameToAdd ));
570
+ }
571
+ }
572
+ }
573
+
574
+ /**
575
+ * Private helper method for add- and appendByIndices. Finds frames and appends them to AddTo.
576
+ */
577
+ private function byIndicesHelper (AddTo : Array <Int >, Prefix : String , Indices : Array <Int >, Postfix : String ): Void
578
+ {
579
+ var l : Int = Indices .length ;
580
+ for (i in 0 ... l )
581
+ {
582
+ var indexToAdd : Int = findSpriteFrame (Prefix , Indices [i ], Postfix );
583
+ if (indexToAdd != - 1 )
584
+ {
585
+ AddTo .push (indexToAdd );
586
+ }
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Private helper method for add- and appendByPrefix. Sorts frames and appends them to AddTo.
592
+ */
593
+ private function byPrefixHelper (AddTo : Array <Int >, AnimFrames : Array <FlxFrame >, Prefix : String ): Void
594
+ {
595
+ var name : String = AnimFrames [0 ].name ;
596
+ var postIndex : Int = name .indexOf (" ." , Prefix .length );
597
+ var postFix : String = name .substring (postIndex == - 1 ? name .length : postIndex , name .length );
598
+ FlxAnimationController .prefixLength = Prefix .length ;
599
+ FlxAnimationController .postfixLength = postFix .length ;
600
+ AnimFrames .sort (FlxAnimationController .frameSortFunction );
601
+
602
+ var l : Int = AnimFrames .length ;
603
+ for (i in 0 ... l )
604
+ {
605
+ AddTo .push (getFrameIndex (AnimFrames [i ]));
606
+ }
607
+ }
608
+
609
+ /**
610
+ * Private helper method for add- and appendByPrefix. Finds frames with the given prefix and appends them to AnimFrames.
611
+ */
612
+ private function findByPrefix (AnimFrames : Array <FlxFrame >, Prefix : String ): Void
613
+ {
614
+ var l : Int = _sprite .framesData .frames .length ;
615
+ for (i in 0 ... l )
616
+ {
617
+ if (StringTools .startsWith (_sprite .framesData .frames [i ].name , Prefix ))
618
+ {
619
+ AnimFrames .push (_sprite .framesData .frames [i ]);
620
+ }
621
+ }
622
+ }
623
+
629
624
private function set_frameIndex (Frame : Int ): Int
630
625
{
631
626
if (_sprite .framesData != null )
0 commit comments