From 18a8514997b9ff68cefeb1bb1ffe4eeb75d1de7c Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Sat, 8 Jun 2013 13:16:31 +0000 Subject: start on api --- js/api.js | 32 ++++++++++++++++++++++++++++++++ js/helpers.js | 6 ++++++ js/imachine_api.js | 4 ++++ js/script_api.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 js/api.js create mode 100644 js/helpers.js create mode 100644 js/imachine_api.js create mode 100644 js/script_api.js (limited to 'js') 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"; +} -- cgit v1.2.3-70-g09d2