Mercurial > parpg-source
diff entities/__init__.py @ 61:2727d6b78978
Implemented creation of dynamic entities.
author | KarstenBock@gmx.net |
---|---|
date | Sun, 18 Sep 2011 16:26:12 +0200 |
parents | 98f26f7636d8 |
children | a9cc5559ec2a |
line wrap: on
line diff
--- a/entities/__init__.py Sun Sep 18 16:07:07 2011 +0200 +++ b/entities/__init__.py Sun Sep 18 16:26:12 2011 +0200 @@ -14,40 +14,27 @@ # along with PARPG. If not, see <http://www.gnu.org/licenses/>. import sys -import character - -ENTITIES = [character.Character] -def getAllEntities (): - """Returns a dictionary with the names of the entity classes - mapped to the classes themselves""" - result = {} - for entity in ENTITIES: - result[entity.__name__] = entity - return result +from parpg.bGrease import Entity -def createEntity(info, extra = None): +def createEntity(info, world, extra = None): """Called when we need to get an actual object. @type info: dict @param info: stores information about the object we want to create @type extra: dict @param extra: stores additionally required attributes @return: the object""" - # First, we try to get the type and world, which every game_obj needs. + # First, we try to get the world, which every game_obj needs. extra = extra or {} - try: - ent_type = info.pop('type') - world = info.pop('world') - except KeyError: - sys.stderr.write("Error: Game object missing type or world.") - sys.exit(False) # add the extra info for key, val in extra.items(): - info[key] = val + info[key].update(val) # this is for testing purposes - try: - return getAllEntities()[ent_type](world, **info) - except KeyError: - return None + new_ent = Entity(world) + for component, data in info.items(): + comp_obj = getattr(new_ent, component) + for key, value in data.items(): + setattr(comp_obj, key, value) + return new_ent