def __init__(self, **fields): self.fields = {} for fname, ftype in list(fields.items()): assert ftype in field.types, fname + " has an illegal field type" self.fields[fname] = field.Field(self, fname, ftype) self.entities = ComponentEntitySet(self) self._added = [] self._deleted = []
def __getattr__(self, name): """Return a queriable :class:`ComponentEntitySet` for the named component Example:: world[MyEntity].movement.velocity > (0, 0) Returns a set of entities where the value of the :attr:`velocity` field of the :attr:`movement` component is greater than ``(0, 0)``. """ component = getattr(self.__world.components, name) return ComponentEntitySet(component, self.entities & component.entities)