amethyst / specs

Specs - Parallel ECS

Home Page:https://amethyst.github.io/specs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ergonomic fetch for components from multiple storages?

Avarel opened this issue · comments

Given an entity key, is there a way to fetch components from multiple storages only if the entity has all of the components? (such that None is returned if the entity does not have all of those components).

Join provides a nice way to iterate over all entities with the components, but I'm looking for something like (&storage1, &storage2).get(entity) where None is returned if entity does not have both components associated with storage1 and storage2, and Some(&component1, &component2) otherwise. I did not see the documentation or the book covering this.

commented

There exists JoinIter::get that you can use like:

(&components1, &components2).join().get(entity, &entities)

However, the API is unsound: #647

It's not the most ergonomic, but I suppose this is fine too:

if let (Some(pos2), Some(mass2)) = (pos.get(target), mass.get(target)) {
    // code...
}