LCOV - code coverage report
Current view: top level - lib/src/components - sprite_animation_component.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 8 18 44.4 %
Date: 2021-08-10 15:50:53 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:ui';
       2             : 
       3             : import 'package:meta/meta.dart';
       4             : 
       5             : import '../extensions/vector2.dart';
       6             : import '../sprite_animation.dart';
       7             : import 'mixins/has_paint.dart';
       8             : import 'position_component.dart';
       9             : 
      10             : export '../sprite_animation.dart';
      11             : 
      12             : class SpriteAnimationComponent extends PositionComponent with HasPaint {
      13             :   SpriteAnimation? animation;
      14             :   bool removeOnFinish = false;
      15             :   bool playing;
      16             : 
      17             :   /// Creates a component with an empty animation which can be set later
      18           3 :   SpriteAnimationComponent({
      19             :     Vector2? position,
      20             :     Vector2? size,
      21             :     int? priority,
      22             :     this.animation,
      23             :     Paint? paint,
      24             :     this.removeOnFinish = false,
      25             :     this.playing = true,
      26           3 :   }) : super(position: position, size: size, priority: priority) {
      27             :     if (paint != null) {
      28           0 :       this.paint = paint;
      29             :     }
      30             :   }
      31             : 
      32             :   /// Creates a SpriteAnimationComponent from a [size], an [image] and [data]. Check [SpriteAnimationData] for more info on the available options.
      33             :   ///
      34             :   /// Optionally [removeOnFinish] can be set to true to have this component be auto removed from the BaseGame when the animation is finished.
      35           0 :   SpriteAnimationComponent.fromFrameData(
      36             :     Image image,
      37             :     SpriteAnimationData data, {
      38             :     Vector2? position,
      39             :     Vector2? size,
      40             :     int? priority,
      41             :     Paint? paint,
      42             :     this.removeOnFinish = false,
      43             :     this.playing = true,
      44           0 :   }) : super(position: position, size: size, priority: priority) {
      45           0 :     animation = SpriteAnimation.fromFrameData(image, data);
      46             : 
      47             :     if (paint != null) {
      48           0 :       this.paint = paint;
      49             :     }
      50             :   }
      51             : 
      52             :   /// Component will be removed after animation is done and [removeOnFinish] is set.
      53             :   ///
      54             :   /// Note: [SpriteAnimationComponent] will not be removed automatically if loop property of [SpriteAnimation] is true.
      55           3 :   @override
      56             :   bool get shouldRemove =>
      57           7 :       super.shouldRemove || (removeOnFinish && (animation?.done() ?? false));
      58             : 
      59           0 :   @mustCallSuper
      60             :   @override
      61             :   void render(Canvas canvas) {
      62           0 :     super.render(canvas);
      63           0 :     animation?.getSprite().render(
      64             :           canvas,
      65           0 :           size: size,
      66           0 :           overridePaint: paint,
      67             :         );
      68             :   }
      69             : 
      70           2 :   @override
      71             :   void update(double dt) {
      72           2 :     super.update(dt);
      73           2 :     if (playing) {
      74           3 :       animation?.update(dt);
      75             :     }
      76             :   }
      77             : }

Generated by: LCOV version 1.15