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 --- api.txt | 12 +++++++----- index.html | 10 +++++++++- js/api.js | 32 ++++++++++++++++++++++++++++++++ js/helpers.js | 6 ++++++ js/imachine_api.js | 4 ++++ js/script_api.js | 28 ++++++++++++++++++++++++++++ lighttpd.conf | 2 +- 7 files changed, 87 insertions(+), 7 deletions(-) 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 diff --git a/api.txt b/api.txt index 17d3213..eff997e 100644 --- a/api.txt +++ b/api.txt @@ -1,18 +1,20 @@ == imachine{,_replay} api == label * -> function -jump_out -> save & register & call -call -> '' +jump_out -> seen_scenes & call +call -> call seen_scene(scene) -> return label in seen_scenes int attraction_* path_end(chr, is_good) -iscene(name, is_h, is_end) -act_op(movie) -imenu(choice) +iscene(name, is_h, is_end) -> promise +✓ act_op(movie) -> promise +imenu(choice) -> promise == script api == chars: in ui_settings.rpy e.g. his(text) -> promise with(transition, action) -> promise +play(stream, name, fade) +stream: sound,music,ambient == prefs == h-scenes (tied to shrinkwrap) diff --git a/index.html b/index.html index 3bf5749..bc45b25 100644 --- a/index.html +++ b/index.html @@ -30,12 +30,20 @@ left: -190px; } } + #bg,#vid { + position: relative; + } + + + +
- + +
It doesn't take long to identify the source as Lilly's room, though the deep timbre of the female voice unmistakably belongs not to her, but to her sister.
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"; +} diff --git a/lighttpd.conf b/lighttpd.conf index a062b6a..ac7cac4 100644 --- a/lighttpd.conf +++ b/lighttpd.conf @@ -1,7 +1,7 @@ server.document-root = "/home/alex/html5ks" server.port = 8080 mimetype.assign = ( - ".html" => "text/html", + ".html" => "text/html; charset=utf-8", ".js" => "text/javascript", ".css" => "text/css", ".txt" => "text/plain", -- cgit v1.2.3-54-g00ecf