diff options
author | Alex Xu <alex_y_xu@yahoo.ca> | 2013-06-08 13:16:31 +0000 |
---|---|---|
committer | Alex Xu <alex_y_xu@yahoo.ca> | 2013-06-08 13:16:31 +0000 |
commit | 18a8514997b9ff68cefeb1bb1ffe4eeb75d1de7c (patch) | |
tree | 240891f6cf7888e545f4cfe08770dbc47fc9a262 /js | |
parent | b08abbc6b196c055b26163c58c795bf09b2bb2c1 (diff) | |
download | html5ks-18a8514997b9ff68cefeb1bb1ffe4eeb75d1de7c.tar.xz html5ks-18a8514997b9ff68cefeb1bb1ffe4eeb75d1de7c.zip |
start on api
Diffstat (limited to 'js')
-rw-r--r-- | js/api.js | 32 | ||||
-rw-r--r-- | js/helpers.js | 6 | ||||
-rw-r--r-- | js/imachine_api.js | 4 | ||||
-rw-r--r-- | js/script_api.js | 28 |
4 files changed, 70 insertions, 0 deletions
diff --git a/js/api.js b/js/api.js new file mode 100644 index 0000000..311f162 --- /dev/null +++ b/js/api.js @@ -0,0 +1,32 @@ +"use strict"; +var save = { + seen_scenes: {}, + attraction: { + kenji: 0, + sc: 0, + hanako: 0 + }, + hdisabled: false +}; +var video = document.getElementById("video"); +function seen_scene(scene) { + return !!save.seen_scenes[scene]; +} +function scene_register(scene) { + save.seen_scenes.scene = true; +} +function play_video(vid_src) { + var deferred = when.defer(); + video.src = "/video/" + vid_src + ".webm"; + video.load(); + video.addEventListener("ended", function () { + deferred.resolve(video); + }, false); + video.addEventListener("error", function () { + deferred.reject(video.error); + }, false); +} +function act_op(this_video) { + // strip off extension + return play_video(this_video.slice(0,-4)); +} diff --git a/js/helpers.js b/js/helpers.js new file mode 100644 index 0000000..e0c5180 --- /dev/null +++ b/js/helpers.js @@ -0,0 +1,6 @@ +function STUB() { + return console.log("STUB: " + arguments.caller); +} +function WARN(msg) { + return console.log("WARN: " + arguments.caller + ": " + msg); +} diff --git a/js/imachine_api.js b/js/imachine_api.js new file mode 100644 index 0000000..672405c --- /dev/null +++ b/js/imachine_api.js @@ -0,0 +1,4 @@ +function iscene(target, is_h, is_end) { + scene_register(target); + return window.script[target](); +} diff --git a/js/script_api.js b/js/script_api.js new file mode 100644 index 0000000..afa5775 --- /dev/null +++ b/js/script_api.js @@ -0,0 +1,28 @@ +function windw(action, transition) { + var deferred = when.defer(); + setTimeout(function () { + deferred.resolve(action); + }, 100); + return deferred.promise; +} +var types = { + "ev": "event", + "evh": "event", + "ovl": "event", + "bg": "bgs", + "": "vfx" +} +// NOT iscene +function scene(type, name) { + if (typeof name == "undefined") name = type; + WARN("don't know extension, trying all"); + var bg = document.getElementById("bg"); + var img = "/" + types[type] + "/" + name; + bg.onerror = function () { + bg.onerror = function () { + bg.src = img + ".jpg"; + }; + bg.src = img + ".png"; + }; + bg.src = img + ".webp"; +} |