More layout setup tweaking
[erdslangetjie.git] / erdslangetjie / data.py
1 '''Simple data loader module.
2
3 Loads data files from the "data" directory shipped with a game.
4
5 Enhancing this to handle caching etc. is left as an exercise for the reader.
6
7 Note that pyglet users should probably just add the data directory to the
8 pyglet.resource search path.
9 '''
10
11 import os
12
13 data_py = os.path.abspath(os.path.dirname(__file__))
14 data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
15
16 def filepath(filename):
17     '''Determine the path to a file in the data directory.
18     '''
19     return os.path.join(data_dir, filename)
20
21 def load(filename, mode='rb'):
22     '''Open a file in the data directory.
23
24     "mode" is passed as the second arg to open().
25     '''
26     return open(os.path.join(data_dir, filename), mode)
27