From 087e45d9bae8ffaef840e907c38e4a8402fab69b Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Mon, 20 Jan 2014 13:53:17 -0500 Subject: Stuff. --- Makefile | 23 +++++++++++++++-------- README | 12 +++++++++++- nginx.inc.conf | 12 +++++++----- www/warn.html | 15 +++++++++------ www/warned.html | 10 ++++++++++ 5 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 www/warned.html diff --git a/Makefile b/Makefile index 5725e9d..3e3506b 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,14 @@ -null := -SPACE := $(null) $(null) +null := +SPACE := $(null) $(null) FFMPEG ?= ffmpeg -FFMPEG += -v warning $(FFMPEGFLAGS) +FFMPEG += -v warning -y OPUSENC ?= opusenc ZOPFLIPNG ?= zopflipng -OPTIPNG ?= optipng -JPEGOPTIM ?= jpegoptim +TRUEPNG ?= wine TruePNG +DEFLOPT ?= wine DeflOpt +DEFLUFF ?= defluff +PNGQUANT ?= pngquant CWEBP ?= cwebp CWEBP += -short -alpha_cleanup WEBPMUX ?= webpmux @@ -35,7 +37,7 @@ video: $(CVIDEO) $(FFMPEG) -i $< -c:v libvpx -crf 15 -b:v 1M -c:a copy $@ %.ogv: %.mkv - $(FFMPEG) -i $< -c:v libtheora -qscale:v 6 -c:a copy $@ + $(FFMPEG) -i $< -c:v libtheora -qscale:v 10 -c:a copy $@ # === AUDIO === @@ -69,11 +71,15 @@ CTC_ANIM := $(DUMP)/ui/ctc_anim.png $(DUMP)/ui/ctc_anim.webp images: $(WEBP) $(CTC_ANIM) www/favicon.ico %.webp: %.png + $(PNGQUANT) --force --speed 1 --ext .png $< $(ZOPFLIPNG) -m -y $< $< + $(DEFLOPT) $< + $(DEFLUFF) < $< > TMP$< + mv TMP$< $< $(CWEBP) -q 99 -m 6 $< -o $@ %.webp: %.jpg - $(JPEGOPTIM) --strip-all $< + $(JPEGMINI) $< $(CWEBP) -q 90 -m 6 $< -o $@ www/favicon.ico: $(DUMP)/ui/icon.png @@ -81,7 +87,8 @@ www/favicon.ico: $(DUMP)/ui/icon.png $(DUMP)/ui/bt-cf-unchecked.webp $(DUMP)/ui/bt-cf-checked.webp: %.webp: %.png $(CONVERT) -trim $< $< - $(OPTIPNG) -o7 $< + $(PNGQUANT) --force --speed 1 --ext .png $< + $(TRUEPNG) $< /o max $(ZOPFLIPNG) -m -y $< $< $(CWEBP) -q 99 -m 6 $< -o $@ diff --git a/README b/README index 7d54461..f1d79fb 100644 --- a/README +++ b/README @@ -6,7 +6,16 @@ This is a WIP HTML5 implementation of the game Katawa Shoujo. [0] - Bash - ffmpeg with fdk-aac, libtheora, libvpx, libx264 - opusenc from opus-tools +- TruePNG +- DeflOpt +- defluff +- pngquant +- recommended: jpegmini +- jpegrescan - cwebp and webpmux from libwebp +- ImageMagick +- apngasm +- uglifyjs === Recommended === - nginx @@ -19,7 +28,8 @@ This is a WIP HTML5 implementation of the game Katawa Shoujo. [0] 0. Get Katawa Shoujo. 1. Copy *.rpyc from Katawa Shoujo/game into unrpyc/ directory. 2. Extract files from Katawa Shoujo/game/data.rpa with an rpa extractor, e.g. unrpa. Put files in www/dump. -3. Run setup.sh. [2] +3. Install prerequisites, download DeflOpt and defluff and place exes in this directory. +4. Run setup.sh. [2] 4. Run nginx.sh to start nginx, then navigate to localhost:8080 in your browser. -- or -- diff --git a/nginx.inc.conf b/nginx.inc.conf index b795a1c..acab0ef 100644 --- a/nginx.inc.conf +++ b/nginx.inc.conf @@ -14,19 +14,19 @@ location ~ ^/(css/font|js/lib)/ { location / { set $warned NO; if ($http_cookie ~ "warned") { - set $warned YES; + set $warned YES; } if ($args ~ "warned") { - set $warned YES; + set $warned YES; } if ($warned = NO) { - return 307 /warn.html; + return 307 /warn.html; } } -location /setcookie.html { +location /warned.ngx { add_header Set-Cookie "warned=1; Expires=Tue, 19 Jan 2038 00:00:00 GMT; HttpOnly"; - return 301 /; + return 301 "/warned.html?$args&language=$http_accept_language"; } location /warn.html { @@ -40,3 +40,5 @@ location /robots.txt { expires 5s; add_header Cache-Control public; add_header X-UA-Compatible "IE=edge"; + +# vim:ft=nginx: 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 @@

