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