From 828588ccb0e7f203c53b1abad1d70f77d3185a81 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Mon, 1 Jul 2013 10:26:53 -0400 Subject: add nvl --- www/js/api.js | 106 +++++++++++++++++++++++++++++++++++++----------------- www/js/html5ks.js | 5 ++- 2 files changed, 78 insertions(+), 33 deletions(-) (limited to 'www/js') diff --git a/www/js/api.js b/www/js/api.js index 1aec74d..34a34d9 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -225,7 +225,8 @@ window.html5ks.api = { /{\/color}/g, "", /{w(=\d*\.\d*)?}.*/, "", /{nw}/, "", - /{fast}/, "" + /{fast}/, "", + /\n/g, "
" ]; for (var i = 0; i < tags.length - 1; i += 2) { str = str.replace(tags[i], tags[i+1]); @@ -233,6 +234,19 @@ window.html5ks.api = { return str; }, + nvlsay: function (text) { + var deferred = when.defer(); + html5ks.elements.nvlsay.innerHTML += text + "
"; + html5ks.elements.nvlctc.style.display = "block"; + html5ks.next = function () { + html5ks.elements.nvlctc.style.display = "none"; + deferred.resolve(); + html5ks.next = function () {}; + }; + return deferred.promise; + }, + + character: function (name, str, extend) { var deferred = when.defer(), text = this.tag(str), @@ -248,46 +262,52 @@ window.html5ks.api = { if ((!w || !w[1] || extend) && char.what_suffix) { text = text + char.what_suffix; } - var who = html5ks.elements.who; - if (!extend) { - who.innerHTML = char.name; - if (char.color) { - who.style.color = char.color; - } else { - who.style.color = "#ffffff"; - } - } - if (extend) { - html5ks.elements.say.innerHTML += text; + if (char.kind === "nvl") { + this.nvlsay(text).then(function () { + deferred.resolve(); + }); } else { - html5ks.elements.say.innerHTML = text; - } + var who = html5ks.elements.who; + if (!extend) { + who.innerHTML = char.name; + if (char.color) { + who.style.color = char.color; + } else { + who.style.color = "#ffffff"; + } + } - if (w) { - html5ks.next = function () { - html5ks.next = function () {}; - html5ks.api.extend(str.substring(w.index + w[0].length)).then(function () { - deferred.resolve(); - }); - }; - if (w[1]) { - setTimeout(html5ks.next, parseFloat(w[1].substring(1), 10) * 1000); - return deferred.promise; + if (extend) { + html5ks.elements.say.innerHTML += text; + } else { + html5ks.elements.say.innerHTML = text; } - } else { - html5ks.next = function () { - html5ks.elements.ctc.style.display = "none"; - deferred.resolve(text); - html5ks.next = function () {}; - }; + + if (w) { + html5ks.next = function () { + html5ks.next = function () {}; + html5ks.api.extend(str.substring(w.index + w[0].length)).then(function () { + deferred.resolve(); + }); + }; + if (w[1]) { + setTimeout(html5ks.next, parseFloat(w[1].substring(1), 10) * 1000); + return deferred.promise; + } + } else { + html5ks.next = function () { + html5ks.elements.ctc.style.display = "none"; + deferred.resolve(text); + html5ks.next = function () {}; + }; + } + html5ks.elements.ctc.style.display = "block"; } if (html5ks.state.skip || str.indexOf("{nw}") > -1) { html5ks.next(); } else if (html5ks.state.auto) { setTimeout(html5ks.next, 1000 + html5ks.persistent.settings.autospeed * text.length); - } else { - html5ks.elements.ctc.style.display = "block"; } return deferred.promise; }, @@ -302,5 +322,27 @@ window.html5ks.api = { deferred.resolve(); }, duration * 1000); return deferred.promise; + }, + + nvl: function (action, transition) { + var deferred = when.defer(), + nvl = html5ks.elements.nvl; + switch (action) { + case "show": + nvl.style.display = "block"; + deferred.resolve(); + break; + case "hide": + nvl.style.display = "none"; + deferred.resolve(); + break; + case "clear": + html5ks.elements.nvlsay.innerHTML = ""; + deferred.resolve(); + break; + default: + console.error("no such nvl action " + action); + } + return deferred.promise; } }; diff --git a/www/js/html5ks.js b/www/js/html5ks.js index 653b407..86278f0 100644 --- a/www/js/html5ks.js +++ b/www/js/html5ks.js @@ -40,7 +40,10 @@ window.html5ks = { say: document.getElementById("say"), bg: document.getElementById("bg"), window: document.getElementById("window"), - ctc: document.getElementById("ctc") + ctc: document.getElementById("ctc"), + nvl: document.getElementById("nvl"), + nvlsay: document.getElementById("nvlsay"), + nvlctc: document.getElementById("nvlctc") }; this.elements.audio.music.loop = true; this.elements.audio.ambient.loop = true; -- cgit v1.2.3-70-g09d2