source: trunk/game/scripts/objects/__init__.py @ 310

Revision 310, 1.9 KB checked in by eliedebrauwer, 10 years ago (diff)

Ticket #66: Patch by saritor (& eliedebrauwer), implements saritors rework of teleporting, at this point it implements the within-a-map teleport successfully, but cross map teleport still has in issue which probably has to do with the setup of the PC. comment[s:trac, t:66]

  • Property svn:eol-style set to native
Line 
1#!/usr/bin/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/>.
17import containers, doors
18import actors
19import sys
20
21object_modules = [containers, actors, doors]
22
23def getAllObjects ():
24    """Returns a dictionary with the names of the concrete game object classes
25    mapped to the classes themselves"""
26    result = {}
27    for module in object_modules:
28        for class_name in module.__all__:
29            result[class_name] = getattr (module,class_name)
30           
31    return result
32
33def createObject(info, extra = {}):
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, like agent layer, engine etc.
39           @return: the object"""
40        # First, we try to get the type and ID, which every game_obj needs.
41        try:
42            obj_type = info.pop('type')
43            ID = info.pop('id')
44        except KeyError:
45            sys.stderr.write("Error: Game object missing type or id.")
46            sys.exit(False)
47       
48        # add the extra info
49        for key, val in extra.items():
50            info[key] = val
51
52        # this is for testing purposes
53        return getAllObjects()[obj_type](ID, **info)
Note: See TracBrowser for help on using the repository browser.