diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/api.js | 9 | ||||
-rw-r--r-- | www/js/imachine.js | 80 |
2 files changed, 56 insertions, 33 deletions
diff --git a/www/js/api.js b/www/js/api.js index d05611e..25e2f4f 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -220,6 +220,10 @@ window.html5ks.api = { } el.style.display = "block"; } + deferred.resolve(); + }; + el.onerror = function () { + deferred.resolve(); }; var nom = name; if (type && type !== "None") { @@ -266,7 +270,6 @@ window.html5ks.api = { el.style.display = "none"; html5ks.elements.show.appendChild(el); } - deferred.resolve(); return deferred.promise; }, hide: function (name) { @@ -365,7 +368,9 @@ window.html5ks.api = { }); }; if (w[1]) { - setTimeout(html5ks.next, parseFloat(w[1], 10) * 1000); + setTimeout(function () { + html5ks.next(); + }, parseFloat(w[1], 10) * 1000); return deferred.promise; } } else { diff --git a/www/js/imachine.js b/www/js/imachine.js index 16d406f..5e21ac6 100644 --- a/www/js/imachine.js +++ b/www/js/imachine.js @@ -12,25 +12,28 @@ html5ks.imachine = (function () { }, run: function (label) { var deferred = when.defer(), - ilabel = typeof label === "string" ? html5ks.data.imachine[label] || label : label, + ilabel = typeof label === "string" ? html5ks.data.imachine[label] : label, i = 0, runInst = function () { var inst = ilabel[i++]; - console.log(inst); switch (typeof inst) { case "undefined": deferred.resolve(); break; - case "string": // jump_out - if (!html5ks.data.imachine[inst]) { - throw new Error("label does not exist"); - } - this.run(inst); - break; case "object": var cmd = inst[0]; var args = inst.slice(1); switch (inst[0]) { + case "jump_out": + var newlabel = args[0]; + if (newlabel === "restart") { + html5ks.menu.mainMenu(); + } else if (!html5ks.data.imachine[newlabel]) { + throw new Error("label does not exist"); + } else { + this.run(newlabel); + } + break; case "iscene": this.scene_register(inst[1]); case "act_op": @@ -44,34 +47,49 @@ html5ks.imachine = (function () { break; case "imenu": html5ks.api.iscene(args[0]).then(function (choice) { - var next = args[1][choice] || args[1].else; - return html5ks.imachine.run(typeof next[0] === "string" ? [next] : next).then(runInst); - }); - break; - case "seen_scene": - var next; - if (this.seen_scene(inst[1])) { - next = inst[2]; - } else { - next = inst[3]; - } - // TODO: there's probably an easier way to do this - this.run(typeof next[0] === "string" ? [next] : next).then(runInst); + this._return = choice; + runInst(); + }.bind(this)); break; - case "attraction": - if (typeof inst[2] === "number") { - if (html5ks.store.attraction[inst[1]] > inst[2]) { - runInst(inst[3]); - } else { - runInst(inst[4]); + case "if": + var cpy = inst.slice(0), + type = ''; + el: while (type = cpy.shift()) { + switch (type) { + case "if": + case "elif": + var cond = cpy.shift(), + next = cpy.shift(); + switch (cond[0]) { + case "_return": + if (this._return == cond[1]) { + break el; + } + break; + case "seen_scene": + if (this.seen_scene(cond[1])) { + break el; + } + break; + case "attraction_sc": + case "attraction_hanako": + case "attraction_kenji": + if (html5ks.store.attraction[cond[0]] > cond[1]) { + break el; + } + default: + throw new Error("unhandled if statement"); + } + break; + case "else": + next = cpy.shift(); + break el; } - } else { - html5ks.store.attraction[inst[1]]++; - runInst(); } + return html5ks.imachine.run(next).then(runInst); break; case "path_end": - // TODO: disp vid + // TODO: disp vid + add to persistent deferred.resolve(); break; default: |