annotate entities/__init__.py @ 53:7b9f6e3513d4

Added code that checks if the object is the player so certain actions (talk, attack) will not appear in the menu.
author KarstenBock@gmx.net
date Thu, 08 Sep 2011 18:36:40 +0200
parents 98f26f7636d8
children 2727d6b78978
rev   line source
35
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
1 # This file is part of PARPG.
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
2
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
3 # PARPG is free software: you can redistribute it and/or modify
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
4 # it under the terms of the GNU General Public License as published by
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
6 # (at your option) any later version.
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
7
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
8 # PARPG is distributed in the hope that it will be useful,
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
11 # GNU General Public License for more details.
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
12
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
13 # You should have received a copy of the GNU General Public License
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>.
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
15
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
16 import sys
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
17 import character
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
18
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
19 ENTITIES = [character.Character]
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
20
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
21 def getAllEntities ():
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
22 """Returns a dictionary with the names of the entity classes
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
23 mapped to the classes themselves"""
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
24 result = {}
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
25 for entity in ENTITIES:
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
26 result[entity.__name__] = entity
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
27 return result
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
28
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
29 def createEntity(info, extra = None):
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
30 """Called when we need to get an actual object.
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
31 @type info: dict
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
32 @param info: stores information about the object we want to create
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
33 @type extra: dict
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
34 @param extra: stores additionally required attributes
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
35 @return: the object"""
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
36 # First, we try to get the type and world, which every game_obj needs.
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
37 extra = extra or {}
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
38 try:
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
39 ent_type = info.pop('type')
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
40 world = info.pop('world')
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
41 except KeyError:
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
42 sys.stderr.write("Error: Game object missing type or world.")
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
43 sys.exit(False)
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
44
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
45 # add the extra info
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
46 for key, val in extra.items():
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
47 info[key] = val
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
48
895be696ae86 Added functions to create entities.
KarstenBock@gmx.net
parents: 12
diff changeset
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