From d42bb52a9592f75ee59e8a354cfaf5b81437141a Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Tue, 6 May 2014 19:58:11 -0400 Subject: fix stuff and whatnot --- www/js/api.js | 38 +++++++++++++++++++++----------------- www/js/menu.js | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) (limited to 'www/js') diff --git a/www/js/api.js b/www/js/api.js index c92d3d7..e88ac91 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -56,7 +56,7 @@ window.html5ks.api = { setTimeout(function () { if (el.src && el.oncanplaythrough) { - console.warn("video not playing after 3 seconds"); + console.warn("media not playing after 3 seconds"); el.oncanplaythrough(); } }, 3000); @@ -77,8 +77,8 @@ window.html5ks.api = { }, play: function (cmd, args) { - var channel = cmd[1]; - this.stop(channel); + var channel = cmd[0]; + this.stop([channel]); var deferred = when.defer(), audio = html5ks.elements.audio[channel]; if (channel === "music" || channel === "ambient") { @@ -98,7 +98,7 @@ window.html5ks.api = { break; case "ambient": case "sound": - src += "sfx/" + html5ks.data.sfx[name]; + src += "sfx/" + html5ks.data.sfx[args.file]; volume = html5ks.persistent.sfxVolume; } @@ -121,18 +121,19 @@ window.html5ks.api = { return deferred.promise; }, - stop: function (channel, ignore, fade) { - if (channel === "all") { + stop: function (cmd, args) { + if (cmd === "all") { return ["music", "sound", "ambient"].forEach(function (channel) { - html5ks.api.stop(channel, ignore, fade); + html5ks.api.stop([channel], args); }); } + var channel = cmd[0]; var audio = html5ks.elements.audio[channel]; if (this._fading[channel]) { clearInterval(this._fading[channel]); } - if (fade) { - this.set_volume(0, fade, channel); + if (args && args.fadeout) { + this.set_volume(0, args.fadeout, channel); } else { audio.pause(); } @@ -203,8 +204,9 @@ window.html5ks.api = { return deferred.promise; }, - _safeCall: function (n, f, args) { - if (f) return f.apply(this, args); + _safeCall: function (obj, key, args) { + console.debug(key, args); + if (obj[key]) return obj[key].apply(obj, args); else { console.error("no such function " + n); debugger; @@ -216,12 +218,12 @@ window.html5ks.api = { runInst: function (inst) { console.debug(inst); var cmd = inst[0].replace(/"/g, ''); - return this._safeCall(cmd, this[cmd], inst.slice(1)); + return this._safeCall(this, cmd, inst.slice(1)); }, UserStatement: function (line, parsed) { - var c = parsed[0][0]; - return this._safeCall(c, this[c], parsed); + console.debug(parsed); + return this._safeCall(this, parsed[0][0], [parsed[0].slice(1)].concat(parsed.slice(1))); }, With: function () { @@ -230,6 +232,7 @@ window.html5ks.api = { window: function (action) { + if (action instanceof Array) action = action[0]; var windw = html5ks.elements.window; switch (action) { case true: @@ -402,11 +405,12 @@ window.html5ks.api = { chr = html5ks.data.characters[who], w = /{w=?(\d*\.\d*)?}(.*)/.exec(what); - if (!chr) { + if (chr) { + chr.what_prefix = chr.what_prefix || "“"; + chr.what_suffix = chr.what_suffix || "“"; + } else { chr = { name: who }; } - chr.what_prefix = chr.what_prefix || "“"; - chr.what_suffix = chr.what_suffix || "“"; this._lastchar = chr; diff --git a/www/js/menu.js b/www/js/menu.js index 25829e1..8539853 100644 --- a/www/js/menu.js +++ b/www/js/menu.js @@ -5,7 +5,7 @@ html5ks.menu = { this.context(false); html5ks.api.stop("all"); html5ks.api.window("hide"); - html5ks.api.play(['', "music"], {file: "music_menus", fadein: 5}); + html5ks.api.play(["music"], {file: "music_menus", fadein: 5}); html5ks.api.Show([['url', 'ui/main/bg-main.png']]); this.elements.mainMenu.style.display = "block"; html5ks.store.status = "menu"; -- cgit v1.2.3-70-g09d2