Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Removed parameter Component.updateTree({callOwnUpdate}) #1224

Merged
merged 16 commits into from
Dec 19, 2021
Merged
8 changes: 2 additions & 6 deletions packages/flame/lib/src/components/component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,9 @@ class Component with Loadable {
/// This method traverses the component tree and calls [update] on all its
/// children according to their [priority] order, relative to the
/// priority of the direct siblings, not the children or the ancestors.
/// If you call this method from [update] you need to set [callOwnUpdate] to
/// false so that you don't get stuck in an infinite loop.
void updateTree(double dt, {bool callOwnUpdate = true}) {
void updateTree(double dt) {
_children?.updateComponentList();
if (callOwnUpdate) {
update(dt);
}
update(dt);
_children?.forEach((c) => c.updateTree(dt));
}

Expand Down
11 changes: 10 additions & 1 deletion packages/flame/lib/src/game/flame_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ class FlameGame extends Component with Game {
super.update(dt);
_cameraWrapper.update(dt);
if (parent == null) {
super.updateTree(dt, callOwnUpdate: false);
updateTree(dt);
}
}

@override
void updateTree(double dt) {
children.updateComponentList();
if (parent != null) {
update(dt);
}
children.forEach((c) => c.updateTree(dt));
}

/// This passes the new size along to every component in the tree via their
/// [Component.onGameResize] method, enabling each one to make their decision
/// of how to handle the resize event.
Expand Down
2 changes: 2 additions & 0 deletions packages/flame_test/lib/src/flame_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ extension FlameGameExtension on Component {
Future<void> ensureAdd(Component component) async {
await add(component);
updateTree(0);
update(0);
st-pasha marked this conversation as resolved.
Show resolved Hide resolved
spydon marked this conversation as resolved.
Show resolved Hide resolved
}

/// Makes sure that the [components] are added to the tree if you wait for the
/// returned future to resolve.
Future<void> ensureAddAll(Iterable<Component> components) async {
await addAll(components);
updateTree(0);
update(0);
spydon marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down