From 50cd60ab9838cbed76f8a5f7c0c4aa660da8bb1c Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 18 Apr 2013 14:19:24 +0200 Subject: [PATCH] Display dialog of levels with errors at startup, rather than crashing --- erdslangetjie/__main__.py | 9 ++++++++- erdslangetjie/level.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/erdslangetjie/__main__.py b/erdslangetjie/__main__.py index ebccae8..74a0c33 100644 --- a/erdslangetjie/__main__.py +++ b/erdslangetjie/__main__.py @@ -5,6 +5,7 @@ from kivy.uix.widget import Widget from kivy.uix.relativelayout import RelativeLayout from kivy.uix.scrollview import ScrollView from kivy.uix.label import Label +from kivy.uix.popup import Popup from kivy.graphics import Color, Rectangle from kivy.utils import platform from kivy.clock import Clock @@ -305,8 +306,8 @@ class GameApp(App): title = "Peter's thread snake" def __init__(self): - self.levels = LevelList() super(GameApp, self).__init__() + self.levels = LevelList() def build(self): root = ScrollView(size_hint=(None, None)) @@ -318,6 +319,12 @@ class GameApp(App): if platform() == 'android': window.fullscreen = True self.root.size = window.size + errors = self.levels.get_errors() + if errors: + popup = Popup(title='Levels excluded', + content=Label(text='\n'.join(errors)), + size_hint=(.5, .5)) + popup.open() self.make_intro() def make_intro(self): diff --git a/erdslangetjie/level.py b/erdslangetjie/level.py index e4bc0e0..2974b88 100644 --- a/erdslangetjie/level.py +++ b/erdslangetjie/level.py @@ -236,6 +236,7 @@ class LevelList(object): def __init__(self): self.levels = [] + self.errors = [] level_list = load(self.LEVELS) for line in level_list: line = line.strip() @@ -245,12 +246,13 @@ class LevelList(object): level_file.close() try: level.validate() + self.levels.append(level) except RuntimeError as err: - raise RuntimeError( + self.errors.append( 'Invalid level %s in level_list: %s' % (line, err)) - self.levels.append(level) else: - raise RuntimeError('Level list includes non-existant level %s' % line) + self.errors.append( + 'Level list includes non-existant level %s' % line) level_list.close() self._cur_level = 0 @@ -260,6 +262,9 @@ class LevelList(object): else: return None + def get_errors(self): + return self.errors + def advance_to_next_level(self): self._cur_level += 1 return self.get_current_level() -- 2.34.1