diff options
-rw-r--r-- | LICENSE | 4 | ||||
-rw-r--r-- | unrpyc/Makefile | 2 | ||||
-rw-r--r-- | unrpyc/decompiler.py | 19 | ||||
-rw-r--r-- | www/css/index.css | 10 | ||||
-rw-r--r-- | www/index.html | 2 | ||||
-rw-r--r-- | www/js/api.js | 9 | ||||
-rw-r--r-- | www/js/imachine.js | 80 |
7 files changed, 86 insertions, 40 deletions
@@ -1,6 +1,8 @@ -Copyright © 2013 Alex Xu (Hello71) +© 2013 Alex Xu (Hello71) All Rights Reserved I haven't decided on an open-source license; contact me [0] to discuss. +The unrpyc/ subdirectory is released under the license in unrpyc/LICENSE. + [0] mailto:alex.hello71@gmail.com diff --git a/unrpyc/Makefile b/unrpyc/Makefile index d30347f..9566bea 100644 --- a/unrpyc/Makefile +++ b/unrpyc/Makefile @@ -27,7 +27,7 @@ test: all jshint --show-non-errors *.json install: all - install -t ../www/scripts script.json script.json.gz + install -t ../www/scripts script.json script.json.gz imachine.json imachine.json.gz .PHONY: all clean test install .PRECIOUS: imachine.json.o diff --git a/unrpyc/decompiler.py b/unrpyc/decompiler.py index d25fa21..75aced6 100644 --- a/unrpyc/decompiler.py +++ b/unrpyc/decompiler.py @@ -282,6 +282,13 @@ class PrintRenPython(python_ast.NodeVisitor): self.f.write(', '.join(map(self.visit, node.keywords))) self.f.write('],\n') + def visit_Compare(self, node): + self.f.write('[') + self.f.write(self.visit(node.left)) + self.f.write(', ') + self.f.write(self.visit(node.comparators[0])) + self.f.write('], ') + def quote(self, string): return '"%s"' % string @@ -395,7 +402,10 @@ def print_Call(f, stmt, indent_level): f.write('],\n') def print_If(f, stmt, indent_level): - f.write('["if", "%s", [\n' % (escape_string(stmt.entries[0][0]), )) + f.write('["if", ') + if_stmt = compile(stmt.entries[0][0], '<unknown>', 'exec', python_ast.PyCF_ONLY_AST).body[0] + PrintRenPython(f).visit(if_stmt) + f.write('[\n') for inner_stmt in stmt.entries[0][1]: print_statement(f, inner_stmt, indent_level + 1) @@ -409,7 +419,10 @@ def print_If(f, stmt, indent_level): for case in elif_entries: indent(f, indent_level) - f.write('], "elif", "%s", [\n' % escape_string(case[0])) + f.write('], "elif", ') + elif_stmt = compile(case[0], '<unknown>', 'exec', python_ast.PyCF_ONLY_AST).body[0] + PrintRenPython(f).visit(if_stmt) + f.write('[\n') for inner_stmt in case[1]: print_statement(f, inner_stmt, indent_level + 1) @@ -433,7 +446,7 @@ def print_args(f, arginfo): f.write(', ') # if name is not None: # f.write("%s = " % json.dumps(name)) - f.write(json.dumps(val)) + f.write(json.dumps(eval(val))) # TODO positional? def print_params(f, paraminfo): diff --git a/www/css/index.css b/www/css/index.css index 8b59a6b..775bfc6 100644 --- a/www/css/index.css +++ b/www/css/index.css @@ -159,11 +159,15 @@ html.no-js #gotit { } #centered { text-align: center; - width: 100%; + top: 0; + bottom: 0; + left: 0; + height: 0; } .centered { position: absolute; margin: auto; + width: 100%; left: 50%; top: 50%; } @@ -173,7 +177,11 @@ html.no-js #gotit { right: 10px; display: none; } +#choices { + left: 0; +} .choice { + text-align: center; background: url("../dump/ui/bg-choice.png") no-repeat top center; height: 35px; line-height: 30px; diff --git a/www/index.html b/www/index.html index 595bcbb..4c4f7fb 100644 --- a/www/index.html +++ b/www/index.html @@ -53,7 +53,7 @@ <img id="nvlctc" src="dump/ui/ctc_rotated.png"> </div> <div id="choices" class="centered"></div> - <div id="centered" class="say"></div> + <div id="centered" class="centered say"></div> <img class="status" id="auto" src="dump/ui/sd-auto.png"> <img class="status" id="skip" src="dump/ui/sd-skip.png"> <div id="main-menu" style="display: none;"> 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: |