def __setattr__(self, name, value):
"""Sets the component data related to the Entity."""
if name in ("_id", "_world"):
object.__setattr__(self, name, value)
else:
# If the value is a compound component (e.g. a Button
# inheriting from a Sprite), it needs to be added to all
# supported component type instances.
mro = inspect.getmro(value.__class__)
if type in mro:
stop = mro.index(type)
else:
stop = mro.index(object)
mro = mro[0:stop]
wctypes = self._world.componenttypes
for clstype in mro:
if clstype not in wctypes:
self._world.add_componenttype(clstype)
self._world.components[clstype][self] = value
评论列表
文章目录