fix GetEntitiesWuthComponent, pickup logic fixed accordingly

This commit is contained in:
2020-09-25 01:13:26 +03:00
parent 9f3eaafa3f
commit 76780d7936
2 changed files with 13 additions and 16 deletions

View File

@ -138,15 +138,20 @@ func (c *Controller) GetEntities() map[Entity]map[string]Component {
}
// GetEntitiesWithComponent returns a list of all entities with a given component attached
// TODO: Allow for passing a list of components
func (c *Controller) GetEntitiesWithComponent(componentType string) []Entity {
func (c *Controller) GetEntitiesWithComponent(componentTypes... string) []Entity {
entitiesWithComponent := make([]Entity, 0)
for entity := range c.entities {
if c.HasComponent(entity, componentType) {
mustAddThis := true
for _, componentType := range componentTypes {
if !c.HasComponent(entity, componentType) {
mustAddThis = false
break
}
}
if mustAddThis {
entitiesWithComponent = append(entitiesWithComponent, entity)
}
}
return entitiesWithComponent
}