Files
pathduck.github.io/vivaldia/vivaldia-main.js
T
2020-11-19 19:47:03 +01:00

656 lines
46 KiB
JavaScript
Executable File

/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */
"use strict";
var Messages;
! function(t) {
t[t.InitWorker = 0] = "InitWorker", t[t.WorkerInitialized = 1] = "WorkerInitialized", t[t.PlaySound = 2] = "PlaySound", t[t.StopSound = 3] = "StopSound", t[t.PlayMusic = 4] = "PlayMusic", t[t.StopMusic = 5] = "StopMusic", t[t.KeyUp = 6] = "KeyUp", t[t.KeyDown = 7] = "KeyDown", t[t.TouchDown = 8] = "TouchDown", t[t.TouchMove = 9] = "TouchMove", t[t.TouchEnd = 10] = "TouchEnd", t[t.LeftThumbStickDown = 11] = "LeftThumbStickDown", t[t.LeftThumbStickX = 12] = "LeftThumbStickX", t[t.LeftThumbStickY = 13] = "LeftThumbStickY", t[t.RightThumbStickDown = 14] = "RightThumbStickDown", t[t.RightThumbStickX = 15] = "RightThumbStickX", t[t.RightThumbStickY = 16] = "RightThumbStickY", t[t.MouseDown = 17] = "MouseDown", t[t.MouseUp = 18] = "MouseUp", t[t.MouseMove = 19] = "MouseMove", t[t.GamepadConnected = 20] = "GamepadConnected", t[t.GamepadDisconnected = 21] = "GamepadDisconnected", t[t.GamepadAxis = 22] = "GamepadAxis", t[t.GamepadButton = 23] = "GamepadButton", t[t.MuteSound = 24] = "MuteSound", t[t.UnmuteSound = 25] = "UnmuteSound", t[t.MuteMusic = 26] = "MuteMusic", t[t.UnmuteMusic = 27] = "UnmuteMusic", t[t.CanvasWasScaled = 28] = "CanvasWasScaled", t[t.SaveToRealStorage = 29] = "SaveToRealStorage"
}(Messages = Messages || {});
var GamepadInfo = function(t) {
this._gamepad = t, this.buttons = []
},
InputFrontEnd = function() {
function t() {}
return t.init = function() {
this._keyDown = {}, this._mousePositionX = 0, this._mousePositionY = 0, this._mouseButtonDown = {}, this._touchDown = !1, this._gamePads = {}, document.addEventListener("mousemove", this._mouseMoveEvent.bind(this)), document.addEventListener("keydown", this._keyDownEvent.bind(this)), document.addEventListener("keyup", this._keyUpEvent.bind(this)), document.addEventListener("mousedown", this._mouseDownEvent.bind(this)), document.addEventListener("mouseup", this._mouseUpEvent.bind(this)), document.addEventListener("touchstart", this._touchStartEvent.bind(this)), document.addEventListener("touchmove", this._touchMoveEvent.bind(this)), document.addEventListener("touchend", this._touchEndEvent.bind(this)), window.addEventListener("gamepadconnected", this._gamePadConnected.bind(this)), window.addEventListener("gamepaddisconnected", this._gamePadDisconnected.bind(this))
}, t._gamePadConnected = function(t) {
0 == Object.keys(this._gamePads).length && (this._gamePadLoopId = requestAnimationFrame(this._gamePadLoop.bind(this))), this._gamePads[t.gamepad.index] = new GamepadInfo(t.gamepad), KaolinMain._worker.postMessage([Messages.GamepadConnected, t.gamepad.index]), console.log(t.gamepad.id + " connected")
}, t._gamePadDisconnected = function(t) {
delete this._gamePads[t.gamepad.index], 0 == Object.keys(this._gamePads).length && cancelAnimationFrame(this._gamePadLoopId), KaolinMain._worker.postMessage([Messages.GamepadDisconnected, t.gamepad.index]), console.log(t.gamepad.id + " disconnected")
}, t._gamePadLoop = function() {
this._gamePadLoopId = requestAnimationFrame(this._gamePadLoop.bind(this));
for (var t = navigator.getGamepads(), e = 0; e < t.length; e++) {
var i = t[e];
if (i) {
for (var s = 0; s < i.axes.length; s++) KaolinMain._worker.postMessage([Messages.GamepadAxis, i.index, s, i.axes[s]]);
for (var n = 0; n < i.buttons.length; n++) {
var o = i.buttons[n].pressed;
(o && !this._gamePads[i.index].buttons[n] || !o && this._gamePads[i.index].buttons[n]) && (KaolinMain._worker.postMessage([Messages.GamepadButton, i.index, n, o]), this._gamePads[i.index].buttons[n] = o)
}
}
}
}, t._keyDownFunc = function(t) {
this._keyDown[t] || (this._keyDown[t] = !0, KaolinMain._worker && KaolinMain._worker.postMessage([Messages.KeyDown, t]))
}, t._keyDownEvent = function(t) {
this._keyDownFunc(t.code)
}, t._keyUpFunc = function(t) {
this._keyDown[t] = !1, KaolinMain._worker && KaolinMain._worker.postMessage([Messages.KeyUp, t])
}, t._keyUpEvent = function(t) {
this._keyUpFunc(t.code)
}, t._mouseMoveEvent = function(t) {
this._mousePositionX = t.offsetX, this._mousePositionY = t.offsetY, KaolinMain._worker && KaolinMain._worker.postMessage([Messages.MouseMove, this._mousePositionX, this._mousePositionY])
}, t._mouseDownEvent = function(t) {
this._mouseButtonDown[t.button] || (this._mouseButtonDown[t.button] = !0, KaolinMain._worker && KaolinMain._worker.postMessage([Messages.MouseDown, t.button]))
}, t._mouseUpEvent = function(t) {
this._mouseButtonDown[t.button] = !1, KaolinMain._worker && KaolinMain._worker.postMessage([Messages.MouseUp, t.button])
}, t._touchStartEvent = function(t) {
var e = t.changedTouches[t.changedTouches.length - 1];
this._mousePositionX = e.clientX - WindowManagerFrontEnd._canvas.offsetLeft, this._mousePositionY = e.clientY - WindowManagerFrontEnd._canvas.offsetTop, this._touchDown = !0, ControllerFrontEnd._mobileControllerVisible || ControllerFrontEnd.showTouchControls(), KaolinMain._worker && KaolinMain._worker.postMessage([Messages.TouchDown, this._mousePositionX, this._mousePositionY])
}, t._touchMoveEvent = function(t) {
var e = t.changedTouches[t.changedTouches.length - 1];
this._mousePositionX = e.clientX - WindowManagerFrontEnd._canvas.offsetLeft, this._mousePositionY = e.clientY - WindowManagerFrontEnd._canvas.offsetTop, KaolinMain._worker && KaolinMain._worker.postMessage([Messages.TouchMove, this._mousePositionX, this._mousePositionY])
}, t._touchEndEvent = function(t) {
var e = t.changedTouches[t.changedTouches.length - 1];
this._mousePositionX = e.clientX - WindowManagerFrontEnd._canvas.offsetLeft, this._mousePositionY = e.clientY - WindowManagerFrontEnd._canvas.offsetTop, this._touchDown = !1, KaolinMain._worker && KaolinMain._worker.postMessage([Messages.TouchEnd, this._mousePositionX, this._mousePositionY])
}, t
}(),
WindowManagerFrontEnd = function() {
function o() {}
return o.init = function(t, e) {
this._canvas = t, this._aspect = t.width / t.height, this._centerX = .5 * t.width, this._centerY = .5 * t.height, this._resize_delay = 100, this._scale = 1, this._isFullscreen = e, this._mobile = !1, this._viewWidth = 0, this._viewHeight = 0, this._isFullscreen && (o._do_resize(), window.addEventListener("resize", o._on_resize.bind(this)))
}, o.triggerMobileLayout = function() {
this._mobile = !0, this._on_resize()
}, o.setFullscreen = function(t) {
this._isFullscreen = t
}, o._do_resize = function() {
var t, e, i, s = window.innerWidth,
n = window.innerHeight;
0 < o._aspect - s / n ? (n = s / o._aspect, t = window.innerHeight - n, this._mobile && t < 270 && (s *= i = (n - (270 - t)) / n, n *= i)) : (s = n * o._aspect, e = window.innerWidth - s, this._mobile && e < 270 && (s *= i = (s - (270 - e)) / s, n *= i)), o._canvas.style.width = s + "px", o._canvas.style.height = n + "px", o._scale = s / o._canvas.width, KaolinMain._worker.postMessage([Messages.CanvasWasScaled, o._scale])
}, o._on_resize = function() {
clearTimeout(this._resize_event), this._resize_event = setTimeout(o._do_resize.bind(this), this._resize_delay)
}, o.shutDown = function() {
window.removeEventListener("resize", o._on_resize)
}, o
}(),
AudioLoader = function() {
function t() {}
return t.init = function(t, e, i) {
this._sounds = {}, this._music = {}, this._soundsLoaded = 0, this._soundsTotal = e.length + i.length;
for (var s = 0; s < e.length; s++) {
var n = e[s];
this._sounds[n] = this.createAudio(n)
}
for (s = 0; s < i.length; s++) {
n = i[s];
this._music[n] = this.createAudio(n)
}
this._loadedCallback = t
}, t.createAudio = function(t) {
var e = this,
i = new Audio;
return httpRequest(t, function(t) {
i.src = URL.createObjectURL(t), e._soundsLoaded++, e._runCallbackIfLoaded()
}, "blob"), i
}, t._runCallbackIfLoaded = function() {
this._soundsTotal == this._soundsLoaded && this._loadedCallback()
}, t
}();
(function() {
var w = void 0,
o = this;
function t(t, e) {
var i, s = t.split("."),
n = o;
s[0] in n || !n.execScript || n.execScript("var " + s[0]);
for (; s.length && (i = s.shift());) s.length || e === w ? n = n[i] ? n[i] : n[i] = {} : n[i] = e
}
var k = "undefined" != typeof Uint8Array && "undefined" != typeof Uint16Array && "undefined" != typeof Uint32Array && "undefined" != typeof DataView;
function A(t) {
for (var e, i, s, n, o, a, r, h, u, l = t.length, d = 0, c = Number.POSITIVE_INFINITY, _ = 0; _ < l; ++_) t[_] > d && (d = t[_]), t[_] < c && (c = t[_]);
for (e = 1 << d, i = new(k ? Uint32Array : Array)(e), s = 1, n = 0, o = 2; s <= d;) {
for (_ = 0; _ < l; ++_)
if (t[_] === s) {
for (r = n, h = a = 0; h < s; ++h) a = a << 1 | 1 & r, r >>= 1;
for (u = s << 16 | _, h = a; h < e; h += o) i[h] = u;
++n
}++ s, n <<= 1, o <<= 1
}
return [i, d, c]
}
function n(t, e) {
switch (this.g = [], this.h = 32768, this.d = this.f = this.a = this.l = 0, this.input = k ? new Uint8Array(t) : t, this.m = !1, this.i = E, this.r = !1, e ? (e.index && (this.a = e.index), e.bufferSize && (this.h = e.bufferSize), e.bufferType && (this.i = e.bufferType), e.resize && (this.r = e.resize)) : e = {}, this.i) {
case S:
this.b = 32768, this.c = new(k ? Uint8Array : Array)(32768 + this.h + 258);
break;
case E:
this.b = 0, this.c = new(k ? Uint8Array : Array)(this.h), this.e = this.z, this.n = this.v, this.j = this.w;
break;
default:
throw Error("invalid inflate mode")
}
}
var S = 0,
E = 1,
e = S,
i = E;
n.prototype.k = function() {
for (; !this.m;) {
var t = D(this, 3);
switch (1 & t && (this.m = !0), t >>>= 1) {
case 0:
var e = this.input,
i = this.a,
s = this.c,
n = this.b,
o = e.length,
a = w,
r = s.length,
h = w;
if (this.d = this.f = 0, o <= i + 1) throw Error("invalid uncompressed block header: LEN");
if (a = e[i++] | e[i++] << 8, o <= i + 1) throw Error("invalid uncompressed block header: NLEN");
if (a === ~(e[i++] | e[i++] << 8)) throw Error("invalid uncompressed block header: length verify");
if (i + a > e.length) throw Error("input buffer is broken");
switch (this.i) {
case S:
for (; n + a > s.length;) {
if (a -= h = r - n, k) s.set(e.subarray(i, i + h), n), n += h, i += h;
else
for (; h--;) s[n++] = e[i++];
this.b = n, s = this.e(), n = this.b
}
break;
case E:
for (; n + a > s.length;) s = this.e({
p: 2
});
break;
default:
throw Error("invalid inflate mode")
}
if (k) s.set(e.subarray(i, i + a), n), n += a, i += a;
else
for (; a--;) s[n++] = e[i++];
this.a = i, this.b = n, this.c = s;
break;
case 1:
this.j(L, T);
break;
case 2:
for (var u, l, d, c, _, g = D(this, 5) + 257, p = D(this, 5) + 1, f = D(this, 4) + 4, m = new(k ? Uint8Array : Array)(K.length), b = w, v = w, M = w, y = w, y = 0; y < f; ++y) m[K[y]] = D(this, 3);
if (!k)
for (y = f, f = m.length; y < f; ++y) m[K[y]] = 0;
for (u = A(m), b = new(k ? Uint8Array : Array)(g + p), y = 0, _ = g + p; y < _;) switch (c = U(this, u), c) {
case 16:
for (M = 3 + D(this, 2); M--;) b[y++] = v;
break;
case 17:
for (M = 3 + D(this, 3); M--;) b[y++] = 0;
v = 0;
break;
case 18:
for (M = 11 + D(this, 7); M--;) b[y++] = 0;
v = 0;
break;
default:
v = b[y++] = c
}
l = A(k ? b.subarray(0, g) : b.slice(0, g)), d = A(k ? b.subarray(g) : b.slice(g)), this.j(l, d);
break;
default:
throw Error("unknown BTYPE: " + t)
}
}
return this.n()
};
for (var s = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15], K = k ? new Uint16Array(s) : s, a = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 258, 258], u = k ? new Uint16Array(a) : a, r = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0], l = k ? new Uint8Array(r) : r, h = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577], d = k ? new Uint16Array(h) : h, c = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13], _ = k ? new Uint8Array(c) : c, g = new(k ? Uint8Array : Array)(288), p = 0, f = g.length; p < f; ++p) g[p] = p <= 143 ? 8 : p <= 255 ? 9 : p <= 279 ? 7 : 8;
for (var L = A(g), m = new(k ? Uint8Array : Array)(30), b = 0, v = m.length; b < v; ++b) m[b] = 5;
var T = A(m);
function D(t, e) {
for (var i, s = t.f, n = t.d, o = t.input, a = t.a, r = o.length; n < e;) {
if (r <= a) throw Error("input buffer is broken");
s |= o[a++] << n, n += 8
}
return i = s & (1 << e) - 1, t.f = s >>> e, t.d = n - e, t.a = a, i
}
function U(t, e) {
for (var i, s, n = t.f, o = t.d, a = t.input, r = t.a, h = a.length, u = e[0], l = e[1]; o < l && !(h <= r);) n |= a[r++] << o, o += 8;
if (o < (s = (i = u[n & (1 << l) - 1]) >>> 16)) throw Error("invalid code length: " + s);
return t.f = n >> s, t.d = o - s, t.a = r, 65535 & i
}
function M(t, e) {
var i, s;
if (this.input = t, this.a = 0, e ? (e.index && (this.a = e.index), e.verify && (this.A = e.verify)) : e = {}, i = t[this.a++], s = t[this.a++], (15 & i) !== y) throw Error("unsupported compression method");
if (this.method = y, 0 != ((i << 8) + s) % 31) throw Error("invalid fcheck flag:" + ((i << 8) + s) % 31);
if (32 & s) throw Error("fdict flag is not supported");
this.q = new n(t, {
index: this.a,
bufferSize: e.bufferSize,
bufferType: e.bufferType,
resize: e.resize
})
}
n.prototype.j = function(t, e) {
var i = this.c,
s = this.b;
this.o = t;
for (var n, o, a, r, h = i.length - 258; 256 !== (n = U(this, t));)
if (n < 256) h <= s && (this.b = s, i = this.e(), s = this.b), i[s++] = n;
else
for (r = u[o = n - 257], 0 < l[o] && (r += D(this, l[o])), n = U(this, e), a = d[n], 0 < _[n] && (a += D(this, _[n])), h <= s && (this.b = s, i = this.e(), s = this.b); r--;) i[s] = i[s++ - a];
for (; 8 <= this.d;) this.d -= 8, this.a--;
this.b = s
}, n.prototype.w = function(t, e) {
var i = this.c,
s = this.b;
this.o = t;
for (var n, o, a, r, h = i.length; 256 !== (n = U(this, t));)
if (n < 256) h <= s && (h = (i = this.e()).length), i[s++] = n;
else
for (r = u[o = n - 257], 0 < l[o] && (r += D(this, l[o])), n = U(this, e), a = d[n], 0 < _[n] && (a += D(this, _[n])), h < s + r && (h = (i = this.e()).length); r--;) i[s] = i[s++ - a];
for (; 8 <= this.d;) this.d -= 8, this.a--;
this.b = s
}, n.prototype.e = function() {
var t, e, i = new(k ? Uint8Array : Array)(this.b - 32768),
s = this.b - 32768,
n = this.c;
if (k) i.set(n.subarray(32768, i.length));
else
for (t = 0, e = i.length; t < e; ++t) i[t] = n[t + 32768];
if (this.g.push(i), this.l += i.length, k) n.set(n.subarray(s, 32768 + s));
else
for (t = 0; t < 32768; ++t) n[t] = n[s + t];
return this.b = 32768, n
}, n.prototype.z = function(t) {
var e, i, s, n = this.input.length / this.a + 1 | 0,
o = this.input,
a = this.c;
return t && ("number" == typeof t.p && (n = t.p), "number" == typeof t.u && (n += t.u)), i = n < 2 ? (s = (o.length - this.a) / this.o[2] / 2 * 258 | 0) < a.length ? a.length + s : a.length << 1 : a.length * n, k ? (e = new Uint8Array(i)).set(a) : e = a, this.c = e
}, n.prototype.n = function() {
var t, e, i, s, n, o = 0,
a = this.c,
r = this.g,
h = new(k ? Uint8Array : Array)(this.l + (this.b - 32768));
if (0 === r.length) return k ? this.c.subarray(32768, this.b) : this.c.slice(32768, this.b);
for (e = 0, i = r.length; e < i; ++e)
for (s = 0, n = (t = r[e]).length; s < n; ++s) h[o++] = t[s];
for (e = 32768, i = this.b; e < i; ++e) h[o++] = a[e];
return this.g = [], this.buffer = h
}, n.prototype.v = function() {
var t, e = this.b;
return k ? this.r ? (t = new Uint8Array(e)).set(this.c.subarray(0, e)) : t = this.c.subarray(0, e) : (this.c.length > e && (this.c.length = e), t = this.c), this.buffer = t
}, M.prototype.k = function() {
var t, e = this.input,
i = this.q.k();
if (this.a = this.q.a, this.A) {
t = (e[this.a++] << 24 | e[this.a++] << 16 | e[this.a++] << 8 | e[this.a++]) >>> 0;
var s = i;
if ("string" == typeof s) {
for (var n = s.split(""), o = 0, a = n.length; o < a; o++) n[o] = (255 & n[o].charCodeAt(0)) >>> 0;
s = n
}
for (var r, h = 1, u = 0, l = s.length, d = 0; 0 < l;) {
for (l -= r = 1024 < l ? 1024 : l; u += h += s[d++], --r;);
h %= 65521, u %= 65521
}
if (t != (u << 16 | h) >>> 0) throw Error("invalid adler-32 checksum")
}
return i
};
var y = 8;
t("Zlib.Inflate", M), t("Zlib.Inflate.prototype.decompress", M.prototype.k);
var C, P, I, F, x = {
ADAPTIVE: i,
BLOCK: e
};
if (Object.keys) C = Object.keys(x);
else
for (P in C = [], I = 0, x) C[I++] = P;
for (I = 0, F = C.length; I < F; ++I) t("Zlib.Inflate.BufferType." + (P = C[I]), x[P])
}).call(this);
var TMap = function(t, e, i, s, n, o, a, r, h, u, l, d, c, _, g, p, f, m, b, v) {
this._filename = t, this._version = e, this._tiledversion = i, this._orientation = s, this._renderorder = n, this._width = o, this._height = a, this._tilewidth = r, this._tileheight = h, this._infinite = u, this._nextlayerid = l, this._tilesets = d, this._layers = c, this._objectgroups = _, this._tileIds = g, this._tileTypes = p, this._animationsById = f, this._animationsByType = m, this._tilesetsByFirstId = b, this._tilesetIds = v
},
TMapTileset = function(t, e, i, s, n, o, a, r) {
this._firstgid = t, this._name = e, this._tilewidth = i, this._tileheight = s, this._tilecount = n, this._columns = o, this._image = a, this._tiles = r
},
TMapImage = function(t, e, i) {
this._source = t, this._width = e, this._height = i
},
TMapTile = function(t, e, i, s) {
this._id = t, this._type = e, this._image = i, this._animation = s
},
TMapAnimationFrame = function(t, e) {
this._id = t, this._duration = e
},
TMapObjectGroup = function(t, e, i, s, n, o) {
this._id = t, this._name = e, this._offsetx = i, this._offsety = s, this._opacity = n, this._objects = o
},
TMapObject = function(t, e, i, s, n, o) {
this._id = t, this._gid = e, this._x = i, this._y = s, this._width = n, this._height = o
},
TMapLayer = function(t, e, i, s, n) {
this._id = t, this._name = e, this._width = i, this._height = s, this._chunks = n
},
TMapChunk = function(t, e, i, s, n) {
this._x = t, this._y = e, this._width = i, this._height = s, this._tileNumbers = n
},
TMapParser = function() {
function t() {}
return t.load = function(t, i) {
var s = this;
this._url = t, this._tilesets = [], this._tileIds = [], this._tileTypes = {}, this._animationsById = {}, this._animationsByType = {}, this._tilesetsByFirstId = {}, this._tilesetIds = [], httpRequest(t, function(t) {
var e;
t ? (e = (new DOMParser).parseFromString(t, "application/xml"), s._mapNode = e.documentElement, s._tilesetsLoaded = 0, s._tilesetNodes = s._mapNode.querySelectorAll("tileset"), s._tilesetProcessCompleteCallback = function() {
i(s._createMap())
}, s._processTileset(0)) : i(null)
})
}, t._addToTileIds = function(t, e) {
-1 == t.indexOf(e) && t.push(e)
}, t._processTileset = function(f) {
var m = this,
b = new DOMParser,
v = this._tilesetNodes[f],
t = v.getAttribute("source");
t && httpRequest(t, function(t) {
var e, i, s, n = v.getAttribute("firstgid"),
c = n ? +n : -1,
o = b.parseFromString(t, "application/xml").documentElement,
a = o.getAttribute("name"),
r = o.getAttribute("tilewidth"),
h = o.getAttribute("tileheight"),
u = o.getAttribute("tilecount"),
l = o.getAttribute("columns"),
d = o.querySelector(":scope > image"),
_ = null;
d && (e = null == d ? void 0 : d.getAttribute("source"), i = null == d ? void 0 : d.getAttribute("width"), s = null == d ? void 0 : d.getAttribute("height"), _ = new TMapImage(e ? "assets/" + e : "", i ? +i : -1, s ? +s : -1));
var g = [];
o.querySelectorAll("tile").forEach(function(t) {
var e = t.getAttribute("id"),
i = t.getAttribute("type"),
s = t.querySelector(":scope > image"),
n = [],
o = e ? +e : -1,
a = c + o,
r = i || "";
i && (m._tileTypes[a] = r, m._addToTileIds(m._tileIds, a)), t.querySelectorAll("frame").forEach(function(t) {
var e = t.getAttribute("tileid"),
i = t.getAttribute("duration");
n.push(new TMapAnimationFrame(e ? +e + c : -1, i ? +i : -1))
});
var h, u, l, d = null;
s && (h = s.getAttribute("source"), u = s.getAttribute("width"), l = s.getAttribute("height"), d = new TMapImage(h ? "assets/" + h : "", u ? +u : -1, l ? +l : -1)), 0 < n.length && (r && (m._animationsByType[r] = n), m._animationsById[a] = n), g.push(new TMapTile(o, r, d, n))
});
var p = new TMapTileset(c, a || "", r ? +r : -1, h ? +h : -1, u ? +u : -1, l ? +l : -1, _, g);
m._tilesetIds.push(c), m._tilesetsByFirstId[c] = p, m._tilesets.push(p), m._tilesetsLoaded++, m._tilesetsLoaded == m._tilesetNodes.length ? m._tilesetProcessCompleteCallback() : m._processTileset(++f)
})
}, t._createMap = function() {
var p = this,
t = this._mapNode.getAttribute("version"),
e = this._mapNode.getAttribute("tiledversion"),
i = this._mapNode.getAttribute("orientation"),
s = this._mapNode.getAttribute("renderorder"),
n = this._mapNode.getAttribute("width"),
o = this._mapNode.getAttribute("height"),
a = this._mapNode.getAttribute("tilewidth"),
r = this._mapNode.getAttribute("tileheight"),
h = this._mapNode.getAttribute("infinite"),
u = this._mapNode.getAttribute("nextlayerid"),
l = [];
this._mapNode.querySelectorAll("objectgroup").forEach(function(t) {
var e = t.getAttribute("id"),
i = t.getAttribute("offsetx"),
s = t.getAttribute("offsety"),
n = t.getAttribute("name"),
o = t.getAttribute("opacity"),
h = [];
t.querySelectorAll("object").forEach(function(t) {
var e = t.getAttribute("id"),
i = t.getAttribute("gid"),
s = t.getAttribute("x"),
n = t.getAttribute("y"),
o = t.getAttribute("width"),
a = t.getAttribute("height"),
r = i ? +i : -1;
0 != r && p._addToTileIds(p._tileIds, r), h.push(new TMapObject(e ? +e : -1, r, s ? +s : -1, n ? +n : -1, o ? +o : -1, a ? +a : -1))
}), l.push(new TMapObjectGroup(e ? +e : -1, n || "", i ? +i : -1, s ? +s : -1, o ? +o : -1, h))
});
var d = [];
return this._mapNode.querySelectorAll("layer").forEach(function(t) {
var e = t.getAttribute("id"),
i = t.getAttribute("name"),
s = t.getAttribute("width"),
n = t.getAttribute("height"),
g = [];
t.querySelectorAll("chunk").forEach(function(t) {
var e, i = t.getAttribute("x"),
s = t.getAttribute("y"),
n = t.getAttribute("width"),
o = t.getAttribute("height"),
a = null === (e = t.textContent) || void 0 === e ? void 0 : e.trim();
if (a) {
for (var r = window.atob(a), h = new Array(r.length), u = 0; u < r.length; u++) h[u] = r.charCodeAt(u);
for (var l = new Zlib.Inflate(h).decompress(), d = [], c = 0; c < l.length; c += 4) {
var _ = Math.pow(1, 8) * l[c] + Math.pow(2, 8) * l[c + 1] + Math.pow(3, 8) * l[c + 2] + Math.pow(4, 8) * l[c + 3];
0 != _ && p._addToTileIds(p._tileIds, _), d.push(_)
}
g.push(new TMapChunk(i ? +i : -1, s ? +s : -1, n ? +n : -1, o ? +o : -1, d))
}
}), d.push(new TMapLayer(e ? +e : -1, i || "", s ? +s : -1, n ? +n : -1, g))
}), new TMap(this._url, t || "", e || "", i || "", s || "", n ? +n : -1, o ? +o : -1, a ? +a : -1, r ? +r : -1, h ? +h : -1, u ? +u : -1, this._tilesets, d, l, this._tileIds, this._tileTypes, this._animationsById, this._animationsByType, this._tilesetsByFirstId, this._tilesetIds)
}, t
}(),
VaultFrontEnd = function() {
function t() {}
return t.save = function(t, e) {
var i;
localStorage ? localStorage.setItem(t, e) : chrome && ((i = {})[t] = e, chrome.storage.local.set(i))
}, t.load = function(t) {
if (localStorage) {
var e = localStorage.getItem(t);
if (e) return e
} else if (chrome) {
var i = "";
return chrome.storage.local.get([t], function(t) {
i = t.key
}), "" != i ? i : null
}
return null
}, t
}();
function httpRequest(t, e, i) {
void 0 === i && (i = "");
var s = new XMLHttpRequest;
s.onload = function() {
e(s.response)
}, s.onerror = function() {
console.error("error trying to get url: " + t), e(null)
}, s.open("GET", t), s.responseType = i, s.send()
}
var CustomMessages, KaolinMainSetup = function(t, e) {
this._canvas = t, this._workerUrl = e, this.startVolume = 1, this.tiledMap = null, this.canPlaySoundOnStartUp = !1, this.vaultData = {}, this.messageCallback = null
},
KaolinMain = function() {
function t() {}
return t.init = function(o) {
this._worker = new Worker(o._workerUrl);
var t = o._canvas.transferControlToOffscreen();
this._worker.onmessage = function(t) {
o.messageCallback && o.messageCallback(t);
var e = t.data[0],
i = t.data[1],
s = t.data[2];
switch (e) {
case Messages.WorkerInitialized:
WindowManagerFrontEnd.init(o._canvas, !0), InputFrontEnd.init();
break;
case Messages.PlaySound:
AudioLoader._sounds[i].currentTime = 0, AudioLoader._sounds[i].play();
break;
case Messages.StopSound:
AudioLoader._sounds[i].currentTime = 0, AudioLoader._sounds[i].pause();
break;
case Messages.PlayMusic:
AudioLoader._music[i].currentTime = 0, AudioLoader._music[i].play();
break;
case Messages.StopMusic:
AudioLoader._music[i].currentTime = 0, AudioLoader._music[i].pause();
break;
case Messages.SaveToRealStorage:
VaultFrontEnd.save(i, s);
break;
case Messages.MuteSound:
for (var n in AudioLoader._sounds) {
AudioLoader._sounds[n].volume = 0
}
break;
case Messages.UnmuteSound:
for (var n in AudioLoader._sounds) {
AudioLoader._sounds[n].volume = 1
}
break;
case Messages.MuteMusic:
for (var n in AudioLoader._music) {
AudioLoader._music[n].volume = 0
}
break;
case Messages.UnmuteMusic:
for (var n in AudioLoader._music) {
AudioLoader._music[n].volume = 1
}
}
}, this._worker.postMessage([Messages.InitWorker, {
canvas: t,
canPlaySoundOnStartUp: o.canPlaySoundOnStartUp,
locationHref: location.href,
tiledMap: o.tiledMap,
vaultData: o.vaultData
}], [t])
}, t
}(),
ControllerFrontEnd = function() {
function t() {}
return t.init = function() {
this._mobileControllerVisible = !1, this._touchStartX = 0, this._touchStartY = 0, this._touchCurrentX = 0, this._touchCurrentY = 0;
var t = document.querySelector("#select_controller1");
t && (this._buttonSelectController1Element = t, this._buttonSelectController1Element.removeEventListener("touchstart", this._showController1.bind(this)), this._buttonSelectController1Element.addEventListener("touchstart", this._showController1.bind(this)));
var e = document.querySelector("#select_controller2");
e && (this._buttonSelectController2Element = e, this._buttonSelectController2Element.removeEventListener("touchstart", this._showController2.bind(this)), this._buttonSelectController2Element.addEventListener("touchstart", this._showController2.bind(this)));
var i = document.querySelector("#button_stick1");
i && ((this._buttonStick1Element = i).removeEventListener("touchstart", this._buttonStickStart.bind(this)), i.addEventListener("touchstart", this._buttonStickStart.bind(this)), i.removeEventListener("touchmove", this._buttonStickMove.bind(this)), i.addEventListener("touchmove", this._buttonStickMove.bind(this)), i.removeEventListener("touchend", this._buttonStickEnd.bind(this)), i.addEventListener("touchend", this._buttonStickEnd.bind(this)));
var s = document.querySelector("#button_stick2");
s && ((this._buttonStick2Element = s).removeEventListener("touchstart", this._buttonStickStart.bind(this)), s.addEventListener("touchstart", this._buttonStickStart.bind(this)), s.removeEventListener("touchmove", this._buttonStickMove.bind(this)), s.addEventListener("touchmove", this._buttonStickMove.bind(this)), s.removeEventListener("touchend", this._buttonStickEnd.bind(this)), s.addEventListener("touchend", this._buttonStickEnd.bind(this)));
var n = document.querySelector("#button_leftright");
n && ((this._buttonLeftRightElement = n).removeEventListener("touchstart", this._buttonStickStart.bind(this)), n.addEventListener("touchstart", this._buttonStickStart.bind(this)), n.removeEventListener("touchmove", this._buttonStickMove.bind(this)), n.addEventListener("touchmove", this._buttonStickMove.bind(this)), n.removeEventListener("touchend", this._buttonStickEnd.bind(this)), n.addEventListener("touchend", this._buttonStickEnd.bind(this)));
var o = document.querySelector("#button_action1");
o && ((this._buttonAction1Element = o).removeEventListener("touchstart", this._buttonAction1Pressed), o.addEventListener("touchstart", this._buttonAction1Pressed), o.removeEventListener("touchend", this._buttonAction1Released), o.addEventListener("touchend", this._buttonAction1Released));
var a = document.querySelector("#button_action2");
a && ((this._buttonAction2Element = a).removeEventListener("touchstart", this._buttonAction2Pressed), a.addEventListener("touchstart", this._buttonAction2Pressed), a.removeEventListener("touchend", this._buttonAction2Released), a.addEventListener("touchend", this._buttonAction2Released));
var r = document.querySelector("#button_action3");
r && ((this._buttonAction3Element = r).removeEventListener("touchstart", this._buttonAction3Pressed), r.addEventListener("touchstart", this._buttonAction3Pressed), r.removeEventListener("touchend", this._buttonAction3Released), r.addEventListener("touchend", this._buttonAction3Released));
var h = document.querySelector("#button_up");
h && ((this._buttonUpElement = h).removeEventListener("touchstart", this._buttonUpPressed), h.addEventListener("touchstart", this._buttonUpPressed), h.removeEventListener("touchend", this._buttonUpReleased), h.addEventListener("touchend", this._buttonUpReleased))
}, t.showTouchControls = function() {
this._mobileControllerVisible = !0, WindowManagerFrontEnd.triggerMobileLayout();
var t = VaultFrontEnd.load("selected-mobile-controller");
if (t) switch (t) {
case "1":
this._showController1();
break;
case "2":
this._showController2()
} else this._showController1()
}, t._showController1 = function() {
this._buttonLeftRightElement.style.display = "inline-block", this._buttonUpElement.style.display = "inline-block", this._buttonAction1Element.style.display = "inline-block", this._buttonAction2Element.style.display = "inline-block", this._buttonAction3Element.style.display = "inline-block", this._buttonSelectController2Element.style.display = "inline-block", this._buttonStick1Element.style.display = "none", this._buttonStick2Element.style.display = "none", this._buttonSelectController1Element.style.display = "none", VaultFrontEnd.save("selected-mobile-controller", "1")
}, t._showController2 = function() {
this._buttonLeftRightElement.style.display = "none", this._buttonUpElement.style.display = "none", this._buttonAction1Element.style.display = "none", this._buttonAction2Element.style.display = "none", this._buttonAction3Element.style.display = "none", this._buttonSelectController2Element.style.display = "none", this._buttonStick1Element.style.display = "inline-block", this._buttonStick2Element.style.display = "inline-block", this._buttonSelectController1Element.style.display = "inline-block", VaultFrontEnd.save("selected-mobile-controller", "2")
}, t._buttonStickStart = function(t) {
t.preventDefault();
var e, i, s, n, o = t.targetTouches[0],
a = null == t ? void 0 : t.target;
a && (this._touchStartX = o.clientX, this._touchStartY = o.clientY, e = .5 * a.clientWidth, i = .5 * a.clientHeight, s = e + a.offsetLeft, n = i + a.offsetTop, this._touchStartX, this._touchStartY, "button_stick1" == a.id ? (KaolinMain._worker.postMessage([Messages.LeftThumbStickDown, !0]), this._buttonStickMove(t)) : "button_stick2" == a.id ? (KaolinMain._worker.postMessage([Messages.RightThumbStickDown, !0]), this._buttonStickMove(t)) : "button_leftright" == a.id && (KaolinMain._worker.postMessage([Messages.LeftThumbStickDown, !0]), this._buttonStickMove(t)))
}, t.calcAngleDegrees = function(t, e) {
return 180 * Math.atan2(e, t) / Math.PI
}, t._buttonStickMove = function(t) {
t.preventDefault();
var e, i, s, n, o, a, r, h, u, l = t.targetTouches[0],
d = null == t ? void 0 : t.target;
d && (this._touchCurrentX = l.clientX, this._touchCurrentY = l.clientY, e = .5 * d.clientWidth, i = .5 * d.clientHeight, s = e + d.offsetLeft, n = i + d.offsetTop, o = (this._touchCurrentX - s) / e, a = (this._touchCurrentY - n) / i, "button_stick1" == d.id ? (this._moveLeftRight(o), .2 < a ? KaolinMain._worker.postMessage([Messages.KeyDown, "KeyS"]) : KaolinMain._worker.postMessage([Messages.KeyUp, "KeyS"]), a < -.3 ? KaolinMain._worker.postMessage([Messages.KeyDown, "KeyW"]) : -.2 < a && KaolinMain._worker.postMessage([Messages.KeyUp, "KeyW"])) : "button_stick2" == d.id ? (r = a - .1, h = .1 + o, 0 < (u = Math.atan2(r, h) / Math.PI) && u <= .77 ? (KaolinMain._worker.postMessage([Messages.KeyDown, "KeyM"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyN"])) : .77 < u || u <= -.5 ? (KaolinMain._worker.postMessage([Messages.KeyDown, "KeyN"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyM"])) : (KaolinMain._worker.postMessage([Messages.KeyDown, "KeyM"]), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyN"]))) : "button_leftright" == d.id && (this._moveLeftRight(o), 0 < a ? KaolinMain._worker.postMessage([Messages.KeyDown, "KeyS"]) : KaolinMain._worker.postMessage([Messages.KeyUp, "KeyS"])))
}, t._moveLeftRight = function(t) {
var e = 1.4 * t;
t <= -.1 ? (KaolinMain._worker.postMessage([Messages.KeyDown, "KeyA"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyD"])) : .1 <= t ? (KaolinMain._worker.postMessage([Messages.KeyDown, "KeyD"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyA"])) : e = 0, KaolinMain._worker.postMessage([Messages.LeftThumbStickX, e])
}, t._buttonStickEnd = function(t) {
t.preventDefault();
t.targetTouches[0];
var e = null == t ? void 0 : t.target;
e && ("button_stick1" == e.id ? (KaolinMain._worker.postMessage([Messages.LeftThumbStickDown, !1]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyW"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyS"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyA"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyD"])) : "button_stick2" == e.id ? (KaolinMain._worker.postMessage([Messages.RightThumbStickDown, !1]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyN"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyM"])) : "button_leftright" == e.id && (KaolinMain._worker.postMessage([Messages.LeftThumbStickDown, !1]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyA"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyD"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyS"])))
}, t._buttonAction1Pressed = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyM"])
}, t._buttonAction1Released = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyM"])
}, t._buttonAction2Pressed = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyN"]), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyM"])
}, t._buttonAction2Released = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyN"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyM"])
}, t._buttonAction3Pressed = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyN"])
}, t._buttonAction3Released = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyN"])
}, t._buttonDownPressed = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyS"])
}, t._buttonDownReleased = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyS"])
}, t._buttonUpPressed = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyDown, "KeyW"]), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyS"])
}, t._buttonUpReleased = function(t) {
t.preventDefault(), KaolinMain._worker.postMessage([Messages.KeyUp, "KeyW"])
}, t
}();
! function(t) {
t[t.VivaldiNameSpaceFound = 100] = "VivaldiNameSpaceFound", t[t.VivaldiaWorkerInitialized = 101] = "VivaldiaWorkerInitialized", t[t.RequestToScreenshot = 102] = "RequestToScreenshot"
}(CustomMessages = CustomMessages || {});
var VivaldiaMain = function() {
function s() {}
return s.init = function() {
var t = this;
this._vivaldiNamespace = "undefined" != typeof vivaldi ? vivaldi : null;
var e, i, s = document.querySelector("#message");
s && (this._message = s, (e = document.querySelector("canvas")) ? (this._canvas = e).transferControlToOffscreen ? (this._fullScreenIsOn = !1, null != (i = document.querySelector("#button_fullscreen")) && i.addEventListener("click", function() {
t._fullScreenIsOn = !t._fullScreenIsOn, t._fullScreenIsOn ? document.documentElement.requestFullscreen() : document.exitFullscreen()
}), this._message.innerHTML = "Loading audio...", ControllerFrontEnd.init(), AudioLoader.init(this._audioLoaded.bind(this), ["assets/Audio/hit1.ogg", "assets/Audio/powerup1.ogg", "assets/Audio/shoot1.ogg", "assets/Audio/shoot2.ogg", "assets/Audio/jump1.ogg", "assets/Audio/beep1.ogg", "assets/Audio/crash1.ogg", "assets/Audio/explosion1.ogg", "assets/Audio/coin1.ogg", "assets/Audio/silent.ogg", "assets/Audio/introHit.ogg", "assets/Audio/glitch1.ogg", "assets/Audio/glitch2.ogg", "assets/Audio/glitch3.ogg", "assets/Audio/glimmer.ogg", "assets/Audio/whoosh.ogg", "assets/Audio/tonyYay.ogg", "assets/Audio/deflect1.ogg", "assets/Audio/teleport1.ogg"], ["assets/Audio/music1.ogg"])) : s.innerHTML = 'Your browser does not support OffscreenCanvas. Check the browser support <a href="https://caniuse.com/#feat=offscreencanvas">here</a>' : this._message.innerHTML = "Canvas not found")
}, s._audioLoaded = function() {
var i = this;
AudioLoader._music["assets/Audio/music1.ogg"].loop = !0, this._message.innerHTML = "Loading map...", this._currentMap = "map.tmx";
var t = location.href.split("map=");
1 < t.length && (t = t[1].split(".tmx"))[0] && (this._currentMap = t[0] + ".tmx"), TMapParser.load(this._currentMap, function(e) {
e ? (i._highScoreKey = "high_score_" + i._currentMap, AudioLoader._sounds["assets/Audio/silent.ogg"].play().then(function(t) {
i._startGame(e, !0)
}).catch(function(t) {
i._startGame(e, !1)
})) : s._message.innerHTML = "Can't find map: " + i._currentMap
})
}, s._startGame = function(t, e) {
var i = new KaolinMainSetup(this._canvas, "vivaldia-worker.js");
i.tiledMap = t, i.vaultData["sfx-volume"] = VaultFrontEnd.load("sfx-volume"), i.vaultData["music-volume"] = VaultFrontEnd.load("music-volume"), i.vaultData[this._highScoreKey] = VaultFrontEnd.load(this._highScoreKey), i.canPlaySoundOnStartUp = e, i.messageCallback = this._messageCallback.bind(this), KaolinMain.init(i), s._message.innerHTML = "Initializing game..."
}, s._messageCallback = function(t) {
var e;
switch (t.data[0]) {
case CustomMessages.VivaldiaWorkerInitialized:
null !== (e = this._message.parentNode) && void 0 !== e && e.removeChild(this._message), this._canvas.style.display = "inline-block", this._vivaldiNamespace && this._vivaldiNamespace.thumbnails && KaolinMain._worker.postMessage([CustomMessages.VivaldiNameSpaceFound]);
break;
case CustomMessages.RequestToScreenshot:
vivaldi.thumbnails.captureTab(0, {
encodeFormat: "png",
fullPage: !0,
height: window.innerHeight,
saveToDisk: !0,
showFileInPath: !0
}, function(t) {})
}
}, s
}();
VivaldiaMain.init();