summaryrefslogtreecommitdiff
path: root/www/js/imachine.js
blob: fd657efbd060d06a3f7e566465e5c1509186140f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
html5ks.imachine = (function () {
  "use strict";
  return {
    start: function () {
      return this.run("imachine");
    },
    run: function (label) {
      var deferred = when.defer(),
          ilabel = html5ks.data.imachine[label],
          i = 0,
          runInst = function () {
            var inst = ilabel[i++];
            console.log(inst);
            switch (typeof inst) {
              case "undefined":
                break;
              case "string": // jump_out
                this.run(inst);
                break;
              case "object":
                switch (inst[0]) {
                  case "iscene":
                  case "act_op":
                    switch (inst[1]) {
                      case "op_vid1":
                        html5ks.api.movie_cutscene("op_1").then(runInst);
                        break;
                      default:
                        html5ks.api[inst[0]](inst[1]).then(runInst);
                    }
                    break;
                  case "seen_scene":
                    if (this.seen_scene(inst[1])) {
                      runInst(inst[2]);
                    } else {
                      runInst(inst[3]);
                    }
                    break;
                  case "attraction_sc":
                  case "attraction_hanako":
                  case "attraction_kenji":
                    if (typeof inst[1] === "number") {
                      if (html5ks.persistent.store[inst[0]] > inst[1]) {
                        runInst(inst[3]);
                      } else {
                        runInst(inst[4]);
                      }
                    } else {
                      html5ks.persistent.store[inst[0]]++;
                    }
                    break;
                  case "path_end":
                    // TODO: disp vid
                    deferred.resolve();
                    break;
                  default:
                    console.error("unknown imachine inst");
                    console.error(inst);
                }
            }
          }.bind(this);
      runInst();
      return deferred.promise;
    }
  };
}());