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

explicitly mention component in methods on DynamicSceneBuilder #15210

Merged
merged 5 commits into from
Sep 15, 2024

Conversation

atornity
Copy link
Contributor

@atornity atornity commented Sep 15, 2024

Objective

The method names on DynamicSceneBuilder are misleading. Specifically, deny_all and allow_all implies everything will be denied/allowed, including all components and resources. In reality, these methods only apply to components (which is mentioned in the docs).

Solution

  • change deny_all and allow_all to deny_all_components and allow_all_components
  • also, change the remaining methods to mention component where it makes sense

We could also add the deny_all and allow_all methods back later, only this time, they would deny/allow both resources and components.

Showcase

Before

let builder = DynamicSceneBuilder::from_world(world)
    .deny_all()
    .deny_all_resources()
    .allow::<MyComponent>();

After

let builder = DynamicSceneBuilder::from_world(world)
    .deny_all_components()
    .deny_all_resources()
    .allow_component::<MyComponent>();

Migration Guide

DynamicSceneBuilder::allow_all and deny_all now set resource accesses, not just components. To return to the previous behavior, use the new allow_all_components or deny_all_components methods.

The following methods for DynamicSceneBuilder have been renamed:

  • with_filter -> with_component_filter
  • allow -> allow_component
  • deny -> deny_component

@atornity atornity changed the title explicitly mention component in DynamicSceneBuilder methods explicitly mention component in methods on DynamicSceneBuilder Sep 15, 2024
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Scenes Serialized ECS data stored on the disk M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 15, 2024
@alice-i-cecile
Copy link
Member

We could also add the deny_all and allow_all methods back later, only this time, they would deny/allow both resources and components.

Agreed, I'd like this functionality (and allow_all_resources) later, but this rename is a much clearer first step.

@atornity
Copy link
Contributor Author

Agreed, I'd like this functionality (and allow_all_resources) later, but this rename is a much clearer first step.

we actually already have deny/allow_all_resources

Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

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

Changing deny_all and allow_all makes sense to me, but why rename deny and allow? Due to static typing, there is no potential confusion there. And in the future, I'd prefer the deny and allow methods to accept both components and resources over duplicating the API for resources. Thoughts, @alice-i-cecile?

The filter changes seem good to me, as there is no static typing keeping you from adding resources to it, but I haven't used that part of the API, so take my comment with a grain of salt.

@atornity
Copy link
Contributor Author

atornity commented Sep 15, 2024

why rename deny and allow? [..] And in the future, I'd prefer the deny and allow methods to accept both components and resources over duplicating the API for resources.

I only renamed deny and allow for consistency with the other changes + the resource counterpart, I agree that there's not real problem with keeping deny and allow as it was.

I would definitely prefer deny and allow to accept both components and resources as well.

I could change that part of the pr back if you'd like, although I still personally prefer it this way for consistency.

@atornity
Copy link
Contributor Author

does anyone know how I can run the doc test locally?

@alice-i-cecile
Copy link
Member

I would definitely prefer deny and allow to accept both components and resources as well.

I don't think this is possible in a type-safe way. You could use ComponentId, or use the Any trait to generate one, but then you can deny things that can't possibly be components or resources. We would need a trait upstream of both Component and Resource.

It would also block both components and resources of that type when both exist, which is confusing. LWIM's InputMap implements both for example.

As a result, I think it's clearer / more future-proof to be explicit about components vs resources.

Copy link
Member

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation! I'm convinced then :)

@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 15, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 15, 2024
Merged via the queue into bevyengine:main with commit 2ea8d35 Sep 15, 2024
26 checks passed
@atornity atornity deleted the scene-filter-renames branch September 15, 2024 15:04
@alice-i-cecile
Copy link
Member

Note: I've combined the migration guide from #15222 into this PR to make for easier preparation of the final notes.

github-merge-queue bot pushed a commit that referenced this pull request Sep 15, 2024
# Objective

It would be convenient to be able to quickly deny or allow all
components and resources on a `DynamicSceneBuilder` with a single method
call.

Context: #15210 renamed `{allow/deny}_all` to
`{allow/deny}_all_components`.

## Solution

Added two new methods to `DynamicSceneBuilder`, `allow_all` and
`deny_all`, which affect both the component and resource filters.


## Showcase

### Before

```rust
let builder = DynamicSceneBuilder::from_world(world)
    .deny_all_components()
    .deny_all_resources();
```

### After

```rust
let builder = DynamicSceneBuilder::from_world(world).deny_all();
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scenes Serialized ECS data stored on the disk C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants