mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 04:47:13 +08:00 
			
		
		
		
	Explicitly set what the effect modifies (#585)
* Explicitly set what the effect modifies * Add changelog entry
This commit is contained in:
		@ -5,6 +5,7 @@
 | 
				
			|||||||
 - Set loop member variable when constructing SpriteAnimationComponent from SpriteAnimationData
 | 
					 - Set loop member variable when constructing SpriteAnimationComponent from SpriteAnimationData
 | 
				
			||||||
 - Effect shouldn't affect unrelated properties on component
 | 
					 - Effect shouldn't affect unrelated properties on component
 | 
				
			||||||
 - Fix rendering of children
 | 
					 - Fix rendering of children
 | 
				
			||||||
 | 
					 - Explicitly define what fields an effect on PositionComponent modifies
 | 
				
			||||||
 - Properly propagate onMount and onRemove to children
 | 
					 - Properly propagate onMount and onRemove to children
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 1.0.0-rc3
 | 
					## 1.0.0-rc3
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,14 @@ class CombinedEffect extends PositionComponentEffect {
 | 
				
			|||||||
    bool isInfinite = false,
 | 
					    bool isInfinite = false,
 | 
				
			||||||
    bool isAlternating = false,
 | 
					    bool isAlternating = false,
 | 
				
			||||||
    void Function() onComplete,
 | 
					    void Function() onComplete,
 | 
				
			||||||
  }) : super(isInfinite, isAlternating, onComplete: onComplete) {
 | 
					  }) : super(
 | 
				
			||||||
 | 
					          isInfinite,
 | 
				
			||||||
 | 
					          isAlternating,
 | 
				
			||||||
 | 
					          modifiesPosition: effects.any((e) => e.modifiesPosition),
 | 
				
			||||||
 | 
					          modifiesAngle: effects.any((e) => e.modifiesAngle),
 | 
				
			||||||
 | 
					          modifiesSize: effects.any((e) => e.modifiesSize),
 | 
				
			||||||
 | 
					          onComplete: onComplete,
 | 
				
			||||||
 | 
					        ) {
 | 
				
			||||||
    assert(
 | 
					    assert(
 | 
				
			||||||
      effects.every((effect) => effect.component == null),
 | 
					      effects.every((effect) => effect.component == null),
 | 
				
			||||||
      'Each effect can only be added once',
 | 
					      'Each effect can only be added once',
 | 
				
			||||||
 | 
				
			|||||||
@ -126,11 +126,19 @@ abstract class PositionComponentEffect
 | 
				
			|||||||
  double endAngle;
 | 
					  double endAngle;
 | 
				
			||||||
  Vector2 endSize;
 | 
					  Vector2 endSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// Whether the state of a certain field was modified by the effect
 | 
				
			||||||
 | 
					  final bool modifiesPosition;
 | 
				
			||||||
 | 
					  final bool modifiesAngle;
 | 
				
			||||||
 | 
					  final bool modifiesSize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  PositionComponentEffect(
 | 
					  PositionComponentEffect(
 | 
				
			||||||
    bool initialIsInfinite,
 | 
					    bool initialIsInfinite,
 | 
				
			||||||
    bool initialIsAlternating, {
 | 
					    bool initialIsAlternating, {
 | 
				
			||||||
    bool isRelative = false,
 | 
					    bool isRelative = false,
 | 
				
			||||||
    Curve curve,
 | 
					    Curve curve,
 | 
				
			||||||
 | 
					    this.modifiesPosition = false,
 | 
				
			||||||
 | 
					    this.modifiesAngle = false,
 | 
				
			||||||
 | 
					    this.modifiesSize = false,
 | 
				
			||||||
    void Function() onComplete,
 | 
					    void Function() onComplete,
 | 
				
			||||||
  }) : super(
 | 
					  }) : super(
 | 
				
			||||||
          initialIsInfinite,
 | 
					          initialIsInfinite,
 | 
				
			||||||
@ -162,13 +170,13 @@ abstract class PositionComponentEffect
 | 
				
			|||||||
  /// another effect, like children of a CombinedEffect or SequenceEffect).
 | 
					  /// another effect, like children of a CombinedEffect or SequenceEffect).
 | 
				
			||||||
  void _setComponentState(Vector2 position, double angle, Vector2 size) {
 | 
					  void _setComponentState(Vector2 position, double angle, Vector2 size) {
 | 
				
			||||||
    if (isRootEffect()) {
 | 
					    if (isRootEffect()) {
 | 
				
			||||||
      if (originalPosition != endPosition) {
 | 
					      if (modifiesPosition) {
 | 
				
			||||||
        component?.position?.setFrom(position);
 | 
					        component?.position?.setFrom(position);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if (originalAngle != endAngle) {
 | 
					      if (modifiesAngle) {
 | 
				
			||||||
        component?.angle = angle;
 | 
					        component?.angle = angle;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if (originalSize != endSize) {
 | 
					      if (modifiesSize) {
 | 
				
			||||||
        component?.size?.setFrom(size);
 | 
					        component?.size?.setFrom(size);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -196,6 +204,9 @@ abstract class SimplePositionComponentEffect extends PositionComponentEffect {
 | 
				
			|||||||
    this.speed,
 | 
					    this.speed,
 | 
				
			||||||
    Curve curve,
 | 
					    Curve curve,
 | 
				
			||||||
    bool isRelative = false,
 | 
					    bool isRelative = false,
 | 
				
			||||||
 | 
					    bool modifiesPosition = false,
 | 
				
			||||||
 | 
					    bool modifiesAngle = false,
 | 
				
			||||||
 | 
					    bool modifiesSize = false,
 | 
				
			||||||
    void Function() onComplete,
 | 
					    void Function() onComplete,
 | 
				
			||||||
  })  : assert(
 | 
					  })  : assert(
 | 
				
			||||||
          (duration != null) ^ (speed != null),
 | 
					          (duration != null) ^ (speed != null),
 | 
				
			||||||
@ -206,6 +217,9 @@ abstract class SimplePositionComponentEffect extends PositionComponentEffect {
 | 
				
			|||||||
          initialIsAlternating,
 | 
					          initialIsAlternating,
 | 
				
			||||||
          isRelative: isRelative,
 | 
					          isRelative: isRelative,
 | 
				
			||||||
          curve: curve,
 | 
					          curve: curve,
 | 
				
			||||||
 | 
					          modifiesPosition: modifiesPosition,
 | 
				
			||||||
 | 
					          modifiesAngle: modifiesAngle,
 | 
				
			||||||
 | 
					          modifiesSize: modifiesSize,
 | 
				
			||||||
          onComplete: onComplete,
 | 
					          onComplete: onComplete,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -45,6 +45,7 @@ class MoveEffect extends SimplePositionComponentEffect {
 | 
				
			|||||||
          speed: speed,
 | 
					          speed: speed,
 | 
				
			||||||
          curve: curve,
 | 
					          curve: curve,
 | 
				
			||||||
          isRelative: isRelative,
 | 
					          isRelative: isRelative,
 | 
				
			||||||
 | 
					          modifiesPosition: true,
 | 
				
			||||||
          onComplete: onComplete,
 | 
					          onComplete: onComplete,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -29,6 +29,7 @@ class RotateEffect extends SimplePositionComponentEffect {
 | 
				
			|||||||
          speed: speed,
 | 
					          speed: speed,
 | 
				
			||||||
          curve: curve,
 | 
					          curve: curve,
 | 
				
			||||||
          isRelative: isRelative,
 | 
					          isRelative: isRelative,
 | 
				
			||||||
 | 
					          modifiesAngle: true,
 | 
				
			||||||
          onComplete: onComplete,
 | 
					          onComplete: onComplete,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -30,6 +30,7 @@ class ScaleEffect extends SimplePositionComponentEffect {
 | 
				
			|||||||
          speed: speed,
 | 
					          speed: speed,
 | 
				
			||||||
          curve: curve,
 | 
					          curve: curve,
 | 
				
			||||||
          isRelative: isRelative,
 | 
					          isRelative: isRelative,
 | 
				
			||||||
 | 
					          modifiesSize: true,
 | 
				
			||||||
          onComplete: onComplete,
 | 
					          onComplete: onComplete,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,14 @@ class SequenceEffect extends PositionComponentEffect {
 | 
				
			|||||||
    bool isInfinite = false,
 | 
					    bool isInfinite = false,
 | 
				
			||||||
    bool isAlternating = false,
 | 
					    bool isAlternating = false,
 | 
				
			||||||
    void Function() onComplete,
 | 
					    void Function() onComplete,
 | 
				
			||||||
  }) : super(isInfinite, isAlternating, onComplete: onComplete) {
 | 
					  }) : super(
 | 
				
			||||||
 | 
					          isInfinite,
 | 
				
			||||||
 | 
					          isAlternating,
 | 
				
			||||||
 | 
					          modifiesPosition: effects.any((e) => e.modifiesPosition),
 | 
				
			||||||
 | 
					          modifiesAngle: effects.any((e) => e.modifiesAngle),
 | 
				
			||||||
 | 
					          modifiesSize: effects.any((e) => e.modifiesSize),
 | 
				
			||||||
 | 
					          onComplete: onComplete,
 | 
				
			||||||
 | 
					        ) {
 | 
				
			||||||
    assert(
 | 
					    assert(
 | 
				
			||||||
      effects.every((effect) => effect.component == null),
 | 
					      effects.every((effect) => effect.component == null),
 | 
				
			||||||
      'Each effect can only be added once',
 | 
					      'Each effect can only be added once',
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user