UNPKG

ngx-spine

Version:

[![Build Status](https://travis-ci.org/PoiScript/ngx-spine.svg?branch=master)](https://travis-ci.org/PoiScript/ngx-spine)

1,622 lines (1,614 loc) 832 kB
import { EventEmitter, Component, ChangeDetectionStrategy, Input as Input$1, ViewChild, ElementRef, Output, NgModule } from '@angular/core'; import { __extends, __values } from 'tslib'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * *************************************************************************** * Spine Runtimes License Agreement * Last updated May 1, 2019. Replaces all prior versions. * * Copyright (c) 2013-2019, Esoteric Software LLC * * Integration of the Spine Runtimes into software or otherwise creating * derivative works of the Spine Runtimes is permitted under the terms and * conditions of Section 2 of the Spine Editor License Agreement: * http://esotericsoftware.com/spine-editor-license * * Otherwise, it is permitted to integrate the Spine Runtimes into software * or otherwise create derivative works of the Spine Runtimes (collectively, * "Products"), provided that each user of the Products must obtain their own * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *************************************************************************** * @abstract */ var /** * *************************************************************************** * Spine Runtimes License Agreement * Last updated May 1, 2019. Replaces all prior versions. * * Copyright (c) 2013-2019, Esoteric Software LLC * * Integration of the Spine Runtimes into software or otherwise creating * derivative works of the Spine Runtimes is permitted under the terms and * conditions of Section 2 of the Spine Editor License Agreement: * http://esotericsoftware.com/spine-editor-license * * Otherwise, it is permitted to integrate the Spine Runtimes into software * or otherwise create derivative works of the Spine Runtimes (collectively, * "Products"), provided that each user of the Products must obtain their own * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *************************************************************************** * @abstract */ Texture = /** @class */ (function () { function Texture(image) { this._image = image; } /** * @return {?} */ Texture.prototype.getImage = /** * @return {?} */ function () { return this._image; }; /** * @param {?} text * @return {?} */ Texture.filterFromString = /** * @param {?} text * @return {?} */ function (text) { switch (text.toLowerCase()) { case "nearest": return TextureFilter.Nearest; case "linear": return TextureFilter.Linear; case "mipmap": return TextureFilter.MipMap; case "mipmapnearestnearest": return TextureFilter.MipMapNearestNearest; case "mipmaplinearnearest": return TextureFilter.MipMapLinearNearest; case "mipmapnearestlinear": return TextureFilter.MipMapNearestLinear; case "mipmaplinearlinear": return TextureFilter.MipMapLinearLinear; default: throw new Error("Unknown texture filter " + text); } }; /** * @param {?} text * @return {?} */ Texture.wrapFromString = /** * @param {?} text * @return {?} */ function (text) { switch (text.toLowerCase()) { case "mirroredtepeat": return TextureWrap.MirroredRepeat; case "clamptoedge": return TextureWrap.ClampToEdge; case "repeat": return TextureWrap.Repeat; default: throw new Error("Unknown texture wrap " + text); } }; return Texture; }()); if (false) { /** * @type {?} * @protected */ Texture.prototype._image; /** * @abstract * @param {?} minFilter * @param {?} magFilter * @return {?} */ Texture.prototype.setFilters = function (minFilter, magFilter) { }; /** * @abstract * @param {?} uWrap * @param {?} vWrap * @return {?} */ Texture.prototype.setWraps = function (uWrap, vWrap) { }; /** * @abstract * @return {?} */ Texture.prototype.dispose = function () { }; } /** @enum {number} */ var TextureFilter = { Nearest: 9728, Linear: 9729, MipMap: 9987, MipMapNearestNearest: 9984, MipMapLinearNearest: 9985, MipMapNearestLinear: 9986, MipMapLinearLinear: 9987 // WebGLRenderingContext.LINEAR_MIPMAP_LINEAR , }; TextureFilter[TextureFilter.Nearest] = 'Nearest'; TextureFilter[TextureFilter.Linear] = 'Linear'; TextureFilter[TextureFilter.MipMap] = 'MipMap'; TextureFilter[TextureFilter.MipMapNearestNearest] = 'MipMapNearestNearest'; TextureFilter[TextureFilter.MipMapLinearNearest] = 'MipMapLinearNearest'; TextureFilter[TextureFilter.MipMapNearestLinear] = 'MipMapNearestLinear'; TextureFilter[TextureFilter.MipMapLinearLinear] = 'MipMapLinearLinear'; /** @enum {number} */ var TextureWrap = { MirroredRepeat: 33648, ClampToEdge: 33071, Repeat: 10497 // WebGLRenderingContext.REPEAT , }; TextureWrap[TextureWrap.MirroredRepeat] = 'MirroredRepeat'; TextureWrap[TextureWrap.ClampToEdge] = 'ClampToEdge'; TextureWrap[TextureWrap.Repeat] = 'Repeat'; var TextureRegion = /** @class */ (function () { function TextureRegion() { this.u = 0; this.v = 0; this.u2 = 0; this.v2 = 0; this.width = 0; this.height = 0; this.rotate = false; this.offsetX = 0; this.offsetY = 0; this.originalWidth = 0; this.originalHeight = 0; } return TextureRegion; }()); if (false) { /** @type {?} */ TextureRegion.prototype.renderObject; /** @type {?} */ TextureRegion.prototype.u; /** @type {?} */ TextureRegion.prototype.v; /** @type {?} */ TextureRegion.prototype.u2; /** @type {?} */ TextureRegion.prototype.v2; /** @type {?} */ TextureRegion.prototype.width; /** @type {?} */ TextureRegion.prototype.height; /** @type {?} */ TextureRegion.prototype.rotate; /** @type {?} */ TextureRegion.prototype.offsetX; /** @type {?} */ TextureRegion.prototype.offsetY; /** @type {?} */ TextureRegion.prototype.originalWidth; /** @type {?} */ TextureRegion.prototype.originalHeight; } var FakeTexture = /** @class */ (function (_super) { __extends(FakeTexture, _super); function FakeTexture() { return _super !== null && _super.apply(this, arguments) || this; } /** * @param {?} minFilter * @param {?} magFilter * @return {?} */ FakeTexture.prototype.setFilters = /** * @param {?} minFilter * @param {?} magFilter * @return {?} */ function (minFilter, magFilter) { }; /** * @param {?} uWrap * @param {?} vWrap * @return {?} */ FakeTexture.prototype.setWraps = /** * @param {?} uWrap * @param {?} vWrap * @return {?} */ function (uWrap, vWrap) { }; /** * @return {?} */ FakeTexture.prototype.dispose = /** * @return {?} */ function () { }; return FakeTexture; }(Texture)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var TextureAtlas = /** @class */ (function () { function TextureAtlas(atlasText, textureLoader) { this.pages = new Array(); this.regions = new Array(); this.load(atlasText, textureLoader); } /** * @private * @param {?} atlasText * @param {?} textureLoader * @return {?} */ TextureAtlas.prototype.load = /** * @private * @param {?} atlasText * @param {?} textureLoader * @return {?} */ function (atlasText, textureLoader) { if (textureLoader == null) throw new Error("textureLoader cannot be null."); /** @type {?} */ var reader = new TextureAtlasReader(atlasText); /** @type {?} */ var tuple = new Array(4); /** @type {?} */ var page = null; while (true) { /** @type {?} */ var line = reader.readLine(); if (line == null) break; line = line.trim(); if (line.length == 0) page = null; else if (!page) { page = new TextureAtlasPage(); page.name = line; if (reader.readTuple(tuple) == 2) { // size is only optional for an atlas packed with an old TexturePacker. page.width = parseInt(tuple[0]); page.height = parseInt(tuple[1]); reader.readTuple(tuple); } // page.format = Format[tuple[0]]; we don't need format in WebGL reader.readTuple(tuple); page.minFilter = Texture.filterFromString(tuple[0]); page.magFilter = Texture.filterFromString(tuple[1]); /** @type {?} */ var direction = reader.readValue(); page.uWrap = TextureWrap.ClampToEdge; page.vWrap = TextureWrap.ClampToEdge; if (direction == "x") page.uWrap = TextureWrap.Repeat; else if (direction == "y") page.vWrap = TextureWrap.Repeat; else if (direction == "xy") page.uWrap = page.vWrap = TextureWrap.Repeat; page.texture = textureLoader(line); page.texture.setFilters(page.minFilter, page.magFilter); page.texture.setWraps(page.uWrap, page.vWrap); page.width = page.texture.getImage().width; page.height = page.texture.getImage().height; this.pages.push(page); } else { /** @type {?} */ var region = new TextureAtlasRegion(); region.name = line; region.page = page; /** @type {?} */ var rotateValue = reader.readValue(); if (rotateValue.toLocaleLowerCase() == "true") { region.degrees = 90; } else if (rotateValue.toLocaleLowerCase() == "false") { region.degrees = 0; } else { region.degrees = parseFloat(rotateValue); } region.rotate = region.degrees == 90; reader.readTuple(tuple); /** @type {?} */ var x = parseInt(tuple[0]); /** @type {?} */ var y = parseInt(tuple[1]); reader.readTuple(tuple); /** @type {?} */ var width = parseInt(tuple[0]); /** @type {?} */ var height = parseInt(tuple[1]); region.u = x / page.width; region.v = y / page.height; if (region.rotate) { region.u2 = (x + height) / page.width; region.v2 = (y + width) / page.height; } else { region.u2 = (x + width) / page.width; region.v2 = (y + height) / page.height; } region.x = x; region.y = y; region.width = Math.abs(width); region.height = Math.abs(height); if (reader.readTuple(tuple) == 4) { // split is optional // region.splits = new Vector.<int>(parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])); if (reader.readTuple(tuple) == 4) { // pad is optional, but only present with splits //region.pads = Vector.<int>(parseInt(tuple[0]), parseInt(tuple[1]), parseInt(tuple[2]), parseInt(tuple[3])); reader.readTuple(tuple); } } region.originalWidth = parseInt(tuple[0]); region.originalHeight = parseInt(tuple[1]); reader.readTuple(tuple); region.offsetX = parseInt(tuple[0]); region.offsetY = parseInt(tuple[1]); region.index = parseInt(reader.readValue()); region.texture = page.texture; this.regions.push(region); } } }; /** * @param {?} name * @return {?} */ TextureAtlas.prototype.findRegion = /** * @param {?} name * @return {?} */ function (name) { for (var i = 0; i < this.regions.length; i++) { if (this.regions[i].name == name) { return this.regions[i]; } } return null; }; /** * @return {?} */ TextureAtlas.prototype.dispose = /** * @return {?} */ function () { for (var i = 0; i < this.pages.length; i++) { this.pages[i].texture.dispose(); } }; return TextureAtlas; }()); if (false) { /** @type {?} */ TextureAtlas.prototype.pages; /** @type {?} */ TextureAtlas.prototype.regions; } var TextureAtlasReader = /** @class */ (function () { function TextureAtlasReader(text) { this.index = 0; this.lines = text.split(/\r\n|\r|\n/); } /** * @return {?} */ TextureAtlasReader.prototype.readLine = /** * @return {?} */ function () { if (this.index >= this.lines.length) return null; return this.lines[this.index++]; }; /** * @return {?} */ TextureAtlasReader.prototype.readValue = /** * @return {?} */ function () { /** @type {?} */ var line = this.readLine(); /** @type {?} */ var colon = line.indexOf(":"); if (colon == -1) throw new Error("Invalid line: " + line); return line.substring(colon + 1).trim(); }; /** * @param {?} tuple * @return {?} */ TextureAtlasReader.prototype.readTuple = /** * @param {?} tuple * @return {?} */ function (tuple) { /** @type {?} */ var line = this.readLine(); /** @type {?} */ var colon = line.indexOf(":"); if (colon == -1) throw new Error("Invalid line: " + line); /** @type {?} */ var i = 0; /** @type {?} */ var lastMatch = colon + 1; for (; i < 3; i++) { /** @type {?} */ var comma = line.indexOf(",", lastMatch); if (comma == -1) break; tuple[i] = line.substr(lastMatch, comma - lastMatch).trim(); lastMatch = comma + 1; } tuple[i] = line.substring(lastMatch).trim(); return i + 1; }; return TextureAtlasReader; }()); if (false) { /** @type {?} */ TextureAtlasReader.prototype.lines; /** @type {?} */ TextureAtlasReader.prototype.index; } var TextureAtlasPage = /** @class */ (function () { function TextureAtlasPage() { } return TextureAtlasPage; }()); if (false) { /** @type {?} */ TextureAtlasPage.prototype.name; /** @type {?} */ TextureAtlasPage.prototype.minFilter; /** @type {?} */ TextureAtlasPage.prototype.magFilter; /** @type {?} */ TextureAtlasPage.prototype.uWrap; /** @type {?} */ TextureAtlasPage.prototype.vWrap; /** @type {?} */ TextureAtlasPage.prototype.texture; /** @type {?} */ TextureAtlasPage.prototype.width; /** @type {?} */ TextureAtlasPage.prototype.height; } var TextureAtlasRegion = /** @class */ (function (_super) { __extends(TextureAtlasRegion, _super); function TextureAtlasRegion() { return _super !== null && _super.apply(this, arguments) || this; } return TextureAtlasRegion; }(TextureRegion)); if (false) { /** @type {?} */ TextureAtlasRegion.prototype.page; /** @type {?} */ TextureAtlasRegion.prototype.name; /** @type {?} */ TextureAtlasRegion.prototype.x; /** @type {?} */ TextureAtlasRegion.prototype.y; /** @type {?} */ TextureAtlasRegion.prototype.index; /** @type {?} */ TextureAtlasRegion.prototype.rotate; /** @type {?} */ TextureAtlasRegion.prototype.degrees; /** @type {?} */ TextureAtlasRegion.prototype.texture; /** @type {?} */ TextureAtlasRegion.prototype.u; /** @type {?} */ TextureAtlasRegion.prototype.v; /** @type {?} */ TextureAtlasRegion.prototype.u2; /** @type {?} */ TextureAtlasRegion.prototype.v2; /** @type {?} */ TextureAtlasRegion.prototype.width; /** @type {?} */ TextureAtlasRegion.prototype.height; /** @type {?} */ TextureAtlasRegion.prototype.originalWidth; /** @type {?} */ TextureAtlasRegion.prototype.originalHeight; /** @type {?} */ TextureAtlasRegion.prototype.offsetX; /** @type {?} */ TextureAtlasRegion.prototype.offsetY; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var AssetManager = /** @class */ (function () { function AssetManager(textureLoader, pathPrefix) { if (pathPrefix === void 0) { pathPrefix = ""; } this.assets = {}; this.errors = {}; this.toLoad = 0; this.loaded = 0; this.textureLoader = textureLoader; this.pathPrefix = pathPrefix; } /** * @private * @param {?} url * @param {?} success * @param {?} error * @return {?} */ AssetManager.downloadText = /** * @private * @param {?} url * @param {?} success * @param {?} error * @return {?} */ function (url, success, error) { /** @type {?} */ var request = new XMLHttpRequest(); request.open("GET", url, true); request.onload = (/** * @return {?} */ function () { if (request.status == 200) { success(request.responseText); } else { error(request.status, request.responseText); } }); request.onerror = (/** * @return {?} */ function () { error(request.status, request.responseText); }); request.send(); }; /** * @private * @param {?} url * @param {?} success * @param {?} error * @return {?} */ AssetManager.downloadBinary = /** * @private * @param {?} url * @param {?} success * @param {?} error * @return {?} */ function (url, success, error) { /** @type {?} */ var request = new XMLHttpRequest(); request.open("GET", url, true); request.responseType = "arraybuffer"; request.onload = (/** * @return {?} */ function () { if (request.status == 200) { success(new Uint8Array((/** @type {?} */ (request.response)))); } else { error(request.status, request.responseText); } }); request.onerror = (/** * @return {?} */ function () { error(request.status, request.responseText); }); request.send(); }; /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ AssetManager.prototype.loadBinary = /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ function (path, success, error) { var _this = this; if (success === void 0) { success = null; } if (error === void 0) { error = null; } path = this.pathPrefix + path; this.toLoad++; AssetManager.downloadBinary(path, (/** * @param {?} data * @return {?} */ function (data) { _this.assets[path] = data; if (success) success(path, data); _this.toLoad--; _this.loaded++; }), (/** * @param {?} state * @param {?} responseText * @return {?} */ function (state, responseText) { _this.errors[path] = "Couldn't load binary " + path + ": status " + status + ", " + responseText; if (error) error(path, "Couldn't load binary " + path + ": status " + status + ", " + responseText); _this.toLoad--; _this.loaded++; })); }; /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ AssetManager.prototype.loadText = /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ function (path, success, error) { var _this = this; if (success === void 0) { success = null; } if (error === void 0) { error = null; } path = this.pathPrefix + path; this.toLoad++; AssetManager.downloadText(path, (/** * @param {?} data * @return {?} */ function (data) { _this.assets[path] = data; if (success) success(path, data); _this.toLoad--; _this.loaded++; }), (/** * @param {?} state * @param {?} responseText * @return {?} */ function (state, responseText) { _this.errors[path] = "Couldn't load text " + path + ": status " + status + ", " + responseText; if (error) error(path, "Couldn't load text " + path + ": status " + status + ", " + responseText); _this.toLoad--; _this.loaded++; })); }; /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ AssetManager.prototype.loadTexture = /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ function (path, success, error) { var _this = this; if (success === void 0) { success = null; } if (error === void 0) { error = null; } path = this.pathPrefix + path; this.toLoad++; /** @type {?} */ var img = new Image(); img.crossOrigin = "anonymous"; img.onload = (/** * @param {?} ev * @return {?} */ function (ev) { /** @type {?} */ var texture = _this.textureLoader(img); _this.assets[path] = texture; _this.toLoad--; _this.loaded++; if (success) success(path, img); }); img.onerror = (/** * @param {?} ev * @return {?} */ function (ev) { _this.errors[path] = "Couldn't load image " + path; _this.toLoad--; _this.loaded++; if (error) error(path, "Couldn't load image " + path); }); img.src = path; }; /** * @param {?} path * @param {?} data * @param {?=} success * @param {?=} error * @return {?} */ AssetManager.prototype.loadTextureData = /** * @param {?} path * @param {?} data * @param {?=} success * @param {?=} error * @return {?} */ function (path, data, success, error) { var _this = this; if (success === void 0) { success = null; } if (error === void 0) { error = null; } path = this.pathPrefix + path; this.toLoad++; /** @type {?} */ var img = new Image(); img.onload = (/** * @param {?} ev * @return {?} */ function (ev) { /** @type {?} */ var texture = _this.textureLoader(img); _this.assets[path] = texture; _this.toLoad--; _this.loaded++; if (success) success(path, img); }); img.onerror = (/** * @param {?} ev * @return {?} */ function (ev) { _this.errors[path] = "Couldn't load image " + path; _this.toLoad--; _this.loaded++; if (error) error(path, "Couldn't load image " + path); }); img.src = data; }; /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ AssetManager.prototype.loadTextureAtlas = /** * @param {?} path * @param {?=} success * @param {?=} error * @return {?} */ function (path, success, error) { var _this = this; if (success === void 0) { success = null; } if (error === void 0) { error = null; } /** @type {?} */ var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; path = this.pathPrefix + path; this.toLoad++; AssetManager.downloadText(path, (/** * @param {?} atlasData * @return {?} */ function (atlasData) { var e_1, _a; /** @type {?} */ var pagesLoaded = { count: 0 }; /** @type {?} */ var atlasPages = new Array(); try { /** @type {?} */ var atlas = new TextureAtlas(atlasData, (/** * @param {?} path * @return {?} */ function (path) { atlasPages.push(parent + "/" + path); /** @type {?} */ var image = (/** @type {?} */ (document.createElement("img"))); image.width = 16; image.height = 16; return new FakeTexture(image); })); } catch (e) { /** @type {?} */ var ex = (/** @type {?} */ (e)); _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message; if (error) error(path, "Couldn't load texture atlas " + path + ": " + ex.message); _this.toLoad--; _this.loaded++; return; } var _loop_1 = function (atlasPage) { /** @type {?} */ var pageLoadError = false; _this.loadTexture(atlasPage, (/** * @param {?} imagePath * @param {?} image * @return {?} */ function (imagePath, image) { pagesLoaded.count++; if (pagesLoaded.count == atlasPages.length) { if (!pageLoadError) { try { /** @type {?} */ var atlas = new TextureAtlas(atlasData, (/** * @param {?} path * @return {?} */ function (path) { return _this.get(parent + "/" + path); })); _this.assets[path] = atlas; if (success) success(path, atlas); _this.toLoad--; _this.loaded++; } catch (e) { /** @type {?} */ var ex = (/** @type {?} */ (e)); _this.errors[path] = "Couldn't load texture atlas " + path + ": " + ex.message; if (error) error(path, "Couldn't load texture atlas " + path + ": " + ex.message); _this.toLoad--; _this.loaded++; } } else { _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path; if (error) error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path); _this.toLoad--; _this.loaded++; } } }), (/** * @param {?} imagePath * @param {?} errorMessage * @return {?} */ function (imagePath, errorMessage) { pageLoadError = true; pagesLoaded.count++; if (pagesLoaded.count == atlasPages.length) { _this.errors[path] = "Couldn't load texture atlas page " + imagePath + "} of atlas " + path; if (error) error(path, "Couldn't load texture atlas page " + imagePath + " of atlas " + path); _this.toLoad--; _this.loaded++; } })); }; try { for (var atlasPages_1 = __values(atlasPages), atlasPages_1_1 = atlasPages_1.next(); !atlasPages_1_1.done; atlasPages_1_1 = atlasPages_1.next()) { var atlasPage = atlasPages_1_1.value; _loop_1(atlasPage); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (atlasPages_1_1 && !atlasPages_1_1.done && (_a = atlasPages_1.return)) _a.call(atlasPages_1); } finally { if (e_1) throw e_1.error; } } }), (/** * @param {?} state * @param {?} responseText * @return {?} */ function (state, responseText) { _this.errors[path] = "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText; if (error) error(path, "Couldn't load texture atlas " + path + ": status " + status + ", " + responseText); _this.toLoad--; _this.loaded++; })); }; /** * @param {?} path * @return {?} */ AssetManager.prototype.get = /** * @param {?} path * @return {?} */ function (path) { path = this.pathPrefix + path; return this.assets[path]; }; /** * @param {?} path * @return {?} */ AssetManager.prototype.remove = /** * @param {?} path * @return {?} */ function (path) { path = this.pathPrefix + path; /** @type {?} */ var asset = this.assets[path]; if (((/** @type {?} */ (asset))).dispose) ((/** @type {?} */ (asset))).dispose(); this.assets[path] = null; }; /** * @return {?} */ AssetManager.prototype.removeAll = /** * @return {?} */ function () { for (var key in this.assets) { /** @type {?} */ var asset = this.assets[key]; if (((/** @type {?} */ (asset))).dispose) ((/** @type {?} */ (asset))).dispose(); } this.assets = {}; }; /** * @return {?} */ AssetManager.prototype.isLoadingComplete = /** * @return {?} */ function () { return this.toLoad == 0; }; /** * @return {?} */ AssetManager.prototype.getToLoad = /** * @return {?} */ function () { return this.toLoad; }; /** * @return {?} */ AssetManager.prototype.getLoaded = /** * @return {?} */ function () { return this.loaded; }; /** * @return {?} */ AssetManager.prototype.dispose = /** * @return {?} */ function () { this.removeAll(); }; /** * @return {?} */ AssetManager.prototype.hasErrors = /** * @return {?} */ function () { return Object.keys(this.errors).length > 0; }; /** * @return {?} */ AssetManager.prototype.getErrors = /** * @return {?} */ function () { return this.errors; }; return AssetManager; }()); if (false) { /** * @type {?} * @private */ AssetManager.prototype.pathPrefix; /** * @type {?} * @private */ AssetManager.prototype.textureLoader; /** * @type {?} * @private */ AssetManager.prototype.assets; /** * @type {?} * @private */ AssetManager.prototype.errors; /** * @type {?} * @private */ AssetManager.prototype.toLoad; /** * @type {?} * @private */ AssetManager.prototype.loaded; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var BlendMode = { Normal: 0, Additive: 1, Multiply: 2, Screen: 3, }; BlendMode[BlendMode.Normal] = 'Normal'; BlendMode[BlendMode.Additive] = 'Additive'; BlendMode[BlendMode.Multiply] = 'Multiply'; BlendMode[BlendMode.Screen] = 'Screen'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var ManagedWebGLRenderingContext = /** @class */ (function () { function ManagedWebGLRenderingContext(canvasOrContext, contextConfig) { var _this = this; if (contextConfig === void 0) { contextConfig = { alpha: "true" }; } this.restorables = new Array(); if (canvasOrContext instanceof HTMLCanvasElement) { /** @type {?} */ var canvas = canvasOrContext; this.gl = (/** @type {?} */ (((canvas.getContext("webgl", contextConfig) || canvas.getContext("experimental-webgl", contextConfig))))); this.canvas = canvas; canvas.addEventListener("webglcontextlost", (/** * @param {?} e * @return {?} */ function (e) { /** @type {?} */ var event = (/** @type {?} */ (e)); if (e) { e.preventDefault(); } })); canvas.addEventListener("webglcontextrestored", (/** * @param {?} e * @return {?} */ function (e) { for (var i = 0, n = _this.restorables.length; i < n; i++) { _this.restorables[i].restore(); } })); } else { this.gl = canvasOrContext; this.canvas = (/** @type {?} */ (this.gl.canvas)); } } /** * @param {?} restorable * @return {?} */ ManagedWebGLRenderingContext.prototype.addRestorable = /** * @param {?} restorable * @return {?} */ function (restorable) { this.restorables.push(restorable); }; /** * @param {?} restorable * @return {?} */ ManagedWebGLRenderingContext.prototype.removeRestorable = /** * @param {?} restorable * @return {?} */ function (restorable) { /** @type {?} */ var index = this.restorables.indexOf(restorable); if (index > -1) this.restorables.splice(index, 1); }; return ManagedWebGLRenderingContext; }()); if (false) { /** @type {?} */ ManagedWebGLRenderingContext.prototype.canvas; /** @type {?} */ ManagedWebGLRenderingContext.prototype.gl; /** * @type {?} * @private */ ManagedWebGLRenderingContext.prototype.restorables; } var WebGLBlendModeConverter = /** @class */ (function () { function WebGLBlendModeConverter() { } /** * @param {?} blendMode * @return {?} */ WebGLBlendModeConverter.getDestGLBlendMode = /** * @param {?} blendMode * @return {?} */ function (blendMode) { switch (blendMode) { case BlendMode.Normal: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; case BlendMode.Additive: return WebGLBlendModeConverter.ONE; case BlendMode.Multiply: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; case BlendMode.Screen: return WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; default: throw new Error("Unknown blend mode: " + blendMode); } }; /** * @param {?} blendMode * @param {?=} premultipliedAlpha * @return {?} */ WebGLBlendModeConverter.getSourceGLBlendMode = /** * @param {?} blendMode * @param {?=} premultipliedAlpha * @return {?} */ function (blendMode, premultipliedAlpha) { if (premultipliedAlpha === void 0) { premultipliedAlpha = false; } switch (blendMode) { case BlendMode.Normal: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA; case BlendMode.Additive: return premultipliedAlpha ? WebGLBlendModeConverter.ONE : WebGLBlendModeConverter.SRC_ALPHA; case BlendMode.Multiply: return WebGLBlendModeConverter.DST_COLOR; case BlendMode.Screen: return WebGLBlendModeConverter.ONE; default: throw new Error("Unknown blend mode: " + blendMode); } }; WebGLBlendModeConverter.ZERO = 0; WebGLBlendModeConverter.ONE = 1; WebGLBlendModeConverter.SRC_COLOR = 0x0300; WebGLBlendModeConverter.ONE_MINUS_SRC_COLOR = 0x0301; WebGLBlendModeConverter.SRC_ALPHA = 0x0302; WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA = 0x0303; WebGLBlendModeConverter.DST_ALPHA = 0x0304; WebGLBlendModeConverter.ONE_MINUS_DST_ALPHA = 0x0305; WebGLBlendModeConverter.DST_COLOR = 0x0306; return WebGLBlendModeConverter; }()); if (false) { /** @type {?} */ WebGLBlendModeConverter.ZERO; /** @type {?} */ WebGLBlendModeConverter.ONE; /** @type {?} */ WebGLBlendModeConverter.SRC_COLOR; /** @type {?} */ WebGLBlendModeConverter.ONE_MINUS_SRC_COLOR; /** @type {?} */ WebGLBlendModeConverter.SRC_ALPHA; /** @type {?} */ WebGLBlendModeConverter.ONE_MINUS_SRC_ALPHA; /** @type {?} */ WebGLBlendModeConverter.DST_ALPHA; /** @type {?} */ WebGLBlendModeConverter.ONE_MINUS_DST_ALPHA; /** @type {?} */ WebGLBlendModeConverter.DST_COLOR; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var GLTexture = /** @class */ (function (_super) { __extends(GLTexture, _super); function GLTexture(context, image, useMipMaps) { if (useMipMaps === void 0) { useMipMaps = false; } var _this = _super.call(this, image) || this; _this.texture = null; _this.boundUnit = 0; _this.useMipMaps = false; _this.context = context instanceof ManagedWebGLRenderingContext ? context : new ManagedWebGLRenderingContext(context); _this.useMipMaps = useMipMaps; _this.restore(); _this.context.addRestorable(_this); return _this; } /** * @param {?} minFilter * @param {?} magFilter * @return {?} */ GLTexture.prototype.setFilters = /** * @param {?} minFilter * @param {?} magFilter * @return {?} */ function (minFilter, magFilter) { /** @type {?} */ var gl = this.context.gl; this.bind(); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, magFilter); }; /** * @param {?} uWrap * @param {?} vWrap * @return {?} */ GLTexture.prototype.setWraps = /** * @param {?} uWrap * @param {?} vWrap * @return {?} */ function (uWrap, vWrap) { /** @type {?} */ var gl = this.context.gl; this.bind(); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, uWrap); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, vWrap); }; /** * @param {?} useMipMaps * @return {?} */ GLTexture.prototype.update = /** * @param {?} useMipMaps * @return {?} */ function (useMipMaps) { /** @type {?} */ var gl = this.context.gl; if (!this.texture) { this.texture = this.context.gl.createTexture(); } this.bind(); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._image); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, useMipMaps ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); if (useMipMaps) gl.generateMipmap(gl.TEXTURE_2D); }; /** * @return {?} */ GLTexture.prototype.restore = /** * @return {?} */ function () { this.texture = null; this.update(this.useMipMaps); }; /** * @param {?=} unit * @return {?} */ GLTexture.prototype.bind = /** * @param {?=} unit * @return {?} */ function (unit) { if (unit === void 0) { unit = 0; } /** @type {?} */ var gl = this.context.gl; this.boundUnit = unit; gl.activeTexture(gl.TEXTURE0 + unit); gl.bindTexture(gl.TEXTURE_2D, this.texture); }; /** * @return {?} */ GLTexture.prototype.unbind = /** * @return {?} */ function () { /** @type {?} */ var gl = this.context.gl; gl.activeTexture(gl.TEXTURE0 + this.boundUnit); gl.bindTexture(gl.TEXTURE_2D, null); }; /** * @return {?} */ GLTexture.prototype.dispose = /** * @return {?} */ function () { this.context.removeRestorable(this); /** @type {?} */ var gl = this.context.gl; gl.deleteTexture(this.texture); }; return GLTexture; }(Texture)); if (false) { /** * @type {?} * @private */ GLTexture.prototype.context; /** * @type {?} * @private */ GLTexture.prototype.texture; /** * @type {?} * @private */ GLTexture.prototype.boundUnit; /** * @type {?} * @private */ GLTexture.prototype.useMipMaps; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var AssetManager$1 = /** @class */ (function (_super) { __extends(AssetManager, _super); function AssetManager(context, pathPrefix) { if (pathPrefix === void 0) { pathPrefix = ""; } return _super.call(this, (/** * @param {?} image * @return {?} */ function (image) { return new GLTexture(context, image); }), pathPrefix) || this; } return AssetManager; }(AssetManager)); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var M00 = 0; /** @type {?} */ var M01 = 4; /** @type {?} */ var M02 = 8; /** @type {?} */ var M03 = 12; /** @type {?} */ var M10 = 1; /** @type {?} */ var M11 = 5; /** @type {?} */ var M12 = 9; /** @type {?} */ var M13 = 13; /** @type {?} */ var M20 = 2; /** @type {?} */ var M21 = 6; /** @type {?} */ var M22 = 10; /** @type {?} */ var M23 = 14; /** @type {?} */ var M30 = 3; /** @type {?} */ var M31 = 7; /** @type {?} */ var M32 = 11; /** @type {?} */ var M33 = 15; var Matrix4 = /** @class */ (function () { function Matrix4() { this.temp = new Float32Array(16); this.values = new Float32Array(16); /** @type {?} */ var v = this.values; v[M00] = 1; v[M11] = 1; v[M22] = 1; v[M33] = 1; } /** * @param {?} values * @return {?} */ Matrix4.prototype.set = /** * @param {?} values * @return {?} */ function (values) { this.values.set(values); return this; }; /** * @return {?} */ Matrix4.prototype.transpose = /** * @return {?} */ function () { /** @type {?} */ var t = this.temp; /** @type {?} */ var v = this.values; t[M00] = v[M00]; t[M01] = v[M10]; t[M02] = v[M20]; t[M03] = v[M30]; t[M10] = v[M01]; t[M11] = v[M11]; t[M12] = v[M21]; t[M13] = v[M31]; t[M20] = v[M02]; t[M21] = v[M12]; t[M22] = v[M22]; t[M23] = v[M32]; t[M30] = v[M03]; t[M31] = v[M13]; t[M32] = v[M23]; t[M33] = v[M33]; return this.set(t); }; /** * @return {?} */ Matrix4.prototype.identity = /** * @return {?} */ function () { /** @type {?} */ var v = this.values; v[M00] = 1; v[M01] = 0; v[M02] = 0; v[M03] = 0; v[M10] = 0; v[M11] = 1; v[M12] = 0; v[M13] = 0; v[M20] = 0; v[M21] = 0; v[M22] = 1; v[M23] = 0; v[M30] = 0; v[M31] = 0; v[M32] = 0; v[M33] = 1; return this; }; /** * @return {?} */ Matrix4.prototype.invert = /** * @return {?} */ function () { /** @type {?} */ var v = this.values; /** @type {?} */ var t = this.temp; /** @type {?} */ var l_det = v[M30] * v[M21] * v[M12] * v[M03] - v[M20] * v[M31] * v[M12] * v[M03] - v[M30] * v[M11] * v[M22] * v[M03] + v[M10] * v[M31] * v[M22] * v[M03] + v[M20] * v[M11] * v[M32] * v[M03] - v[M10] * v[M21] * v[M32] * v[M03] - v[M30] * v[M21] * v[M02] * v[M13] + v[M20] * v[M31] * v[M02] * v[M13] + v[M30] * v[M01] * v[M22] * v[M13] - v[M00] * v[M31] * v[M22] * v[M13] - v[M20] * v[M01] * v[M32] * v[M13] + v[M00] * v[M21] * v[M32] * v[M13] + v[M30] * v[M11] * v[M02] * v[M23] - v[M10] * v[M31] * v[M02] * v[M23] - v[M30] * v[M01] * v[M12] * v[M23] + v[M00] * v[M31] * v[M12] * v[M23] + v[M10] * v[M01] * v[M32] * v[M23] - v[M00] * v[M11] * v[M32] * v[M23] - v[M20] * v[M11] * v[M02] * v[M33] + v[M10] * v[M21] * v[M02] * v[M33] + v[M20] * v[M01] * v[M12] * v[M33] - v[M00] * v[M21] * v[M12] * v[M33] - v[M10] * v[M01] * v[M22] * v[M33] + v[M00] * v[M11] * v[M22] * v[M33]; if (l_det == 0) throw new Error("non-invertible matrix"); /** @type {?} */ var inv_det = 1.0 / l_det; t[M00] = v[M12] * v[M23] * v[M31] - v[M13] * v[M22