5 import pygame.locals as pgl
7 from .base import BaseScene
8 from ..events import SceneChangeEvent
9 from ..widgets import TextButton
10 from ..loader import loader
13 class LoadLevelScene(BaseScene):
15 def _list_stations(self):
16 station_path = loader.full_path("stations")
17 files = [f for f in os.listdir(station_path) if f.endswith(".json")]
19 return [loader.load_station(f) for f in files]
21 def enter(self, gamestate):
22 """Construct list of stations"""
26 for station in self._list_stations():
27 title = station["config"]["name"]
29 button = TextButton(title, (255, 255, 255), None, pos)
30 button.station = station
35 height += button.get_height() + 20
36 self._buttons.append(button)
38 def render(self, surface, gamestate):
39 surface.fill((0, 128, 128))
40 for button in self._buttons:
41 button.render(surface)
43 def _get_pressed(self, ev):
44 for button in self._buttons:
45 if button.pressed(ev):
49 def _do_load(self, station, gamestate):
50 from .day import DayScene
51 print "Loading station", station["config"]["name"]
52 gamestate.set_station(station)
53 SceneChangeEvent.post(scene=DayScene())
55 def event(self, ev, gamestate):
56 if ev.type == pgl.KEYDOWN:
58 self._do_load("station_alpha.json", gamestate)
59 elif ev.type == pgl.MOUSEBUTTONDOWN:
60 pressed = self._get_pressed(ev)
62 self._do_load(pressed.station, gamestate)