Mercurial > rinkhals
annotate gamelib/data.py @ 80:ad9d1bc7ef0c
Kill foxes that don't reach safety
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Tue, 01 Sep 2009 11:21:43 +0000 |
parents | 498e4732bc1f |
children | c0455e6c99f4 |
rev | line source |
---|---|
2 | 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 ''' | |
42
498e4732bc1f
Auto-convert unix / http path separators to platform appropriate ones -- we should now just be able to use slash as the path separator through-out our own code.
Simon Cross <hodgestar@gmail.com>
parents:
2
diff
changeset
|
23 # convert unix path separator to platform appropriate one |
498e4732bc1f
Auto-convert unix / http path separators to platform appropriate ones -- we should now just be able to use slash as the path separator through-out our own code.
Simon Cross <hodgestar@gmail.com>
parents:
2
diff
changeset
|
24 filename = os.path.join(*filename.split("/")) |
2 | 25 return open(os.path.join(data_dir, filename), mode) |
26 |