mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
Stabilize MoveEffect tests
This commit is contained in:
@ -22,8 +22,8 @@ abstract class Component {
|
||||
/// All components on [BaseGame] are always updated by the same amount. The time each one takes to update adds up to the next update cycle.
|
||||
@mustCallSuper
|
||||
void update(double dt) {
|
||||
_effects.forEach((e) => e.update(dt));
|
||||
_effects.removeWhere((e) => e.hasFinished());
|
||||
_effects.forEach((e) => e.update(dt));
|
||||
}
|
||||
|
||||
/// Renders this component on the provided Canvas [c].
|
||||
|
||||
@ -109,9 +109,6 @@ class MoveEffect extends SimplePositionComponentEffect {
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
if (hasFinished()) {
|
||||
return;
|
||||
}
|
||||
super.update(dt);
|
||||
_currentSubPath ??= _percentagePath.first;
|
||||
if (!curveDirection.isNegative && _currentSubPath.endAt < curveProgress ||
|
||||
|
||||
@ -19,7 +19,6 @@ void effectTest(
|
||||
PositionComponent component,
|
||||
PositionComponentEffect effect, {
|
||||
bool hasFinished = true,
|
||||
bool hitEdges = false,
|
||||
double iterations = 1.0,
|
||||
double expectedAngle = 0.0,
|
||||
Vector2 expectedPosition,
|
||||
@ -30,21 +29,22 @@ void effectTest(
|
||||
final Callback callback = Callback();
|
||||
effect.onComplete = callback.call;
|
||||
final BaseGame game = BaseGame();
|
||||
final double duration = (random.nextDouble() * 100).roundToDouble();
|
||||
game.add(component);
|
||||
component.addEffect(effect);
|
||||
final double duration = effect.totalTravelTime;
|
||||
await tester.pumpWidget(game.widget);
|
||||
double timeLeft = iterations * duration;
|
||||
while(timeLeft > 0) {
|
||||
final double stepDelta = hitEdges ? 0.01 : random.nextDouble() / 10;
|
||||
final double stepDelta = random.nextInt(100) / 1000;
|
||||
game.update(stepDelta);
|
||||
timeLeft -= stepDelta;
|
||||
}
|
||||
expect(component.position, expectedPosition);
|
||||
expect(component.angle, expectedAngle);
|
||||
expect(component.size, expectedSize);
|
||||
expect(effect.hasFinished(), hasFinished);
|
||||
expect(callback.isCalled, hasFinished);
|
||||
expect(component.angle, expectedAngle);
|
||||
expect(component.position, expectedPosition);
|
||||
expect(component.size, expectedSize);
|
||||
game.update(0.0); // Since effects are removed before they are updated
|
||||
expect(component.effects.isEmpty, hasFinished);
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ void main() {
|
||||
MoveEffect effect(bool isInfinite, bool isAlternating) {
|
||||
return MoveEffect(
|
||||
path: path,
|
||||
duration: random.nextDouble() * 10,
|
||||
duration: random.nextDouble() * 100,
|
||||
isInfinite: isInfinite,
|
||||
isAlternating: isAlternating,
|
||||
);
|
||||
@ -60,23 +60,19 @@ void main() {
|
||||
testWidgets('MoveEffect alternation can peak', (WidgetTester tester) async {
|
||||
final MoveEffect moveEffect = effect(false, true);
|
||||
final PositionComponent positionComponent = component();
|
||||
print(path);
|
||||
print(positionComponent.position);
|
||||
effectTest(
|
||||
tester,
|
||||
positionComponent,
|
||||
moveEffect,
|
||||
expectedPosition: path.last,
|
||||
hitEdges: true,
|
||||
iterations: 1.4,
|
||||
hasFinished: false,
|
||||
iterations: 0.5,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('MoveEffect can be infinite', (WidgetTester tester) async {
|
||||
final MoveEffect moveEffect = effect(true, false);
|
||||
final PositionComponent positionComponent = component();
|
||||
print(path);
|
||||
print(positionComponent.position);
|
||||
effectTest(
|
||||
tester,
|
||||
positionComponent,
|
||||
|
||||
Reference in New Issue
Block a user