annotate gamelib/data.py @ 494:7ae663c687ed

Hook computer control panel to engine room computer. Tweak sign above door
author Stefano Rivera <stefano@rivera.za.net>
date Sun, 29 Aug 2010 20:04:05 +0200
parents 05f4e9e09764
children fe51223e0c8d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
1 '''Simple data loader module.
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
2
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
3 Loads data files from the "data" directory shipped with a game.
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
4
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
5 Enhancing this to handle caching etc. is left as an exercise for the reader.
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
6 '''
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
7
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
8 import os
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
9
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
10 data_py = os.path.abspath(os.path.dirname(__file__))
15
05f4e9e09764 rename in data.py as well
Neil Muller <neil@dip.sun.ac.za>
parents: 0
diff changeset
11 data_dir = os.path.normpath(os.path.join(data_py, '..', 'Resources'))
0
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
12
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
13 def filepath(filename):
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
14 '''Determine the path to a file in the data directory.
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
15 '''
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
16 return os.path.join(data_dir, filename)
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
17
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
18 def load(filename, mode='rb'):
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
19 '''Open a file in the data directory.
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
20
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
21 "mode" is passed as the second arg to open().
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
22 '''
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
23 return open(os.path.join(data_dir, filename), mode)
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
24