Mercurial > nagslang
diff nagslang/level.py @ 209:ad1d3de210cd
Drop compatibility imports, and allow an optional module on classnames
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Tue, 03 Sep 2013 23:45:56 +0200 |
parents | 3495a2025bc6 |
children | 988cf7c8b402 |
line wrap: on
line diff
--- a/nagslang/level.py Tue Sep 03 23:42:51 2013 +0200 +++ b/nagslang/level.py Tue Sep 03 23:45:56 2013 +0200 @@ -72,9 +72,16 @@ self._create_enemy(space, **enemy_dict) def _create_game_object(self, space, classname, args, name=None): - # We should probably build a registry of game objects or something. - # At least this is better than just calling `eval`, right? - cls = getattr(go, classname) + modules = { + 'game_object': go, + 'puzzle': puzzle, + } + if '.' in classname: + module, classname = classname.split('.') + else: + module = 'game_object' + cls = getattr(modules[module], classname) + if issubclass(cls, puzzle.Puzzler): gobj = cls(*args) elif issubclass(cls, go.GameObject):