Mercurial > mamba
comparison mamba/data.py @ 0:08941f788c15
Skellington! Inna repo!
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 10:39:08 +0200 |
parents | |
children | 66ae99f6903e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:08941f788c15 |
---|---|
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 | |
17 def filepath(filename): | |
18 '''Determine the path to a file in the data directory. | |
19 ''' | |
20 return os.path.join(data_dir, filename) | |
21 | |
22 | |
23 def load(filename, mode='rb'): | |
24 '''Open a file in the data directory. | |
25 | |
26 "mode" is passed as the second arg to open(). | |
27 ''' | |
28 return open(os.path.join(data_dir, filename), mode) |