Package scripts :: Package objects
[hide private]
[frames] | no frames]

Source Code for Package scripts.objects

 1  #!/usr/bin/env python 
 2   
 3  #   This file is part of PARPG. 
 4   
 5  #   PARPG is free software: you can redistribute it and/or modify 
 6  #   it under the terms of the GNU General Public License as published by 
 7  #   the Free Software Foundation, either version 3 of the License, or 
 8  #   (at your option) any later version. 
 9   
10  #   PARPG is distributed in the hope that it will be useful, 
11  #   but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13  #   GNU General Public License for more details. 
14   
15  #   You should have received a copy of the GNU General Public License 
16  #   along with PARPG.  If not, see <http://www.gnu.org/licenses/>. 
17   
18  import containers 
19  import doors 
20  import actors 
21  import items 
22  import sys 
23   
24  OBJECT_MODULES = [containers, actors, doors, items] 
25   
26 -def getAllObjects ():
27 """Returns a dictionary with the names of the concrete game object classes 28 mapped to the classes themselves""" 29 result = {} 30 for module in OBJECT_MODULES: 31 for class_name in module.__all__: 32 result[class_name] = getattr (module, class_name) 33 return result
34
35 -def createObject(info, extra = None):
36 """Called when we need to get an actual object. 37 @type info: dict 38 @param info: stores information about the object we want to create 39 @type extra: dict 40 @param extra: stores additionally required attributes 41 @return: the object""" 42 # First, we try to get the type and ID, which every game_obj needs. 43 extra = extra or {} 44 try: 45 obj_type = info.pop('type') 46 ID = info.pop('id') 47 except KeyError: 48 sys.stderr.write("Error: Game object missing type or id.") 49 sys.exit(False) 50 51 # add the extra info 52 for key, val in extra.items(): 53 info[key] = val 54 55 # this is for testing purposes 56 return getAllObjects()[obj_type](ID, **info)
57