comparison src/parpg/objects/__init__.py @ 0:1fd2201f5c36

Initial commit of parpg-core.
author M. George Hansen <technopolitica@gmail.com>
date Sat, 14 May 2011 01:12:35 -0700
parents
children ccf4d6cffcf1
comparison
equal deleted inserted replaced
-1:000000000000 0:1fd2201f5c36
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 containers
17 import doors
18 import actors
19 import items
20 import sys
21
22 OBJECT_MODULES = [containers, actors, doors, items]
23
24 def getAllObjects ():
25 """Returns a dictionary with the names of the concrete game object classes
26 mapped to the classes themselves"""
27 result = {}
28 for module in OBJECT_MODULES:
29 for class_name in module.__all__:
30 result[class_name] = getattr (module, class_name)
31 return result
32
33 def createObject(info, extra = None):
34 """Called when we need to get an actual object.
35 @type info: dict
36 @param info: stores information about the object we want to create
37 @type extra: dict
38 @param extra: stores additionally required attributes
39 @return: the object"""
40 # First, we try to get the type and ID, which every game_obj needs.
41 extra = extra or {}
42 try:
43 obj_type = info.pop('type')
44 ID = info.pop('id')
45 except KeyError:
46 sys.stderr.write("Error: Game object missing type or id.")
47 sys.exit(False)
48
49 # add the extra info
50 for key, val in extra.items():
51 info[key] = val
52
53 # this is for testing purposes
54 return getAllObjects()[obj_type](ID, **info)