aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-06-11 16:02:06 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-06-11 16:02:06 -0700
commit57fa1f9b4affabe5486618e17eb4779bc1f7f6c7 (patch)
treecf6b2c8bb76313226b5500235a9071c457c35f43 /tools
parent4fe6e47928fa1f095a0f35a230cda4a9e9cb448b (diff)
make image and audio preloading closure-safe and accessible from outside closured code
Diffstat (limited to 'tools')
-rw-r--r--tools/file_packager.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index ebd3d37a..b4512938 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -6,7 +6,7 @@ This is called by emcc. You can also call it yourself.
Usage:
- file_packager.py TARGET [--preload A [B..]] [--embed C [D..]] [--compress COMPRESSION_DATA]
+ file_packager.py TARGET [--preload A [B..]] [--embed C [D..]] [--compress COMPRESSION_DATA] [--pre-run]
'''
@@ -26,19 +26,27 @@ in_preload = False
in_embed = False
has_preloaded = False
in_compress = 0
+pre_run = False
for arg in sys.argv[1:]:
if arg == '--preload':
in_preload = True
in_embed = False
has_preloaded = True
+ in_compress = 0
elif arg == '--embed':
in_embed = True
in_preload = False
+ in_compress = 0
elif arg == '--compress':
Compression.on = True
in_compress = 1
in_preload = False
in_embed = False
+ elif arg == '--pre-run':
+ pre_run = True
+ in_preload = False
+ in_embed = False
+ in_compress = 0
elif in_preload:
data_files.append({ 'name': arg, 'mode': 'preload' })
elif in_embed:
@@ -70,8 +78,8 @@ if has_preloaded:
}
'''
- code += 'var preloadedImages = {}; // maps url to image data\n'
- code += 'var preloadedAudios = {}; // maps url to audio data\n'
+ code += 'Module["preloadedImages"] = {}; // maps url to image data\n'
+ code += 'Module["preloadedAudios"] = {}; // maps url to audio data\n'
# Expand directories into individual files
def add(mode, dirname, names):
@@ -157,7 +165,7 @@ for file_ in data_files:
canvas.height = img.height;
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
- preloadedImages['%(filename)s'] = canvas;
+ Module["preloadedImages"]['%(filename)s'] = canvas;
URLObject.revokeObjectURL(url);
removeRunDependency();
};
@@ -176,7 +184,7 @@ for file_ in data_files:
audio.removedDependency = false;
audio['oncanplaythrough'] = function() { // XXX string for closure
audio['oncanplaythrough'] = null;
- preloadedAudios['%(filename)s'] = audio;
+ Module["preloadedAudios"]['%(filename)s'] = audio;
if (!audio.removedDependency) {
removeRunDependency();
audio.removedDependency = true;
@@ -192,7 +200,7 @@ for file_ in data_files:
setTimeout(audio.onerror, 2000); // workaround for chromium bug 124926 (still no audio with this, but at least we don't hang)
audio.src = url;
} else {
- preloadedAudios['%(filename)s'] = new Audio(); // empty shim
+ Module["preloadedAudios"]['%(filename)s'] = new Audio(); // empty shim
removeRunDependency();
}
''' % { 'filename': filename, 'mimetype': AUDIO_MIMETYPES[suffix(filename)] }
@@ -260,5 +268,11 @@ if has_preloaded:
if (Module['setStatus']) Module['setStatus']('Downloading...');
''' % (Compression.compressed_name(data_target) if Compression.on else data_target, use_data)
+if pre_run:
+ print 'Module["preRun"] = function() {'
+
print code
+if pre_run:
+ print '};'
+