Mercurial > parpg-source
annotate entities/__init__.py @ 68:8915ff6183b0
Added equip to the usable components of the World class.
author | KarstenBock@gmx.net |
---|---|
date | Wed, 21 Sep 2011 16:48:01 +0200 |
parents | 2727d6b78978 |
children | a9cc5559ec2a |
rev | line source |
---|---|
35 | 1 # This file is part of PARPG. |
2 | |
3 # PARPG is free software: you can redistribute it and/or modify | |
4 # it under the terms of the GNU General Public License as published by | |
5 # the Free Software Foundation, either version 3 of the License, or | |
6 # (at your option) any later version. | |
7 | |
8 # PARPG is distributed in the hope that it will be useful, | |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 # GNU General Public License for more details. | |
12 | |
13 # You should have received a copy of the GNU General Public License | |
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. | |
15 | |
16 import sys | |
17 | |
61
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
18 from parpg.bGrease import Entity |
35 | 19 |
61
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
20 def createEntity(info, world, extra = None): |
35 | 21 """Called when we need to get an actual object. |
22 @type info: dict | |
23 @param info: stores information about the object we want to create | |
24 @type extra: dict | |
25 @param extra: stores additionally required attributes | |
26 @return: the object""" | |
61
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
27 # First, we try to get the world, which every game_obj needs. |
35 | 28 extra = extra or {} |
29 | |
30 # add the extra info | |
31 for key, val in extra.items(): | |
61
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
32 info[key].update(val) |
35 | 33 |
34 # this is for testing purposes | |
61
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
35 new_ent = Entity(world) |
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
36 for component, data in info.items(): |
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
37 comp_obj = getattr(new_ent, component) |
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
38 for key, value in data.items(): |
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
39 setattr(comp_obj, key, value) |
2727d6b78978
Implemented creation of dynamic entities.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
40 return new_ent |