leudz / shipyard

Entity Component System focused on usability and flexibility.
Other
754 stars 46 forks source link

Can I get all of the components of the entity? #188

Closed PudgeKim closed 10 months ago

PudgeKim commented 10 months ago

I need to get all components of the entity to debug..! If some entity has two components.

#[derive(Component)]
struct Coordinate {
  x: i32,
  y: i32,
}

#[derive(Component)]
struct Bag {
  m: HashMap<String, String>
}

I need some api which returns "Coordinate", "Bag". Is there any function like this in shipyard? I can do it using AllStoragesView.borrow<View<Coordinate>> but I should type all of the component.

leudz commented 10 months ago

You can't iterate all components with their types, rust can't do that (or in a very arcane way).

Currently you can get basic debug information about storages, like component name, how many components they have. But there is no function to do what you want.

I can add a function that iterates over all storages, then you could check if the entity is present in the storage and print the component name or match with your components' TypeId. Would that be enough?

PudgeKim commented 10 months ago

yeah I'd be glad if it's component name~!