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

Storage type lookup utility function from World #2117

Closed
alice-i-cecile opened this issue May 6, 2021 · 2 comments
Closed

Storage type lookup utility function from World #2117

alice-i-cecile opened this issue May 6, 2021 · 2 comments
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

While trying to write a new Query parameter, I need to figure out which storage type a specific component has.

I can only search over the tables field of my Storages, rather than being able to check directly.

This is frustratingly indirect and will result in subtle bugs if and when we add more storage types.

What solution would you like?

Create a lookup(ComponentId) -> StorageType method on Storages.

What alternative(s) have you considered?

I would prefer to just be able to pass in the type directly, but that's not possible :(

Additional context

Discovered during #2116.

When adding this functionality, we should check all other code accessing Storages to see if it applies to future-proof our work.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use labels May 6, 2021
@cart
Copy link
Member

cart commented May 6, 2021

This is already possible from World:

let components = world.components();
let id = components.get_id(TypeId::of::<Transform>()).unwrap();
let storage_type = components.get_info(id).unwrap().storage_type();

You can also do it from systems:

fn system(components: &Components) {
    let id = components.get_id(TypeId::of::<Transform>()).unwrap();
    let storage_type = components.get_info(id).unwrap().storage_type();
}

@alice-i-cecile
Copy link
Member Author

Aha! Thank you <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Feature A new feature, making something new possible C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

No branches or pull requests

2 participants