From: Simon Cross Date: Sat, 10 Sep 2016 12:12:20 +0000 (+0200) Subject: List levels by title. X-Git-Tag: tabakrolletjie-v1.0.0~113 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=772506e91d10df538f2dbbcb5cb0e27599672c61;p=tabakrolletjie.git List levels by title. --- diff --git a/tabakrolletjie/gamestate.py b/tabakrolletjie/gamestate.py index c678bef..f50d9f9 100644 --- a/tabakrolletjie/gamestate.py +++ b/tabakrolletjie/gamestate.py @@ -38,8 +38,8 @@ class GameState(object): def seeds(self, value): self._state['seeds'] = value - def load_station(self, station): - self._state["station"] = loader.load_station(station) + def set_station(self, station): + self._state["station"] = station def get_spawn_positions(self): return self._state["station"]["config"]["spawn positions"] diff --git a/tabakrolletjie/scenes/load_level.py b/tabakrolletjie/scenes/load_level.py index 7b34789..4cf267b 100644 --- a/tabakrolletjie/scenes/load_level.py +++ b/tabakrolletjie/scenes/load_level.py @@ -14,23 +14,20 @@ class LoadLevelScene(BaseScene): def _list_stations(self): station_path = loader.full_path("stations") - files = os.listdir(station_path) - result = [] - for f in files: - name, ext = os.path.splitext(f) - if ext == '.json': - result.append((name, f)) - result.sort() - return result + files = [f for f in os.listdir(station_path) if f.endswith(".json")] + files.sort() + return [loader.load_station(f) for f in files] def enter(self, gamestate): """Construct list of stations""" height = 50 - self._buttons = [] width = 30 - for station, filename in self._list_stations(): + self._buttons = [] + for station in self._list_stations(): + title = station["config"]["name"] pos = (width, height) - button = TextButton(station, (255, 255, 255), filename, pos) + button = TextButton(title, (255, 255, 255), None, pos) + button.station = station if width < 400: width += 350 else: @@ -46,13 +43,13 @@ class LoadLevelScene(BaseScene): def _get_pressed(self, ev): for button in self._buttons: if button.pressed(ev): - return button.name + return button return None - def _do_load(self, name, gamestate): + def _do_load(self, station, gamestate): from .day import DayScene - print "Loading station", name - gamestate.load_station(name) + print "Loading station", station["config"]["name"] + gamestate.set_station(station) SceneChangeEvent.post(scene=DayScene()) def event(self, ev, gamestate): @@ -62,4 +59,4 @@ class LoadLevelScene(BaseScene): elif ev.type == pgl.MOUSEBUTTONDOWN: pressed = self._get_pressed(ev) if pressed: - self._do_load(pressed, gamestate) + self._do_load(pressed.station, gamestate) diff --git a/tabakrolletjie/scenes/menu.py b/tabakrolletjie/scenes/menu.py index 7a4366a..9dc54c1 100644 --- a/tabakrolletjie/scenes/menu.py +++ b/tabakrolletjie/scenes/menu.py @@ -13,7 +13,7 @@ class MenuScene(BaseScene): def enter(self, gamestate): if gamestate.station is None: print "Loading Station Alpha ..." - gamestate.load_station("station-alpha.json") + gamestate.set_station(loader.load_station("station-alpha.json")) font_title = loader.load_font(FONTS['bold'], size=32) self._title = font_title.render('A Game with a title', True, (255, 255, 255))