summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
authorAlex Xu <alex_y_xu@yahoo.ca>2014-02-11 15:24:22 -0500
committerAlex Xu <alex_y_xu@yahoo.ca>2014-02-11 15:24:22 -0500
commitf7bcc14a493f3714c8a06df5111de8c2a901de61 (patch)
treee4267db51eeaa6c455f7ebb27e1c0ce1fa199692 /www/js
parent7afd49eed799fddccc6339130f1980832b833c62 (diff)
downloadhtml5ks-f7bcc14a493f3714c8a06df5111de8c2a901de61.tar.xz
html5ks-f7bcc14a493f3714c8a06df5111de8c2a901de61.zip
misc stuff
Diffstat (limited to 'www/js')
-rw-r--r--www/js/api.js7
-rw-r--r--www/js/imachine.js208
2 files changed, 106 insertions, 109 deletions
diff --git a/www/js/api.js b/www/js/api.js
index 2f204b9..3c3864c 100644
--- a/www/js/api.js
+++ b/www/js/api.js
@@ -1,5 +1,4 @@
-window.html5ks.api = new (function () {
- "use strict"; return {
+window.html5ks.api = {
init: function () {
var chrs = html5ks.data.characters;
for (var ch in chrs) {
@@ -105,7 +104,7 @@ window.html5ks.api = new (function () {
['audio/ogg; codecs="vorbis"', "ogg"],
['audio/x-m4a', "m4a"],
['audio/aac', "aac"],
- ['audio/wav; codecs="1"', "wav"]])
+ ['audio/wav; codecs="1"', "wav"]]);
return deferred.promise;
},
@@ -589,4 +588,4 @@ window.html5ks.api = new (function () {
document.getElementById("skip").style.display = "none";
}
}
-};})();
+};
diff --git a/www/js/imachine.js b/www/js/imachine.js
index 1795fdf..2fb8922 100644
--- a/www/js/imachine.js
+++ b/www/js/imachine.js
@@ -1,107 +1,105 @@
-html5ks.imachine = new (function () {
- "use strict";
- return {
- seen_scene: function (scene) {
- return !!html5ks.store.seen_scenes[scene];
- },
- scene_register: function (scene) {
- html5ks.store.seen_scenes[scene] = true;
- },
- start: function () {
- return this.run("imachine");
- },
- run: function (label) {
- var deferred = when.defer(),
- cmds = typeof label === "string" ? html5ks.data.imachine[label] : label,
- i = 0,
- runInst = function () {
- var inst = cmds[i++];
- switch (typeof inst) {
- case "undefined":
- deferred.resolve();
- 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]) {
- deferred.reject(Error("label does not exist"));
- } else {
- this.run(newlabel);
- }
- break;
- case "iscene":
- this.scene_register(inst[1]);
- /* falls through */
- case "act_op":
- switch (inst[1]) {
- case "op_vid1":
- html5ks.api.movie_cutscene("op_1").then(runInst, deferred.reject);
+"use strict";
+html5ks.imachine = {
+ seen_scene: function (scene) {
+ return !!html5ks.store.seen_scenes[scene];
+ },
+ scene_register: function (scene) {
+ html5ks.store.seen_scenes[scene] = true;
+ },
+ start: function () {
+ return this.run("imachine");
+ },
+ run: function (label) {
+ var deferred = when.defer(),
+ cmds = typeof label === "string" ? html5ks.data.imachine[label] : label,
+ i = 0,
+ runInst = function () {
+ var inst = cmds[i++];
+ switch (typeof inst) {
+ case "undefined":
+ deferred.resolve();
+ 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]) {
+ deferred.reject(new Error("label does not exist"));
+ } else {
+ this.run(newlabel);
+ }
+ break;
+ case "iscene":
+ this.scene_register(inst[1]);
+ /* 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;
- 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;
- }
+ 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;
- default:
- deferred.reject(Error("unknown imachine inst: " + inst));
- }
- }
- }.bind(this);
- runInst();
- return deferred.promise;
- }
- };
-})();
+ }
+ 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;
+ default:
+ deferred.reject(new Error("unknown imachine inst: " + inst));
+ }
+ }
+ }.bind(this);
+ runInst();
+ return deferred.promise;
+ }
+};