summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-rw-r--r--www/js/api.js125
-rw-r--r--www/js/html5ks.js26
-rw-r--r--www/js/menu.js13
3 files changed, 84 insertions, 80 deletions
diff --git a/www/js/api.js b/www/js/api.js
index 0043724..67c8320 100644
--- a/www/js/api.js
+++ b/www/js/api.js
@@ -12,25 +12,24 @@ window.html5ks.api = {
_fading: {},
- set_volume: function (target, delay, channel) {
+ set_volume: function (target, fade, channel) {
var audio = html5ks.elements.audio[channel],
- step = (target - audio.volume) / (delay * 20);
- if (!delay) {
- audio.volume = target;
- } else {
- this._fading[channel] = setInterval(function () {
- // clamp new volume 0-1
- audio.volume = Math.min(Math.max(audio.volume + step, 0), 1);
- switch (audio.volume) {
- case 0:
- audio.pause();
- /* falls through */
- case 1:
- clearInterval(this._fading[channel]);
- delete this._fading[channel];
- }
- }.bind(this), 50);
- }
+ step = (target - audio.volume) / (fade * 20);
+ var nextVol = function () {
+ // clamp new volume 0-1
+ audio.volume = Math.min(Math.max(audio.volume + step, 0), 1);
+ switch (audio.volume) {
+ case 0:
+ audio.pause();
+ /* falls through */
+ case 1:
+ clearInterval(this._fading[channel]);
+ delete this._fading[channel];
+ return false;
+ }
+ return true;
+ };
+ if (nextVol()) this._fading[channel] = setInterval(nextVol, 50);
return when.resolve();
},
@@ -77,7 +76,8 @@ window.html5ks.api = {
_nextType();
},
- play: function (channel, name, _, fade) {
+ play: function (cmd, args) {
+ var channel = cmd[1];
this.stop(channel);
var deferred = when.defer(),
audio = html5ks.elements.audio[channel];
@@ -85,13 +85,13 @@ window.html5ks.api = {
audio.loop = true;
}
html5ks.elements.audio[channel] = audio;
- html5ks.store[channel] = name;
+ html5ks.store[channel] = args.file;
var src = "dump/", volume;
switch (channel) {
case "music":
- var fname = html5ks.data.music[name];
+ var fname = html5ks.data.music[args.file.replace(/ $/, '')];
src += "bgm/" + fname;
volume = html5ks.persistent.musicVolume;
document.getElementById("current-music-track").innerHTML = fname.replace(/_/g, " ");
@@ -104,13 +104,13 @@ window.html5ks.api = {
audio.addEventListener("playing", function playing() {
audio.removeEventListener("playing", playing, false);
- if (fade) {
- html5ks.api.set_volume(volume, fade, channel);
+ if (args.fadein) {
+ html5ks.api.set_volume(volume, args.fadein, channel);
}
deferred.resolve();
}, false);
- audio.volume = fade ? 0 : volume;
+ audio.volume = args.fadein ? 0 : volume;
this._loadMedia(audio, src, [
['audio/ogg; codecs="opus"', "opus"],
['audio/ogg; codecs="vorbis"', "ogg"],
@@ -194,8 +194,8 @@ window.html5ks.api = {
real_target = html5ks.persistent.language + "_" + target.replace(/"/g, ''),
i = 0;
html5ks.fetch('script', real_target).then(function run(l) {
- if (l[i]) {
- html5ks.api.runInst(l[i++]).then(run, console.error);
+ if (l[i++]) {
+ html5ks.api.runInst(l[i]).then(function(){run(l)}, console.error);
} else {
deferred.resolve();
}
@@ -203,22 +203,28 @@ window.html5ks.api = {
return deferred.promise;
},
+ _safeCall: function (n, f, args) {
+ if (f) return f.apply(this, args);
+ else {
+ console.error("no such function " + n);
+ debugger;
+ return when.resolve();
+ }
+ },
+
runInst: function (inst) {
- var cmd = inst[0].replace(/"/g, ''),
- args = inst.slice(1);
- if (html5ks.data.characters[cmd]) {
- return this.say(cmd, args[0]);
- } else {
- if (this[cmd]) {
- return this[cmd].apply(this, args);
- } else if (inst.length === 1) {
- return this.say("name_only", cmd);
- } else {
- console.error("no such cmd " + cmd);
- return when.resolve();
- }
- }
+ var cmd = inst[0].replace(/"/g, '');
+ return this._safeCall(cmd, this[cmd], inst.slice(1));
+ },
+
+ UserStatement: function (line, parsed) {
+ var c = parsed[0][0];
+ return this._safeCall(c, this[c], parsed);
+ },
+
+ With: function () {
+ return when.resolve();
},
@@ -240,9 +246,9 @@ window.html5ks.api = {
},
- scene: function () {
+ Scene: function () {
html5ks.elements.show.innerHTML = "";
- return this.show.apply(this, arguments);
+ return this.Show.apply(this, arguments);
},
@@ -265,8 +271,11 @@ window.html5ks.api = {
bgright: { xpos: 0.6, xanchor: 0.5, ypos: 1.0, yanchor: 1.0 }
},
- show: function (name, type, location) {
+ Show: function (imspec) {
var deferred = when.defer();
+ var name =
+ console.log(imspec);
+ return when.resolve();
var lookup = document.getElementById(name),
el = lookup || document.createElement("img");
if (!location && !lookup) location = "center";
@@ -406,31 +415,27 @@ window.html5ks.api = {
});
},
- say: function (chrName, str, extend) {
+ Say: function (who, what, with_, extend) {
var deferred = when.defer(),
- chr = typeof chrName === "string" ? html5ks.data.characters[chrName] : chrName,
- w = /{w=?(\d*\.\d*)?}(.*)/.exec(str);
+ chr = html5ks.data.characters[who],
+ w = /{w=?(\d*\.\d*)?}(.*)/.exec(what);
if (!chr) {
- chr = {
- name: chrName
- };
- }
- if (typeof chr.what_prefix === "undefined") {
- chr.what_prefix = "“";
- chr.what_suffix = "”";
+ chr = { name: who };
}
+ chr.what_prefix = chr.what_prefix || "“";
+ chr.what_suffix = chr.what_suffix || "“";
this._lastchar = chr;
if (!extend && chr.what_prefix) {
- str = chr.what_prefix + str;
+ what = chr.what_prefix + what;
}
if ((!w || !w[1]) && chr.what_suffix) {
- str = str + chr.what_suffix;
+ what += chr.what_suffix;
}
- var text = this.dlgTag(str),
+ var text = this.dlgTag(what),
say, ctc;
if (chr.kind === "nvl") {
@@ -478,14 +483,14 @@ window.html5ks.api = {
ctc.style.display = "none";
deferred.resolve();
}
- html5ks.api._setNextTimeout(str, true);
+ html5ks.api._setNextTimeout(what, true);
};
if (html5ks.persistent.textSpeed == 200) {
ptxt(true);
}
- this._setNextTimeout(str, false);
+ this._setNextTimeout(what, false);
return deferred.promise;
},
@@ -501,10 +506,6 @@ window.html5ks.api = {
}
},
- extend: function (str) {
- return this.say(this._lastchar, str, true);
- },
-
Pause: function (duration) {
var deferred = when.defer();
setTimeout(function () {
diff --git a/www/js/html5ks.js b/www/js/html5ks.js
index 13bd198..4113c1d 100644
--- a/www/js/html5ks.js
+++ b/www/js/html5ks.js
@@ -143,7 +143,7 @@ window.html5ks = {
},
initEvents: function () {
window.onresize = html5ks.scale;
- this.elements.container.addEventListener("mouseup", function (e) {
+ this.elements.container.addEventListener("click", function (e) {
if (html5ks.store.status === "scene") {
switch (e.button) {
case 0:
@@ -157,39 +157,33 @@ window.html5ks = {
e.preventDefault();
}, false);
},
- warnUnsupported: function () {
+ warn: function () {
if (!html5ks.persistent.gotit) {
var interstitial = document.getElementById("interstitial");
- document.getElementById("gotit").addEventListener("mouseup", function () {
- interstitial.style.mozAnimation = "1s dissolveout";
- interstitial.style.webkitAnimation = "1s dissolveout";
- interstitial.style.animation = "1s dissolveout";
- interstitial.style.opacity = 0;
+ interstitial.style.display = "block";
+ document.getElementById("lets-go").addEventListener("click", function () {
+ interstitial.style.display = "none";
html5ks.persistent.gotit = true;
html5ks.start();
}, false);
- var warns = document.getElementById("warns").children;
+ var features = document.getElementById("features").children;
if (/MSIE/.test(navigator.userAgent)) {
document.getElementById("ie").style.display = "block";
+ document.getElementById("missing-features").style.display = "block";
}
if (!Modernizr.audio.opus) {
document.getElementById("opus").style.display = "block";
- }
- for (var i = 0; i < warns.length; i++) {
- var warn = warns[i];
- if (window.getComputedStyle(warns[i]).getPropertyValue("display") !== "none") {
- warn.style.display = "block";
- return true;
- }
+ document.getElementById("missing-features").style.display = "block";
}
}
+ return !html5ks.persistent.gotit;
},
onload: function () {
FastClick.attach(document.body);
this.initElements();
this.scale();
this.initEvents();
- if (!this.warnUnsupported()) {
+ if (!this.warn()) {
this.start();
}
this.i18n.init();
diff --git a/www/js/menu.js b/www/js/menu.js
index 93616db..5b646b9 100644
--- a/www/js/menu.js
+++ b/www/js/menu.js
@@ -5,8 +5,8 @@ html5ks.menu = {
this.context(false);
html5ks.api.stop("all");
html5ks.api.window("hide");
- html5ks.api.play("music", "music_menus");
- html5ks.api.show("url", "ui/main/bg-main.png");
+ html5ks.api.play(['', "music"], {file: "music_menus", fadein: 5});
+ html5ks.api.Show("url", "ui/main/bg-main.png");
this.elements.mainMenu.style.display = "block";
html5ks.store.status = "menu";
},
@@ -161,6 +161,15 @@ html5ks.menu = {
console.error("unknown option type %s", option.type);
}
}
+
+ document.getElementById("clear-persistent").addEventListener("click", function () {
+ if (delete localStorage.persistent) {
+ alert("clear succeeded, refreshing...");
+ location.reload();
+ } else {
+ alert("clear failed");
+ }
+ }, false);
},
init: function () {