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

          Line data    Source code
       1             : import 'dart:ui';
       2             : 
       3             : import 'package:flutter/animation.dart';
       4             : 
       5             : import '../../components.dart';
       6             : import '../extensions/vector2.dart';
       7             : import 'effects.dart';
       8             : 
       9             : class ScaleEffect extends SimplePositionComponentEffect {
      10             :   Vector2 scale;
      11             :   late Vector2 _startScale;
      12             :   late Vector2 _delta;
      13             : 
      14             :   /// Duration or speed needs to be defined
      15           1 :   ScaleEffect({
      16             :     required this.scale,
      17             :     double? duration, // How long it should take for completion
      18             :     double? speed, // The speed of the scaling in pixels per second
      19             :     Curve? curve,
      20             :     bool isInfinite = false,
      21             :     bool isAlternating = false,
      22             :     bool isRelative = false,
      23             :     VoidCallback? onComplete,
      24             :   })  : assert(
      25           0 :           duration != null || speed != null,
      26             :           'Either speed or duration necessary',
      27             :         ),
      28           1 :         super(
      29             :           isInfinite,
      30             :           isAlternating,
      31             :           duration: duration,
      32             :           speed: speed,
      33             :           curve: curve,
      34             :           isRelative: isRelative,
      35             :           modifiesScale: true,
      36             :           onComplete: onComplete,
      37             :         );
      38             : 
      39           1 :   @override
      40             :   void initialize(PositionComponent component) {
      41           1 :     super.initialize(component);
      42           3 :     _startScale = component.scale.clone();
      43           5 :     _delta = isRelative ? scale : scale - _startScale;
      44           1 :     if (!isAlternating) {
      45           4 :       endScale = _startScale + _delta;
      46             :     }
      47           5 :     speed ??= _delta.length / duration!;
      48           1 :     duration ??= _delta.length / speed!;
      49           5 :     peakTime = isAlternating ? duration! / 2 : duration!;
      50             :   }
      51             : 
      52           1 :   @override
      53             :   void update(double dt) {
      54           1 :     super.update(dt);
      55           8 :     component?.scale.setFrom(_startScale + _delta * curveProgress);
      56             :   }
      57             : }

Generated by: LCOV version 1.15