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

feat: Allow for bodyDef and fixtureDefs to be prepared earlier #2768

Merged
merged 4 commits into from
Oct 2, 2023

Conversation

l1553k
Copy link
Contributor

@l1553k l1553k commented Sep 24, 2023

Description

This change introduces a way to create BodyDef and FixtureDefs as early as in constructor - or even earlier. This allows to pass position and other body/fixture related parameters to constructor, and not have them stick around as this.initialThis or this.initialThat.

For example:

class OffroadWheel extends BodyComponent {
  OffroadWheel(
    Vector2 initialPosition,
    double radius,
  ) : super(
    bodyDef: BodyDef(position: initialPosition), type: BodyType.dynamic),
    fixtureDef: FixtureDef(CircleShape()..radius = radius),
  );
}

I added fixtureDef constructor argument for convenience.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • No, this PR is not a breaking change.

Related Issues

@l1553k
Copy link
Contributor Author

l1553k commented Sep 24, 2023

@spydon we spoke about this on discord recently. Please provide some initial feedback; if you think this is going in the right direction then I will work on making it merge worthy.

Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the analyze warnings and the comment I made I think it looks good!

@@ -21,14 +21,27 @@ abstract class BodyComponent<T extends Forge2DGame> extends Component
super.children,
super.priority,
this.renderBody = true,
this.bodyDef,
FixtureDef? fixtureDef,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can skip this one and only have the list of fixture definitions

@l1553k l1553k changed the title WIP: feat: Allow for bodyDef and fixtureDefs to be prepared earlier feat: Allow for bodyDef and fixtureDefs to be prepared earlier Sep 24, 2023
@spydon
Copy link
Member

spydon commented Sep 24, 2023

Just these small things left and I think we're ready to merge:

  • Added docs in the flame_forge2d section
  • A line about the new arguments in the BodyComponent dartdocs
  • Some basic test

@l1553k
Copy link
Contributor Author

l1553k commented Sep 25, 2023

  • A line about the new arguments in the BodyComponent dartdocs

I'm sorry for my noob question, but what do you mean?

@spydon
Copy link
Member

spydon commented Sep 25, 2023

  • A line about the new arguments in the BodyComponent dartdocs

I'm sorry for my noob question, but what do you mean?

The dartdocs are the ones that start with /// above the class, so if you could just add two lines saying something like:

/// You can use the optional [bodyDef] and [fixtureDefs] arguments to create the [BodyComponent]'s body without having to create the definitions within the component.

doc/bridge_packages/flame_forge2d/forge2d.md Outdated Show resolved Hide resolved
packages/flame_forge2d/lib/body_component.dart Outdated Show resolved Hide resolved
packages/flame_forge2d/lib/body_component.dart Outdated Show resolved Hide resolved
packages/flame_forge2d/lib/body_component.dart Outdated Show resolved Hide resolved
packages/flame_forge2d/lib/body_component.dart Outdated Show resolved Hide resolved
@spydon spydon enabled auto-merge (squash) October 2, 2023 09:39
Copy link
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix line length
EDIT: Accidentally made a comment instead of a push through the web IDE.

@spydon spydon merged commit 21357bc into flame-engine:main Oct 2, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants