""" The game state. """
+from .loader import loader
+
class GameState(object):
- pass
+ def __init__(self):
+ self._state = {
+ "station": None,
+ }
+
+ @property
+ def station(self):
+ return self._state["station"]
+
+ def load_station(self, station):
+ self._state["station"] = loader.load_station(station)
--- /dev/null
+""" Utilities for loading resource files. """
+
+import json
+import os
+
+
+class Loader(object):
+ """ Load data files from beneath a prefix. """
+
+ def __init__(self, prefix):
+ self._prefix = prefix
+
+ def full_path(self, *parts):
+ path = "/".join(parts)
+ rel_path = os.path.join(*path.split("/"))
+ abs_path = os.path.join(self._prefix, rel_path)
+ print abs_path
+ return abs_path
+
+ def open_file(self, *parts):
+ return file(self.full_path(*parts), "rb")
+
+ def load_station(self, *parts):
+ with self.open_file("stations", *parts) as f:
+ return json.load(f)
+
+
+_DATA_PREFIX = os.path.abspath(
+ os.path.join(os.path.dirname(__file__), "..", "data"))
+
+loader = Loader(_DATA_PREFIX)
elif ev.key == pgl.K_n:
from .night import NightScene
SceneChangeEvent.post(scene=NightScene())
+ elif ev.key == pgl.K_l:
+ print "Loading Station Alpha ..."
+ gamestate.load_station("station-alpha.json")
class NightScene(BaseScene):
+ def enter(self, gamestate):
+ import pprint
+ pprint.pprint(gamestate.station)
+
def render(self, surface, gamestate):
surface.fill((0, 0, 255))