source: nagslang/data.py@ 0:1ea8fa09b70f

Last change on this file since 0:1ea8fa09b70f was 0:1ea8fa09b70f, checked in by Neil Muller <drnlmuller@…>, 8 years ago

Add skellington

File size: 737 bytes
Line 
1'''Simple data loader module.
2
3Loads data files from the "data" directory shipped with a game.
4
5Enhancing this to handle caching etc. is left as an exercise for the reader.
6
7Note that pyglet users should probably just add the data directory to the
8pyglet.resource search path.
9'''
10
11import os
12
13data_py = os.path.abspath(os.path.dirname(__file__))
14data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
15
16def filepath(filename):
17 '''Determine the path to a file in the data directory.
18 '''
19 return os.path.join(data_dir, filename)
20
21def 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
Note: See TracBrowser for help on using the repository browser.