From: Neil Date: Thu, 18 Apr 2013 12:13:08 +0000 (+0200) Subject: Move game validation to level_list X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=3bc9b0f02fe5766addeb4d45162866ff628fb2ab;p=erdslangetjie.git Move game validation to level_list --- diff --git a/erdslangetjie/__main__.py b/erdslangetjie/__main__.py index 5cd9b7f..71ef53b 100644 --- a/erdslangetjie/__main__.py +++ b/erdslangetjie/__main__.py @@ -25,7 +25,6 @@ class GameWindow(RelativeLayout): def __init__(self, level_list, app): self.level_list = level_list self.level_obj = self.level_list.get_current_level() - self.level_obj.validate() self.level_obj.load_tiles() self.tiles = {} self.view = app.root @@ -207,7 +206,6 @@ class GameWindow(RelativeLayout): self.remove_widget(self.nemesis_tile) self.nemesis.reset_pos() if self.level_obj: - self.level_obj.validate() self.level_obj.load_tiles() self.player.pos = self.level_obj.enter_pos self.remove_widget(self.player_tile) diff --git a/erdslangetjie/level.py b/erdslangetjie/level.py index b5dbe13..e4bc0e0 100644 --- a/erdslangetjie/level.py +++ b/erdslangetjie/level.py @@ -241,8 +241,14 @@ class LevelList(object): line = line.strip() if os.path.exists(filepath(line)): level_file = load(line) - self.levels.append(Level(level_file)) + level = Level(level_file) level_file.close() + try: + level.validate() + except RuntimeError as err: + raise RuntimeError( + 'Invalid level %s in level_list: %s' % (line, err)) + self.levels.append(level) else: raise RuntimeError('Level list includes non-existant level %s' % line) level_list.close()