mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:12:01 +08:00
Do not reset state if not root effect
This commit is contained in:
@ -85,6 +85,7 @@ abstract class ComponentEffect<T extends Component> {
|
||||
|
||||
bool isMax() => percentage == null ? false : percentage == 1.0;
|
||||
bool isMin() => percentage == null ? false : percentage == 0.0;
|
||||
bool isRootEffect() => component?.effects?.contains(this) ?? false;
|
||||
|
||||
void reset() {
|
||||
_isDisposed = false;
|
||||
@ -155,28 +156,22 @@ abstract class PositionComponentEffect
|
||||
endAngle = component.angle;
|
||||
endSize = component.size.clone();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void setComponentToOriginalState() {
|
||||
component?.position?.setFrom(originalPosition);
|
||||
component?.angle = originalAngle;
|
||||
component?.size?.setFrom(endSize);
|
||||
if(isRootEffect()) {
|
||||
component?.position?.setFrom(originalPosition);
|
||||
component?.angle = originalAngle;
|
||||
component?.size?.setFrom(endSize);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void setComponentToEndState() {
|
||||
// TODO: Remove ifs
|
||||
if (originalPosition != endPosition) {
|
||||
component.position.setFrom(endPosition);
|
||||
print("Set position end state");
|
||||
}
|
||||
if (originalAngle != endAngle) {
|
||||
component.angle = endAngle;
|
||||
print("Set angle end state");
|
||||
}
|
||||
if (originalSize != endSize) {
|
||||
print("Set size end state $originalSize $endSize ${component.size}");
|
||||
component.size.setFrom(endSize);
|
||||
if(isRootEffect()) {
|
||||
component?.position?.setFrom(endPosition);
|
||||
component?.angle = endAngle;
|
||||
component?.size?.setFrom(endSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,9 +42,11 @@ class SequenceEffect extends PositionComponentEffect {
|
||||
endAngle = effect.endAngle;
|
||||
endSize = effect.endSize;
|
||||
});
|
||||
// Add all the effects iteration time since they can alternate within the
|
||||
// sequence effect
|
||||
peakTime = effects.fold(
|
||||
0,
|
||||
(time, effect) => time + effect.peakTime,
|
||||
(time, effect) => time + effect.iterationTime,
|
||||
);
|
||||
if (isAlternating) {
|
||||
endPosition = originalPosition;
|
||||
|
||||
@ -29,6 +29,7 @@ void main() {
|
||||
final ScaleEffect scale = ScaleEffect(
|
||||
size: argumentSize,
|
||||
duration: randomDuration(),
|
||||
isAlternating: true,
|
||||
);
|
||||
final RotateEffect rotate = RotateEffect(
|
||||
angle: argumentAngle,
|
||||
|
||||
@ -41,9 +41,6 @@ void effectTest(
|
||||
game.update(stepDelta);
|
||||
timeLeft -= stepDelta;
|
||||
}
|
||||
print("Current time: ${effect.currentTime}");
|
||||
print("Current peak: ${effect.peakTime}");
|
||||
print("Current perc: ${effect.percentage}");
|
||||
|
||||
if (!shouldComplete) {
|
||||
const double floatRange = 0.01;
|
||||
@ -70,16 +67,12 @@ void effectTest(
|
||||
);
|
||||
} else {
|
||||
// To account for float number operations making effects not finish
|
||||
const double epsilon = 0.000001;
|
||||
const double epsilon = 0.001;
|
||||
if (effect.percentage < epsilon) {
|
||||
print("Last update min");
|
||||
game.update(effect.currentTime);
|
||||
} else if (1.0 - effect.percentage < epsilon) {
|
||||
print("Last update max");
|
||||
game.update(effect.peakTime - effect.currentTime);
|
||||
}
|
||||
print("Current perc after: ${effect.percentage}");
|
||||
print("hasCompleted: ${effect.hasCompleted()}");
|
||||
|
||||
expect(
|
||||
component.position,
|
||||
|
||||
@ -23,7 +23,7 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
SequenceEffect effect(bool isInfinite, bool isAlternating) {
|
||||
SequenceEffect effect({bool isInfinite = false, bool isAlternating = false}) {
|
||||
final MoveEffect move = MoveEffect(path: path, duration: randomDuration());
|
||||
final ScaleEffect scale = ScaleEffect(
|
||||
size: argumentSize,
|
||||
@ -44,7 +44,7 @@ void main() {
|
||||
effectTest(
|
||||
tester,
|
||||
component(),
|
||||
effect(false, false),
|
||||
effect(),
|
||||
expectedPosition: path.last,
|
||||
expectedAngle: argumentAngle,
|
||||
expectedSize: argumentSize,
|
||||
@ -57,7 +57,7 @@ void main() {
|
||||
effectTest(
|
||||
tester,
|
||||
component(),
|
||||
effect(false, false),
|
||||
effect(),
|
||||
expectedPosition: path.last,
|
||||
expectedAngle: argumentAngle,
|
||||
expectedSize: argumentSize,
|
||||
@ -73,7 +73,7 @@ void main() {
|
||||
effectTest(
|
||||
tester,
|
||||
positionComponent,
|
||||
effect(false, true),
|
||||
effect(isAlternating: true),
|
||||
expectedPosition: positionComponent.position.clone(),
|
||||
expectedAngle: positionComponent.angle,
|
||||
expectedSize: positionComponent.size.clone(),
|
||||
@ -88,7 +88,7 @@ void main() {
|
||||
effectTest(
|
||||
tester,
|
||||
positionComponent,
|
||||
effect(true, true),
|
||||
effect(isInfinite: true, isAlternating: true),
|
||||
expectedPosition: positionComponent.position.clone(),
|
||||
expectedAngle: positionComponent.angle,
|
||||
expectedSize: positionComponent.size.clone(),
|
||||
@ -103,7 +103,7 @@ void main() {
|
||||
effectTest(
|
||||
tester,
|
||||
positionComponent,
|
||||
effect(false, true),
|
||||
effect(isAlternating: true),
|
||||
expectedPosition: path.last,
|
||||
expectedAngle: argumentAngle,
|
||||
expectedSize: argumentSize,
|
||||
@ -117,7 +117,7 @@ void main() {
|
||||
effectTest(
|
||||
tester,
|
||||
positionComponent,
|
||||
effect(true, false),
|
||||
effect(isInfinite: true),
|
||||
expectedPosition: path.last,
|
||||
expectedAngle: argumentAngle,
|
||||
expectedSize: argumentSize,
|
||||
|
||||
Reference in New Issue
Block a user