summaryrefslogtreecommitdiff
path: root/www/js/imachine.js
blob: 37ce701083e28336210dd6db6900b96ff552aee0 (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
"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 (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);
                  break;
                default:
                  throw new Error('unknown Call label: ' + inst.label);
              }
              break;
            case 'UserStatement':
              inst = inst.parsed;
              switch (inst[0][0]) {
                case "jump_out":
                  html5ks.api.nvl("clear");
                  /* falls through */
                case "jump_in":
                  return this.run(inst[1].label);
                default:
                  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();
    return deferred.promise;
  }
};