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"]
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:
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):
elif ev.type == pgl.MOUSEBUTTONDOWN:
pressed = self._get_pressed(ev)
if pressed:
- self._do_load(pressed, gamestate)
+ self._do_load(pressed.station, gamestate)
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))