Changeset 209:ad1d3de210cd


Ignore:
Timestamp:
Sep 3, 2013, 9:45:56 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
rebase_source:
f1360a9f17513461c73dc5956d46723e00073e5c
Message:

Drop compatibility imports, and allow an optional module on classnames

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • data/levels/level1

    r197 r209  
    2828  name: light2
    2929- args: [light_switch, door_switch]
    30   classname: StateLogicalAndPuzzler
     30  classname: puzzle.StateLogicalAndPuzzler
    3131  name: both_switches
    3232- args:
  • data/levels/level2

    r178 r209  
    77  - [600, 700]
    88  classname: Door
     9lines: []
    910polygons:
    1011  1:
  • nagslang/game_object.py

    r208 r209  
    1010from nagslang.events import DoorEvent
    1111from nagslang.widgets.text import LabelWidget
    12 
    13 
    14 # For levels to import, until we get module names in 'classname'
    15 StateProxyPuzzler = puzzle.StateProxyPuzzler
    16 StateLogicalAndPuzzler = puzzle.StateLogicalAndPuzzler
    17 CollidePuzzler = puzzle.CollidePuzzler
    1812
    1913
  • nagslang/level.py

    r201 r209  
    7373
    7474    def _create_game_object(self, space, classname, args, name=None):
    75         # We should probably build a registry of game objects or something.
    76         # At least this is better than just calling `eval`, right?
    77         cls = getattr(go, classname)
     75        modules = {
     76            'game_object': go,
     77            'puzzle': puzzle,
     78        }
     79        if '.' in classname:
     80            module, classname = classname.split('.')
     81        else:
     82            module = 'game_object'
     83        cls = getattr(modules[module], classname)
     84
    7885        if issubclass(cls, puzzle.Puzzler):
    7986            gobj = cls(*args)
  • nagslang/tests/test_level.py

    r202 r209  
    44
    55from nagslang import game_object as go
     6from nagslang import puzzle
    67from nagslang.level import Level
    78from nagslang.yamlish import load
     
    7778                             sorted(puzzle_bits.keys()))
    7879            self.assertTrue(
    79                 isinstance(puzzle_bits['foo_proxy'], go.StateProxyPuzzler))
     80                isinstance(puzzle_bits['foo_proxy'], puzzle.StateProxyPuzzler))
    8081            self.assertEqual('foo', puzzle_bits['foo_proxy']._state_source)
    81             self.assertTrue(isinstance(puzzle_bits['foo'], go.CollidePuzzler))
     82            self.assertTrue(isinstance(puzzle_bits['foo'],
     83                                       puzzle.CollidePuzzler))
    8284
    8385        level = self.make_level('foo', {
     
    9799                {
    98100                    'name': 'foo_proxy',
    99                     'classname': 'StateProxyPuzzler',
     101                    'classname': 'puzzle.StateProxyPuzzler',
    100102                    'args': ['foo'],
    101103                },
Note: See TracChangeset for help on using the changeset viewer.