Mercurial > parpg-source
annotate entities/__init__.py @ 44:98f26f7636d8
Changes to make PARPG "runable" with grease. (With the correct modified assets)
author | KarstenBock@gmx.net |
---|---|
date | Tue, 06 Sep 2011 15:22:51 +0200 |
parents | 895be696ae86 |
children | 2727d6b78978 |
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 import character | |
18 | |
19 ENTITIES = [character.Character] | |
20 | |
21 def getAllEntities (): | |
22 """Returns a dictionary with the names of the entity classes | |
23 mapped to the classes themselves""" | |
24 result = {} | |
25 for entity in ENTITIES: | |
26 result[entity.__name__] = entity | |
27 return result | |
28 | |
29 def createEntity(info, extra = None): | |
30 """Called when we need to get an actual object. | |
31 @type info: dict | |
32 @param info: stores information about the object we want to create | |
33 @type extra: dict | |
34 @param extra: stores additionally required attributes | |
35 @return: the object""" | |
36 # First, we try to get the type and world, which every game_obj needs. | |
37 extra = extra or {} | |
38 try: | |
39 ent_type = info.pop('type') | |
40 world = info.pop('world') | |
41 except KeyError: | |
42 sys.stderr.write("Error: Game object missing type or world.") | |
43 sys.exit(False) | |
44 | |
45 # add the extra info | |
46 for key, val in extra.items(): | |
47 info[key] = val | |
48 | |
49 # this is for testing purposes | |
44
98f26f7636d8
Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents:
35
diff
changeset
|
50 try: |
98f26f7636d8
Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents:
35
diff
changeset
|
51 return getAllEntities()[ent_type](world, **info) |
98f26f7636d8
Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents:
35
diff
changeset
|
52 except KeyError: |
98f26f7636d8
Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents:
35
diff
changeset
|
53 return None |