summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Xu <alex_y_xu@yahoo.ca>2014-01-05 20:22:51 -0500
committerAlex Xu <alex_y_xu@yahoo.ca>2014-01-05 20:22:51 -0500
commit055870a6b2914949ee0aab4cd7eb5e802d9c551c (patch)
tree544f236917c355915e0e3e0e001062e681b88ea8
parent00faee3432b8c78ce0f4c528e602f550663390e9 (diff)
downloadhtml5ks-055870a6b2914949ee0aab4cd7eb5e802d9c551c.tar.xz
html5ks-055870a6b2914949ee0aab4cd7eb5e802d9c551c.zip
Add console.error to most .then, speed up Makefile
-rw-r--r--Makefile3
-rw-r--r--www/js/api.js26
-rw-r--r--www/js/html5ks.js7
-rw-r--r--www/js/i18n.js2
-rw-r--r--www/js/imachine.js8
-rw-r--r--www/js/menu.js4
6 files changed, 33 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 8114faf..48d796e 100644
--- a/Makefile
+++ b/Makefile
@@ -94,9 +94,10 @@ $(DUMP)/ui/ctc_anim.webp: $(CTC_ANIM_TMP_WEBP)
js: www/js/all.min.js
www/js/all.min.js: www/js/html5ks.js www/js/menu.js www/js/api.js www/js/play.js www/js/images.js www/js/characters.js www/js/imachine.js www/js/i18n.js
- $(UGLIFYJS) $^ -o $@ --source-map $@.map -p 2 -m -c
+ $(UGLIFYJS) $^ -o $@ -p 2 -m -c
clean:
$(RM) $(CVIDEO) $(CAUDIO) $(WEBP) www/favicon.ico
.PHONY: video audio images js clean
+.SUFFIXES:
diff --git a/www/js/api.js b/www/js/api.js
index 648d0f8..89ecdd3 100644
--- a/www/js/api.js
+++ b/www/js/api.js
@@ -51,12 +51,18 @@ window.html5ks.api = new (function () {
volume = html5ks.persistent.sfxVolume;
}
- ["opus", "ogg", "m4a", "wav"].some(function (type) {
- if (Modernizr.audio[type]) {
- audio.src = src + "." + type;
- return true;
+ var types = ["opus", "ogg", "m4a", "wav"];
+
+ var setNextType = function (i) {
+ for (; i < types.length; i++) {
+ if (Modernizr.audio[types[i]]) {
+ audio.src = src + "." + types[i];
+ return i;
+ }
}
- });
+ };
+
+ var i = setNextType(0);
audio.addEventListener("playing", function playing() {
audio.removeEventListener("playing", playing, false);
@@ -66,8 +72,14 @@ window.html5ks.api = new (function () {
deferred.resolve();
}, false);
audio.onerror = function (e) {
- console.error(audio.error);
- deferred.resolve();
+ if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) {
+ i = setNextType(i);
+ if (i) {
+ deferred.resolve();
+ } else {
+ throw new Error(e);
+ }
+ }
};
audio.load();
audio.volume = fade ? 0 : volume;
diff --git a/www/js/html5ks.js b/www/js/html5ks.js
index f6f226a..25b7c23 100644
--- a/www/js/html5ks.js
+++ b/www/js/html5ks.js
@@ -178,10 +178,10 @@ window.html5ks = {
delete d[k];
}
}
- });
+ }, console.error);
html5ks.api.movie_cutscene("4ls", true).then(function () {
html5ks.menu.mainMenu();
- });
+ }, console.error);
},
fetch: function (type, name) {
var deferred = when.defer();
@@ -197,6 +197,9 @@ window.html5ks = {
html5ks.data[name] = d;
deferred.resolve(d);
};
+ xhr.onerror = function () {
+ deferred.reject();
+ };
xhr.send();
}
break;
diff --git a/www/js/i18n.js b/www/js/i18n.js
index 692104d..a41a7d2 100644
--- a/www/js/i18n.js
+++ b/www/js/i18n.js
@@ -9,6 +9,6 @@ html5ks.i18n = {
e[i].textContent = uiStrings[k];
}
}
- });
+ }, console.error);
}
};
diff --git a/www/js/imachine.js b/www/js/imachine.js
index c2cc03b..ba2894e 100644
--- a/www/js/imachine.js
+++ b/www/js/imachine.js
@@ -39,17 +39,17 @@ html5ks.imachine = new (function () {
case "act_op":
switch (inst[1]) {
case "op_vid1":
- html5ks.api.movie_cutscene("op_1").then(runInst);
+ html5ks.api.movie_cutscene("op_1").then(runInst, deferred.reject);
break;
default:
- html5ks.api[cmd].apply(html5ks.api, args).then(function () { runInst(); });
+ html5ks.api[cmd].apply(html5ks.api, args).then(function () { runInst(); }, deferred.reject);
}
break;
case "imenu":
html5ks.api.iscene(args[0]).then(function (choice) {
this._return = choice;
runInst();
- }.bind(this));
+ }.bind(this), console.error);
break;
case "if":
var cpy = inst.slice(0),
@@ -88,7 +88,7 @@ html5ks.imachine = new (function () {
break el;
}
}
- return html5ks.imachine.run(next).then(runInst);
+ return html5ks.imachine.run(next).then(runInst, console.error);
case "path_end":
// TODO: disp vid + add to persistent
deferred.resolve();
diff --git a/www/js/menu.js b/www/js/menu.js
index c03523e..bf0b52c 100644
--- a/www/js/menu.js
+++ b/www/js/menu.js
@@ -172,10 +172,10 @@
var start = this.elements.main.start;
start.addEventListener("click", function () {
this.elements.mainMenu.style.display = "none";
- html5ks.imachine.start().then(this.mainMenu.bind(this));
+ html5ks.imachine.start().then(this.mainMenu.bind(this), console.error);
}.bind(this), false);
start.className = start.className.replace("disabled", "");
- }.bind(this));
+ }.bind(this), console.error);
},
_state: null,