annotate gamelib/data.py @ 546:ad4d6ffd25d7

update tags
author convert-repo
date Sat, 21 Jun 2014 17:38:39 +0000
parents fe51223e0c8d
children
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
530
fe51223e0c8d PEP8 cleanup data.py and endscreen.py
Neil Muller <neil@dip.sun.ac.za>
parents: 15
diff changeset
13
0
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
14 def filepath(filename):
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
15 '''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
16 '''
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
17 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
18
530
fe51223e0c8d PEP8 cleanup data.py and endscreen.py
Neil Muller <neil@dip.sun.ac.za>
parents: 15
diff changeset
19
0
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
20 def load(filename, mode='rb'):
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
21 '''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
22
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
23 "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
24 '''
f2c3b516741b Theme is 'Caught'. Start with Skellington 1.9.
Simon Cross <hodgestar+bzr@gmail.com>
parents:
diff changeset
25 return open(os.path.join(data_dir, filename), mode)