diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mamba/data.py	Sun Sep 11 10:39:08 2011 +0200
@@ -0,0 +1,28 @@
+'''Simple data loader module.
+
+Loads data files from the "data" directory shipped with a game.
+
+Enhancing this to handle caching etc. is left as an exercise for the reader.
+
+Note that pyglet users should probably just add the data directory to the
+pyglet.resource search path.
+'''
+
+import os
+
+data_py = os.path.abspath(os.path.dirname(__file__))
+data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
+
+
+def filepath(filename):
+    '''Determine the path to a file in the data directory.
+    '''
+    return os.path.join(data_dir, filename)
+
+
+def load(filename, mode='rb'):
+    '''Open a file in the data directory.
+
+    "mode" is passed as the second arg to open().
+    '''
+    return open(os.path.join(data_dir, filename), mode)