Okay, before we start, we need to go through a few things first.

If you don't know what Katawa Shoujo is, see http://www.katawa-shoujo.com/, then come back.

-

The full version of Katawa Shoujo contains adult material.
- Promise that you are over 18 years old and that you will not make the material available to persons below that age. -

+

There's like, a little bit of... inappropriate content, so we have to make you promise you're over 18.

+

If you don't want to see any, er, explicit content, hit the appropriate checkbox at the bottom of the page.

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.
- This includes typos, graphical misplacement, downtime, and any other glitches of any sort. Bug me instead: https://bugzilla.happinessforme.com/, 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: https://bugzilla.happinessforme.com/, or use the official distribution until HTML5KS is feature-complete.

-

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.

-

OK? Great.

+

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.

+
+

+
+ +

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 @@ + + + +If you're seeing this, something's gone wrong. Go back and report a bug. -- cgit v1.2.3-70-g09d2 From 9891068394c31d45654a0625b2b115804e8ff46b Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Mon, 20 Jan 2014 22:00:55 -0500 Subject: Makefile build stuff. --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 3e3506b..8644167 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ FFMPEG ?= ffmpeg FFMPEG += -v warning -y OPUSENC ?= opusenc ZOPFLIPNG ?= zopflipng -TRUEPNG ?= wine TruePNG DEFLOPT ?= wine DeflOpt DEFLUFF ?= defluff PNGQUANT ?= pngquant @@ -34,7 +33,7 @@ video: $(CVIDEO) $(FFMPEG) -i $< -c:v libx264 -preset slower -tune animation -c:a libfdk_aac $@ %.webm: %.mkv - $(FFMPEG) -i $< -c:v libvpx -crf 15 -b:v 1M -c:a copy $@ + $(FFMPEG) -i $< -strict -2 -c:v libvpx-vp9 -crf 8 -b:v 1M -c:a copy $@ %.ogv: %.mkv $(FFMPEG) -i $< -c:v libtheora -qscale:v 10 -c:a copy $@ @@ -52,10 +51,10 @@ audio: $(CAUDIO) $(FFMPEG) -i $< -c:a pcm_s16le $@ %.opus: %.wav - $(OPUSENC) --bitrate 64 $< $@ + $(FFMPEG) -i $< -c:a libopus -b:a 64 $@ %.m4a: %.wav - $(FFMPEG) -i $< -c:a libfdk_aac -vbr 2 $@ + $(FFMPEG) -i $< -c:a libfdk_aac -vbr 1 $@ # === IMAGES === @@ -79,7 +78,6 @@ images: $(WEBP) $(CTC_ANIM) www/favicon.ico $(CWEBP) -q 99 -m 6 $< -o $@ %.webp: %.jpg - $(JPEGMINI) $< $(CWEBP) -q 90 -m 6 $< -o $@ www/favicon.ico: $(DUMP)/ui/icon.png @@ -88,12 +86,14 @@ www/favicon.ico: $(DUMP)/ui/icon.png $(DUMP)/ui/bt-cf-unchecked.webp $(DUMP)/ui/bt-cf-checked.webp: %.webp: %.png $(CONVERT) -trim $< $< $(PNGQUANT) --force --speed 1 --ext .png $< - $(TRUEPNG) $< /o max $(ZOPFLIPNG) -m -y $< $< + $(DEFLOPT) $< + $(DEFLUFF) < $< > TMP$< $(CWEBP) -q 99 -m 6 $< -o $@ $(DUMP)/ui/ctc_strip-0.png: $(CTC_ANIM_SRC) $(CONVERT) $< -crop 16x16 $(patsubst %.png,%*.png,$<) + $(PNGQUANT) --force --speed 1 --ext .png $< $(DUMP)/ui/ctc_strip-%.png: $(CTC_ANIM_SRC) $(DUMP)/ui/ctc_strip-0.png @touch $@ -- cgit v1.2.3-70-g09d2 From 0463505d98e98a204215e8669ce3270ab0448d1a Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Tue, 21 Jan 2014 11:32:44 -0500 Subject: Makefile: stuff --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8644167..9d9ac11 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ audio: $(CAUDIO) $(FFMPEG) -i $< -c:a pcm_s16le $@ %.opus: %.wav - $(FFMPEG) -i $< -c:a libopus -b:a 64 $@ + $(FFMPEG) -i $< -c:a libopus -b:a 64k $@ %.m4a: %.wav $(FFMPEG) -i $< -c:a libfdk_aac -vbr 1 $@ @@ -73,8 +73,8 @@ images: $(WEBP) $(CTC_ANIM) www/favicon.ico $(PNGQUANT) --force --speed 1 --ext .png $< $(ZOPFLIPNG) -m -y $< $< $(DEFLOPT) $< - $(DEFLUFF) < $< > TMP$< - mv TMP$< $< + $(DEFLUFF) < $< > $<.tmp + mv -f $<.tmp $< $(CWEBP) -q 99 -m 6 $< -o $@ %.webp: %.jpg -- cgit v1.2.3-70-g09d2 From a17e2dfe7a2ed9b033ce8ee224395fdaea21bdfe Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Tue, 21 Jan 2014 13:37:18 -0500 Subject: Stuff. --- www/js/api.js | 8 ++++---- www/js/html5ks.js | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/www/js/api.js b/www/js/api.js index 833b120..d659cbb 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -78,13 +78,13 @@ window.html5ks.api = new (function () { audio.onerror = function (e) { if (e.code === e.MEDIA_ERR_SRC_NOT_SUPPORTED) { i = setNextType(i); - if (i) { + if (!i) { + console.log("no audio formats supported"); deferred.resolve(); - } else { - throw new Error(e); } } else { - throw new Error(e); + console.error("unknown audio error"); + deferred.resolve(); } }; audio.load(); 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 () { -- cgit v1.2.3-70-g09d2 From 5e8257aca57b5952e0cff830a2da2ec23182c965 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Wed, 22 Jan 2014 09:30:59 -0500 Subject: Stuff. --- Makefile | 6 ++++++ www/js/api.js | 1 + 2 files changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 9d9ac11..3c8c77c 100644 --- a/Makefile +++ b/Makefile @@ -29,10 +29,16 @@ CVIDEO := $(MP4) $(WEBM) $(OGV) video: $(CVIDEO) +%.y4m: %.mkv + $(FFMPEG) -i $< -c:a copy $@ + %.mp4: %.mkv $(FFMPEG) -i $< -c:v libx264 -preset slower -tune animation -c:a libfdk_aac $@ %.webm: %.mkv + $(FFMPEG) -i $< -strict -2 -c:v libvpx -crf 10 -b:v 1M -c:a copy $@ + +%.vp9.webm: %.mkv $(FFMPEG) -i $< -strict -2 -c:v libvpx-vp9 -crf 8 -b:v 1M -c:a copy $@ %.ogv: %.mkv diff --git a/www/js/api.js b/www/js/api.js index d659cbb..ed357de 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -125,6 +125,7 @@ window.html5ks.api = new (function () { } var types = { + "vp9": "vp9.webm", "webm": "webm", "ogg": "ogv", "h264": "mp4" -- cgit v1.2.3-70-g09d2 From 678a7f0dfa4fcb45b6e8418b11ba73cc72107c2e Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Wed, 22 Jan 2014 09:33:08 -0500 Subject: More stuff. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3c8c77c..0784215 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ audio: $(CAUDIO) # === IMAGES === -PNG := $(shell find $(DUMP) -name '*.png') +PNG := $(shell find $(DUMP) -name '*.png' ! -name 'ctc_strip.png') JPG := $(shell find $(DUMP) -name '*.jpg') WEBP := $(patsubst %.png,%.webp,$(PNG)) \ $(patsubst %.jpg,%.webp,$(JPG)) -- cgit v1.2.3-70-g09d2 From c2a228a3ca04c22819b90872a3a3d5398f4df8ee Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Wed, 22 Jan 2014 09:36:11 -0500 Subject: Makefile: Stuff. --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 0784215..daa413b 100644 --- a/Makefile +++ b/Makefile @@ -75,6 +75,9 @@ CTC_ANIM := $(DUMP)/ui/ctc_anim.png $(DUMP)/ui/ctc_anim.webp images: $(WEBP) $(CTC_ANIM) www/favicon.ico +$(DUMP)/ui/ctc_strip.webp: $(DUMP)/ui/ctc_strip.png + : + %.webp: %.png $(PNGQUANT) --force --speed 1 --ext .png $< $(ZOPFLIPNG) -m -y $< $< -- cgit v1.2.3-70-g09d2 From e1ba0f1152f14c32c4b4717e98fc7179f80da29a Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Wed, 22 Jan 2014 09:39:39 -0500 Subject: Makefile: Split vp9 to separate file. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index daa413b..bc592dd 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,9 @@ all: video audio images js VIDEO := $(wildcard $(DUMP)/video/*.mkv) MP4 := $(patsubst %.mkv,%.mp4,$(VIDEO)) WEBM := $(patsubst %.mkv,%.webm,$(VIDEO)) +VP9 := $(patsubst %.mkv,%.vp9.webm,$(VIDEO)) OGV := $(patsubst %.mkv,%.ogv,$(VIDEO)) -CVIDEO := $(MP4) $(WEBM) $(OGV) +CVIDEO := $(MP4) $(WEBM) $(VP9) $(OGV) video: $(CVIDEO) -- cgit v1.2.3-70-g09d2 From 81d121665888f7e05cc3b36d8c12bc3796fa8273 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Wed, 22 Jan 2014 13:54:51 -0500 Subject: Makefile: more stuff --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bc592dd..352cd94 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ video: $(CVIDEO) $(FFMPEG) -i $< -c:v libx264 -preset slower -tune animation -c:a libfdk_aac $@ %.webm: %.mkv - $(FFMPEG) -i $< -strict -2 -c:v libvpx -crf 10 -b:v 1M -c:a copy $@ + $(FFMPEG) -i $< -crf 10 -b:v 1M -c:a copy $@ %.vp9.webm: %.mkv $(FFMPEG) -i $< -strict -2 -c:v libvpx-vp9 -crf 8 -b:v 1M -c:a copy $@ @@ -98,7 +98,8 @@ $(DUMP)/ui/bt-cf-unchecked.webp $(DUMP)/ui/bt-cf-checked.webp: %.webp: %.png $(PNGQUANT) --force --speed 1 --ext .png $< $(ZOPFLIPNG) -m -y $< $< $(DEFLOPT) $< - $(DEFLUFF) < $< > TMP$< + $(DEFLUFF) < $< > $<.tmp + mv -f $<.tmp $< $(CWEBP) -q 99 -m 6 $< -o $@ $(DUMP)/ui/ctc_strip-0.png: $(CTC_ANIM_SRC) -- cgit v1.2.3-70-g09d2 From 4dc2aa175624a4d29e4c4e8d3881461df093d13f Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Thu, 23 Jan 2014 09:25:19 -0500 Subject: stuff --- Makefile | 58 ++++++++++++++++++------------------ www/js/api.js | 95 ++++++++++++++++++++++++++++++----------------------------- 2 files changed, 78 insertions(+), 75 deletions(-) diff --git a/Makefile b/Makefile index 352cd94..4534644 100644 --- a/Makefile +++ b/Makefile @@ -31,19 +31,19 @@ CVIDEO := $(MP4) $(WEBM) $(VP9) $(OGV) video: $(CVIDEO) %.y4m: %.mkv - $(FFMPEG) -i $< -c:a copy $@ + $(FFMPEG) -i "$<" -c:a copy "$@" %.mp4: %.mkv - $(FFMPEG) -i $< -c:v libx264 -preset slower -tune animation -c:a libfdk_aac $@ + $(FFMPEG) -i "$<" -c:v libx264 -preset slower -tune animation -c:a libfdk_aac "$@" %.webm: %.mkv - $(FFMPEG) -i $< -crf 10 -b:v 1M -c:a copy $@ + $(FFMPEG) -i "$<" -crf 10 -b:v 1M -c:a copy "$@" %.vp9.webm: %.mkv - $(FFMPEG) -i $< -strict -2 -c:v libvpx-vp9 -crf 8 -b:v 1M -c:a copy $@ + $(FFMPEG) -i "$<" -strict -2 -c:v libvpx-vp9 -crf 8 -b:v 1M -c:a libopus -vbr 1 -b:a 64k "$@" %.ogv: %.mkv - $(FFMPEG) -i $< -c:v libtheora -qscale:v 10 -c:a copy $@ + $(FFMPEG) -i "$<" -c:v libtheora -qscale:v 10 -c:a copy "$@" # === AUDIO === @@ -55,13 +55,13 @@ CAUDIO := $(OPUS) $(M4A) audio: $(CAUDIO) %.wav: %.ogg - $(FFMPEG) -i $< -c:a pcm_s16le $@ + $(FFMPEG) -i "$<" -c:a pcm_s16le "$@" %.opus: %.wav - $(FFMPEG) -i $< -c:a libopus -b:a 64k $@ + $(FFMPEG) -i "$<" -c:a libopus -vbr 1 -b:a 64k "$@" %.m4a: %.wav - $(FFMPEG) -i $< -c:a libfdk_aac -vbr 1 $@ + $(FFMPEG) -i "$<" -c:a libfdk_aac -vbr 1 "$@" # === IMAGES === @@ -80,40 +80,40 @@ $(DUMP)/ui/ctc_strip.webp: $(DUMP)/ui/ctc_strip.png : %.webp: %.png - $(PNGQUANT) --force --speed 1 --ext .png $< - $(ZOPFLIPNG) -m -y $< $< - $(DEFLOPT) $< - $(DEFLUFF) < $< > $<.tmp - mv -f $<.tmp $< - $(CWEBP) -q 99 -m 6 $< -o $@ + $(PNGQUANT) --force --speed 1 --ext .png "$<" + $(ZOPFLIPNG) -m -y "$<" "$<" + $(DEFLOPT) "$<" + $(DEFLUFF) < "$<" > "$<".tmp + mv -f "$<".tmp "$<" + $(CWEBP) -q 99 -m 6 "$<" -o "$@" %.webp: %.jpg - $(CWEBP) -q 90 -m 6 $< -o $@ + $(CWEBP) -q 90 -m 6 "$<" -o "$@" www/favicon.ico: $(DUMP)/ui/icon.png - $(CONVERT) $< -resize 256x256 -transparent white $@ + $(CONVERT) "$<" -resize 256x256 -transparent white "$@" $(DUMP)/ui/bt-cf-unchecked.webp $(DUMP)/ui/bt-cf-checked.webp: %.webp: %.png - $(CONVERT) -trim $< $< - $(PNGQUANT) --force --speed 1 --ext .png $< - $(ZOPFLIPNG) -m -y $< $< - $(DEFLOPT) $< - $(DEFLUFF) < $< > $<.tmp - mv -f $<.tmp $< - $(CWEBP) -q 99 -m 6 $< -o $@ + $(CONVERT) -trim "$<" "$<" + $(PNGQUANT) --force --speed 1 --ext .png "$<" + $(ZOPFLIPNG) -m -y "$<" "$<" + $(DEFLOPT) "$<" + $(DEFLUFF) < "$<" > "$<".tmp + mv -f "$<".tmp "$<" + $(CWEBP) -q 99 -m 6 "$<" -o "$@" $(DUMP)/ui/ctc_strip-0.png: $(CTC_ANIM_SRC) - $(CONVERT) $< -crop 16x16 $(patsubst %.png,%*.png,$<) - $(PNGQUANT) --force --speed 1 --ext .png $< + $(CONVERT) "$<" -crop 16x16 $(patsubst %.png,%*.png,$<) + $(PNGQUANT) --force --speed 1 --ext .png "$<" $(DUMP)/ui/ctc_strip-%.png: $(CTC_ANIM_SRC) $(DUMP)/ui/ctc_strip-0.png - @touch $@ + @touch "$@" $(DUMP)/ui/ctc_anim.png: $(CTC_ANIM_TMP) - $(APNGASM) $@ $^ 3 100 + $(APNGASM) "$@" $^ 3 100 $(DUMP)/ui/ctc_anim.webp: $(CTC_ANIM_TMP_WEBP) - $(WEBPMUX) -frame $(subst $(SPACE), +30 -frame ,$^) +30 -loop 0 -o $@ + $(WEBPMUX) -frame $(subst $(SPACE), +30 -frame ,$^) +30 -loop 0 -o "$@" # === JS === @@ -122,7 +122,7 @@ JS := www/js/html5ks.js www/js/menu.js www/js/api.js www/js/play.js www/js/image js: www/js/all.min.js www/js/all.min.js: $(JS) - $(UGLIFYJS) $^ -o $@ -p 2 -m -c + $(UGLIFYJS) $^ -o "$@" --source-map "$@".map --source-map-url ./all.min.js.map -p 2 -m -c # === MISC === diff --git a/www/js/api.js b/www/js/api.js index ed357de..e029413 100644 --- a/www/js/api.js +++ b/www/js/api.js @@ -33,6 +33,38 @@ 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(); + el.play(); + return true; + } + } + return false; + }; + + _nextType(); + + 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,19 +87,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]; - return i; - } - } - }; - - var i = setNextType(0); - audio.addEventListener("playing", function playing() { audio.removeEventListener("playing", playing, false); if (fade) { @@ -75,21 +94,16 @@ 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.log("no audio formats supported"); - deferred.resolve(); - } - } else { - console.error("unknown audio error"); - deferred.resolve(); - } - }; - audio.load(); + audio.volume = fade ? 0 : volume; - audio.play(); + 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; }, @@ -115,7 +129,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); @@ -124,23 +138,15 @@ window.html5ks.api = new (function () { return deferred.resolve(); } - var types = { - "vp9": "vp9.webm", - "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(); @@ -159,9 +165,6 @@ window.html5ks.api = new (function () { } }; video.onended = done; - video.onerror = function () { - deferred.reject(this.error); - }; return deferred.promise; }, -- cgit v1.2.3-70-g09d2