From: Neil Date: Fri, 19 Apr 2013 10:33:50 +0000 (+0200) Subject: Hook up some stuff to the settings options X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=16f38ab01c4dc966c5be8c81361380739d36e480;p=erdslangetjie.git Hook up some stuff to the settings options --- diff --git a/erdslangetjie/__main__.py b/erdslangetjie/__main__.py index 93b39f5..dd96a96 100644 --- a/erdslangetjie/__main__.py +++ b/erdslangetjie/__main__.py @@ -343,8 +343,40 @@ class GameApp(App): self.levels = LevelList() self.game = None + def build_config(self, config): + config.setdefaults('bane', { + 'start_level': 'levels/level1.txt', + 'sound': 'True' + }) + + def build_settings(self, settings): + config_json = """[ + { "type": "title", + "title": "Bane's Befuddlement" + }, + + { "type": "options", + "title": "Start Level", + "desc": "Level to start at", + "section": "bane", + "key": "start_level", + "options": ["%s"] }, + + { "type": "bool", + "title": "Sound", + "desc": "Enable sound", + "section": "bane", + "key": "sound" + } + ]""" % '", "'.join(self.levels.get_level_names()) + settings.add_json_panel("Bane's Befuddlement", + self.config, data=config_json) + def build(self): root = ScrollView(size_hint=(None, None)) + level_name = self.config.getdefault('bane', 'start_level', None) + if level_name: + self.levels.set_level_to(level_name) return root def on_start(self): diff --git a/erdslangetjie/level.py b/erdslangetjie/level.py index f430f5d..2246b1f 100644 --- a/erdslangetjie/level.py +++ b/erdslangetjie/level.py @@ -288,8 +288,9 @@ class LevelList(object): LEVELS = 'level_list' def __init__(self): - self.levels = [] - self.errors = [] + self._levels = [] + self._level_names = [] + self._errors = [] level_list = load(self.LEVELS) for line in level_list: line = line.strip() @@ -299,24 +300,32 @@ class LevelList(object): level_file.close() try: level.validate() - self.levels.append(level) + self._levels.append(level) + self._level_names.append(line) except RuntimeError as err: - self.errors.append( + self._errors.append( 'Invalid level %s in level_list: %s' % (line, err)) else: - self.errors.append( + self._errors.append( 'Level list includes non-existant level %s' % line) level_list.close() self._cur_level = 0 def get_current_level(self): - if self._cur_level < len(self.levels): - return self.levels[self._cur_level] + if self._cur_level < len(self._levels): + return self._levels[self._cur_level] else: return None def get_errors(self): - return self.errors + return self._errors + + def get_level_names(self): + return self._level_names + + def set_level_to(self, level_name): + if level_name in self._level_names: + self._cur_level = self._level_names.index(level_name) def advance_to_next_level(self): self._cur_level += 1