diff options
author | Alex Xu <alex_y_xu@yahoo.ca> | 2014-01-24 18:07:37 -0500 |
---|---|---|
committer | Alex Xu <alex_y_xu@yahoo.ca> | 2014-01-24 18:07:37 -0500 |
commit | 3a367a00e45880de6b5472c07ce65043ab83eae7 (patch) | |
tree | d361c4212e1a4745ebd0ade192769a7cf50a3150 /www | |
parent | 941668dbb44260573f6c7d590e120a986ac99c62 (diff) | |
parent | 4dc2aa175624a4d29e4c4e8d3881461df093d13f (diff) | |
download | html5ks-3a367a00e45880de6b5472c07ce65043ab83eae7.tar.xz html5ks-3a367a00e45880de6b5472c07ce65043ab83eae7.zip |
Merge branch 'master' of happinessforme.com:html5ks
Conflicts:
Makefile
www/js/api.js
Diffstat (limited to 'www')
-rw-r--r-- | www/js/api.js | 103 | ||||
-rw-r--r-- | www/js/html5ks.js | 6 | ||||
-rw-r--r-- | www/warn.html | 15 | ||||
-rw-r--r-- | www/warned.html | 10 |
4 files changed, 75 insertions, 59 deletions
diff --git a/www/js/api.js b/www/js/api.js index 84cc881..74971ae 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -33,6 +33,41 @@ window.html5ks.api = new (function () { return when.resolve(); }, + _loadMedia: function (el, src, types) { + var deferred = when.defer(); + var i = 0; + var _nextType = function () { + for (; i < types.length; i++) { + var type = types[i]; + if (el.canPlayType(type[0])) { + el.src = src + "." + type[1]; + el.load(); + return true; + } + } + return false; + }; + + _nextType(); + + el.oncanplaythrough = function () { + el.play(); + }; + + el.onerror = function (e) { + if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) { + if (!_nextType()) { + console.log("no audio formats supported"); + deferred.resolve(); + } + } else { + console.error("unknown audio error"); + deferred.resolve(); + } + }; + return deferred.promise; + }, + play: function (channel, name, ignore, fade) { this.stop(channel); var deferred = when.defer(), @@ -55,26 +90,6 @@ window.html5ks.api = new (function () { volume = html5ks.persistent.sfxVolume; } - var types = ["opus", "ogg", "m4a", "wav"]; - - var setNextType = function (i) { - for (; i < types.length; i++) { - if (Modernizr.audio[types[i]]) { - audio.src = src + "." + types[i]; - audio.load(); - audio.volume = fade ? 0 : volume; - return i; - } - } - return null; - }; - - var i; - - audio.addEventListener("canplaythrough", function canplaythrough() { - audio.removeEventListener("canplaythrough", canplaythrough, false); - audio.play(); - }); audio.addEventListener("playing", function playing() { audio.removeEventListener("playing", playing, false); if (fade) { @@ -82,21 +97,15 @@ window.html5ks.api = new (function () { } deferred.resolve(); }, false); - audio.onerror = function (e) { - if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) { - i = setNextType(++i); - if (!i) { - console.error("No media formats appear to be supported."); - console.error(e); - deferred.resolve(); - } - } else { - console.error(e); - deferred.resolve(); - } - }; - i = setNextType(0); + audio.volume = fade ? 0 : volume; + this._loadMedia(audio, src, [ + ['audio/ogg; codecs="opus"', "opus"], + ['audio/ogg; codecs="vorbis"', "ogg"], + ['audio/x-m4a', "m4a"], + ['audio/aac', "aac"], + ['audio/wav; codecs="1"', "wav"]]).then(function () { deferred.resolve(); }); + // TODO: fix this garbage -------------------------------^ return deferred.promise; }, @@ -123,7 +132,7 @@ window.html5ks.api = new (function () { movie_cutscene: function (vid_src, skippable) { var deferred = when.defer(), video = html5ks.elements.video, - src = "dump/video/" + vid_src + "."; + src = "dump/video/" + vid_src; this.stop("all"); clearInterval(html5ks._nextTimeout); @@ -132,22 +141,15 @@ window.html5ks.api = new (function () { return deferred.resolve(); } - var types = { - "webm": "webm", - "ogg": "ogv", - "h264": "mp4" - }; - for (var type in types) { - if (Modernizr.video[type]) { - video.src = src + types[type]; - break; - } - } - - video.load(); + this._loadMedia(video, src, [ + ['video/webm; codecs="vp9,opus"', "vp9.webm"], + ['video/webm; codecs="vp8,vorbis"', "webm"], + ['video/ogg; codecs="theora,vorbis"', "ogv"], + // TODO: check that this is the right codec + ['video/mp4; codecs="avc1.42E01E,mp4a.40.2"']]).then(function () { deferred.resolve(); }); + // TODO: fix this garbage video.style.display = "block"; video.volume = html5ks.persistent.musicVolume; - video.play(); var done = function () { video.style.display = "none"; video.pause(); @@ -166,9 +168,6 @@ window.html5ks.api = new (function () { } }; video.onended = done; - video.onerror = function () { - deferred.reject(this.error); - }; return deferred.promise; }, diff --git a/www/js/html5ks.js b/www/js/html5ks.js index e1c0bd7..093505e 100644 --- a/www/js/html5ks.js +++ b/www/js/html5ks.js @@ -19,7 +19,11 @@ window.html5ks = { sfxVolume: 1, language: "en" }; - var loaded = localStorage.persistent ? JSON.parse(localStorage.persistent) : {}; + try { + var loaded = localStorage.persistent ? JSON.parse(localStorage.persistent) : {}; + } catch (e) { + var loaded = {}; + } var defProp = function (v) { Object.defineProperty(html5ks.persistent, k, { get: function () { diff --git a/www/warn.html b/www/warn.html index 5d41083..5c7c898 100644 --- a/www/warn.html +++ b/www/warn.html @@ -6,13 +6,16 @@ <body> <p>Okay, before we start, we need to go through a few things first.</p> <p>If you don't know what Katawa Shoujo is, see <a href="http://www.katawa-shoujo.com/">http://www.katawa-shoujo.com/</a>, then come back.</p> - <p>The full version of Katawa Shoujo contains adult material.<br> - Promise that you are over <b>18 years</b> old and that you will not make the material available to persons below that age. - </p> + <p>There's like, a little bit of... inappropriate content, so we have to make you promise you're over 18.</p> + <p>If you don't want to see any, er, explicit content, hit the appropriate checkbox at the bottom of the page.</p> <p>Also, please don't bother the original developers on the forums or IRC about bugs in this. This is entirely unofficial and not controlled by them whatsoever.<br> - This includes typos, graphical misplacement, downtime, and any other glitches of any sort. Bug me instead: <a href="https://bugzilla.happinessforme.com/">https://bugzilla.happinessforme.com/</a>, or use the official distribution until HTML5KS is feature-complete. + This includes missing features, typos, downtime, and any other glitches of any sort. Bug me instead: <a href="https://bugzilla.happinessforme.com/">https://bugzilla.happinessforme.com/</a>, or use the official distribution until HTML5KS is feature-complete. </p> - <p>FYI, this site sets a single anonymous cookie (warned=1) so that you won't have to keep seeing this page. It also sets localStorage to keep your settings and saves (when that's implemented). This stays on your computer and never goes anywhere. If you live in the EU, please don't sue me.</p> - <p><a href="setcookie.html">OK? Great.</a></p> + <p>FYI, this site sets a single anonymous cookie (warned=1) so that you won't have to keep seeing this page. It also sets localStorage to keep your settings and saves. The latter always stays on your computer and never goes anywhere. If you live in the EU, please don't sue me.</p> + <form method="GET" action="warned.ngx"> + <p><input type="checkbox" name="hdisable"><label for="hdisable">Disable adult content</label> + <br> + <input type="submit" value="Let's go!"> + </form> </body> </html> diff --git a/www/warned.html b/www/warned.html new file mode 100644 index 0000000..5d44d7c --- /dev/null +++ b/www/warned.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html><head> +<script> +localStorage.persistent = { + hdisable: location.search.indexOf("hdisable=on") > -1, + language: location.search.search("language=.*[=,]en") > -1 ? "en" : "fr" +}; +location.replace("./"); +</script> +</head><body>If you're seeing this, something's gone wrong. Go back and report a bug.</body></html> |