diff options
author | Alex Xu <alex_y_xu@yahoo.ca> | 2014-04-06 13:19:51 -0400 |
---|---|---|
committer | Alex Xu <alex_y_xu@yahoo.ca> | 2014-04-06 13:19:51 -0400 |
commit | dc1c0b327a5427057e4268be74da8b2e46f0f98e (patch) | |
tree | 2a668bdac8a0c8c968c097b775c3cdb90c7cba19 /www/js | |
parent | 3332be343ea24925795b7552155a8af2cea6c8d5 (diff) | |
download | html5ks-dc1c0b327a5427057e4268be74da8b2e46f0f98e.tar.xz html5ks-dc1c0b327a5427057e4268be74da8b2e46f0f98e.zip |
reimplement imachine
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/imachine.js | 99 | ||||
-rw-r--r-- | www/js/menu.js | 23 |
2 files changed, 30 insertions, 92 deletions
diff --git a/www/js/imachine.js b/www/js/imachine.js index 2fb8922..694aea5 100644 --- a/www/js/imachine.js +++ b/www/js/imachine.js @@ -15,88 +15,33 @@ html5ks.imachine = { i = 0, runInst = function () { var inst = cmds[i++]; - switch (typeof inst) { - case "undefined": - deferred.resolve(); + switch (inst._type) { + case 'Call': + switch (inst.label) { + case "act_op": + case "iscene": + html5ks.api[inst.label].call(html5ks.api, inst['arguments'][0][0][1]).then(runInst, deferred.reject); + default: + throw new Error('unknown Call label'); + } break; - case "object": - var cmd = inst[0]; - var args = inst.slice(1); - switch (inst[0]) { + case 'UserStatement': + inst = inst.parsed; + switch (inst[0][0]) { case "jump_out": - var newlabel = args[0]; - if (newlabel === "restart") { - html5ks.menu.mainMenu(); - } else if (!html5ks.data.imachine[newlabel]) { - deferred.reject(new Error("label does not exist")); - } else { - this.run(newlabel); - } - break; - case "iscene": - this.scene_register(inst[1]); + html5ks.api.nvl("clear"); /* falls through */ - case "act_op": - switch (inst[1]) { - case "op_vid1": - html5ks.api.movie_cutscene("op_1").then(runInst, deferred.reject); - break; - default: - html5ks.api[cmd].apply(html5ks.api, args).then(runInst, deferred.reject); - } - break; - case "imenu": - html5ks.api.iscene(args[0]).then(function (choice) { - this._return = choice; - runInst(); - }.bind(this), console.error); - break; - case "if": - var cpy = inst.slice(0), - type = '', - next = null; - 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; - } - break; - default: - throw new Error("unhandled if statement"); - } - break; - case "else": - next = cpy.shift(); - break el; - } - } - return html5ks.imachine.run(next).then(runInst, console.error); - case "path_end": - console.error("TODO: disp vid + add to persistent, args:"); - console.log(args); - deferred.resolve(); - break; + case "jump_in": + return this.run(inst[1].label); default: - deferred.reject(new Error("unknown imachine inst: " + inst)); + throw new Error('not implemented'); } + case 'If': + throw new Error('not implemented'); + case 'Pass': + break; + default: + throw new Error('unknown imachine inst'); } }.bind(this); runInst(); diff --git a/www/js/menu.js b/www/js/menu.js index eb87111..93616db 100644 --- a/www/js/menu.js +++ b/www/js/menu.js @@ -168,21 +168,14 @@ html5ks.menu = { this.initEvents(); this.initOptions(); - when.all([html5ks.fetch("json", "imachine"), - html5ks.fetch("json", "script").then(function (d) { - for (var k in d) { - if (k.slice(0, 3) === (html5ks.persistent.language === "en" ? "fr_" : "en_")) { - delete d[k]; - } - } - }, console.error)]).then(function () { - var start = this.elements.main.start; - start.addEventListener("click", function () { - this.elements.mainMenu.style.display = "none"; - html5ks.imachine.start().then(this.mainMenu.bind(this), console.error); - }.bind(this), false); - start.classList.remove("disabled"); - }.bind(this), console.error); + html5ks.fetch("json", "imachine").then(function () { + var start = this.elements.main.start; + start.addEventListener("click", function () { + this.elements.mainMenu.style.display = "none"; + html5ks.imachine.start().then(this.mainMenu.bind(this), console.error); + }.bind(this), false); + start.classList.remove("disabled"); + }.bind(this), console.error); }, context: function (show) { |