comparison gamelib/data.py @ 0:d0de8832774b

Import skellington-1.9 into the repo
author Neil Muller <drnlmuller+bitbucket@gmail.com>
date Sat, 05 May 2012 13:52:29 +0200
parents
children c90a6586cd66
comparison
equal deleted inserted replaced
-1:000000000000 0:d0de8832774b
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
8 import os
9
10 data_py = os.path.abspath(os.path.dirname(__file__))
11 data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
12
13 def filepath(filename):
14 '''Determine the path to a file in the data directory.
15 '''
16 return os.path.join(data_dir, filename)
17
18 def load(filename, mode='rb'):
19 '''Open a file in the data directory.
20
21 "mode" is passed as the second arg to open().
22 '''
23 return open(os.path.join(data_dir, filename), mode)
24