From 85a42fa7e8ebf0ea5762e9fe32f5bd0cc50049c7 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Sat, 8 Feb 2014 10:15:22 -0500 Subject: code reduction --- www/js/api.js | 11 ++--------- www/js/imachine.js | 14 +++++++------- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'www') diff --git a/www/js/api.js b/www/js/api.js index 1c28f74..784134a 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -34,7 +34,6 @@ window.html5ks.api = new (function () { }, _loadMedia: function (el, src, types) { - var deferred = when.defer(); var i = 0; var _nextType = function () { i++; @@ -59,14 +58,11 @@ window.html5ks.api = new (function () { if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) { if (!_nextType()) { console.log("no audio formats supported"); - deferred.resolve(); } } else { console.error("unknown audio error"); - deferred.resolve(); } }; - return deferred.promise; }, play: function (channel, name, ignore, fade) { @@ -108,8 +104,7 @@ window.html5ks.api = new (function () { ['audio/ogg; codecs="vorbis"', "ogg"], ['audio/x-m4a', "m4a"], ['audio/aac', "aac"], - ['audio/wav; codecs="1"', "wav"]]).then(function () { deferred.resolve(); }); - // TODO: fix this garbage -------------------------------^ + ['audio/wav; codecs="1"', "wav"]]) return deferred.promise; }, @@ -150,8 +145,7 @@ window.html5ks.api = new (function () { ['video/webm; codecs="vp8,vorbis"', "webm"], ['video/ogg; codecs="theora,vorbis"', "ogv"], // TODO: check that this is the right codec - ['video/mp4; codecs="avc1.42E01E,mp4a.40.2"']]).then(function () { deferred.resolve(); }); - // TODO: fix this garbage + ['video/mp4; codecs="avc1.42E01E,mp4a.40.2"']]); video.style.display = "block"; video.volume = html5ks.persistent.musicVolume; var done = function () { @@ -271,7 +265,6 @@ window.html5ks.api = new (function () { // calculate position // we don't actually know how big the image is till we fetch it var pos = html5ks.api._positions[location]; - // TODO: implement transitions if (pos) { el.style.left = pos.xpos * 800 + "px"; el.style.top = pos.ypos * 600 + "px"; diff --git a/www/js/imachine.js b/www/js/imachine.js index 968df84..1795fdf 100644 --- a/www/js/imachine.js +++ b/www/js/imachine.js @@ -12,10 +12,10 @@ html5ks.imachine = new (function () { }, run: function (label) { var deferred = when.defer(), - ilabel = typeof label === "string" ? html5ks.data.imachine[label] : label, + cmds = typeof label === "string" ? html5ks.data.imachine[label] : label, i = 0, runInst = function () { - var inst = ilabel[i++]; + var inst = cmds[i++]; switch (typeof inst) { case "undefined": deferred.resolve(); @@ -29,7 +29,7 @@ html5ks.imachine = new (function () { if (newlabel === "restart") { html5ks.menu.mainMenu(); } else if (!html5ks.data.imachine[newlabel]) { - throw new Error("label does not exist"); + deferred.reject(Error("label does not exist")); } else { this.run(newlabel); } @@ -43,7 +43,7 @@ html5ks.imachine = new (function () { html5ks.api.movie_cutscene("op_1").then(runInst, deferred.reject); break; default: - html5ks.api[cmd].apply(html5ks.api, args).then(function () { runInst(); }, deferred.reject); + html5ks.api[cmd].apply(html5ks.api, args).then(runInst, deferred.reject); } break; case "imenu": @@ -91,12 +91,12 @@ html5ks.imachine = new (function () { } return html5ks.imachine.run(next).then(runInst, console.error); case "path_end": - // TODO: disp vid + add to persistent + console.error("TODO: disp vid + add to persistent, args:"); + console.log(args); deferred.resolve(); break; default: - console.error("unknown imachine inst"); - console.log(inst); + deferred.reject(Error("unknown imachine inst: " + inst)); } } }.bind(this); -- cgit v1.2.3-54-g00ecf