1 '''Simple data loader module.
3 Loads data files from the "data" directory shipped with a game.
5 Enhancing this to handle caching etc. is left as an exercise for the reader.
7 Note that pyglet users should probably just add the data directory to the
8 pyglet.resource search path.
13 data_py = os.path.abspath(os.path.dirname(__file__))
14 data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
16 def filepath(filename):
17 '''Determine the path to a file in the data directory.
19 return os.path.join(data_dir, filename)
21 def load(filename, mode='rb'):
22 '''Open a file in the data directory.
24 "mode" is passed as the second arg to open().
26 return open(os.path.join(data_dir, filename), mode)