source: branches/active/character_customization/game/parpg/objects/__init__.py @ 736

Revision 736, 1.8 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

  • renamed scripts package to parpg
  • renamed parpg module to application
  • removed packaging and other related files (kept locally for reference, will reintroduce similar scripts to resolve bug #275
  • updated all import statements to respect changes above
  • Property svn:eol-style set to native
Line 
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
18import containers
19import doors
20import actors
21import items
22import sys
23
24OBJECT_MODULES = [containers, actors, doors, items]
25
26def 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
35def 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)
Note: See TracBrowser for help on using the repository browser.