diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index 2439ff38..8b2f6efb 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -150,7 +150,6 @@ declare abstract class Component extends egret.DisplayObjectContainer { onRemovedFromEntity(): void; onEnabled(): void; onDisabled(): void; - onEntityTransformChanged(comp: ComponentTransform): void; update(): void; debugRender(): void; registerComponent(): void; @@ -193,7 +192,6 @@ declare class Entity extends egret.DisplayObjectContainer { update(): void; onAddedToScene(): void; onRemovedFromScene(): void; - onTransformChanged(comp: ComponentTransform): void; destroy(): void; } declare class Scene extends egret.DisplayObjectContainer { @@ -240,70 +238,6 @@ declare class SceneManager { static render(): void; static startSceneTransition(sceneTransition: T): T; } -declare enum DirtyType { - clean = 0, - positionDirty = 1, - scaleDirty = 2, - rotationDirty = 3 -} -declare enum ComponentTransform { - position = 0, - scale = 1, - rotation = 2 -} -declare class Transform { - readonly entity: Entity; - private _children; - private _parent; - private _localPosition; - private _localRotation; - private _localScale; - private _translationMatrix; - private _rotationMatrix; - private _scaleMatrix; - private _worldTransform; - private _worldToLocalTransform; - private _worldInverseTransform; - private _rotation; - private _position; - private _scale; - private _localTransform; - private _hierachyDirty; - private _localDirty; - private _localPositionDirty; - private _localScaleDirty; - private _localRotationDirty; - private _positionDirty; - private _worldToLocalDirty; - private _worldInverseDirty; - readonly childCount: number; - constructor(entity: Entity); - getChild(index: number): Transform; - readonly worldInverseTransform: Matrix2D; - readonly localToWorldTransform: Matrix2D; - readonly worldToLocalTransform: Matrix2D; - parent: Transform; - setParent(parent: Transform): this; - rotation: number; - localRotation: number; - position: Vector2; - localPosition: Vector2; - scale: Vector2; - localScale: Vector2; - rotationDegrees: number; - localRotationDegrees: number; - setLocalScale(scale: Vector2): this; - setScale(scale: Vector2): this; - setLocalRotationDegrees(degrees: number): this; - setLocalRotation(radians: number): this; - setRotation(radians: number): this; - setRotationDegrees(degrees: number): this; - setLocalPosition(localPosition: Vector2): this; - setPosition(position: Vector2): this; - setDirty(dirtyFlagType: DirtyType): void; - roundPosition(): void; - updateTransform(): void; -} declare class Camera extends Component { private _zoom; private _origin; @@ -347,26 +281,6 @@ declare class ComponentPool { obtain(): T; free(component: T): void; } -declare class Mesh extends Component { - private _verts; - private _primitiveCount; - private _triangles; - private _topLeftVertPosition; - private _width; - private _height; - initialize(): void; - setVertPosition(positions: Vector2[]): this; - setTriangles(triangles: number[]): this; - recalculateBounds(): this; - render(): void; -} -declare class VertexPosition { - position: Vector2; - constructor(position: Vector2); -} -declare class PolygonMesh extends Mesh { - constructor(points: Vector2[], arePointsCCW?: boolean); -} declare abstract class PooledComponent extends Component { abstract reset(): any; } @@ -386,10 +300,15 @@ declare abstract class RenderableComponent extends PooledComponent implements IR protected onBecameInvisible(): void; abstract render(camera: Camera): any; isVisibleFromCamera(camera: Camera): boolean; - onEntityTransformChanged(comp: ComponentTransform): void; } -declare class ScreenSpaceCamera extends Camera { - protected updateMatrixes(): void; +declare class Mesh extends RenderableComponent { + private _mesh; + constructor(); + setTexture(texture: egret.Texture): Mesh; + onAddedToEntity(): void; + onRemovedFromEntity(): void; + render(camera: Camera): void; + reset(): void; } declare class Sprite { texture2D: egret.Texture; @@ -446,7 +365,6 @@ declare abstract class Collider extends Component { collidesWith(collider: Collider, motion: Vector2): CollisionResult; onAddedToEntity(): void; onRemovedFromEntity(): void; - onEntityTransformChanged(comp: ComponentTransform): void; onEnabled(): void; onDisabled(): void; } @@ -528,7 +446,6 @@ declare class ComponentList { getComponent(type: any, onlyReturnInitializedComponents: boolean): T; getComponents(typeName: string | any, components?: any): any; update(): void; - onEntityTransformChanged(comp: any): void; } declare class ComponentTypeManager { private static _componentTypesMask; @@ -632,8 +549,6 @@ declare class Viewport { bounds: Rectangle; constructor(x: number, y: number, width: number, height: number); } -declare abstract class GraphicsResource { -} declare class GaussianBlurEffect extends egret.CustomFilter { private static blur_frag; constructor(); @@ -656,16 +571,6 @@ declare class PostProcessor { protected drawFullscreenQuad(): void; unload(): void; } -declare class BloomSettings { - readonly threshold: any; - readonly blurAmount: any; - readonly intensity: any; - readonly baseIntensity: any; - readonly saturation: any; - readonly baseStaturation: any; - constructor(bloomThreshold: number, blurAmount: number, bloomIntensity: number, baseIntensity: number, bloomSaturation: number, baseSaturation: number); - static presetSettings: BloomSettings[]; -} declare class GaussianBlurPostProcessor extends PostProcessor { onAddedToScene(scene: Scene): void; } diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index d970796c..0f65d055 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -1,5859 +1,4858 @@ -var __extends = - (this && this.__extends) || - (function () { - var extendStatics = - Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && - function (d, b) { - d.__proto__ = b; - }) || - function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - }; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { - extendStatics(d, b); - function __() { - this.constructor = d; - } - d.prototype = - b === null - ? Object.create(b) - : ((__.prototype = b.prototype), new __()); - }; - })(); -var __awaiter = - (this && this.__awaiter) || - function (thisArg, _arguments, P, generator) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { - try { - step(generator.next(value)); - } catch (e) { - reject(e); - } - } - function rejected(value) { - try { - step(generator["throw"](value)); - } catch (e) { - reject(e); - } - } - function step(result) { - result.done - ? resolve(result.value) - : new P(function (resolve) { - resolve(result.value); - }).then(fulfilled, rejected); - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); }); - }; -var __generator = - (this && this.__generator) || - function (thisArg, body) { - var _ = { - label: 0, - sent: function () { - if (t[0] & 1) throw t[1]; - return t[1]; - }, - trys: [], - ops: [], - }, - f, - y, - t, - g; - return ( - (g = { next: verb(0), throw: verb(1), return: verb(2) }), - typeof Symbol === "function" && - (g[Symbol.iterator] = function () { - return this; - }), - g - ); - function verb(n) { - return function (v) { - return step([n, v]); - }; - } +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) - try { - if ( - ((f = 1), - y && - (t = - op[0] & 2 - ? y["return"] - : op[0] - ? y["throw"] || ((t = y["return"]) && t.call(y), 0) - : y.next) && - !(t = t.call(y, op[1])).done) - ) - return t; - if (((y = 0), t)) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: - case 1: - t = op; - break; - case 4: - _.label++; - return { value: op[1], done: false }; - case 5: - _.label++; - y = op[1]; - op = [0]; - continue; - case 7: - op = _.ops.pop(); - _.trys.pop(); - continue; - default: - if ( - !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && - (op[0] === 6 || op[0] === 2) - ) { - _ = 0; - continue; - } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { - _.label = op[1]; - break; - } - if (op[0] === 6 && _.label < t[1]) { - _.label = t[1]; - t = op; - break; - } - if (t && _.label < t[2]) { - _.label = t[2]; - _.ops.push(op); - break; - } - if (t[2]) _.ops.pop(); - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } catch (e) { - op = [6, e]; - y = 0; - } finally { - f = t = 0; - } - if (op[0] & 5) throw op[1]; - return { value: op[0] ? op[1] : void 0, done: true }; + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - }; +}; Array.prototype.findIndex = function (predicate) { - function findIndex(array, predicate) { - for (var i = 0, len = array.length; i < len; i++) { - if (predicate.call(arguments[2], array[i], i, array)) { - return i; - } + function findIndex(array, predicate) { + for (var i = 0, len = array.length; i < len; i++) { + if (predicate.call(arguments[2], array[i], i, array)) { + return i; + } + } + return -1; } - return -1; - } - return findIndex(this, predicate); + return findIndex(this, predicate); }; Array.prototype.any = function (predicate) { - function any(array, predicate) { - return array.findIndex(predicate) > -1; - } - return any(this, predicate); + function any(array, predicate) { + return array.findIndex(predicate) > -1; + } + return any(this, predicate); }; Array.prototype.firstOrDefault = function (predicate) { - function firstOrDefault(array, predicate) { - var index = array.findIndex(predicate); - return index == -1 ? null : array[index]; - } - return firstOrDefault(this, predicate); + function firstOrDefault(array, predicate) { + var index = array.findIndex(predicate); + return index == -1 ? null : array[index]; + } + return firstOrDefault(this, predicate); }; Array.prototype.find = function (predicate) { - function find(array, predicate) { - return array.firstOrDefault(predicate); - } - return find(this, predicate); + function find(array, predicate) { + return array.firstOrDefault(predicate); + } + return find(this, predicate); }; Array.prototype.where = function (predicate) { - function where(array, predicate) { - if (typeof array.reduce === "function") { - return array.reduce(function (ret, element, index) { - if (predicate.call(arguments[2], element, index, array)) { - ret.push(element); + function where(array, predicate) { + if (typeof (array.reduce) === "function") { + return array.reduce(function (ret, element, index) { + if (predicate.call(arguments[2], element, index, array)) { + ret.push(element); + } + return ret; + }, []); + } + else { + var ret = []; + for (var i = 0, len = array.length; i < len; i++) { + var element = array[i]; + if (predicate.call(arguments[2], element, i, array)) { + ret.push(element); + } + } + return ret; } - return ret; - }, []); - } else { - var ret = []; - for (var i = 0, len = array.length; i < len; i++) { - var element = array[i]; - if (predicate.call(arguments[2], element, i, array)) { - ret.push(element); - } - } - return ret; } - } - return where(this, predicate); + return where(this, predicate); }; Array.prototype.count = function (predicate) { - function count(array, predicate) { - return array.where(predicate).length; - } - return count(this, predicate); + function count(array, predicate) { + return array.where(predicate).length; + } + return count(this, predicate); }; Array.prototype.findAll = function (predicate) { - function findAll(array, predicate) { - return array.where(predicate); - } - return findAll(this, predicate); + function findAll(array, predicate) { + return array.where(predicate); + } + return findAll(this, predicate); }; Array.prototype.contains = function (value) { - function contains(array, value) { - for (var i = 0, len = array.length; i < len; i++) { - if (array[i] == value) { - return true; - } + function contains(array, value) { + for (var i = 0, len = array.length; i < len; i++) { + if (array[i] == value) { + return true; + } + } + return false; } - return false; - } - return contains(this, value); + return contains(this, value); }; Array.prototype.removeAll = function (predicate) { - function removeAll(array, predicate) { - var index; - do { - index = array.findIndex(predicate); - if (index >= 0) { - array.splice(index, 1); - } - } while (index >= 0); - } - removeAll(this, predicate); + function removeAll(array, predicate) { + var index; + do { + index = array.findIndex(predicate); + if (index >= 0) { + array.splice(index, 1); + } + } while (index >= 0); + } + removeAll(this, predicate); }; Array.prototype.remove = function (element) { - function remove(array, element) { - var index = array.findIndex(function (x) { - return x === element; - }); - if (index >= 0) { - array.splice(index, 1); - return true; - } else { - return false; + function remove(array, element) { + var index = array.findIndex(function (x) { + return x === element; + }); + if (index >= 0) { + array.splice(index, 1); + return true; + } + else { + return false; + } } - } - return remove(this, element); + return remove(this, element); }; Array.prototype.removeAt = function (index) { - function removeAt(array, index) { - array.splice(index, 1); - } - return removeAt(this, index); + function removeAt(array, index) { + array.splice(index, 1); + } + return removeAt(this, index); }; Array.prototype.removeRange = function (index, count) { - function removeRange(array, index, count) { - array.splice(index, count); - } - return removeRange(this, index, count); + function removeRange(array, index, count) { + array.splice(index, count); + } + return removeRange(this, index, count); }; Array.prototype.select = function (selector) { - function select(array, selector) { - if (typeof array.reduce === "function") { - return array.reduce(function (ret, element, index) { - ret.push(selector.call(arguments[2], element, index, array)); - return ret; - }, []); - } else { - var ret = []; - for (var i = 0, len = array.length; i < len; i++) { - ret.push(selector.call(arguments[2], array[i], i, array)); - } - return ret; + function select(array, selector) { + if (typeof (array.reduce) === "function") { + return array.reduce(function (ret, element, index) { + ret.push(selector.call(arguments[2], element, index, array)); + return ret; + }, []); + } + else { + var ret = []; + for (var i = 0, len = array.length; i < len; i++) { + ret.push(selector.call(arguments[2], array[i], i, array)); + } + return ret; + } } - } - return select(this, selector); + return select(this, selector); }; Array.prototype.orderBy = function (keySelector, comparer) { - function orderBy(array, keySelector, comparer) { - array.sort(function (x, y) { - var v1 = keySelector(x); - var v2 = keySelector(y); - if (comparer) { - return comparer(v1, v2); - } else { - return v1 > v2 ? 1 : -1; - } - }); - return array; - } - return orderBy(this, keySelector, comparer); + function orderBy(array, keySelector, comparer) { + array.sort(function (x, y) { + var v1 = keySelector(x); + var v2 = keySelector(y); + if (comparer) { + return comparer(v1, v2); + } + else { + return (v1 > v2) ? 1 : -1; + } + }); + return array; + } + return orderBy(this, keySelector, comparer); }; Array.prototype.orderByDescending = function (keySelector, comparer) { - function orderByDescending(array, keySelector, comparer) { - array.sort(function (x, y) { - var v1 = keySelector(x); - var v2 = keySelector(y); - if (comparer) { - return -comparer(v1, v2); - } else { - return v1 < v2 ? 1 : -1; - } - }); - return array; - } - return orderByDescending(this, keySelector, comparer); + function orderByDescending(array, keySelector, comparer) { + array.sort(function (x, y) { + var v1 = keySelector(x); + var v2 = keySelector(y); + if (comparer) { + return -comparer(v1, v2); + } + else { + return (v1 < v2) ? 1 : -1; + } + }); + return array; + } + return orderByDescending(this, keySelector, comparer); }; Array.prototype.groupBy = function (keySelector) { - function groupBy(array, keySelector) { - if (typeof array.reduce === "function") { - var keys_1 = []; - return array.reduce(function (groups, element, index) { - var key = JSON.stringify( - keySelector.call(arguments[1], element, index, array) - ); - var index2 = keys_1.findIndex(function (x) { - return x === key; - }); - if (index2 < 0) { - index2 = keys_1.push(key) - 1; - } - if (!groups[index2]) { - groups[index2] = []; - } - groups[index2].push(element); - return groups; - }, []); - } else { - var groups = []; - var keys = []; - var _loop_1 = function (i, len) { - var key = JSON.stringify( - keySelector.call(arguments_1[1], array[i], i, array) - ); - var index = keys.findIndex(function (x) { - return x === key; - }); - if (index < 0) { - index = keys.push(key) - 1; - } - if (!groups[index]) { - groups[index] = []; - } - groups[index].push(array[i]); - }; - var arguments_1 = arguments; - for (var i = 0, len = array.length; i < len; i++) { - _loop_1(i, len); - } - return groups; + function groupBy(array, keySelector) { + if (typeof (array.reduce) === "function") { + var keys_1 = []; + return array.reduce(function (groups, element, index) { + var key = JSON.stringify(keySelector.call(arguments[1], element, index, array)); + var index2 = keys_1.findIndex(function (x) { return x === key; }); + if (index2 < 0) { + index2 = keys_1.push(key) - 1; + } + if (!groups[index2]) { + groups[index2] = []; + } + groups[index2].push(element); + return groups; + }, []); + } + else { + var groups = []; + var keys = []; + var _loop_1 = function (i, len) { + var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array)); + var index = keys.findIndex(function (x) { return x === key; }); + if (index < 0) { + index = keys.push(key) - 1; + } + if (!groups[index]) { + groups[index] = []; + } + groups[index].push(array[i]); + }; + var arguments_1 = arguments; + for (var i = 0, len = array.length; i < len; i++) { + _loop_1(i, len); + } + return groups; + } } - } - return groupBy(this, keySelector); + return groupBy(this, keySelector); }; Array.prototype.sum = function (selector) { - function sum(array, selector) { - var ret; - for (var i = 0, len = array.length; i < len; i++) { - if (i == 0) { - if (selector) { - ret = selector.call(arguments[2], array[i], i, array); - } else { - ret = array[i]; - } - } else { - if (selector) { - ret += selector.call(arguments[2], array[i], i, array); - } else { - ret += array[i]; - } - } + function sum(array, selector) { + var ret; + for (var i = 0, len = array.length; i < len; i++) { + if (i == 0) { + if (selector) { + ret = selector.call(arguments[2], array[i], i, array); + } + else { + ret = array[i]; + } + } + else { + if (selector) { + ret += selector.call(arguments[2], array[i], i, array); + } + else { + ret += array[i]; + } + } + } + return ret; } - return ret; - } - return sum(this, selector); + return sum(this, selector); }; var PriorityQueueNode = (function () { - function PriorityQueueNode() { - this.priority = 0; - this.insertionIndex = 0; - this.queueIndex = 0; - } - return PriorityQueueNode; -})(); -var AStarPathfinder = (function () { - function AStarPathfinder() {} - AStarPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new AStarNode(start), 0); - costSoFar.set(start, 0); - var _loop_2 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = - costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priority = newCost + graph.heuristic(next, goal); - frontier.enqueue(new AStarNode(next), priority); - cameFrom.set(next, current.data); - } - }); - }; - while (frontier.count > 0) { - var state_1 = _loop_2(); - if (state_1 === "break") break; - } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - AStarPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (((r = iterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return true; + function PriorityQueueNode() { + this.priority = 0; + this.insertionIndex = 0; + this.queueIndex = 0; } - return false; - }; - AStarPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (((r = iterator.next()), (v = valueIterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return v.value; - } - return null; - }; - AStarPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return AStarPathfinder; -})(); + return PriorityQueueNode; +}()); +var AStarPathfinder = (function () { + function AStarPathfinder() { + } + AStarPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new PriorityQueue(1000); + frontier.enqueue(new AStarNode(start), 0); + costSoFar.set(start, 0); + var _loop_2 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priority = newCost + graph.heuristic(next, goal); + frontier.enqueue(new AStarNode(next), priority); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_1 = _loop_2(); + if (state_1 === "break") + break; + } + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; + }; + AStarPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + AStarPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + AStarPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return AStarPathfinder; +}()); var AStarNode = (function (_super) { - __extends(AStarNode, _super); - function AStarNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return AStarNode; -})(PriorityQueueNode); + __extends(AStarNode, _super); + function AStarNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return AStarNode; +}(PriorityQueueNode)); var AstarGridGraph = (function () { - function AstarGridGraph(width, height) { - this.dirs = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]; - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - } - AstarGridGraph.prototype.isNodeInBounds = function (node) { - return ( - 0 <= node.x && - node.x < this._width && - 0 <= node.y && - node.y < this._height - ); - }; - AstarGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { - return JSON.stringify(wall) == JSON.stringify(node); - }); - }; - AstarGridGraph.prototype.search = function (start, goal) { - return AStarPathfinder.search(this, start, goal); - }; - AstarGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this.dirs.forEach(function (dir) { - var next = new Point(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - AstarGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (p) { - return JSON.stringify(p) == JSON.stringify(to); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }; - AstarGridGraph.prototype.heuristic = function (node, goal) { - return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); - }; - return AstarGridGraph; -})(); + function AstarGridGraph(width, height) { + this.dirs = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, 1) + ]; + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; + } + AstarGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + AstarGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + AstarGridGraph.prototype.search = function (start, goal) { + return AStarPathfinder.search(this, start, goal); + }; + AstarGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this.dirs.forEach(function (dir) { + var next = new Point(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + AstarGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + AstarGridGraph.prototype.heuristic = function (node, goal) { + return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); + }; + return AstarGridGraph; +}()); var PriorityQueue = (function () { - function PriorityQueue(maxNodes) { - this._numNodes = 0; - this._nodes = new Array(maxNodes + 1); - this._numNodesEverEnqueued = 0; - } - PriorityQueue.prototype.clear = function () { - this._nodes.splice(1, this._numNodes); - this._numNodes = 0; - }; - Object.defineProperty(PriorityQueue.prototype, "count", { - get: function () { - return this._numNodes; - }, - enumerable: true, - configurable: true, - }); - PriorityQueue.prototype.contains = function (node) { - return this._nodes[node.queueIndex] == node; - }; - PriorityQueue.prototype.enqueue = function (node, priority) { - node.priority = priority; - this._numNodes++; - this._nodes[this._numNodes] = node; - node.queueIndex = this._numNodes; - node.insertionIndex = this._numNodesEverEnqueued++; - this.cascadeUp(this._nodes[this._numNodes]); - }; - PriorityQueue.prototype.dequeue = function () { - var returnMe = this._nodes[1]; - this.remove(returnMe); - return returnMe; - }; - PriorityQueue.prototype.remove = function (node) { - if (node.queueIndex == this._numNodes) { - this._nodes[this._numNodes] = null; - this._numNodes--; - return; - } - var formerLastNode = this._nodes[this._numNodes]; - this.swap(node, formerLastNode); - delete this._nodes[this._numNodes]; - this._numNodes--; - this.onNodeUpdated(formerLastNode); - }; - PriorityQueue.prototype.isValidQueue = function () { - for (var i = 1; i < this._nodes.length; i++) { - if (this._nodes[i]) { - var childLeftIndex = 2 * i; - if ( - childLeftIndex < this._nodes.length && - this._nodes[childLeftIndex] && - this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i]) - ) - return false; - var childRightIndex = childLeftIndex + 1; - if ( - childRightIndex < this._nodes.length && - this._nodes[childRightIndex] && - this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i]) - ) - return false; - } - } - return true; - }; - PriorityQueue.prototype.onNodeUpdated = function (node) { - var parentIndex = Math.floor(node.queueIndex / 2); - var parentNode = this._nodes[parentIndex]; - if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { - this.cascadeUp(node); - } else { - this.cascadeDown(node); - } - }; - PriorityQueue.prototype.cascadeDown = function (node) { - var newParent; - var finalQueueIndex = node.queueIndex; - while (true) { - newParent = node; - var childLeftIndex = 2 * finalQueueIndex; - if (childLeftIndex > this._numNodes) { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - var childLeft = this._nodes[childLeftIndex]; - if (this.hasHigherPriority(childLeft, newParent)) { - newParent = childLeft; - } - var childRightIndex = childLeftIndex + 1; - if (childRightIndex <= this._numNodes) { - var childRight = this._nodes[childRightIndex]; - if (this.hasHigherPriority(childRight, newParent)) { - newParent = childRight; - } - } - if (newParent != node) { - this._nodes[finalQueueIndex] = newParent; - var temp = newParent.queueIndex; - newParent.queueIndex = finalQueueIndex; - finalQueueIndex = temp; - } else { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - } - }; - PriorityQueue.prototype.cascadeUp = function (node) { - var parent = Math.floor(node.queueIndex / 2); - while (parent >= 1) { - var parentNode = this._nodes[parent]; - if (this.hasHigherPriority(parentNode, node)) break; - this.swap(node, parentNode); - parent = Math.floor(node.queueIndex / 2); - } - }; - PriorityQueue.prototype.swap = function (node1, node2) { - this._nodes[node1.queueIndex] = node2; - this._nodes[node2.queueIndex] = node1; - var temp = node1.queueIndex; - node1.queueIndex = node2.queueIndex; - node2.queueIndex = temp; - }; - PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { - return ( - higher.priority < lower.priority || - (higher.priority == lower.priority && - higher.insertionIndex < lower.insertionIndex) - ); - }; - return PriorityQueue; -})(); + function PriorityQueue(maxNodes) { + this._numNodes = 0; + this._nodes = new Array(maxNodes + 1); + this._numNodesEverEnqueued = 0; + } + PriorityQueue.prototype.clear = function () { + this._nodes.splice(1, this._numNodes); + this._numNodes = 0; + }; + Object.defineProperty(PriorityQueue.prototype, "count", { + get: function () { + return this._numNodes; + }, + enumerable: true, + configurable: true + }); + PriorityQueue.prototype.contains = function (node) { + return (this._nodes[node.queueIndex] == node); + }; + PriorityQueue.prototype.enqueue = function (node, priority) { + node.priority = priority; + this._numNodes++; + this._nodes[this._numNodes] = node; + node.queueIndex = this._numNodes; + node.insertionIndex = this._numNodesEverEnqueued++; + this.cascadeUp(this._nodes[this._numNodes]); + }; + PriorityQueue.prototype.dequeue = function () { + var returnMe = this._nodes[1]; + this.remove(returnMe); + return returnMe; + }; + PriorityQueue.prototype.remove = function (node) { + if (node.queueIndex == this._numNodes) { + this._nodes[this._numNodes] = null; + this._numNodes--; + return; + } + var formerLastNode = this._nodes[this._numNodes]; + this.swap(node, formerLastNode); + delete this._nodes[this._numNodes]; + this._numNodes--; + this.onNodeUpdated(formerLastNode); + }; + PriorityQueue.prototype.isValidQueue = function () { + for (var i = 1; i < this._nodes.length; i++) { + if (this._nodes[i]) { + var childLeftIndex = 2 * i; + if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && + this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) + return false; + var childRightIndex = childLeftIndex + 1; + if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && + this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) + return false; + } + } + return true; + }; + PriorityQueue.prototype.onNodeUpdated = function (node) { + var parentIndex = Math.floor(node.queueIndex / 2); + var parentNode = this._nodes[parentIndex]; + if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { + this.cascadeUp(node); + } + else { + this.cascadeDown(node); + } + }; + PriorityQueue.prototype.cascadeDown = function (node) { + var newParent; + var finalQueueIndex = node.queueIndex; + while (true) { + newParent = node; + var childLeftIndex = 2 * finalQueueIndex; + if (childLeftIndex > this._numNodes) { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } + var childLeft = this._nodes[childLeftIndex]; + if (this.hasHigherPriority(childLeft, newParent)) { + newParent = childLeft; + } + var childRightIndex = childLeftIndex + 1; + if (childRightIndex <= this._numNodes) { + var childRight = this._nodes[childRightIndex]; + if (this.hasHigherPriority(childRight, newParent)) { + newParent = childRight; + } + } + if (newParent != node) { + this._nodes[finalQueueIndex] = newParent; + var temp = newParent.queueIndex; + newParent.queueIndex = finalQueueIndex; + finalQueueIndex = temp; + } + else { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } + } + }; + PriorityQueue.prototype.cascadeUp = function (node) { + var parent = Math.floor(node.queueIndex / 2); + while (parent >= 1) { + var parentNode = this._nodes[parent]; + if (this.hasHigherPriority(parentNode, node)) + break; + this.swap(node, parentNode); + parent = Math.floor(node.queueIndex / 2); + } + }; + PriorityQueue.prototype.swap = function (node1, node2) { + this._nodes[node1.queueIndex] = node2; + this._nodes[node2.queueIndex] = node1; + var temp = node1.queueIndex; + node1.queueIndex = node2.queueIndex; + node2.queueIndex = temp; + }; + PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { + return (higher.priority < lower.priority || + (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); + }; + return PriorityQueue; +}()); var BreadthFirstPathfinder = (function () { - function BreadthFirstPathfinder() {} - BreadthFirstPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var frontier = []; - frontier.unshift(start); - var cameFrom = new Map(); - cameFrom.set(start, start); - var _loop_3 = function () { - var current = frontier.shift(); - if (JSON.stringify(current) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current).forEach(function (next) { - if (!_this.hasKey(cameFrom, next)) { - frontier.unshift(next); - cameFrom.set(next, current); - } - }); - }; - while (frontier.length > 0) { - var state_2 = _loop_3(); - if (state_2 === "break") break; - } - return foundPath - ? AStarPathfinder.recontructPath(cameFrom, start, goal) - : null; - }; - BreadthFirstPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (((r = iterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return true; - } - return false; - }; - return BreadthFirstPathfinder; -})(); + function BreadthFirstPathfinder() { + } + BreadthFirstPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var frontier = []; + frontier.unshift(start); + var cameFrom = new Map(); + cameFrom.set(start, start); + var _loop_3 = function () { + var current = frontier.shift(); + if (JSON.stringify(current) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current).forEach(function (next) { + if (!_this.hasKey(cameFrom, next)) { + frontier.unshift(next); + cameFrom.set(next, current); + } + }); + }; + while (frontier.length > 0) { + var state_2 = _loop_3(); + if (state_2 === "break") + break; + } + return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null; + }; + BreadthFirstPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + return BreadthFirstPathfinder; +}()); var UnweightedGraph = (function () { - function UnweightedGraph() { - this.edges = new Map(); - } - UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { - this.edges.set(node, edges); - return this; - }; - UnweightedGraph.prototype.getNeighbors = function (node) { - return this.edges.get(node); - }; - return UnweightedGraph; -})(); + function UnweightedGraph() { + this.edges = new Map(); + } + UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { + this.edges.set(node, edges); + return this; + }; + UnweightedGraph.prototype.getNeighbors = function (node) { + return this.edges.get(node); + }; + return UnweightedGraph; +}()); var Point = (function () { - function Point(x, y) { - this.x = x ? x : 0; - this.y = y ? y : this.x; - } - return Point; -})(); -var UnweightedGridGraph = (function () { - function UnweightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { - allowDiagonalSearch = false; + function Point(x, y) { + this.x = x ? x : 0; + this.y = y ? y : this.x; } - this.walls = []; - this._neighbors = new Array(4); - this._width = width; - this._hegiht = height; - this._dirs = allowDiagonalSearch - ? UnweightedGridGraph.COMPASS_DIRS - : UnweightedGridGraph.CARDINAL_DIRS; - } - UnweightedGridGraph.prototype.isNodeInBounds = function (node) { - return ( - 0 <= node.x && - node.x < this._width && - 0 <= node.y && - node.y < this._hegiht - ); - }; - UnweightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { - return JSON.stringify(wall) == JSON.stringify(node); - }); - }; - UnweightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Point(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - UnweightedGridGraph.prototype.search = function (start, goal) { - return BreadthFirstPathfinder.search(this, start, goal); - }; - UnweightedGridGraph.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, -1), - ]; - UnweightedGridGraph.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]; - return UnweightedGridGraph; -})(); + return Point; +}()); +var UnweightedGridGraph = (function () { + function UnweightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this._neighbors = new Array(4); + this._width = width; + this._hegiht = height; + this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; + } + UnweightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; + }; + UnweightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + UnweightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new Point(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + UnweightedGridGraph.prototype.search = function (start, goal) { + return BreadthFirstPathfinder.search(this, start, goal); + }; + UnweightedGridGraph.CARDINAL_DIRS = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, -1) + ]; + UnweightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return UnweightedGridGraph; +}()); var WeightedGridGraph = (function () { - function WeightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { - allowDiagonalSearch = false; - } - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - this._dirs = allowDiagonalSearch - ? WeightedGridGraph.COMPASS_DIRS - : WeightedGridGraph.CARDINAL_DIRS; - } - WeightedGridGraph.prototype.isNodeInBounds = function (node) { - return ( - 0 <= node.x && - node.x < this._width && - 0 <= node.y && - node.y < this._height - ); - }; - WeightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { - return JSON.stringify(wall) == JSON.stringify(node); - }); - }; - WeightedGridGraph.prototype.search = function (start, goal) { - return WeightedPathfinder.search(this, start, goal); - }; - WeightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Point(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - WeightedGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (t) { - return JSON.stringify(t) == JSON.stringify(to); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }; - WeightedGridGraph.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]; - WeightedGridGraph.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]; - return WeightedGridGraph; -})(); + function WeightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; + this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; + } + WeightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + WeightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + WeightedGridGraph.prototype.search = function (start, goal) { + return WeightedPathfinder.search(this, start, goal); + }; + WeightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new Point(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + WeightedGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + WeightedGridGraph.CARDINAL_DIRS = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, 1) + ]; + WeightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return WeightedGridGraph; +}()); var WeightedNode = (function (_super) { - __extends(WeightedNode, _super); - function WeightedNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return WeightedNode; -})(PriorityQueueNode); + __extends(WeightedNode, _super); + function WeightedNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return WeightedNode; +}(PriorityQueueNode)); var WeightedPathfinder = (function () { - function WeightedPathfinder() {} - WeightedPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new WeightedNode(start), 0); - costSoFar.set(start, 0); - var _loop_4 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = - costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priprity = newCost; - frontier.enqueue(new WeightedNode(next), priprity); - cameFrom.set(next, current.data); - } - }); - }; - while (frontier.count > 0) { - var state_3 = _loop_4(); - if (state_3 === "break") break; - } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - WeightedPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (((r = iterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return true; - } - return false; - }; - WeightedPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (((r = iterator.next()), (v = valueIterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return v.value; - } - return null; - }; - WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return WeightedPathfinder; -})(); + function WeightedPathfinder() { + } + WeightedPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new PriorityQueue(1000); + frontier.enqueue(new WeightedNode(start), 0); + costSoFar.set(start, 0); + var _loop_4 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priprity = newCost; + frontier.enqueue(new WeightedNode(next), priprity); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_3 = _loop_4(); + if (state_3 === "break") + break; + } + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; + }; + WeightedPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + WeightedPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return WeightedPathfinder; +}()); var DebugDefaults = (function () { - function DebugDefaults() {} - DebugDefaults.verletParticle = 0xdc345e; - DebugDefaults.verletConstraintEdge = 0x433e36; - return DebugDefaults; -})(); -var Component = (function (_super) { - __extends(Component, _super); - function Component() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this._enabled = true; - _this.updateInterval = 1; - return _this; - } - Object.defineProperty(Component.prototype, "enabled", { - get: function () { - return this.entity ? this.entity.enabled && this._enabled : this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true, - }); - Component.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); - } else { - this.onDisabled(); - } + function DebugDefaults() { } - return this; - }; - Component.prototype.initialize = function () {}; - Component.prototype.onAddedToEntity = function () {}; - Component.prototype.onRemovedFromEntity = function () {}; - Component.prototype.onEnabled = function () {}; - Component.prototype.onDisabled = function () {}; - Component.prototype.onEntityTransformChanged = function (comp) {}; - Component.prototype.update = function () {}; - Component.prototype.debugRender = function () {}; - Component.prototype.registerComponent = function () { - this.entity.componentBits.set( - ComponentTypeManager.getIndexFor(this), - false - ); - this.entity.scene.entityProcessors.onComponentAdded(this.entity); - }; - Component.prototype.deregisterComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)); - this.entity.scene.entityProcessors.onComponentRemoved(this.entity); - }; - return Component; -})(egret.DisplayObjectContainer); + DebugDefaults.verletParticle = 0xDC345E; + DebugDefaults.verletConstraintEdge = 0x433E36; + return DebugDefaults; +}()); +var Component = (function (_super) { + __extends(Component, _super); + function Component() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._enabled = true; + _this.updateInterval = 1; + return _this; + } + Object.defineProperty(Component.prototype, "enabled", { + get: function () { + return this.entity ? this.entity.enabled && this._enabled : this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Component.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } + } + return this; + }; + Component.prototype.initialize = function () { + }; + Component.prototype.onAddedToEntity = function () { + }; + Component.prototype.onRemovedFromEntity = function () { + }; + Component.prototype.onEnabled = function () { + }; + Component.prototype.onDisabled = function () { + }; + Component.prototype.update = function () { + }; + Component.prototype.debugRender = function () { + }; + Component.prototype.registerComponent = function () { + this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false); + this.entity.scene.entityProcessors.onComponentAdded(this.entity); + }; + Component.prototype.deregisterComponent = function () { + this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)); + this.entity.scene.entityProcessors.onComponentRemoved(this.entity); + }; + return Component; +}(egret.DisplayObjectContainer)); var Entity = (function (_super) { - __extends(Entity, _super); - function Entity(name) { - var _this = _super.call(this) || this; - _this._position = Vector2.zero; - _this._updateOrder = 0; - _this._enabled = true; - _this._tag = 0; - _this.name = name; - _this.components = new ComponentList(_this); - _this.id = Entity._idGenerator++; - _this.componentBits = new BitSet(); - return _this; - } - Object.defineProperty(Entity.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "position", { - get: function () { - return this._position; - }, - set: function (value) { - this._position = value; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "scale", { - get: function () { - return new Vector2(this.scaleX, this.scaleY); - }, - set: function (value) { - this.scaleX = value.x; - this.scaleY = value.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true, - }); - Entity.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - } - return this; - }; - Object.defineProperty(Entity.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (value) { - this.setTag(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "stage", { - get: function () { - if (!this.scene) return null; - return this.scene.stage; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (value) { - this.setUpdateOrder(value); - }, - enumerable: true, - configurable: true, - }); - Entity.prototype.roundPosition = function () { - this.position = Vector2Ext.round(this.position); - }; - Entity.prototype.setUpdateOrder = function (updateOrder) { - if (this._updateOrder != updateOrder) { - this._updateOrder = updateOrder; - if (this.scene) { - } - return this; - } - }; - Entity.prototype.setTag = function (tag) { - if (this._tag != tag) { - if (this.scene) { - this.scene.entities.removeFromTagList(this); - } - this._tag = tag; - if (this.scene) { - this.scene.entities.addToTagList(this); - } - } - return this; - }; - Entity.prototype.attachToScene = function (newScene) { - this.scene = newScene; - newScene.entities.add(this); - this.components.registerAllComponents(); - for (var i = 0; i < this.numChildren; i++) { - this.getChildAt(i).entity.attachToScene(newScene); - } - }; - Entity.prototype.detachFromScene = function () { - this.scene.entities.remove(this); - this.components.deregisterAllComponents(); - for (var i = 0; i < this.numChildren; i++) - this.getChildAt(i).entity.detachFromScene(); - }; - Entity.prototype.addComponent = function (component) { - component.entity = this; - this.components.add(component); - this.addChild(component); - component.initialize(); - return component; - }; - Entity.prototype.hasComponent = function (type) { - return this.components.getComponent(type, false) != null; - }; - Entity.prototype.getOrCreateComponent = function (type) { - var comp = this.components.getComponent(type, true); - if (!comp) { - comp = this.addComponent(type); - } - return comp; - }; - Entity.prototype.getComponent = function (type) { - return this.components.getComponent(type, false); - }; - Entity.prototype.getComponents = function (typeName, componentList) { - return this.components.getComponents(typeName, componentList); - }; - Entity.prototype.removeComponentForType = function (type) { - var comp = this.getComponent(type); - if (comp) { - this.removeComponent(comp); - return true; - } - return false; - }; - Entity.prototype.removeComponent = function (component) { - this.components.remove(component); - }; - Entity.prototype.removeAllComponents = function () { - for (var i = 0; i < this.components.count; i++) { - this.removeComponent(this.components.buffer[i]); - } - }; - Entity.prototype.update = function () { - this.components.update(); - }; - Entity.prototype.onAddedToScene = function () {}; - Entity.prototype.onRemovedFromScene = function () { - if (this._isDestoryed) this.components.removeAllComponents(); - }; - Entity.prototype.onTransformChanged = function (comp) { - this.components.onEntityTransformChanged(comp); - }; - Entity.prototype.destroy = function () { - this._isDestoryed = true; - this.scene.entities.remove(this); - this.removeChildren(); - for (var i = this.numChildren - 1; i >= 0; i--) { - var child = this.getChildAt(i); - child.entity.destroy(); - } - }; - return Entity; -})(egret.DisplayObjectContainer); -var Scene = (function (_super) { - __extends(Scene, _super); - function Scene() { - var _this = _super.call(this) || this; - _this.enablePostProcessing = true; - _this._renderers = []; - _this._postProcessors = []; - _this.entityProcessors = new EntityProcessorList(); - _this.renderableComponents = new RenderableComponentList(); - _this.entities = new EntityList(_this); - _this.content = new ContentManager(); - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); - _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); - return _this; - } - Scene.prototype.createEntity = function (name) { - var entity = new Entity(name); - entity.position = new Vector2(0, 0); - return this.addEntity(entity); - }; - Scene.prototype.addEntity = function (entity) { - this.entities.add(entity); - entity.scene = this; - this.addChild(entity); - for (var i = 0; i < entity.numChildren; i++) - this.addEntity(entity.getChildAt(i).entity); - return entity; - }; - Scene.prototype.destroyAllEntities = function () { - for (var i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destroy(); - } - }; - Scene.prototype.findEntity = function (name) { - return this.entities.findEntity(name); - }; - Scene.prototype.addEntityProcessor = function (processor) { - processor.scene = this; - this.entityProcessors.add(processor); - return processor; - }; - Scene.prototype.removeEntityProcessor = function (processor) { - this.entityProcessors.remove(processor); - }; - Scene.prototype.getEntityProcessor = function () { - return this.entityProcessors.getProcessor(); - }; - Scene.prototype.addRenderer = function (renderer) { - this._renderers.push(renderer); - this._renderers.sort(); - renderer.onAddedToScene(this); - return renderer; - }; - Scene.prototype.getRenderer = function (type) { - for (var i = 0; i < this._renderers.length; i++) { - if (this._renderers[i] instanceof type) return this._renderers[i]; - } - return null; - }; - Scene.prototype.removeRenderer = function (renderer) { - this._renderers.remove(renderer); - renderer.unload(); - }; - Scene.prototype.begin = function () { - if (SceneManager.sceneTransition) { - SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); - } else { - SceneManager.stage.addChild(this); - } - if (this._renderers.length == 0) { - this.addRenderer(new DefaultRenderer()); - console.warn( - "场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染" - ); - } - this.camera = this.createEntity("camera").getOrCreateComponent( - new Camera() - ); - Physics.reset(); - if (this.entityProcessors) this.entityProcessors.begin(); - this.camera.onSceneSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ); - this._didSceneBegin = true; - this.onStart(); - }; - Scene.prototype.end = function () { - this._didSceneBegin = false; - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].unload(); - } - for (var i = 0; i < this._postProcessors.length; i++) { - this._postProcessors[i].unload(); - } - this.entities.removeAllEntities(); - this.removeChildren(); - Physics.clear(); - this.camera = null; - this.content.dispose(); - if (this.entityProcessors) this.entityProcessors.end(); - this.unload(); - }; - Scene.prototype.onStart = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2]; - }); + __extends(Entity, _super); + function Entity(name) { + var _this = _super.call(this) || this; + _this._position = Vector2.zero; + _this._updateOrder = 0; + _this._enabled = true; + _this._tag = 0; + _this.name = name; + _this.components = new ComponentList(_this); + _this.id = Entity._idGenerator++; + _this.componentBits = new BitSet(); + return _this; + } + Object.defineProperty(Entity.prototype, "isDestoryed", { + get: function () { + return this._isDestoryed; + }, + enumerable: true, + configurable: true }); - }; - Scene.prototype.onActive = function () {}; - Scene.prototype.onDeactive = function () {}; - Scene.prototype.unload = function () {}; - Scene.prototype.update = function () { - this.entities.updateLists(); - if (this.entityProcessors) this.entityProcessors.update(); - this.entities.update(); - if (this.entityProcessors) this.entityProcessors.lateUpdate(); - this.renderableComponents.updateList(); - }; - Scene.prototype.postRender = function () { - var enabledCounter = 0; - if (this.enablePostProcessing) { - for (var i = 0; i < this._postProcessors.length; i++) { - if (this._postProcessors[i].enable) { - var isEven = MathHelper.isEven(enabledCounter); - enabledCounter++; - this._postProcessors[i].process(); - } - } - } - }; - Scene.prototype.render = function () { - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].render(this); - } - }; - Scene.prototype.addPostProcessor = function (postProcessor) { - this._postProcessors.push(postProcessor); - this._postProcessors.sort(); - postProcessor.onAddedToScene(this); - if (this._didSceneBegin) { - postProcessor.onSceneBackBufferSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ); - } - return postProcessor; - }; - return Scene; -})(egret.DisplayObjectContainer); -var SceneManager = (function () { - function SceneManager(stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - SceneManager.stage = stage; - SceneManager.initialize(stage); - } - Object.defineProperty(SceneManager, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - if (!value) throw new Error("场景不能为空"); - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - } else { - this._nextScene = value; - } - }, - enumerable: true, - configurable: true, - }); - SceneManager.initialize = function (stage) { - Input.initialize(stage); - }; - SceneManager.update = function () { - Time.update(egret.getTimer()); - if (SceneManager._scene) { - for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } - if ( - !SceneManager.sceneTransition || - (SceneManager.sceneTransition && - (!SceneManager.sceneTransition.loadsNewScene || - SceneManager.sceneTransition.isNewSceneLoaded)) - ) { - SceneManager._scene.update(); - } - if (SceneManager._nextScene) { - SceneManager._scene.end(); - for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { - var entity = SceneManager._scene.entities.buffer[i]; - entity.destroy(); - } - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._scene.begin(); - } - } - SceneManager.render(); - }; - SceneManager.render = function () { - if (this.sceneTransition) { - this.sceneTransition.preRender(); - if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { - this._scene.render(); - this._scene.postRender(); - } - this.sceneTransition.render(); - } - } else if (this._scene) { - this._scene.render(); - this._scene.postRender(); - } - }; - SceneManager.startSceneTransition = function (sceneTransition) { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; - } - this.sceneTransition = sceneTransition; - return sceneTransition; - }; - return SceneManager; -})(); -var DirtyType; -(function (DirtyType) { - DirtyType[(DirtyType["clean"] = 0)] = "clean"; - DirtyType[(DirtyType["positionDirty"] = 1)] = "positionDirty"; - DirtyType[(DirtyType["scaleDirty"] = 2)] = "scaleDirty"; - DirtyType[(DirtyType["rotationDirty"] = 3)] = "rotationDirty"; -})(DirtyType || (DirtyType = {})); -var ComponentTransform; -(function (ComponentTransform) { - ComponentTransform[(ComponentTransform["position"] = 0)] = "position"; - ComponentTransform[(ComponentTransform["scale"] = 1)] = "scale"; - ComponentTransform[(ComponentTransform["rotation"] = 2)] = "rotation"; -})(ComponentTransform || (ComponentTransform = {})); -var Transform = (function () { - function Transform(entity) { - this._localRotation = 0; - this._worldTransform = Matrix2D.identity; - this._worldToLocalTransform = Matrix2D.identity; - this._worldInverseTransform = Matrix2D.identity; - this._rotation = 0; - this.entity = entity; - this._scale = this._localScale = Vector2.one; - this._children = []; - } - Object.defineProperty(Transform.prototype, "childCount", { - get: function () { - return this._children.length; - }, - enumerable: true, - configurable: true, - }); - Transform.prototype.getChild = function (index) { - return this._children[index]; - }; - Object.defineProperty(Transform.prototype, "worldInverseTransform", { - get: function () { - this.updateTransform(); - if (this._worldInverseDirty) { - this._worldInverseTransform = Matrix2D.invert( - this._worldTransform, - this._worldInverseTransform - ); - this._worldInverseDirty = false; - } - return this._worldInverseTransform; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localToWorldTransform", { - get: function () { - this.updateTransform(); - return this._worldTransform; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "worldToLocalTransform", { - get: function () { - if (this._worldToLocalDirty) { - if (!this.parent) { - this._worldInverseTransform = new Matrix2D(); - } else { - this.parent.updateTransform(); - this._worldToLocalTransform = Matrix2D.invert( - this.parent._worldTransform, - this._worldToLocalTransform - ); - } - this._worldToLocalDirty = false; - } - return this._worldToLocalTransform; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "parent", { - get: function () { - return this._parent; - }, - set: function (value) { - this.setParent(value); - }, - enumerable: true, - configurable: true, - }); - Transform.prototype.setParent = function (parent) { - if (this._parent == parent) return this; - if (this._parent) this._parent._children.remove(this); - if (parent) parent._children.push(this); - this._parent = parent; - return this; - }; - Object.defineProperty(Transform.prototype, "rotation", { - get: function () { - this.updateTransform(); - return this._rotation; - }, - set: function (value) { - this.setRotation(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localRotation", { - get: function () { - this.updateTransform(); - return this._localRotation; - }, - set: function (value) { - this.setLocalRotation(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "position", { - get: function () { - this.updateTransform(); - if (this._positionDirty) { - if (!this.parent) { - this._position = this._localPosition; - } else { - this.parent.updateTransform(); - this._position = Vector2Ext.transformR( - this._localPosition, - this.parent._worldTransform - ); - } - this._positionDirty = false; - } - return this._position; - }, - set: function (value) { - this.setPosition(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localPosition", { - get: function () { - this.updateTransform(); - return this._localPosition; - }, - set: function (value) { - this.setLocalPosition(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "scale", { - get: function () { - this.updateTransform(); - return this._scale; - }, - set: function (value) { - this.setScale(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localScale", { - get: function () { - this.updateTransform(); - return this._localScale; - }, - set: function (value) { - this.setLocalScale(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._rotation); - }, - set: function (value) { - this.setRotation(MathHelper.toRadians(value)); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localRotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._localRotation); - }, - set: function (value) { - this.localRotation = MathHelper.toRadians(value); - }, - enumerable: true, - configurable: true, - }); - Transform.prototype.setLocalScale = function (scale) { - this._localScale = scale; - this._localDirty = this._positionDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.scaleDirty); - return this; - }; - Transform.prototype.setScale = function (scale) { - this._scale = scale; - if (this.parent) { - this.localScale = Vector2.divide(scale, this.parent._scale); - } else { - this.localScale = scale; - } - return this; - }; - Transform.prototype.setLocalRotationDegrees = function (degrees) { - return this.setLocalRotation(MathHelper.toRadians(degrees)); - }; - Transform.prototype.setLocalRotation = function (radians) { - this._localRotation = radians; - this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.rotationDirty); - return this; - }; - Transform.prototype.setRotation = function (radians) { - this._rotation = radians; - if (this.parent) { - this.localRotation = this.parent.rotation + radians; - } else { - this.localRotation = radians; - } - return this; - }; - Transform.prototype.setRotationDegrees = function (degrees) { - return this.setRotation(MathHelper.toRadians(degrees)); - }; - Transform.prototype.setLocalPosition = function (localPosition) { - if (localPosition == this._localPosition) return this; - this._localPosition = localPosition; - this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.positionDirty); - return this; - }; - Transform.prototype.setPosition = function (position) { - if (position == this._position) return this; - this._position = position; - if (this.parent) { - this.localPosition = Vector2.transform( - this._position, - this._worldToLocalTransform - ); - } else { - this.localPosition = position; - } - this._positionDirty = false; - return this; - }; - Transform.prototype.setDirty = function (dirtyFlagType) { - if ((this._hierachyDirty & dirtyFlagType) == 0) { - this._hierachyDirty |= dirtyFlagType; - switch (dirtyFlagType) { - case DirtyType.positionDirty: - this.entity.onTransformChanged(ComponentTransform.position); - break; - case DirtyType.rotationDirty: - this.entity.onTransformChanged(ComponentTransform.rotation); - break; - case DirtyType.scaleDirty: - this.entity.onTransformChanged(ComponentTransform.scale); - break; - } - if (this._children == null) this._children = []; - for (var i = 0; i < this._children.length; i++) { - this._children[i].setDirty(dirtyFlagType); - } - } - }; - Transform.prototype.roundPosition = function () { - this.position = this._position.round(); - }; - Transform.prototype.updateTransform = function () { - if (this._hierachyDirty != DirtyType.clean) { - if (this.parent) this.parent.updateTransform(); - if (this._localDirty) { - if (this._localPositionDirty) { - this._translationMatrix = Matrix2D.createTranslation( - this._localPosition.x, - this._localPosition.y - ); - this._localPositionDirty = false; - } - if (this._localRotationDirty) { - this._rotationMatrix = Matrix2D.createRotation(this._localRotation); - this._localRotationDirty = false; - } - if (this._localScaleDirty) { - this._scaleMatrix = Matrix2D.createScale( - this._localScale.x, - this._localScale.y - ); - this._localScaleDirty = false; - } - this._localTransform = Matrix2D.multiply( - this._scaleMatrix, - this._rotationMatrix - ); - this._localTransform = Matrix2D.multiply( - this._localTransform, - this._translationMatrix - ); - if (!this.parent) { - this._worldTransform = this._localTransform; - this._rotation = this._localRotation; - this._scale = this._localScale; - this._worldInverseDirty = true; - } - this._localDirty = false; - } - if (this.parent) { - this._worldTransform = Matrix2D.multiply( - this._localTransform, - this.parent._worldTransform - ); - this._rotation = this._localRotation + this.parent._rotation; - this._scale = Vector2.multiply(this.parent._scale, this._localScale); - this._worldInverseDirty = true; - } - this._worldToLocalDirty = true; - this._positionDirty = true; - this._hierachyDirty = DirtyType.clean; - } - }; - return Transform; -})(); -var Camera = (function (_super) { - __extends(Camera, _super); - function Camera() { - var _this = _super.call(this) || this; - _this._origin = Vector2.zero; - _this._minimumZoom = 0.3; - _this._maximumZoom = 3; - _this.followLerp = 0.1; - _this.deadzone = new Rectangle(); - _this.focusOffset = new Vector2(); - _this.mapLockEnabled = false; - _this.mapSize = new Vector2(); - _this._worldSpaceDeadZone = new Rectangle(); - _this._desiredPositionDelta = new Vector2(); - _this.cameraStyle = CameraStyle.lockOn; - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.setZoom(0); - return _this; - } - Object.defineProperty(Camera.prototype, "zoom", { - get: function () { - if (this._zoom == 0) return 1; - if (this._zoom < 1) - return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); - return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); - }, - set: function (value) { - this.setZoom(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "minimumZoom", { - get: function () { - return this._minimumZoom; - }, - set: function (value) { - this.setMinimumZoom(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "maximumZoom", { - get: function () { - return this._maximumZoom; - }, - set: function (value) { - this.setMaximumZoom(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (value) { - if (this._origin != value) { - this._origin = value; - } - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "position", { - get: function () { - return this.entity.position; - }, - set: function (value) { - this.entity.position = value; - }, - enumerable: true, - configurable: true, - }); - Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { - var oldOrigin = this._origin; - this.origin = new Vector2(newWidth / 2, newHeight / 2); - this.entity.position = Vector2.add( - this.entity.position, - Vector2.subtract(this._origin, oldOrigin) - ); - }; - Camera.prototype.setMinimumZoom = function (minZoom) { - if (this._zoom < minZoom) this._zoom = this.minimumZoom; - this._minimumZoom = minZoom; - return this; - }; - Camera.prototype.setMaximumZoom = function (maxZoom) { - if (this._zoom > maxZoom) this._zoom = maxZoom; - this._maximumZoom = maxZoom; - return this; - }; - Camera.prototype.setZoom = function (zoom) { - var newZoom = MathHelper.clamp(zoom, -1, 1); - if (newZoom == 0) { - this._zoom = 1; - } else if (newZoom < 0) { - this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); - } else { - this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); - } - SceneManager.scene.scaleX = this._zoom; - SceneManager.scene.scaleY = this._zoom; - return this; - }; - Camera.prototype.setRotation = function (rotation) { - SceneManager.scene.rotation = rotation; - return this; - }; - Camera.prototype.setPosition = function (position) { - this.entity.position = position; - return this; - }; - Camera.prototype.follow = function (targetEntity, cameraStyle) { - if (cameraStyle === void 0) { - cameraStyle = CameraStyle.cameraWindow; - } - this.targetEntity = targetEntity; - this.cameraStyle = cameraStyle; - var cameraBounds = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - switch (this.cameraStyle) { - case CameraStyle.cameraWindow: - var w = cameraBounds.width / 6; - var h = cameraBounds.height / 3; - this.deadzone = new Rectangle( - (cameraBounds.width - w) / 2, - (cameraBounds.height - h) / 2, - w, - h - ); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle( - cameraBounds.width / 2, - cameraBounds.height / 2, - 10, - 10 - ); - break; - } - }; - Camera.prototype.update = function () { - var cameraBounds = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - var halfScreen = Vector2.multiply( - new Vector2(cameraBounds.width, cameraBounds.height), - new Vector2(0.5) - ); - this._worldSpaceDeadZone.x = - this.position.x - halfScreen.x + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = - this.position.y - halfScreen.y + this.deadzone.y + this.focusOffset.y; - this._worldSpaceDeadZone.width = this.deadzone.width; - this._worldSpaceDeadZone.height = this.deadzone.height; - if (this.targetEntity) this.updateFollow(); - this.position = Vector2.lerp( - this.position, - Vector2.add(this.position, this._desiredPositionDelta), - this.followLerp - ); - this.entity.roundPosition(); - if (this.mapLockEnabled) { - this.position = this.clampToMapSize(this.position); - this.entity.roundPosition(); - } - }; - Camera.prototype.clampToMapSize = function (position) { - var cameraBounds = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - var halfScreen = Vector2.multiply( - new Vector2(cameraBounds.width, cameraBounds.height), - new Vector2(0.5) - ); - var cameraMax = new Vector2( - this.mapSize.x - halfScreen.x, - this.mapSize.y - halfScreen.y - ); - return Vector2.clamp(position, halfScreen, cameraMax); - }; - Camera.prototype.updateFollow = function () { - this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; - if (this.cameraStyle == CameraStyle.lockOn) { - var targetX = this.targetEntity.position.x; - var targetY = this.targetEntity.position.y; - if (this._worldSpaceDeadZone.x > targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - else if (this._worldSpaceDeadZone.x < targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - if (this._worldSpaceDeadZone.y < targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - else if (this._worldSpaceDeadZone.y > targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - } else { - if (!this._targetCollider) { - this._targetCollider = this.targetEntity.getComponent(Collider); - if (!this._targetCollider) return; - } - var targetBounds = this.targetEntity.getComponent(Collider).bounds; - if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { - if (this._worldSpaceDeadZone.left > targetBounds.left) - this._desiredPositionDelta.x = - targetBounds.left - this._worldSpaceDeadZone.left; - else if (this._worldSpaceDeadZone.right < targetBounds.right) - this._desiredPositionDelta.x = - targetBounds.right - this._worldSpaceDeadZone.right; - if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) - this._desiredPositionDelta.y = - targetBounds.bottom - this._worldSpaceDeadZone.bottom; - else if (this._worldSpaceDeadZone.top > targetBounds.top) - this._desiredPositionDelta.y = - targetBounds.top - this._worldSpaceDeadZone.top; - } - } - }; - return Camera; -})(Component); -var CameraStyle; -(function (CameraStyle) { - CameraStyle[(CameraStyle["lockOn"] = 0)] = "lockOn"; - CameraStyle[(CameraStyle["cameraWindow"] = 1)] = "cameraWindow"; + Object.defineProperty(Entity.prototype, "position", { + get: function () { + return this._position; + }, + set: function (value) { + this._position = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "scale", { + get: function () { + return new Vector2(this.scaleX, this.scaleY); + }, + set: function (value) { + this.scaleX = value.x; + this.scaleY = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Entity.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + } + return this; + }; + Object.defineProperty(Entity.prototype, "tag", { + get: function () { + return this._tag; + }, + set: function (value) { + this.setTag(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "stage", { + get: function () { + if (!this.scene) + return null; + return this.scene.stage; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "updateOrder", { + get: function () { + return this._updateOrder; + }, + set: function (value) { + this.setUpdateOrder(value); + }, + enumerable: true, + configurable: true + }); + Entity.prototype.roundPosition = function () { + this.position = Vector2Ext.round(this.position); + }; + Entity.prototype.setUpdateOrder = function (updateOrder) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; + if (this.scene) { + } + return this; + } + }; + Entity.prototype.setTag = function (tag) { + if (this._tag != tag) { + if (this.scene) { + this.scene.entities.removeFromTagList(this); + } + this._tag = tag; + if (this.scene) { + this.scene.entities.addToTagList(this); + } + } + return this; + }; + Entity.prototype.attachToScene = function (newScene) { + this.scene = newScene; + newScene.entities.add(this); + this.components.registerAllComponents(); + for (var i = 0; i < this.numChildren; i++) { + this.getChildAt(i).entity.attachToScene(newScene); + } + }; + Entity.prototype.detachFromScene = function () { + this.scene.entities.remove(this); + this.components.deregisterAllComponents(); + for (var i = 0; i < this.numChildren; i++) + this.getChildAt(i).entity.detachFromScene(); + }; + Entity.prototype.addComponent = function (component) { + component.entity = this; + this.components.add(component); + this.addChild(component); + component.initialize(); + return component; + }; + Entity.prototype.hasComponent = function (type) { + return this.components.getComponent(type, false) != null; + }; + Entity.prototype.getOrCreateComponent = function (type) { + var comp = this.components.getComponent(type, true); + if (!comp) { + comp = this.addComponent(type); + } + return comp; + }; + Entity.prototype.getComponent = function (type) { + return this.components.getComponent(type, false); + }; + Entity.prototype.getComponents = function (typeName, componentList) { + return this.components.getComponents(typeName, componentList); + }; + Entity.prototype.removeComponentForType = function (type) { + var comp = this.getComponent(type); + if (comp) { + this.removeComponent(comp); + return true; + } + return false; + }; + Entity.prototype.removeComponent = function (component) { + this.components.remove(component); + }; + Entity.prototype.removeAllComponents = function () { + for (var i = 0; i < this.components.count; i++) { + this.removeComponent(this.components.buffer[i]); + } + }; + Entity.prototype.update = function () { + this.components.update(); + }; + Entity.prototype.onAddedToScene = function () { + }; + Entity.prototype.onRemovedFromScene = function () { + if (this._isDestoryed) + this.components.removeAllComponents(); + }; + Entity.prototype.destroy = function () { + this._isDestoryed = true; + this.scene.entities.remove(this); + this.removeChildren(); + for (var i = this.numChildren - 1; i >= 0; i--) { + var child = this.getChildAt(i); + child.entity.destroy(); + } + }; + return Entity; +}(egret.DisplayObjectContainer)); +var Scene = (function (_super) { + __extends(Scene, _super); + function Scene() { + var _this = _super.call(this) || this; + _this.enablePostProcessing = true; + _this._renderers = []; + _this._postProcessors = []; + _this.entityProcessors = new EntityProcessorList(); + _this.renderableComponents = new RenderableComponentList(); + _this.entities = new EntityList(_this); + _this.content = new ContentManager(); + _this.width = SceneManager.stage.stageWidth; + _this.height = SceneManager.stage.stageHeight; + _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); + _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); + return _this; + } + Scene.prototype.createEntity = function (name) { + var entity = new Entity(name); + entity.position = new Vector2(0, 0); + return this.addEntity(entity); + }; + Scene.prototype.addEntity = function (entity) { + this.entities.add(entity); + entity.scene = this; + this.addChild(entity); + for (var i = 0; i < entity.numChildren; i++) + this.addEntity(entity.getChildAt(i).entity); + return entity; + }; + Scene.prototype.destroyAllEntities = function () { + for (var i = 0; i < this.entities.count; i++) { + this.entities.buffer[i].destroy(); + } + }; + Scene.prototype.findEntity = function (name) { + return this.entities.findEntity(name); + }; + Scene.prototype.addEntityProcessor = function (processor) { + processor.scene = this; + this.entityProcessors.add(processor); + return processor; + }; + Scene.prototype.removeEntityProcessor = function (processor) { + this.entityProcessors.remove(processor); + }; + Scene.prototype.getEntityProcessor = function () { + return this.entityProcessors.getProcessor(); + }; + Scene.prototype.addRenderer = function (renderer) { + this._renderers.push(renderer); + this._renderers.sort(); + renderer.onAddedToScene(this); + return renderer; + }; + Scene.prototype.getRenderer = function (type) { + for (var i = 0; i < this._renderers.length; i++) { + if (this._renderers[i] instanceof type) + return this._renderers[i]; + } + return null; + }; + Scene.prototype.removeRenderer = function (renderer) { + this._renderers.remove(renderer); + renderer.unload(); + }; + Scene.prototype.begin = function () { + if (SceneManager.sceneTransition) { + SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); + } + else { + SceneManager.stage.addChild(this); + } + if (this._renderers.length == 0) { + this.addRenderer(new DefaultRenderer()); + console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); + } + this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); + Physics.reset(); + if (this.entityProcessors) + this.entityProcessors.begin(); + this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + this._didSceneBegin = true; + this.onStart(); + }; + Scene.prototype.end = function () { + this._didSceneBegin = false; + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].unload(); + } + for (var i = 0; i < this._postProcessors.length; i++) { + this._postProcessors[i].unload(); + } + this.entities.removeAllEntities(); + this.removeChildren(); + Physics.clear(); + this.camera = null; + this.content.dispose(); + if (this.entityProcessors) + this.entityProcessors.end(); + this.unload(); + }; + Scene.prototype.onStart = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2]; + }); + }); + }; + Scene.prototype.onActive = function () { + }; + Scene.prototype.onDeactive = function () { + }; + Scene.prototype.unload = function () { }; + Scene.prototype.update = function () { + this.entities.updateLists(); + if (this.entityProcessors) + this.entityProcessors.update(); + this.entities.update(); + if (this.entityProcessors) + this.entityProcessors.lateUpdate(); + this.renderableComponents.updateList(); + }; + Scene.prototype.postRender = function () { + var enabledCounter = 0; + if (this.enablePostProcessing) { + for (var i = 0; i < this._postProcessors.length; i++) { + if (this._postProcessors[i].enable) { + var isEven = MathHelper.isEven(enabledCounter); + enabledCounter++; + this._postProcessors[i].process(); + } + } + } + }; + Scene.prototype.render = function () { + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].render(this); + } + }; + Scene.prototype.addPostProcessor = function (postProcessor) { + this._postProcessors.push(postProcessor); + this._postProcessors.sort(); + postProcessor.onAddedToScene(this); + if (this._didSceneBegin) { + postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + } + return postProcessor; + }; + return Scene; +}(egret.DisplayObjectContainer)); +var SceneManager = (function () { + function SceneManager(stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); + SceneManager.stage = stage; + SceneManager.initialize(stage); + } + Object.defineProperty(SceneManager, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + if (!value) + throw new Error("场景不能为空"); + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + } + else { + this._nextScene = value; + } + }, + enumerable: true, + configurable: true + }); + SceneManager.initialize = function (stage) { + Input.initialize(stage); + }; + SceneManager.update = function () { + Time.update(egret.getTimer()); + if (SceneManager._scene) { + for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (GlobalManager.globalManagers[i].enabled) + GlobalManager.globalManagers[i].update(); + } + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + SceneManager._scene.update(); + } + if (SceneManager._nextScene) { + SceneManager._scene.end(); + for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { + var entity = SceneManager._scene.entities.buffer[i]; + entity.destroy(); + } + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + SceneManager._scene.begin(); + } + } + SceneManager.render(); + }; + SceneManager.render = function () { + if (this.sceneTransition) { + this.sceneTransition.preRender(); + if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { + this._scene.render(); + this._scene.postRender(); + this.sceneTransition.onBeginTransition(); + } + else if (this.sceneTransition) { + if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + this.sceneTransition.render(); + } + } + else if (this._scene) { + this._scene.render(); + this._scene.postRender(); + } + }; + SceneManager.startSceneTransition = function (sceneTransition) { + if (this.sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } + this.sceneTransition = sceneTransition; + return sceneTransition; + }; + return SceneManager; +}()); +var Camera = (function (_super) { + __extends(Camera, _super); + function Camera() { + var _this = _super.call(this) || this; + _this._origin = Vector2.zero; + _this._minimumZoom = 0.3; + _this._maximumZoom = 3; + _this.followLerp = 0.1; + _this.deadzone = new Rectangle(); + _this.focusOffset = new Vector2(); + _this.mapLockEnabled = false; + _this.mapSize = new Vector2(); + _this._worldSpaceDeadZone = new Rectangle(); + _this._desiredPositionDelta = new Vector2(); + _this.cameraStyle = CameraStyle.lockOn; + _this.width = SceneManager.stage.stageWidth; + _this.height = SceneManager.stage.stageHeight; + _this.setZoom(0); + return _this; + } + Object.defineProperty(Camera.prototype, "zoom", { + get: function () { + if (this._zoom == 0) + return 1; + if (this._zoom < 1) + return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); + return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); + }, + set: function (value) { + this.setZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "minimumZoom", { + get: function () { + return this._minimumZoom; + }, + set: function (value) { + this.setMinimumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "maximumZoom", { + get: function () { + return this._maximumZoom; + }, + set: function (value) { + this.setMaximumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + if (this._origin != value) { + this._origin = value; + } + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "position", { + get: function () { + return this.entity.position; + }, + set: function (value) { + this.entity.position = value; + }, + enumerable: true, + configurable: true + }); + Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { + var oldOrigin = this._origin; + this.origin = new Vector2(newWidth / 2, newHeight / 2); + this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); + }; + Camera.prototype.setMinimumZoom = function (minZoom) { + if (this._zoom < minZoom) + this._zoom = this.minimumZoom; + this._minimumZoom = minZoom; + return this; + }; + Camera.prototype.setMaximumZoom = function (maxZoom) { + if (this._zoom > maxZoom) + this._zoom = maxZoom; + this._maximumZoom = maxZoom; + return this; + }; + Camera.prototype.setZoom = function (zoom) { + var newZoom = MathHelper.clamp(zoom, -1, 1); + if (newZoom == 0) { + this._zoom = 1; + } + else if (newZoom < 0) { + this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); + } + else { + this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); + } + SceneManager.scene.scaleX = this._zoom; + SceneManager.scene.scaleY = this._zoom; + return this; + }; + Camera.prototype.setRotation = function (rotation) { + SceneManager.scene.rotation = rotation; + return this; + }; + Camera.prototype.setPosition = function (position) { + this.entity.position = position; + return this; + }; + Camera.prototype.follow = function (targetEntity, cameraStyle) { + if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; } + this.targetEntity = targetEntity; + this.cameraStyle = cameraStyle; + var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + switch (this.cameraStyle) { + case CameraStyle.cameraWindow: + var w = cameraBounds.width / 6; + var h = cameraBounds.height / 3; + this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h); + break; + case CameraStyle.lockOn: + this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10); + break; + } + }; + Camera.prototype.update = function () { + var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.width = this.deadzone.width; + this._worldSpaceDeadZone.height = this.deadzone.height; + if (this.targetEntity) + this.updateFollow(); + this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); + this.entity.roundPosition(); + if (this.mapLockEnabled) { + this.position = this.clampToMapSize(this.position); + this.entity.roundPosition(); + } + }; + Camera.prototype.clampToMapSize = function (position) { + var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); + var cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); + return Vector2.clamp(position, halfScreen, cameraMax); + }; + Camera.prototype.updateFollow = function () { + this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; + if (this.cameraStyle == CameraStyle.lockOn) { + var targetX = this.targetEntity.position.x; + var targetY = this.targetEntity.position.y; + if (this._worldSpaceDeadZone.x > targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + else if (this._worldSpaceDeadZone.x < targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + if (this._worldSpaceDeadZone.y < targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + else if (this._worldSpaceDeadZone.y > targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + } + else { + if (!this._targetCollider) { + this._targetCollider = this.targetEntity.getComponent(Collider); + if (!this._targetCollider) + return; + } + var targetBounds = this.targetEntity.getComponent(Collider).bounds; + if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { + if (this._worldSpaceDeadZone.left > targetBounds.left) + this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; + else if (this._worldSpaceDeadZone.right < targetBounds.right) + this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; + if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) + this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; + else if (this._worldSpaceDeadZone.top > targetBounds.top) + this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; + } + } + }; + return Camera; +}(Component)); +var CameraStyle; +(function (CameraStyle) { + CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; + CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; })(CameraStyle || (CameraStyle = {})); var ComponentPool = (function () { - function ComponentPool(typeClass) { - this._type = typeClass; - this._cache = []; - } - ComponentPool.prototype.obtain = function () { - try { - return this._cache.length > 0 ? this._cache.shift() : new this._type(); - } catch (err) { - throw new Error(this._type + err); - } - }; - ComponentPool.prototype.free = function (component) { - component.reset(); - this._cache.push(component); - }; - return ComponentPool; -})(); -var Mesh = (function (_super) { - __extends(Mesh, _super); - function Mesh() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - Mesh.prototype.initialize = function () {}; - Mesh.prototype.setVertPosition = function (positions) { - var createVerts = !this._verts || this._verts.length != positions.length; - if (createVerts) this._verts = new Array(positions.length); - for (var i = 0; i < this._verts.length; i++) { - this._verts[i] = new VertexPosition(positions[i]); + function ComponentPool(typeClass) { + this._type = typeClass; + this._cache = []; } - return this; - }; - Mesh.prototype.setTriangles = function (triangles) { - this._primitiveCount = triangles.length / 3; - this._triangles = triangles; - return this; - }; - Mesh.prototype.recalculateBounds = function () { - this._topLeftVertPosition = new Vector2(Number.MAX_VALUE, Number.MAX_VALUE); - var max = new Vector2(Number.MIN_VALUE, Number.MIN_VALUE); - for (var i = 0; i < this._verts.length; i++) { - this._topLeftVertPosition.x = Math.min( - this._topLeftVertPosition.x, - this._verts[i].position.x - ); - this._topLeftVertPosition.y = Math.min( - this._topLeftVertPosition.y, - this._verts[i].position.y - ); - max.x = Math.max(max.x, this._verts[i].position.x); - max.y = Math.max(max.y, this._verts[i].position.y); - } - this._width = max.x - this._topLeftVertPosition.x; - this._height = max.y - this._topLeftVertPosition.y; - return this; - }; - Mesh.prototype.render = function () {}; - return Mesh; -})(Component); -var VertexPosition = (function () { - function VertexPosition(position) { - this.position = position; - } - return VertexPosition; -})(); -var PolygonMesh = (function (_super) { - __extends(PolygonMesh, _super); - function PolygonMesh(points, arePointsCCW) { - if (arePointsCCW === void 0) { - arePointsCCW = true; - } - var _this = _super.call(this) || this; - var triangulator = new Triangulator(); - triangulator.triangulate(points, arePointsCCW); - _this.setVertPosition(points); - _this.setTriangles(triangulator.triangleIndices); - _this.recalculateBounds(); - return _this; - } - return PolygonMesh; -})(Mesh); + ComponentPool.prototype.obtain = function () { + try { + return this._cache.length > 0 ? this._cache.shift() : new this._type(); + } + catch (err) { + throw new Error(this._type + err); + } + }; + ComponentPool.prototype.free = function (component) { + component.reset(); + this._cache.push(component); + }; + return ComponentPool; +}()); var PooledComponent = (function (_super) { - __extends(PooledComponent, _super); - function PooledComponent() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - return PooledComponent; -})(Component); + __extends(PooledComponent, _super); + function PooledComponent() { + return _super !== null && _super.apply(this, arguments) || this; + } + return PooledComponent; +}(Component)); var RenderableComponent = (function (_super) { - __extends(RenderableComponent, _super); - function RenderableComponent() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this._areBoundsDirty = true; - _this._bounds = new Rectangle(); - _this._localOffset = Vector2.zero; - _this.color = 0x000000; - return _this; - } - Object.defineProperty(RenderableComponent.prototype, "width", { - get: function () { - return this.getWidth(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponent.prototype, "height", { - get: function () { - return this.getHeight(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponent.prototype, "isVisible", { - get: function () { - return this._isVisible; - }, - set: function (value) { - this._isVisible = value; - if (this._isVisible) this.onBecameVisible(); - else this.onBecameInvisible(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponent.prototype, "bounds", { - get: function () { - return new Rectangle( - this.getBounds().x, - this.getBounds().y, - this.getBounds().width, - this.getBounds().height - ); - }, - enumerable: true, - configurable: true, - }); - RenderableComponent.prototype.getWidth = function () { - return this.bounds.width; - }; - RenderableComponent.prototype.getHeight = function () { - return this.bounds.height; - }; - RenderableComponent.prototype.onBecameVisible = function () {}; - RenderableComponent.prototype.onBecameInvisible = function () {}; - RenderableComponent.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = camera.getBounds().intersects(this.getBounds()); - return this.isVisible; - }; - RenderableComponent.prototype.onEntityTransformChanged = function (comp) { - this._areBoundsDirty = true; - }; - return RenderableComponent; -})(PooledComponent); -var ScreenSpaceCamera = (function (_super) { - __extends(ScreenSpaceCamera, _super); - function ScreenSpaceCamera() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - ScreenSpaceCamera.prototype.updateMatrixes = function () {}; - return ScreenSpaceCamera; -})(Camera); + __extends(RenderableComponent, _super); + function RenderableComponent() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._areBoundsDirty = true; + _this._bounds = new Rectangle(); + _this._localOffset = Vector2.zero; + _this.color = 0x000000; + return _this; + } + Object.defineProperty(RenderableComponent.prototype, "width", { + get: function () { + return this.getWidth(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "height", { + get: function () { + return this.getHeight(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "isVisible", { + get: function () { + return this._isVisible; + }, + set: function (value) { + this._isVisible = value; + if (this._isVisible) + this.onBecameVisible(); + else + this.onBecameInvisible(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "bounds", { + get: function () { + return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); + }, + enumerable: true, + configurable: true + }); + RenderableComponent.prototype.getWidth = function () { + return this.bounds.width; + }; + RenderableComponent.prototype.getHeight = function () { + return this.bounds.height; + }; + RenderableComponent.prototype.onBecameVisible = function () { }; + RenderableComponent.prototype.onBecameInvisible = function () { }; + RenderableComponent.prototype.isVisibleFromCamera = function (camera) { + this.isVisible = camera.getBounds().intersects(this.getBounds()); + return this.isVisible; + }; + return RenderableComponent; +}(PooledComponent)); +var Mesh = (function (_super) { + __extends(Mesh, _super); + function Mesh() { + var _this = _super.call(this) || this; + _this._mesh = new egret.Mesh(); + return _this; + } + Mesh.prototype.setTexture = function (texture) { + this._mesh.texture = texture; + return this; + }; + Mesh.prototype.onAddedToEntity = function () { + this.addChild(this._mesh); + }; + Mesh.prototype.onRemovedFromEntity = function () { + this.removeChild(this._mesh); + }; + Mesh.prototype.render = function (camera) { + this.x = this.entity.position.x - camera.position.x + camera.origin.x; + this.y = this.entity.position.y - camera.position.y + camera.origin.y; + }; + Mesh.prototype.reset = function () { + }; + return Mesh; +}(RenderableComponent)); var Sprite = (function () { - function Sprite(texture, sourceRect, origin) { - if (sourceRect === void 0) { - sourceRect = new Rectangle( - 0, - 0, - texture.textureWidth, - texture.textureHeight - ); - } - if (origin === void 0) { - origin = sourceRect.getHalfSize(); - } - this.uvs = new Rectangle(); - this.texture2D = texture; - this.sourceRect = sourceRect; - this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); - this.origin = origin; - var inverseTexW = 1 / texture.textureWidth; - var inverseTexH = 1 / texture.textureHeight; - this.uvs.x = sourceRect.x * inverseTexW; - this.uvs.y = sourceRect.y * inverseTexH; - this.uvs.width = sourceRect.width * inverseTexW; - this.uvs.height = sourceRect.height * inverseTexH; - } - return Sprite; -})(); + function Sprite(texture, sourceRect, origin) { + if (sourceRect === void 0) { sourceRect = new Rectangle(0, 0, texture.textureWidth, texture.textureHeight); } + if (origin === void 0) { origin = sourceRect.getHalfSize(); } + this.uvs = new Rectangle(); + this.texture2D = texture; + this.sourceRect = sourceRect; + this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); + this.origin = origin; + var inverseTexW = 1 / texture.textureWidth; + var inverseTexH = 1 / texture.textureHeight; + this.uvs.x = sourceRect.x * inverseTexW; + this.uvs.y = sourceRect.y * inverseTexH; + this.uvs.width = sourceRect.width * inverseTexW; + this.uvs.height = sourceRect.height * inverseTexH; + } + return Sprite; +}()); var SpriteRenderer = (function (_super) { - __extends(SpriteRenderer, _super); - function SpriteRenderer() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - Object.defineProperty(SpriteRenderer.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (value) { - this.setOrigin(value); - }, - enumerable: true, - configurable: true, - }); - SpriteRenderer.prototype.setOrigin = function (origin) { - if (this._origin != origin) { - this._origin = origin; + __extends(SpriteRenderer, _super); + function SpriteRenderer() { + return _super !== null && _super.apply(this, arguments) || this; } - return this; - }; - SpriteRenderer.prototype.setSprite = function (sprite) { - this.removeChildren(); - this._sprite = sprite; - if (this._sprite) this._origin = this._sprite.origin; - this._bitmap = new egret.Bitmap(sprite.texture2D); - this.addChild(this._bitmap); - return this; - }; - SpriteRenderer.prototype.setColor = function (color) { - var colorMatrix = [ - 1, - 0, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 1, - 0, - ]; - colorMatrix[0] = Math.floor(color / 256 / 256) / 255; - colorMatrix[6] = Math.floor((color / 256) % 256) / 255; - colorMatrix[12] = (color % 256) / 255; - var colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this.filters = [colorFilter]; - return this; - }; - SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = new Rectangle( - 0, - 0, - this.stage.stageWidth, - this.stage.stageHeight - ).intersects(this.bounds); - this.visible = this.isVisible; - return this.isVisible; - }; - SpriteRenderer.prototype.render = function (camera) { - this.x = - this.entity.position.x - - this.origin.x - - camera.position.x + - camera.origin.x; - this.y = - this.entity.position.y - - this.origin.y - - camera.position.y + - camera.origin.y; - }; - SpriteRenderer.prototype.onRemovedFromEntity = function () { - if (this.parent) this.parent.removeChild(this); - }; - SpriteRenderer.prototype.reset = function () {}; - return SpriteRenderer; -})(RenderableComponent); + Object.defineProperty(SpriteRenderer.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + this.setOrigin(value); + }, + enumerable: true, + configurable: true + }); + SpriteRenderer.prototype.setOrigin = function (origin) { + if (this._origin != origin) { + this._origin = origin; + } + return this; + }; + SpriteRenderer.prototype.setSprite = function (sprite) { + this.removeChildren(); + this._sprite = sprite; + if (this._sprite) + this._origin = this._sprite.origin; + this._bitmap = new egret.Bitmap(sprite.texture2D); + this.addChild(this._bitmap); + return this; + }; + SpriteRenderer.prototype.setColor = function (color) { + var colorMatrix = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 + ]; + colorMatrix[0] = Math.floor(color / 256 / 256) / 255; + colorMatrix[6] = Math.floor(color / 256 % 256) / 255; + colorMatrix[12] = color % 256 / 255; + var colorFilter = new egret.ColorMatrixFilter(colorMatrix); + this.filters = [colorFilter]; + return this; + }; + SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { + this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); + this.visible = this.isVisible; + return this.isVisible; + }; + SpriteRenderer.prototype.render = function (camera) { + this.x = this.entity.position.x - this.origin.x - camera.position.x + camera.origin.x; + this.y = this.entity.position.y - this.origin.y - camera.position.y + camera.origin.y; + }; + SpriteRenderer.prototype.onRemovedFromEntity = function () { + if (this.parent) + this.parent.removeChild(this); + }; + SpriteRenderer.prototype.reset = function () { + }; + return SpriteRenderer; +}(RenderableComponent)); var Mover = (function (_super) { - __extends(Mover, _super); - function Mover() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - Mover.prototype.onAddedToEntity = function () { - this._triggerHelper = new ColliderTriggerHelper(this.entity); - }; - Mover.prototype.calculateMovement = function (motion) { - var collisionResult = new CollisionResult(); - if (!this.entity.getComponent(Collider) || !this._triggerHelper) { - return null; - } - var colliders = this.entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - if (collider.isTrigger) continue; - var bounds = collider.bounds; - bounds.x += motion.x; - bounds.y += motion.y; - var neighbors = Physics.boxcastBroadphaseExcludingSelf( - collider, - bounds, - collider.collidesWithLayers - ); - for (var j = 0; j < neighbors.length; j++) { - var neighbor = neighbors[j]; - if (neighbor.isTrigger) continue; - var _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult) { - motion = Vector2.subtract( - motion, - _internalcollisionResult.minimumTranslationVector - ); - if (_internalcollisionResult.collider) { - collisionResult = _internalcollisionResult; - } - } - } + __extends(Mover, _super); + function Mover() { + return _super !== null && _super.apply(this, arguments) || this; } - ListPool.free(colliders); - return collisionResult; - }; - Mover.prototype.applyMovement = function (motion) { - this.entity.position = Vector2.add(this.entity.position, motion); - if (this._triggerHelper) this._triggerHelper.update(); - }; - Mover.prototype.move = function (motion) { - var collisionResult = this.calculateMovement(motion); - this.applyMovement(motion); - return collisionResult; - }; - return Mover; -})(Component); + Mover.prototype.onAddedToEntity = function () { + this._triggerHelper = new ColliderTriggerHelper(this.entity); + }; + Mover.prototype.calculateMovement = function (motion) { + var collisionResult = new CollisionResult(); + if (!this.entity.getComponent(Collider) || !this._triggerHelper) { + return null; + } + var colliders = this.entity.getComponents(Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + if (collider.isTrigger) + continue; + var bounds = collider.bounds; + bounds.x += motion.x; + bounds.y += motion.y; + var neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); + for (var j = 0; j < neighbors.length; j++) { + var neighbor = neighbors[j]; + if (neighbor.isTrigger) + continue; + var _internalcollisionResult = collider.collidesWith(neighbor, motion); + if (_internalcollisionResult) { + motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); + if (_internalcollisionResult.collider) { + collisionResult = _internalcollisionResult; + } + } + } + } + ListPool.free(colliders); + return collisionResult; + }; + Mover.prototype.applyMovement = function (motion) { + this.entity.position = Vector2.add(this.entity.position, motion); + if (this._triggerHelper) + this._triggerHelper.update(); + }; + Mover.prototype.move = function (motion) { + var collisionResult = this.calculateMovement(motion); + this.applyMovement(motion); + return collisionResult; + }; + return Mover; +}(Component)); var Collider = (function (_super) { - __extends(Collider, _super); - function Collider() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this.physicsLayer = 1 << 0; - _this.shouldColliderScaleAndRotationWithTransform = true; - _this.collidesWithLayers = Physics.allLayers; - _this._isPositionDirty = true; - _this._isRotationDirty = true; - _this._localOffset = new Vector2(0, 0); - return _this; - } - Object.defineProperty(Collider.prototype, "bounds", { - get: function () { - if (this._isPositionDirty || this._isRotationDirty) { - this.shape.recalculateBounds(this); - this._isPositionDirty = this._isRotationDirty = false; - } - return this.shape.bounds; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Collider.prototype, "localOffset", { - get: function () { - return this._localOffset; - }, - set: function (value) { - this.setLocalOffset(value); - }, - enumerable: true, - configurable: true, - }); - Collider.prototype.setLocalOffset = function (offset) { - if (this._localOffset != offset) { - this.unregisterColliderWithPhysicsSystem(); - this._localOffset = offset; - this._localOffsetLength = this._localOffset.length(); - this._isPositionDirty = true; - this.registerColliderWithPhysicsSystem(); - } - }; - Collider.prototype.registerColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { - Physics.addCollider(this); - this._isColliderRegistered = true; - } - }; - Collider.prototype.unregisterColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && this._isColliderRegistered) { - Physics.removeCollider(this); - } - this._isColliderRegistered = false; - }; - Collider.prototype.overlaps = function (other) { - return this.shape.overlaps(other.shape); - }; - Collider.prototype.collidesWith = function (collider, motion) { - var oldPosition = this.shape.position; - this.shape.position = Vector2.add(this.shape.position, motion); - var result = this.shape.collidesWithShape(collider.shape); - if (result) result.collider = collider; - this.shape.position = oldPosition; - return result; - }; - Collider.prototype.onAddedToEntity = function () { - if (this._colliderRequiresAutoSizing) { - if (!(this instanceof BoxCollider)) { - console.error( - "Only box and circle colliders can be created automatically" - ); - } - var renderable = this.entity.getComponent(RenderableComponent); - if (renderable) { - var renderbaleBounds = renderable.bounds; - var width = renderbaleBounds.width / this.entity.scale.x; - var height = renderbaleBounds.height / this.entity.scale.y; - if (this instanceof BoxCollider) { - var boxCollider = this; - boxCollider.width = width; - boxCollider.height = height; - this.localOffset = Vector2.subtract( - renderbaleBounds.center, - this.entity.position - ); - } - } - } - this._isParentEntityAddedToScene = true; - this.registerColliderWithPhysicsSystem(); - }; - Collider.prototype.onRemovedFromEntity = function () { - this.unregisterColliderWithPhysicsSystem(); - this._isParentEntityAddedToScene = false; - }; - Collider.prototype.onEntityTransformChanged = function (comp) { - switch (comp) { - case ComponentTransform.position: - this._isPositionDirty = true; - break; - case ComponentTransform.scale: - this._isPositionDirty = true; - break; - case ComponentTransform.rotation: - this._isRotationDirty = true; - break; - } - if (this._isColliderRegistered) Physics.updateCollider(this); - }; - Collider.prototype.onEnabled = function () { - this.registerColliderWithPhysicsSystem(); - this._isPositionDirty = this._isRotationDirty = true; - }; - Collider.prototype.onDisabled = function () { - this.unregisterColliderWithPhysicsSystem(); - }; - return Collider; -})(Component); + __extends(Collider, _super); + function Collider() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.physicsLayer = 1 << 0; + _this.shouldColliderScaleAndRotationWithTransform = true; + _this.collidesWithLayers = Physics.allLayers; + _this._isPositionDirty = true; + _this._isRotationDirty = true; + _this._localOffset = new Vector2(0, 0); + return _this; + } + Object.defineProperty(Collider.prototype, "bounds", { + get: function () { + if (this._isPositionDirty || this._isRotationDirty) { + this.shape.recalculateBounds(this); + this._isPositionDirty = this._isRotationDirty = false; + } + return this.shape.bounds; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "localOffset", { + get: function () { + return this._localOffset; + }, + set: function (value) { + this.setLocalOffset(value); + }, + enumerable: true, + configurable: true + }); + Collider.prototype.setLocalOffset = function (offset) { + if (this._localOffset != offset) { + this.unregisterColliderWithPhysicsSystem(); + this._localOffset = offset; + this._localOffsetLength = this._localOffset.length(); + this._isPositionDirty = true; + this.registerColliderWithPhysicsSystem(); + } + }; + Collider.prototype.registerColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { + Physics.addCollider(this); + this._isColliderRegistered = true; + } + }; + Collider.prototype.unregisterColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && this._isColliderRegistered) { + Physics.removeCollider(this); + } + this._isColliderRegistered = false; + }; + Collider.prototype.overlaps = function (other) { + return this.shape.overlaps(other.shape); + }; + Collider.prototype.collidesWith = function (collider, motion) { + var oldPosition = this.shape.position; + this.shape.position = Vector2.add(this.shape.position, motion); + var result = this.shape.collidesWithShape(collider.shape); + if (result) + result.collider = collider; + this.shape.position = oldPosition; + return result; + }; + Collider.prototype.onAddedToEntity = function () { + if (this._colliderRequiresAutoSizing) { + if (!(this instanceof BoxCollider)) { + console.error("Only box and circle colliders can be created automatically"); + } + var renderable = this.entity.getComponent(RenderableComponent); + if (renderable) { + var renderbaleBounds = renderable.bounds; + var width = renderbaleBounds.width / this.entity.scale.x; + var height = renderbaleBounds.height / this.entity.scale.y; + if (this instanceof BoxCollider) { + var boxCollider = this; + boxCollider.width = width; + boxCollider.height = height; + this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position); + } + } + } + this._isParentEntityAddedToScene = true; + this.registerColliderWithPhysicsSystem(); + }; + Collider.prototype.onRemovedFromEntity = function () { + this.unregisterColliderWithPhysicsSystem(); + this._isParentEntityAddedToScene = false; + }; + Collider.prototype.onEnabled = function () { + this.registerColliderWithPhysicsSystem(); + this._isPositionDirty = this._isRotationDirty = true; + }; + Collider.prototype.onDisabled = function () { + this.unregisterColliderWithPhysicsSystem(); + }; + return Collider; +}(Component)); var BoxCollider = (function (_super) { - __extends(BoxCollider, _super); - function BoxCollider() { - var _this = _super.call(this) || this; - _this.shape = new Box(1, 1); - _this._colliderRequiresAutoSizing = true; - return _this; - } - Object.defineProperty(BoxCollider.prototype, "width", { - get: function () { - return this.shape.width; - }, - set: function (value) { - this.setWidth(value); - }, - enumerable: true, - configurable: true, - }); - BoxCollider.prototype.setWidth = function (width) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width) { - box.updateBox(width, box.height); - this._isPositionDirty = true; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - Object.defineProperty(BoxCollider.prototype, "height", { - get: function () { - return this.shape.height; - }, - set: function (value) { - this.setHeight(value); - }, - enumerable: true, - configurable: true, - }); - BoxCollider.prototype.setHeight = function (height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (height != box.height) { - box.updateBox(box.width, height); - this._isPositionDirty = true; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - }; - BoxCollider.prototype.setSize = function (width, height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width || height != box.height) { - box.updateBox(width, height); - this._isPositionDirty = true; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - return BoxCollider; -})(Collider); -var EntitySystem = (function () { - function EntitySystem(matcher) { - this._entities = []; - this._matcher = matcher ? matcher : Matcher.empty(); - } - Object.defineProperty(EntitySystem.prototype, "matcher", { - get: function () { - return this._matcher; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(EntitySystem.prototype, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - this._scene = value; - this._entities = []; - }, - enumerable: true, - configurable: true, - }); - EntitySystem.prototype.initialize = function () {}; - EntitySystem.prototype.onChanged = function (entity) { - var contains = this._entities.contains(entity); - var interest = this._matcher.IsIntersted(entity); - if (interest && !contains) this.add(entity); - else if (!interest && contains) this.remove(entity); - }; - EntitySystem.prototype.add = function (entity) { - this._entities.push(entity); - this.onAdded(entity); - }; - EntitySystem.prototype.onAdded = function (entity) {}; - EntitySystem.prototype.remove = function (entity) { - this._entities.remove(entity); - this.onRemoved(entity); - }; - EntitySystem.prototype.onRemoved = function (entity) {}; - EntitySystem.prototype.update = function () { - this.begin(); - this.process(this._entities); - }; - EntitySystem.prototype.lateUpdate = function () { - this.lateProcess(this._entities); - this.end(); - }; - EntitySystem.prototype.begin = function () {}; - EntitySystem.prototype.process = function (entities) {}; - EntitySystem.prototype.lateProcess = function (entities) {}; - EntitySystem.prototype.end = function () {}; - return EntitySystem; -})(); -var EntityProcessingSystem = (function (_super) { - __extends(EntityProcessingSystem, _super); - function EntityProcessingSystem(matcher) { - return _super.call(this, matcher) || this; - } - EntityProcessingSystem.prototype.lateProcessEntity = function (entity) {}; - EntityProcessingSystem.prototype.process = function (entities) { - var _this = this; - entities.forEach(function (entity) { - return _this.processEntity(entity); + __extends(BoxCollider, _super); + function BoxCollider() { + var _this = _super.call(this) || this; + _this.shape = new Box(1, 1); + _this._colliderRequiresAutoSizing = true; + return _this; + } + Object.defineProperty(BoxCollider.prototype, "width", { + get: function () { + return this.shape.width; + }, + set: function (value) { + this.setWidth(value); + }, + enumerable: true, + configurable: true }); - }; - EntityProcessingSystem.prototype.lateProcess = function (entities) { - var _this = this; - entities.forEach(function (entity) { - return _this.lateProcessEntity(entity); + BoxCollider.prototype.setWidth = function (width) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width) { + box.updateBox(width, box.height); + this._isPositionDirty = true; + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + return this; + }; + Object.defineProperty(BoxCollider.prototype, "height", { + get: function () { + return this.shape.height; + }, + set: function (value) { + this.setHeight(value); + }, + enumerable: true, + configurable: true }); - }; - return EntityProcessingSystem; -})(EntitySystem); -var PassiveSystem = (function (_super) { - __extends(PassiveSystem, _super); - function PassiveSystem() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - PassiveSystem.prototype.onChanged = function (entity) {}; - PassiveSystem.prototype.process = function (entities) { - this.begin(); - this.end(); - }; - return PassiveSystem; -})(EntitySystem); -var ProcessingSystem = (function (_super) { - __extends(ProcessingSystem, _super); - function ProcessingSystem() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - ProcessingSystem.prototype.onChanged = function (entity) {}; - ProcessingSystem.prototype.process = function (entities) { - this.begin(); - this.processSystem(); - this.end(); - }; - return ProcessingSystem; -})(EntitySystem); -var BitSet = (function () { - function BitSet(nbits) { - if (nbits === void 0) { - nbits = 64; - } - var length = nbits >> 6; - if ((nbits & BitSet.LONG_MASK) != 0) length++; - this._bits = new Array(length); - } - BitSet.prototype.and = function (bs) { - var max = Math.min(this._bits.length, bs._bits.length); - var i; - for (var i_1 = 0; i_1 < max; ++i_1) this._bits[i_1] &= bs._bits[i_1]; - while (i < this._bits.length) this._bits[i++] = 0; - }; - BitSet.prototype.andNot = function (bs) { - var i = Math.min(this._bits.length, bs._bits.length); - while (--i >= 0) this._bits[i] &= ~bs._bits[i]; - }; - BitSet.prototype.cardinality = function () { - var card = 0; - for (var i = this._bits.length - 1; i >= 0; i--) { - var a = this._bits[i]; - if (a == 0) continue; - if (a == -1) { - card += 64; - continue; - } - a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); - a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); - var b = (a >> 32) + a; - b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); - b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); - card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); - } - return card; - }; - BitSet.prototype.clear = function (pos) { - if (pos != undefined) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] &= ~(1 << pos); - } else { - for (var i = 0; i < this._bits.length; i++) this._bits[i] = 0; - } - }; - BitSet.prototype.ensure = function (lastElt) { - if (lastElt >= this._bits.length) { - var nd = new Number[lastElt + 1](); - nd = this._bits.copyWithin(0, 0, this._bits.length); - this._bits = nd; - } - }; - BitSet.prototype.get = function (pos) { - var offset = pos >> 6; - if (offset >= this._bits.length) return false; - return (this._bits[offset] & (1 << pos)) != 0; - }; - BitSet.prototype.intersects = function (set) { - var i = Math.min(this._bits.length, set._bits.length); - while (--i >= 0) { - if ((this._bits[i] & set._bits[i]) != 0) return true; - } - return false; - }; - BitSet.prototype.isEmpty = function () { - for (var i = this._bits.length - 1; i >= 0; i--) { - if (this._bits[i]) return false; + BoxCollider.prototype.setHeight = function (height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (height != box.height) { + box.updateBox(box.width, height); + this._isPositionDirty = true; + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + }; + BoxCollider.prototype.setSize = function (width, height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width || height != box.height) { + box.updateBox(width, height); + this._isPositionDirty = true; + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + return this; + }; + return BoxCollider; +}(Collider)); +var EntitySystem = (function () { + function EntitySystem(matcher) { + this._entities = []; + this._matcher = matcher ? matcher : Matcher.empty(); } - return true; - }; - BitSet.prototype.nextSetBit = function (from) { - var offset = from >> 6; - var mask = 1 << from; - while (offset < this._bits.length) { - var h = this._bits[offset]; - do { - if ((h & mask) != 0) return from; - mask <<= 1; - from++; - } while (mask != 0); - mask = 1; - offset++; + Object.defineProperty(EntitySystem.prototype, "matcher", { + get: function () { + return this._matcher; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(EntitySystem.prototype, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + this._scene = value; + this._entities = []; + }, + enumerable: true, + configurable: true + }); + EntitySystem.prototype.initialize = function () { + }; + EntitySystem.prototype.onChanged = function (entity) { + var contains = this._entities.contains(entity); + var interest = this._matcher.IsIntersted(entity); + if (interest && !contains) + this.add(entity); + else if (!interest && contains) + this.remove(entity); + }; + EntitySystem.prototype.add = function (entity) { + this._entities.push(entity); + this.onAdded(entity); + }; + EntitySystem.prototype.onAdded = function (entity) { + }; + EntitySystem.prototype.remove = function (entity) { + this._entities.remove(entity); + this.onRemoved(entity); + }; + EntitySystem.prototype.onRemoved = function (entity) { + }; + EntitySystem.prototype.update = function () { + this.begin(); + this.process(this._entities); + }; + EntitySystem.prototype.lateUpdate = function () { + this.lateProcess(this._entities); + this.end(); + }; + EntitySystem.prototype.begin = function () { + }; + EntitySystem.prototype.process = function (entities) { + }; + EntitySystem.prototype.lateProcess = function (entities) { + }; + EntitySystem.prototype.end = function () { + }; + return EntitySystem; +}()); +var EntityProcessingSystem = (function (_super) { + __extends(EntityProcessingSystem, _super); + function EntityProcessingSystem(matcher) { + return _super.call(this, matcher) || this; } - return -1; - }; - BitSet.prototype.set = function (pos, value) { - if (value === void 0) { - value = true; + EntityProcessingSystem.prototype.lateProcessEntity = function (entity) { + }; + EntityProcessingSystem.prototype.process = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.processEntity(entity); }); + }; + EntityProcessingSystem.prototype.lateProcess = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.lateProcessEntity(entity); }); + }; + return EntityProcessingSystem; +}(EntitySystem)); +var PassiveSystem = (function (_super) { + __extends(PassiveSystem, _super); + function PassiveSystem() { + return _super !== null && _super.apply(this, arguments) || this; } - if (value) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] |= 1 << pos; - } else { - this.clear(pos); + PassiveSystem.prototype.onChanged = function (entity) { + }; + PassiveSystem.prototype.process = function (entities) { + this.begin(); + this.end(); + }; + return PassiveSystem; +}(EntitySystem)); +var ProcessingSystem = (function (_super) { + __extends(ProcessingSystem, _super); + function ProcessingSystem() { + return _super !== null && _super.apply(this, arguments) || this; } - }; - BitSet.LONG_MASK = 0x3f; - return BitSet; -})(); + ProcessingSystem.prototype.onChanged = function (entity) { + }; + ProcessingSystem.prototype.process = function (entities) { + this.begin(); + this.processSystem(); + this.end(); + }; + return ProcessingSystem; +}(EntitySystem)); +var BitSet = (function () { + function BitSet(nbits) { + if (nbits === void 0) { nbits = 64; } + var length = nbits >> 6; + if ((nbits & BitSet.LONG_MASK) != 0) + length++; + this._bits = new Array(length); + } + BitSet.prototype.and = function (bs) { + var max = Math.min(this._bits.length, bs._bits.length); + var i; + for (var i_1 = 0; i_1 < max; ++i_1) + this._bits[i_1] &= bs._bits[i_1]; + while (i < this._bits.length) + this._bits[i++] = 0; + }; + BitSet.prototype.andNot = function (bs) { + var i = Math.min(this._bits.length, bs._bits.length); + while (--i >= 0) + this._bits[i] &= ~bs._bits[i]; + }; + BitSet.prototype.cardinality = function () { + var card = 0; + for (var i = this._bits.length - 1; i >= 0; i--) { + var a = this._bits[i]; + if (a == 0) + continue; + if (a == -1) { + card += 64; + continue; + } + a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); + a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); + var b = ((a >> 32) + a); + b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); + b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); + card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); + } + return card; + }; + BitSet.prototype.clear = function (pos) { + if (pos != undefined) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] &= ~(1 << pos); + } + else { + for (var i = 0; i < this._bits.length; i++) + this._bits[i] = 0; + } + }; + BitSet.prototype.ensure = function (lastElt) { + if (lastElt >= this._bits.length) { + var nd = new Number[lastElt + 1]; + nd = this._bits.copyWithin(0, 0, this._bits.length); + this._bits = nd; + } + }; + BitSet.prototype.get = function (pos) { + var offset = pos >> 6; + if (offset >= this._bits.length) + return false; + return (this._bits[offset] & (1 << pos)) != 0; + }; + BitSet.prototype.intersects = function (set) { + var i = Math.min(this._bits.length, set._bits.length); + while (--i >= 0) { + if ((this._bits[i] & set._bits[i]) != 0) + return true; + } + return false; + }; + BitSet.prototype.isEmpty = function () { + for (var i = this._bits.length - 1; i >= 0; i--) { + if (this._bits[i]) + return false; + } + return true; + }; + BitSet.prototype.nextSetBit = function (from) { + var offset = from >> 6; + var mask = 1 << from; + while (offset < this._bits.length) { + var h = this._bits[offset]; + do { + if ((h & mask) != 0) + return from; + mask <<= 1; + from++; + } while (mask != 0); + mask = 1; + offset++; + } + return -1; + }; + BitSet.prototype.set = function (pos, value) { + if (value === void 0) { value = true; } + if (value) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] |= 1 << pos; + } + else { + this.clear(pos); + } + }; + BitSet.LONG_MASK = 0x3f; + return BitSet; +}()); var ComponentList = (function () { - function ComponentList(entity) { - this._components = []; - this._componentsToAdd = []; - this._componentsToRemove = []; - this._tempBufferList = []; - this._entity = entity; - } - Object.defineProperty(ComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(ComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true, - }); - ComponentList.prototype.add = function (component) { - this._componentsToAdd.push(component); - }; - ComponentList.prototype.remove = function (component) { - if (this._componentsToAdd.contains(component)) { - this._componentsToAdd.remove(component); - return; - } - this._componentsToRemove.push(component); - }; - ComponentList.prototype.removeAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - this.handleRemove(this._components[i]); - } - this._components.length = 0; - this._componentsToAdd.length = 0; - this._componentsToRemove.length = 0; - }; - ComponentList.prototype.deregisterAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component), - false - ); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - } - }; - ComponentList.prototype.registerAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component) - ); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - } - }; - ComponentList.prototype.updateLists = function () { - if (this._componentsToRemove.length > 0) { - for (var i = 0; i < this._componentsToRemove.length; i++) { - this.handleRemove(this._componentsToRemove[i]); - this._components.remove(this._componentsToRemove[i]); - } - this._componentsToRemove.length = 0; - } - if (this._componentsToAdd.length > 0) { - for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { - var component = this._componentsToAdd[i]; + function ComponentList(entity) { + this._components = []; + this._componentsToAdd = []; + this._componentsToRemove = []; + this._tempBufferList = []; + this._entity = entity; + } + Object.defineProperty(ComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(ComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true + }); + ComponentList.prototype.add = function (component) { + this._componentsToAdd.push(component); + }; + ComponentList.prototype.remove = function (component) { + if (this._componentsToAdd.contains(component)) { + this._componentsToAdd.remove(component); + return; + } + this._componentsToRemove.push(component); + }; + ComponentList.prototype.removeAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + this.handleRemove(this._components[i]); + } + this._components.length = 0; + this._componentsToAdd.length = 0; + this._componentsToRemove.length = 0; + }; + ComponentList.prototype.deregisterAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + } + }; + ComponentList.prototype.registerAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + } + }; + ComponentList.prototype.updateLists = function () { + if (this._componentsToRemove.length > 0) { + for (var i = 0; i < this._componentsToRemove.length; i++) { + this.handleRemove(this._componentsToRemove[i]); + this._components.remove(this._componentsToRemove[i]); + } + this._componentsToRemove.length = 0; + } + if (this._componentsToAdd.length > 0) { + for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + this._components.push(component); + this._tempBufferList.push(component); + } + this._componentsToAdd.length = 0; + for (var i = 0; i < this._tempBufferList.length; i++) { + var component = this._tempBufferList[i]; + component.onAddedToEntity(); + if (component.enabled) { + component.onEnabled(); + } + } + this._tempBufferList.length = 0; + } + }; + ComponentList.prototype.handleRemove = function (component) { if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component) - ); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - this._components.push(component); - this._tempBufferList.push(component); - } - this._componentsToAdd.length = 0; - for (var i = 0; i < this._tempBufferList.length; i++) { - var component = this._tempBufferList[i]; - component.onAddedToEntity(); - if (component.enabled) { - component.onEnabled(); - } - } - this._tempBufferList.length = 0; - } - }; - ComponentList.prototype.handleRemove = function (component) { - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component), - false - ); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - component.onRemovedFromEntity(); - component.entity = null; - }; - ComponentList.prototype.getComponent = function ( - type, - onlyReturnInitializedComponents - ) { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof type) return component; - } - if (!onlyReturnInitializedComponents) { - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; - if (component instanceof type) return component; - } - } - return null; - }; - ComponentList.prototype.getComponents = function (typeName, components) { - if (!components) components = []; - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (typeof typeName == "string") { - if (egret.is(component, typeName)) { - components.push(component); - } - } else { - if (component instanceof typeName) { - components.push(component); - } - } - } - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; - if (typeof typeName == "string") { - if (egret.is(component, typeName)) { - components.push(component); + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + component.onRemovedFromEntity(); + component.entity = null; + }; + ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof type) + return component; } - } else { - if (component instanceof typeName) { - components.push(component); + if (!onlyReturnInitializedComponents) { + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof type) + return component; + } } - } - } - return components; - }; - ComponentList.prototype.update = function () { - this.updateLists(); - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if ( - component.enabled && - (component.updateInterval == 1 || - Time.frameCount % component.updateInterval == 0) - ) - component.update(); - } - }; - ComponentList.prototype.onEntityTransformChanged = function (comp) { - for (var i = 0; i < this._components.length; i++) { - if (this._components[i].enabled) - this._components[i].onEntityTransformChanged(comp); - } - for (var i = 0; i < this._componentsToAdd.length; i++) { - if (this._componentsToAdd[i].enabled) - this._componentsToAdd[i].onEntityTransformChanged(comp); - } - }; - return ComponentList; -})(); + return null; + }; + ComponentList.prototype.getComponents = function (typeName, components) { + if (!components) + components = []; + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } + } + } + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } + } + } + return components; + }; + ComponentList.prototype.update = function () { + this.updateLists(); + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component.enabled && (component.updateInterval == 1 || Time.frameCount % component.updateInterval == 0)) + component.update(); + } + }; + return ComponentList; +}()); var ComponentTypeManager = (function () { - function ComponentTypeManager() {} - ComponentTypeManager.add = function (type) { - if (!this._componentTypesMask.has(type)) - this._componentTypesMask[type] = this._componentTypesMask.size; - }; - ComponentTypeManager.getIndexFor = function (type) { - var v = -1; - if (!this._componentTypesMask.has(type)) { - this.add(type); - v = this._componentTypesMask.get(type); + function ComponentTypeManager() { } - return v; - }; - ComponentTypeManager._componentTypesMask = new Map(); - return ComponentTypeManager; -})(); + ComponentTypeManager.add = function (type) { + if (!this._componentTypesMask.has(type)) + this._componentTypesMask[type] = this._componentTypesMask.size; + }; + ComponentTypeManager.getIndexFor = function (type) { + var v = -1; + if (!this._componentTypesMask.has(type)) { + this.add(type); + v = this._componentTypesMask.get(type); + } + return v; + }; + ComponentTypeManager._componentTypesMask = new Map(); + return ComponentTypeManager; +}()); var EntityList = (function () { - function EntityList(scene) { - this._entitiesToRemove = []; - this._entitiesToAdded = []; - this._tempEntityList = []; - this._entities = []; - this._entityDict = new Map(); - this._unsortedTags = []; - this.scene = scene; - } - Object.defineProperty(EntityList.prototype, "count", { - get: function () { - return this._entities.length; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(EntityList.prototype, "buffer", { - get: function () { - return this._entities; - }, - enumerable: true, - configurable: true, - }); - EntityList.prototype.add = function (entity) { - if (this._entitiesToAdded.indexOf(entity) == -1) - this._entitiesToAdded.push(entity); - }; - EntityList.prototype.remove = function (entity) { - if (this._entitiesToAdded.contains(entity)) { - this._entitiesToAdded.remove(entity); - return; - } - if (!this._entitiesToRemove.contains(entity)) - this._entitiesToRemove.push(entity); - }; - EntityList.prototype.findEntity = function (name) { - for (var i = 0; i < this._entities.length; i++) { - if (this._entities[i].name == name) return this._entities[i]; - } - return this._entitiesToAdded.firstOrDefault(function (entity) { - return entity.name == name; + function EntityList(scene) { + this._entitiesToRemove = []; + this._entitiesToAdded = []; + this._tempEntityList = []; + this._entities = []; + this._entityDict = new Map(); + this._unsortedTags = []; + this.scene = scene; + } + Object.defineProperty(EntityList.prototype, "count", { + get: function () { + return this._entities.length; + }, + enumerable: true, + configurable: true }); - }; - EntityList.prototype.getTagList = function (tag) { - var list = this._entityDict.get(tag); - if (!list) { - list = []; - this._entityDict.set(tag, list); - } - return this._entityDict.get(tag); - }; - EntityList.prototype.addToTagList = function (entity) { - var list = this.getTagList(entity.tag); - if (!list.contains(entity)) { - list.push(entity); - this._unsortedTags.push(entity.tag); - } - }; - EntityList.prototype.removeFromTagList = function (entity) { - var list = this._entityDict.get(entity.tag); - if (list) { - list.remove(entity); - } - }; - EntityList.prototype.update = function () { - for (var i = 0; i < this._entities.length; i++) { - var entity = this._entities[i]; - if (entity.enabled) entity.update(); - } - }; - EntityList.prototype.removeAllEntities = function () { - this._entitiesToAdded.length = 0; - this.updateLists(); - for (var i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestoryed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; - } - this._entities.length = 0; - this._entityDict.clear(); - }; - EntityList.prototype.updateLists = function () { - var _this = this; - if (this._entitiesToRemove.length > 0) { - var temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - _this._entities.remove(entity); - entity.scene = null; - _this.scene.entityProcessors.onEntityRemoved(entity); - }); - this._tempEntityList.length = 0; - } - if (this._entitiesToAdded.length > 0) { - var temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - if (!_this._entities.contains(entity)) { - _this._entities.push(entity); - entity.scene = _this.scene; - _this.scene.entityProcessors.onEntityAdded(entity); - } - }); - this._tempEntityList.forEach(function (entity) { - return entity.onAddedToScene(); - }); - this._tempEntityList.length = 0; - } - if (this._unsortedTags.length > 0) { - this._unsortedTags.forEach(function (tag) { - _this._entityDict.get(tag).sort(); - }); - this._unsortedTags.length = 0; - } - }; - return EntityList; -})(); + Object.defineProperty(EntityList.prototype, "buffer", { + get: function () { + return this._entities; + }, + enumerable: true, + configurable: true + }); + EntityList.prototype.add = function (entity) { + if (this._entitiesToAdded.indexOf(entity) == -1) + this._entitiesToAdded.push(entity); + }; + EntityList.prototype.remove = function (entity) { + if (this._entitiesToAdded.contains(entity)) { + this._entitiesToAdded.remove(entity); + return; + } + if (!this._entitiesToRemove.contains(entity)) + this._entitiesToRemove.push(entity); + }; + EntityList.prototype.findEntity = function (name) { + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].name == name) + return this._entities[i]; + } + return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; }); + }; + EntityList.prototype.getTagList = function (tag) { + var list = this._entityDict.get(tag); + if (!list) { + list = []; + this._entityDict.set(tag, list); + } + return this._entityDict.get(tag); + }; + EntityList.prototype.addToTagList = function (entity) { + var list = this.getTagList(entity.tag); + if (!list.contains(entity)) { + list.push(entity); + this._unsortedTags.push(entity.tag); + } + }; + EntityList.prototype.removeFromTagList = function (entity) { + var list = this._entityDict.get(entity.tag); + if (list) { + list.remove(entity); + } + }; + EntityList.prototype.update = function () { + for (var i = 0; i < this._entities.length; i++) { + var entity = this._entities[i]; + if (entity.enabled) + entity.update(); + } + }; + EntityList.prototype.removeAllEntities = function () { + this._entitiesToAdded.length = 0; + this.updateLists(); + for (var i = 0; i < this._entities.length; i++) { + this._entities[i]._isDestoryed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + this._entities.length = 0; + this._entityDict.clear(); + }; + EntityList.prototype.updateLists = function () { + var _this = this; + if (this._entitiesToRemove.length > 0) { + var temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + _this._entities.remove(entity); + entity.scene = null; + _this.scene.entityProcessors.onEntityRemoved(entity); + }); + this._tempEntityList.length = 0; + } + if (this._entitiesToAdded.length > 0) { + var temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + if (!_this._entities.contains(entity)) { + _this._entities.push(entity); + entity.scene = _this.scene; + _this.scene.entityProcessors.onEntityAdded(entity); + } + }); + this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); + this._tempEntityList.length = 0; + } + if (this._unsortedTags.length > 0) { + this._unsortedTags.forEach(function (tag) { + _this._entityDict.get(tag).sort(); + }); + this._unsortedTags.length = 0; + } + }; + return EntityList; +}()); var EntityProcessorList = (function () { - function EntityProcessorList() { - this._processors = []; - } - EntityProcessorList.prototype.add = function (processor) { - this._processors.push(processor); - }; - EntityProcessorList.prototype.remove = function (processor) { - this._processors.remove(processor); - }; - EntityProcessorList.prototype.onComponentAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onComponentRemoved = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityRemoved = function (entity) { - this.removeFromProcessors(entity); - }; - EntityProcessorList.prototype.notifyEntityChanged = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].onChanged(entity); - } - }; - EntityProcessorList.prototype.removeFromProcessors = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].remove(entity); - } - }; - EntityProcessorList.prototype.begin = function () {}; - EntityProcessorList.prototype.update = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].update(); - } - }; - EntityProcessorList.prototype.lateUpdate = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].lateUpdate(); + function EntityProcessorList() { + this._processors = []; } - }; - EntityProcessorList.prototype.end = function () {}; - EntityProcessorList.prototype.getProcessor = function () { - for (var i = 0; i < this._processors.length; i++) { - var processor = this._processors[i]; - if (processor instanceof EntitySystem) return processor; - } - return null; - }; - return EntityProcessorList; -})(); + EntityProcessorList.prototype.add = function (processor) { + this._processors.push(processor); + }; + EntityProcessorList.prototype.remove = function (processor) { + this._processors.remove(processor); + }; + EntityProcessorList.prototype.onComponentAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onComponentRemoved = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityRemoved = function (entity) { + this.removeFromProcessors(entity); + }; + EntityProcessorList.prototype.notifyEntityChanged = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].onChanged(entity); + } + }; + EntityProcessorList.prototype.removeFromProcessors = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].remove(entity); + } + }; + EntityProcessorList.prototype.begin = function () { + }; + EntityProcessorList.prototype.update = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].update(); + } + }; + EntityProcessorList.prototype.lateUpdate = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].lateUpdate(); + } + }; + EntityProcessorList.prototype.end = function () { + }; + EntityProcessorList.prototype.getProcessor = function () { + for (var i = 0; i < this._processors.length; i++) { + var processor = this._processors[i]; + if (processor instanceof EntitySystem) + return processor; + } + return null; + }; + return EntityProcessorList; +}()); var Matcher = (function () { - function Matcher() { - this.allSet = new BitSet(); - this.exclusionSet = new BitSet(); - this.oneSet = new BitSet(); - } - Matcher.empty = function () { - return new Matcher(); - }; - Matcher.prototype.getAllSet = function () { - return this.allSet; - }; - Matcher.prototype.getExclusionSet = function () { - return this.exclusionSet; - }; - Matcher.prototype.getOneSet = function () { - return this.oneSet; - }; - Matcher.prototype.IsIntersted = function (e) { - if (!this.allSet.isEmpty()) { - for ( - var i = this.allSet.nextSetBit(0); - i >= 0; - i = this.allSet.nextSetBit(i + 1) - ) { - if (!e.componentBits.get(i)) return false; - } - } - if ( - !this.exclusionSet.isEmpty() && - this.exclusionSet.intersects(e.componentBits) - ) - return false; - if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) - return false; - return true; - }; - Matcher.prototype.all = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + function Matcher() { + this.allSet = new BitSet(); + this.exclusionSet = new BitSet(); + this.oneSet = new BitSet(); } - types.forEach(function (type) { - _this.allSet.set(ComponentTypeManager.getIndexFor(type)); - }); - return this; - }; - Matcher.prototype.exclude = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + Matcher.empty = function () { + return new Matcher(); + }; + Matcher.prototype.getAllSet = function () { + return this.allSet; + }; + Matcher.prototype.getExclusionSet = function () { + return this.exclusionSet; + }; + Matcher.prototype.getOneSet = function () { + return this.oneSet; + }; + Matcher.prototype.IsIntersted = function (e) { + if (!this.allSet.isEmpty()) { + for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { + if (!e.componentBits.get(i)) + return false; + } + } + if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) + return false; + if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) + return false; + return true; + }; + Matcher.prototype.all = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.allSet.set(ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.exclude = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.one = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.oneSet.set(ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + return Matcher; +}()); +var RenderableComponentList = (function () { + function RenderableComponentList() { + this._components = []; } - types.forEach(function (type) { - _this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(RenderableComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true }); - return this; - }; - Matcher.prototype.one = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; - } - types.forEach(function (type) { - _this.oneSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(RenderableComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true }); - return this; - }; - return Matcher; -})(); -var RenderableComponentList = (function () { - function RenderableComponentList() { - this._components = []; - } - Object.defineProperty(RenderableComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true, - }); - RenderableComponentList.prototype.add = function (component) { - this._components.push(component); - }; - RenderableComponentList.prototype.remove = function (component) { - this._components.remove(component); - }; - RenderableComponentList.prototype.updateList = function () {}; - return RenderableComponentList; -})(); + RenderableComponentList.prototype.add = function (component) { + this._components.push(component); + }; + RenderableComponentList.prototype.remove = function (component) { + this._components.remove(component); + }; + RenderableComponentList.prototype.updateList = function () { + }; + return RenderableComponentList; +}()); var Time = (function () { - function Time() {} - Time.update = function (currentTime) { - var dt = (currentTime - this._lastTime) / 1000; - this.deltaTime = dt * this.timeScale; - this.unscaledDeltaTime = dt; - this.frameCount++; - this._lastTime = currentTime; - }; - Time.deltaTime = 0; - Time.timeScale = 1; - Time.frameCount = 0; - Time._lastTime = 0; - return Time; -})(); + function Time() { + } + ; + Time.update = function (currentTime) { + var dt = (currentTime - this._lastTime) / 1000; + this.deltaTime = dt * this.timeScale; + this.unscaledDeltaTime = dt; + this.frameCount++; + this._lastTime = currentTime; + }; + Time.deltaTime = 0; + Time.timeScale = 1; + Time.frameCount = 0; + Time._lastTime = 0; + return Time; +}()); var GraphicsCapabilities = (function () { - function GraphicsCapabilities() {} - GraphicsCapabilities.prototype.initialize = function (device) { - this.platformInitialize(device); - }; - GraphicsCapabilities.prototype.platformInitialize = function (device) { - var gl = new egret.sys.RenderBuffer().context.getInstance(); - this.supportsNonPowerOfTwo = false; - this.supportsTextureFilterAnisotropic = - gl.getExtension("EXT_texture_filter_anisotropic") != null; - this.supportsDepth24 = true; - this.supportsPackedDepthStencil = true; - this.supportsDepthNonLinear = false; - this.supportsTextureMaxLevel = true; - this.supportsS3tc = - gl.getExtension("WEBGL_compressed_texture_s3tc") != null || - gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null; - this.supportsDxt1 = this.supportsS3tc; - this.supportsPvrtc = false; - this.supportsAtitc = - gl.getExtension("WEBGL_compressed_texture_astc") != null; - this.supportsFramebufferObjectARB = false; - }; - return GraphicsCapabilities; -})(); + function GraphicsCapabilities() { + } + GraphicsCapabilities.prototype.initialize = function (device) { + this.platformInitialize(device); + }; + GraphicsCapabilities.prototype.platformInitialize = function (device) { + var gl = new egret.sys.RenderBuffer().context.getInstance(); + this.supportsNonPowerOfTwo = false; + this.supportsTextureFilterAnisotropic = gl.getExtension("EXT_texture_filter_anisotropic") != null; + this.supportsDepth24 = true; + this.supportsPackedDepthStencil = true; + this.supportsDepthNonLinear = false; + this.supportsTextureMaxLevel = true; + this.supportsS3tc = gl.getExtension("WEBGL_compressed_texture_s3tc") != null || + gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null; + this.supportsDxt1 = this.supportsS3tc; + this.supportsPvrtc = false; + this.supportsAtitc = gl.getExtension("WEBGL_compressed_texture_astc") != null; + this.supportsFramebufferObjectARB = false; + }; + return GraphicsCapabilities; +}()); var GraphicsDevice = (function () { - function GraphicsDevice() { - this.graphicsCapabilities = new GraphicsCapabilities(); - this.graphicsCapabilities.initialize(this); - } - return GraphicsDevice; -})(); + function GraphicsDevice() { + this.graphicsCapabilities = new GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); + } + return GraphicsDevice; +}()); var Viewport = (function () { - function Viewport(x, y, width, height) { - this._x = x; - this._y = y; - this._width = width; - this._height = height; - this._minDepth = 0; - this._maxDepth = 1; - } - Object.defineProperty(Viewport.prototype, "aspectRatio", { - get: function () { - if (this._height != 0 && this._width != 0) - return this._width / this._height; - return 0; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Viewport.prototype, "bounds", { - get: function () { - return new Rectangle(this._x, this._y, this._width, this._height); - }, - set: function (value) { - this._x = value.x; - this._y = value.y; - this._width = value.width; - this._height = value.height; - }, - enumerable: true, - configurable: true, - }); - return Viewport; -})(); -var GraphicsResource = (function () { - function GraphicsResource() {} - return GraphicsResource; -})(); + function Viewport(x, y, width, height) { + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } + Object.defineProperty(Viewport.prototype, "aspectRatio", { + get: function () { + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Viewport.prototype, "bounds", { + get: function () { + return new Rectangle(this._x, this._y, this._width, this._height); + }, + set: function (value) { + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + }, + enumerable: true, + configurable: true + }); + return Viewport; +}()); var GaussianBlurEffect = (function (_super) { - __extends(GaussianBlurEffect, _super); - function GaussianBlurEffect() { - return ( - _super.call( - this, - PostProcessor.default_vert, - GaussianBlurEffect.blur_frag, - { - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight, - } - ) || this - ); - } - GaussianBlurEffect.blur_frag = - "precision mediump float;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float screenWidth;\n" + - "uniform float screenHeight;\n" + - "float normpdf(in float x, in float sigma)\n" + - "{\n" + - "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + - "}\n" + - "void main()\n" + - "{\n" + - "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "const int mSize = 11;\n" + - "const int kSize = (mSize - 1)/2;\n" + - "float kernel[mSize];\n" + - "vec3 final_colour = vec3(0.0);\n" + - "float sigma = 7.0;\n" + - "float z = 0.0;\n" + - "for (int j = 0; j <= kSize; ++j)\n" + - "{\n" + - "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + - "}\n" + - "for (int j = 0; j < mSize; ++j)\n" + - "{\n" + - "z += kernel[j];\n" + - "}\n" + - "for (int i = -kSize; i <= kSize; ++i)\n" + - "{\n" + - "for (int j = -kSize; j <= kSize; ++j)\n" + - "{\n" + - "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "}\n}\n" + - "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + - "}"; - return GaussianBlurEffect; -})(egret.CustomFilter); + __extends(GaussianBlurEffect, _super); + function GaussianBlurEffect() { + return _super.call(this, PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { + screenWidth: SceneManager.stage.stageWidth, + screenHeight: SceneManager.stage.stageHeight + }) || this; + } + GaussianBlurEffect.blur_frag = "precision mediump float;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float screenWidth;\n" + + "uniform float screenHeight;\n" + + "float normpdf(in float x, in float sigma)\n" + + "{\n" + + "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + + "}\n" + + "void main()\n" + + "{\n" + + "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "const int mSize = 11;\n" + + "const int kSize = (mSize - 1)/2;\n" + + "float kernel[mSize];\n" + + "vec3 final_colour = vec3(0.0);\n" + + "float sigma = 7.0;\n" + + "float z = 0.0;\n" + + "for (int j = 0; j <= kSize; ++j)\n" + + "{\n" + + "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + + "}\n" + + "for (int j = 0; j < mSize; ++j)\n" + + "{\n" + + "z += kernel[j];\n" + + "}\n" + + "for (int i = -kSize; i <= kSize; ++i)\n" + + "{\n" + + "for (int j = -kSize; j <= kSize; ++j)\n" + + "{\n" + + "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "}\n}\n" + + "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + + "}"; + return GaussianBlurEffect; +}(egret.CustomFilter)); var PolygonLightEffect = (function (_super) { - __extends(PolygonLightEffect, _super); - function PolygonLightEffect() { - return ( - _super.call( - this, - PolygonLightEffect.vertSrc, - PolygonLightEffect.fragmentSrc - ) || this - ); - } - PolygonLightEffect.vertSrc = - "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - PolygonLightEffect.fragmentSrc = - "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + - "#define SAMPLE_COUNT 15\n" + - "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + - "uniform float _sampleWeights[SAMPLE_COUNT];\n" + - "void main(void) {\n" + - "vec4 c = vec4(0, 0, 0, 0);\n" + - "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + - " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + - "gl_FragColor = c;\n" + - "}"; - return PolygonLightEffect; -})(egret.CustomFilter); + __extends(PolygonLightEffect, _super); + function PolygonLightEffect() { + return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this; + } + PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + PolygonLightEffect.fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + + "#define SAMPLE_COUNT 15\n" + + "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + + "uniform float _sampleWeights[SAMPLE_COUNT];\n" + + "void main(void) {\n" + + "vec4 c = vec4(0, 0, 0, 0);\n" + + "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + + " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + + "gl_FragColor = c;\n" + + "}"; + return PolygonLightEffect; +}(egret.CustomFilter)); var PostProcessor = (function () { - function PostProcessor(effect) { - if (effect === void 0) { - effect = null; - } - this.enable = true; - this.effect = effect; - } - PostProcessor.prototype.onAddedToScene = function (scene) { - this.scene = scene; - this.shape = new egret.Shape(); - this.shape.graphics.beginFill(0xffffff, 1); - this.shape.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - this.shape.graphics.endFill(); - scene.addChild(this.shape); - }; - PostProcessor.prototype.process = function () { - this.drawFullscreenQuad(); - }; - PostProcessor.prototype.onSceneBackBufferSizeChanged = function ( - newWidth, - newHeight - ) {}; - PostProcessor.prototype.drawFullscreenQuad = function () { - this.scene.filters = [this.effect]; - }; - PostProcessor.prototype.unload = function () { - if (this.effect) { - this.effect = null; - } - this.scene.removeChild(this.shape); - this.scene = null; - }; - PostProcessor.default_vert = - "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "attribute vec2 aColor;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "varying vec4 vColor;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - "vTextureCoord = aTextureCoord;\n" + - "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + - "}"; - return PostProcessor; -})(); -var BloomSettings = (function () { - function BloomSettings( - bloomThreshold, - blurAmount, - bloomIntensity, - baseIntensity, - bloomSaturation, - baseSaturation - ) { - this.threshold = bloomThreshold; - this.blurAmount = blurAmount; - this.intensity = bloomIntensity; - this.baseIntensity = baseIntensity; - this.saturation = bloomSaturation; - this.baseStaturation = baseSaturation; - } - BloomSettings.presetSettings = [ - new BloomSettings(0.1, 0.6, 2, 1, 1, 0), - new BloomSettings(0, 3, 1, 1, 1, 1), - new BloomSettings(0.5, 8, 2, 1, 0, 1), - new BloomSettings(0.25, 8, 1.3, 1, 1, 0), - new BloomSettings(0, 2, 1, 0.1, 1, 1), - new BloomSettings(0.5, 2, 1, 1, 1, 1), - ]; - return BloomSettings; -})(); + function PostProcessor(effect) { + if (effect === void 0) { effect = null; } + this.enable = true; + this.effect = effect; + } + PostProcessor.prototype.onAddedToScene = function (scene) { + this.scene = scene; + this.shape = new egret.Shape(); + this.shape.graphics.beginFill(0xFFFFFF, 1); + this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this.shape.graphics.endFill(); + scene.addChild(this.shape); + }; + PostProcessor.prototype.process = function () { + this.drawFullscreenQuad(); + }; + PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { }; + PostProcessor.prototype.drawFullscreenQuad = function () { + this.scene.filters = [this.effect]; + }; + PostProcessor.prototype.unload = function () { + if (this.effect) { + this.effect = null; + } + this.scene.removeChild(this.shape); + this.scene = null; + }; + PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "attribute vec2 aColor;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "varying vec4 vColor;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + "vTextureCoord = aTextureCoord;\n" + + "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + + "}"; + return PostProcessor; +}()); var GaussianBlurPostProcessor = (function (_super) { - __extends(GaussianBlurPostProcessor, _super); - function GaussianBlurPostProcessor() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { - _super.prototype.onAddedToScene.call(this, scene); - this.effect = new GaussianBlurEffect(); - }; - return GaussianBlurPostProcessor; -})(PostProcessor); + __extends(GaussianBlurPostProcessor, _super); + function GaussianBlurPostProcessor() { + return _super !== null && _super.apply(this, arguments) || this; + } + GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { + _super.prototype.onAddedToScene.call(this, scene); + this.effect = new GaussianBlurEffect(); + }; + return GaussianBlurPostProcessor; +}(PostProcessor)); var Renderer = (function () { - function Renderer() {} - Renderer.prototype.onAddedToScene = function (scene) {}; - Renderer.prototype.beginRender = function (cam) {}; - Renderer.prototype.unload = function () {}; - Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { - renderable.render(cam); - }; - return Renderer; -})(); -var DefaultRenderer = (function (_super) { - __extends(DefaultRenderer, _super); - function DefaultRenderer() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - DefaultRenderer.prototype.render = function (scene) { - var cam = this.camera ? this.camera : scene.camera; - this.beginRender(cam); - for (var i = 0; i < scene.renderableComponents.count; i++) { - var renderable = scene.renderableComponents.buffer[i]; - if (renderable.enabled && renderable.isVisibleFromCamera(cam)) - this.renderAfterStateCheck(renderable, cam); + function Renderer() { } - }; - return DefaultRenderer; -})(Renderer); + Renderer.prototype.onAddedToScene = function (scene) { }; + Renderer.prototype.beginRender = function (cam) { + }; + Renderer.prototype.unload = function () { }; + Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { + renderable.render(cam); + }; + return Renderer; +}()); +var DefaultRenderer = (function (_super) { + __extends(DefaultRenderer, _super); + function DefaultRenderer() { + return _super !== null && _super.apply(this, arguments) || this; + } + DefaultRenderer.prototype.render = function (scene) { + var cam = this.camera ? this.camera : scene.camera; + this.beginRender(cam); + for (var i = 0; i < scene.renderableComponents.count; i++) { + var renderable = scene.renderableComponents.buffer[i]; + if (renderable.enabled && renderable.isVisibleFromCamera(cam)) + this.renderAfterStateCheck(renderable, cam); + } + }; + return DefaultRenderer; +}(Renderer)); var ScreenSpaceRenderer = (function (_super) { - __extends(ScreenSpaceRenderer, _super); - function ScreenSpaceRenderer() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - ScreenSpaceRenderer.prototype.render = function (scene) {}; - return ScreenSpaceRenderer; -})(Renderer); -var PolyLight = (function (_super) { - __extends(PolyLight, _super); - function PolyLight(radius, color, power) { - var _this = _super.call(this) || this; - _this._indices = []; - _this.radius = radius; - _this.power = power; - _this.color = color; - _this.computeTriangleIndices(); - return _this; - } - Object.defineProperty(PolyLight.prototype, "radius", { - get: function () { - return this._radius; - }, - set: function (value) { - this.setRadius(value); - }, - enumerable: true, - configurable: true, - }); - PolyLight.prototype.computeTriangleIndices = function (totalTris) { - if (totalTris === void 0) { - totalTris = 20; + __extends(ScreenSpaceRenderer, _super); + function ScreenSpaceRenderer() { + return _super !== null && _super.apply(this, arguments) || this; } - this._indices.length = 0; - for (var i = 0; i < totalTris; i += 2) { - this._indices.push(0); - this._indices.push(i + 2); - this._indices.push(i + 1); - } - }; - PolyLight.prototype.setRadius = function (radius) { - if (radius != this._radius) { - this._radius = radius; - this._areBoundsDirty = true; - } - }; - PolyLight.prototype.render = function (camera) {}; - PolyLight.prototype.reset = function () {}; - return PolyLight; -})(RenderableComponent); -var SceneTransition = (function () { - function SceneTransition(sceneLoadAction) { - this.sceneLoadAction = sceneLoadAction; - this.loadsNewScene = sceneLoadAction != null; - } - Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { - get: function () { - if (!this._hasPreviousSceneRender) { - this._hasPreviousSceneRender = true; - return false; - } - return true; - }, - enumerable: true, - configurable: true, - }); - SceneTransition.prototype.preRender = function () {}; - SceneTransition.prototype.render = function () {}; - SceneTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - _a.sent(); - this.transitionComplete(); - return [2]; - } - }); + ScreenSpaceRenderer.prototype.render = function (scene) { + }; + return ScreenSpaceRenderer; +}(Renderer)); +var PolyLight = (function (_super) { + __extends(PolyLight, _super); + function PolyLight(radius, color, power) { + var _this = _super.call(this) || this; + _this._indices = []; + _this.radius = radius; + _this.power = power; + _this.color = color; + _this.computeTriangleIndices(); + return _this; + } + Object.defineProperty(PolyLight.prototype, "radius", { + get: function () { + return this._radius; + }, + set: function (value) { + this.setRadius(value); + }, + enumerable: true, + configurable: true }); - }; - SceneTransition.prototype.transitionComplete = function () { - SceneManager.sceneTransition = null; - if (this.onTransitionCompleted) { - this.onTransitionCompleted(); - } - }; - SceneTransition.prototype.loadNextScene = function () { - return __awaiter(this, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (this.onScreenObscured) this.onScreenObscured(); - if (!this.loadsNewScene) { - this.isNewSceneLoaded = true; + PolyLight.prototype.computeTriangleIndices = function (totalTris) { + if (totalTris === void 0) { totalTris = 20; } + this._indices.length = 0; + for (var i = 0; i < totalTris; i += 2) { + this._indices.push(0); + this._indices.push(i + 2); + this._indices.push(i + 1); + } + }; + PolyLight.prototype.setRadius = function (radius) { + if (radius != this._radius) { + this._radius = radius; + this._areBoundsDirty = true; + } + }; + PolyLight.prototype.render = function (camera) { + }; + PolyLight.prototype.reset = function () { + }; + return PolyLight; +}(RenderableComponent)); +var SceneTransition = (function () { + function SceneTransition(sceneLoadAction) { + this.sceneLoadAction = sceneLoadAction; + this.loadsNewScene = sceneLoadAction != null; + } + Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { + get: function () { + if (!this._hasPreviousSceneRender) { + this._hasPreviousSceneRender = true; + return false; } - _a = SceneManager; - return [4, this.sceneLoadAction()]; - case 1: - _a.scene = _b.sent(); - this.isNewSceneLoaded = true; - return [2]; - } - }); - }); - }; - SceneTransition.prototype.tickEffectProgressProperty = function ( - filter, - duration, - easeType, - reverseDirection - ) { - if (reverseDirection === void 0) { - reverseDirection = false; - } - return new Promise(function (resolve) { - var start = reverseDirection ? 1 : 0; - var end = reverseDirection ? 0 : 1; - egret.Tween.get(filter.uniforms) - .set({ _progress: start }) - .to({ _progress: end }, duration * 1000, easeType) - .call(function () { - resolve(); - }); + return true; + }, + enumerable: true, + configurable: true }); - }; - return SceneTransition; -})(); -var FadeTransition = (function (_super) { - __extends(FadeTransition, _super); - function FadeTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.fadeToColor = 0x000000; - _this.fadeOutDuration = 0.4; - _this.fadeEaseType = egret.Ease.quadInOut; - _this.delayBeforeFadeInDuration = 0.1; - _this._alpha = 0; - _this._mask = new egret.Shape(); - return _this; - } - FadeTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - this._mask.graphics.endFill(); - SceneManager.stage.addChild(this._mask); - egret.Tween.get(this) - .to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) - .call(function () { - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { + SceneTransition.prototype.preRender = function () { }; + SceneTransition.prototype.render = function () { + }; + SceneTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { switch (_a.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - _a.sent(); - return [2]; + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + this.transitionComplete(); + return [2]; } - }); }); - }) - .wait(this.delayBeforeFadeInDuration) - .call(function () { - egret.Tween.get(_this) - .to( - { _alpha: 0 }, - _this.fadeOutDuration * 1000, - _this.fadeEaseType - ) - .call(function () { - _this.transitionComplete(); - SceneManager.stage.removeChild(_this._mask); - }); - }); - return [2]; - }); - }); - }; - FadeTransition.prototype.render = function () { - this._mask.graphics.clear(); - this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - this._mask.graphics.endFill(); - }; - return FadeTransition; -})(SceneTransition); + }); + }; + SceneTransition.prototype.transitionComplete = function () { + SceneManager.sceneTransition = null; + if (this.onTransitionCompleted) { + this.onTransitionCompleted(); + } + }; + SceneTransition.prototype.loadNextScene = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (this.onScreenObscured) + this.onScreenObscured(); + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + } + _a = SceneManager; + return [4, this.sceneLoadAction()]; + case 1: + _a.scene = _b.sent(); + this.isNewSceneLoaded = true; + return [2]; + } + }); + }); + }; + SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) { + if (reverseDirection === void 0) { reverseDirection = false; } + return new Promise(function (resolve) { + var start = reverseDirection ? 1 : 0; + var end = reverseDirection ? 0 : 1; + egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () { + resolve(); + }); + }); + }; + return SceneTransition; +}()); +var FadeTransition = (function (_super) { + __extends(FadeTransition, _super); + function FadeTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.fadeToColor = 0x000000; + _this.fadeOutDuration = 0.4; + _this.fadeEaseType = egret.Ease.quadInOut; + _this.delayBeforeFadeInDuration = 0.1; + _this._alpha = 0; + _this._mask = new egret.Shape(); + return _this; + } + FadeTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + this._mask.graphics.beginFill(this.fadeToColor, 1); + this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + SceneManager.stage.addChild(this._mask); + egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) + .call(function () { return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + return [2]; + } + }); + }); }).wait(this.delayBeforeFadeInDuration).call(function () { + egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { + _this.transitionComplete(); + SceneManager.stage.removeChild(_this._mask); + }); + }); + return [2]; + }); + }); + }; + FadeTransition.prototype.render = function () { + this._mask.graphics.clear(); + this._mask.graphics.beginFill(this.fadeToColor, this._alpha); + this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + }; + return FadeTransition; +}(SceneTransition)); var WindTransition = (function (_super) { - __extends(WindTransition, _super); - function WindTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.duration = 1; - _this.easeType = egret.Ease.quadOut; - var vertexSrc = - "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - var fragmentSrc = - "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float _progress;\n" + - "uniform float _size;\n" + - "uniform float _windSegments;\n" + - "void main(void) {\n" + - "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + - "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + - "float r = x - floor(x);\n" + - "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + - "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + - "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + - "}"; - _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { - _progress: 0, - _size: 0.3, - _windSegments: 100, + __extends(WindTransition, _super); + function WindTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.duration = 1; + _this.easeType = egret.Ease.quadOut; + var vertexSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + var fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float _progress;\n" + + "uniform float _size;\n" + + "uniform float _windSegments;\n" + + "void main(void) {\n" + + "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + + "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + + "float r = x - floor(x);\n" + + "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + + "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + + "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + + "}"; + _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { + _progress: 0, + _size: 0.3, + _windSegments: 100 + }); + _this._mask = new egret.Shape(); + _this._mask.graphics.beginFill(0xFFFFFF, 1); + _this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + _this._mask.graphics.endFill(); + _this._mask.filters = [_this._windEffect]; + SceneManager.stage.addChild(_this._mask); + return _this; + } + Object.defineProperty(WindTransition.prototype, "windSegments", { + set: function (value) { + this._windEffect.uniforms._windSegments = value; + }, + enumerable: true, + configurable: true }); - _this._mask = new egret.Shape(); - _this._mask.graphics.beginFill(0xffffff, 1); - _this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - _this._mask.graphics.endFill(); - _this._mask.filters = [_this._windEffect]; - SceneManager.stage.addChild(_this._mask); - return _this; - } - Object.defineProperty(WindTransition.prototype, "windSegments", { - set: function (value) { - this._windEffect.uniforms._windSegments = value; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(WindTransition.prototype, "size", { - set: function (value) { - this._windEffect.uniforms._size = value; - }, - enumerable: true, - configurable: true, - }); - WindTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.loadNextScene(); - return [ - 4, - this.tickEffectProgressProperty( - this._windEffect, - this.duration, - this.easeType - ), - ]; - case 1: - _a.sent(); - this.transitionComplete(); - SceneManager.stage.removeChild(this._mask); - return [2]; - } - }); + Object.defineProperty(WindTransition.prototype, "size", { + set: function (value) { + this._windEffect.uniforms._size = value; + }, + enumerable: true, + configurable: true }); - }; - return WindTransition; -})(SceneTransition); + WindTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.loadNextScene(); + return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)]; + case 1: + _a.sent(); + this.transitionComplete(); + SceneManager.stage.removeChild(this._mask); + return [2]; + } + }); + }); + }; + return WindTransition; +}(SceneTransition)); var BaseView = (function (_super) { - __extends(BaseView, _super); - function BaseView() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - BaseView.prototype.init = function () {}; - BaseView.prototype.show = function (data) {}; - BaseView.prototype.refreshData = function (data) { - this._data = data; - }; - BaseView.prototype.refreshView = function () {}; - BaseView.prototype.close = function () {}; - BaseView.prototype.destroy = function () { - if (this.parent) { - this.parent.removeChild(this); - } - while (this.numChildren > 0) { - this.removeChildAt(0); + __extends(BaseView, _super); + function BaseView() { + return _super !== null && _super.apply(this, arguments) || this; } - }; - return BaseView; -})(egret.DisplayObjectContainer); + BaseView.prototype.init = function () { + }; + BaseView.prototype.show = function (data) { + }; + BaseView.prototype.refreshData = function (data) { + this._data = data; + }; + BaseView.prototype.refreshView = function () { + }; + BaseView.prototype.close = function () { + }; + BaseView.prototype.destroy = function () { + if (this.parent) { + this.parent.removeChild(this); + } + while (this.numChildren > 0) { + this.removeChildAt(0); + } + }; + return BaseView; +}(egret.DisplayObjectContainer)); var BaseFuiView = (function (_super) { - __extends(BaseFuiView, _super); - function BaseFuiView(name) { - var _this = _super.call(this) || this; - _this.name = name; - return _this; - } - return BaseFuiView; -})(BaseView); + __extends(BaseFuiView, _super); + function BaseFuiView(name) { + var _this = _super.call(this) || this; + _this.name = name; + return _this; + } + return BaseFuiView; +}(BaseView)); var BaseSingle = (function () { - function BaseSingle() {} - BaseSingle.getInstance = function () { - if (this._instance == null) { - this._instance = new this(); + function BaseSingle() { } - return this._instance; - }; - BaseSingle.prototype.clearFuiObj = function (obj) { - if (obj) { - egret.Tween.removeTweens(obj.displayObject); - if (obj.displayObject && obj.displayObject.parent) { - obj.displayObject.parent.removeChild(obj.displayObject); - } - obj.dispose(); - obj = null; - return true; - } - return false; - }; - return BaseSingle; -})(); + BaseSingle.getInstance = function () { + if (this._instance == null) { + this._instance = new this(); + } + return this._instance; + }; + BaseSingle.prototype.clearFuiObj = function (obj) { + if (obj) { + egret.Tween.removeTweens(obj.displayObject); + if (obj.displayObject && obj.displayObject.parent) { + obj.displayObject.parent.removeChild(obj.displayObject); + } + obj.dispose(); + obj = null; + return true; + } + return false; + }; + return BaseSingle; +}()); var ViewManager = (function (_super) { - __extends(ViewManager, _super); - function ViewManager() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this._openDic = []; - return _this; - } - ViewManager.prototype.refreshView = function (viewClass, data) { - var view = this.getView(viewClass); - if (view) { - view.refreshData(data); - view.refreshView(); - } - }; - ViewManager.prototype.openView = function (viewClass, data, complete) { - var newView = this.getView(viewClass); - if (!newView) { - newView = new viewClass(); - } - if (this.existView(viewClass)) { - newView.refreshData(data); - newView.refreshView(); - return; - } - this._openDic.push(newView); - }; - ViewManager.prototype.getView = function (viewClass) { - var result = this._openDic.firstOrDefault(function (a) { - return a instanceof viewClass; - }); - return result; - }; - ViewManager.prototype.existView = function (viewClass) { - return ( - this._openDic.findIndex(function (a) { - return a instanceof viewClass; - }) != -1 - ); - }; - return ViewManager; -})(BaseSingle); + __extends(ViewManager, _super); + function ViewManager() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._openDic = []; + return _this; + } + ViewManager.prototype.refreshView = function (viewClass, data) { + var view = this.getView(viewClass); + if (view) { + view.refreshData(data); + view.refreshView(); + } + }; + ViewManager.prototype.openView = function (viewClass, data, complete) { + var newView = this.getView(viewClass); + if (!newView) { + newView = new viewClass(); + } + if (this.existView(viewClass)) { + newView.refreshData(data); + newView.refreshView(); + return; + } + this._openDic.push(newView); + }; + ViewManager.prototype.getView = function (viewClass) { + var result = this._openDic.firstOrDefault(function (a) { + return a instanceof viewClass; + }); + return result; + }; + ViewManager.prototype.existView = function (viewClass) { + return this._openDic.findIndex(function (a) { + return a instanceof viewClass; + }) != -1; + }; + return ViewManager; +}(BaseSingle)); var Flags = (function () { - function Flags() {} - Flags.isFlagSet = function (self, flag) { - return (self & flag) != 0; - }; - Flags.isUnshiftedFlagSet = function (self, flag) { - flag = 1 << flag; - return (self & flag) != 0; - }; - Flags.setFlagExclusive = function (self, flag) { - return 1 << flag; - }; - Flags.setFlag = function (self, flag) { - return self | (1 << flag); - }; - Flags.unsetFlag = function (self, flag) { - flag = 1 << flag; - return self & ~flag; - }; - Flags.invertFlags = function (self) { - return ~self; - }; - return Flags; -})(); -var MathHelper = (function () { - function MathHelper() {} - MathHelper.toDegrees = function (radians) { - return radians * 57.295779513082320876798154814105; - }; - MathHelper.toRadians = function (degrees) { - return degrees * 0.017453292519943295769236907684886; - }; - MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { - return ( - rightMin + - ((value - leftMin) * (rightMax - rightMin)) / (leftMax - leftMin) - ); - }; - MathHelper.lerp = function (value1, value2, amount) { - return value1 + (value2 - value1) * amount; - }; - MathHelper.clamp = function (value, min, max) { - if (value < min) return min; - if (value > max) return max; - return value; - }; - MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { - var radians = MathHelper.toRadians(angleInDegrees); - return new Vector2( - Math.cos(radians) * radians + circleCenter.x, - Math.sin(radians) * radians + circleCenter.y - ); - }; - MathHelper.isEven = function (value) { - return value % 2 == 0; - }; - MathHelper.Epsilon = 0.00001; - MathHelper.Rad2Deg = 57.29578; - MathHelper.Deg2Rad = 0.0174532924; - return MathHelper; -})(); -var Matrix2D = (function () { - function Matrix2D(m11, m12, m21, m22, m31, m32) { - this.m11 = 0; - this.m12 = 0; - this.m21 = 0; - this.m22 = 0; - this.m31 = 0; - this.m32 = 0; - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; - } - Object.defineProperty(Matrix2D, "identity", { - get: function () { - return Matrix2D._identity; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "translation", { - get: function () { - return new Vector2(this.m31, this.m32); - }, - set: function (value) { - this.m31 = value.x; - this.m32 = value.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "rotation", { - get: function () { - return Math.atan2(this.m21, this.m11); - }, - set: function (value) { - var val1 = Math.cos(value); - var val2 = Math.sin(value); - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this.rotation); - }, - set: function (value) { - this.rotation = MathHelper.toRadians(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "scale", { - get: function () { - return new Vector2(this.m11, this.m22); - }, - set: function (value) { - this.m11 = value.x; - this.m12 = value.y; - }, - enumerable: true, - configurable: true, - }); - Matrix2D.add = function (matrix1, matrix2) { - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; - return matrix1; - }; - Matrix2D.divide = function (matrix1, matrix2) { - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; - return matrix1; - }; - Matrix2D.multiply = function (matrix1, matrix2) { - var result = new Matrix2D(); - var m11 = matrix1.m11 * matrix2.m11 + matrix1.m12 * matrix2.m21; - var m12 = matrix1.m11 * matrix2.m12 + matrix1.m12 * matrix2.m22; - var m21 = matrix1.m21 * matrix2.m11 + matrix1.m22 * matrix2.m21; - var m22 = matrix1.m21 * matrix2.m12 + matrix1.m22 * matrix2.m22; - var m31 = - matrix1.m31 * matrix2.m11 + matrix1.m32 * matrix2.m21 + matrix2.m31; - var m32 = - matrix1.m31 * matrix2.m12 + matrix1.m32 * matrix2.m22 + matrix2.m32; - result.m11 = m11; - result.m12 = m12; - result.m21 = m21; - result.m22 = m22; - result.m31 = m31; - result.m32 = m32; - return result; - }; - Matrix2D.multiplyTranslation = function (matrix, x, y) { - var trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); - }; - Matrix2D.prototype.determinant = function () { - return this.m11 * this.m22 - this.m12 * this.m21; - }; - Matrix2D.invert = function (matrix, result) { - if (result === void 0) { - result = new Matrix2D(); + function Flags() { } - var det = 1 / matrix.determinant(); - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - return result; - }; - Matrix2D.createTranslation = function (xPosition, yPosition, result) { - result = result ? result : new Matrix2D(); - result.m11 = 1; - result.m12 = 0; - result.m21 = 0; - result.m22 = 1; - result.m31 = xPosition; - result.m32 = yPosition; - return result; - }; - Matrix2D.createRotation = function (radians, result) { - result = new Matrix2D(); - var val1 = Math.cos(radians); - var val2 = Math.sin(radians); - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - return result; - }; - Matrix2D.createScale = function (xScale, yScale, result) { - if (result === void 0) { - result = new Matrix2D(); + Flags.isFlagSet = function (self, flag) { + return (self & flag) != 0; + }; + Flags.isUnshiftedFlagSet = function (self, flag) { + flag = 1 << flag; + return (self & flag) != 0; + }; + Flags.setFlagExclusive = function (self, flag) { + return 1 << flag; + }; + Flags.setFlag = function (self, flag) { + return (self | 1 << flag); + }; + Flags.unsetFlag = function (self, flag) { + flag = 1 << flag; + return (self & (~flag)); + }; + Flags.invertFlags = function (self) { + return ~self; + }; + return Flags; +}()); +var MathHelper = (function () { + function MathHelper() { } - result.m11 = xScale; - result.m12 = 0; - result.m21 = 0; - result.m22 = yScale; - result.m31 = 0; - result.m32 = 0; - return result; - }; - Matrix2D.prototype.toEgretMatrix = function () { - var matrix = new egret.Matrix( - this.m11, - this.m12, - this.m21, - this.m22, - this.m31, - this.m32 - ); - return matrix; - }; - Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); - return Matrix2D; -})(); + MathHelper.toDegrees = function (radians) { + return radians * 57.295779513082320876798154814105; + }; + MathHelper.toRadians = function (degrees) { + return degrees * 0.017453292519943295769236907684886; + }; + MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { + return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); + }; + MathHelper.lerp = function (value1, value2, amount) { + return value1 + (value2 - value1) * amount; + }; + MathHelper.clamp = function (value, min, max) { + if (value < min) + return min; + if (value > max) + return max; + return value; + }; + MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { + var radians = MathHelper.toRadians(angleInDegrees); + return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); + }; + MathHelper.isEven = function (value) { + return value % 2 == 0; + }; + MathHelper.Epsilon = 0.00001; + MathHelper.Rad2Deg = 57.29578; + MathHelper.Deg2Rad = 0.0174532924; + return MathHelper; +}()); +var Matrix2D = (function () { + function Matrix2D(m11, m12, m21, m22, m31, m32) { + this.m11 = 0; + this.m12 = 0; + this.m21 = 0; + this.m22 = 0; + this.m31 = 0; + this.m32 = 0; + this.m11 = m11 ? m11 : 1; + this.m12 = m12 ? m12 : 0; + this.m21 = m21 ? m21 : 0; + this.m22 = m22 ? m22 : 1; + this.m31 = m31 ? m31 : 0; + this.m32 = m32 ? m32 : 0; + } + Object.defineProperty(Matrix2D, "identity", { + get: function () { + return Matrix2D._identity; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "translation", { + get: function () { + return new Vector2(this.m31, this.m32); + }, + set: function (value) { + this.m31 = value.x; + this.m32 = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotation", { + get: function () { + return Math.atan2(this.m21, this.m11); + }, + set: function (value) { + var val1 = Math.cos(value); + var val2 = Math.sin(value); + this.m11 = val1; + this.m12 = val2; + this.m21 = -val2; + this.m22 = val1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { + get: function () { + return MathHelper.toDegrees(this.rotation); + }, + set: function (value) { + this.rotation = MathHelper.toRadians(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "scale", { + get: function () { + return new Vector2(this.m11, this.m22); + }, + set: function (value) { + this.m11 = value.x; + this.m12 = value.y; + }, + enumerable: true, + configurable: true + }); + Matrix2D.add = function (matrix1, matrix2) { + matrix1.m11 += matrix2.m11; + matrix1.m12 += matrix2.m12; + matrix1.m21 += matrix2.m21; + matrix1.m22 += matrix2.m22; + matrix1.m31 += matrix2.m31; + matrix1.m32 += matrix2.m32; + return matrix1; + }; + Matrix2D.divide = function (matrix1, matrix2) { + matrix1.m11 /= matrix2.m11; + matrix1.m12 /= matrix2.m12; + matrix1.m21 /= matrix2.m21; + matrix1.m22 /= matrix2.m22; + matrix1.m31 /= matrix2.m31; + matrix1.m32 /= matrix2.m32; + return matrix1; + }; + Matrix2D.multiply = function (matrix1, matrix2) { + var result = new Matrix2D(); + var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); + var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); + var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); + var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); + var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; + var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; + result.m11 = m11; + result.m12 = m12; + result.m21 = m21; + result.m22 = m22; + result.m31 = m31; + result.m32 = m32; + return result; + }; + Matrix2D.multiplyTranslation = function (matrix, x, y) { + var trans = Matrix2D.createTranslation(x, y); + return Matrix2D.multiply(matrix, trans); + }; + Matrix2D.prototype.determinant = function () { + return this.m11 * this.m22 - this.m12 * this.m21; + }; + Matrix2D.invert = function (matrix, result) { + if (result === void 0) { result = new Matrix2D(); } + var det = 1 / matrix.determinant(); + result.m11 = matrix.m22 * det; + result.m12 = -matrix.m12 * det; + result.m21 = -matrix.m21 * det; + result.m22 = matrix.m11 * det; + result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; + result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; + return result; + }; + Matrix2D.createTranslation = function (xPosition, yPosition, result) { + result = result ? result : new Matrix2D(); + result.m11 = 1; + result.m12 = 0; + result.m21 = 0; + result.m22 = 1; + result.m31 = xPosition; + result.m32 = yPosition; + return result; + }; + Matrix2D.createRotation = function (radians, result) { + result = new Matrix2D(); + var val1 = Math.cos(radians); + var val2 = Math.sin(radians); + result.m11 = val1; + result.m12 = val2; + result.m21 = -val2; + result.m22 = val1; + return result; + }; + Matrix2D.createScale = function (xScale, yScale, result) { + if (result === void 0) { result = new Matrix2D(); } + result.m11 = xScale; + result.m12 = 0; + result.m21 = 0; + result.m22 = yScale; + result.m31 = 0; + result.m32 = 0; + return result; + }; + Matrix2D.prototype.toEgretMatrix = function () { + var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + }; + Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); + return Matrix2D; +}()); var Rectangle = (function () { - function Rectangle(x, y, width, height) { - this.x = x ? x : 0; - this.y = y ? y : 0; - this.width = width ? width : 0; - this.height = height ? height : 0; - } - Object.defineProperty(Rectangle.prototype, "left", { - get: function () { - return this.x; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "right", { - get: function () { - return this.x + this.width; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "top", { - get: function () { - return this.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "bottom", { - get: function () { - return this.y + this.height; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "center", { - get: function () { - return new Vector2(this.x + this.width / 2, this.y + this.height / 2); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "location", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (value) { - this.x = value.x; - this.y = value.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "size", { - get: function () { - return new Vector2(this.width, this.height); - }, - set: function (value) { - this.width = value.x; - this.height = value.y; - }, - enumerable: true, - configurable: true, - }); - Rectangle.prototype.intersects = function (value) { - return ( - value.left < this.right && - this.left < value.right && - value.top < this.bottom && - this.top < value.bottom - ); - }; - Rectangle.prototype.contains = function (value) { - return ( - this.x <= value.x && - value.x < this.x + this.width && - this.y <= value.y && - value.y < this.y + this.height - ); - }; - Rectangle.prototype.containsRect = function (value) { - return ( - this.x <= value.x && - value.x < this.x + this.width && - this.y <= value.y && - value.y < this.y + this.height - ); - }; - Rectangle.prototype.getHalfSize = function () { - return new Vector2(this.width * 0.5, this.height * 0.5); - }; - Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { - return new Rectangle(minX, minY, maxX - minX, maxY - minY); - }; - Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function ( - point - ) { - var edgeNormal = new Vector2(0, 0); - var res = new Vector2(0, 0); - res.x = MathHelper.clamp(point.x, this.left, this.right); - res.y = MathHelper.clamp(point.y, this.top, this.bottom); - if (this.contains(res)) { - var dl = res.x - this.left; - var dr = this.right - res.x; - var dt = res.y - this.top; - var db = this.bottom - res.y; - var min = Math.min(dl, dr, dt, db); - if (min == dt) { - res.y = this.top; - edgeNormal.y = -1; - } else if (min == db) { - res.y = this.bottom; - edgeNormal.y = 1; - } else if (min == dl) { - res.x = this.left; - edgeNormal.x = -1; - } else { - res.x = this.right; - edgeNormal.x = 1; - } - } else { - if (res.x == this.left) { - edgeNormal.x = -1; - } - if (res.x == this.right) { - edgeNormal.x = 1; - } - if (res.y == this.top) { - edgeNormal.y = -1; - } - if (res.y == this.bottom) { - edgeNormal.y = 1; - } - } - return { res: res, edgeNormal: edgeNormal }; - }; - Rectangle.prototype.calculateBounds = function ( - parentPosition, - position, - origin, - scale, - rotation, - width, - height - ) { - if (rotation == 0) { - this.x = parentPosition.x + position.x - origin.x * scale.x; - this.y = parentPosition.y + position.y - origin.y * scale.y; - this.width = width * scale.x; - this.height = height * scale.y; - } else { - var worldPosX = parentPosition.x + position.x; - var worldPosY = parentPosition.y + position.y; - this._transformMat = Matrix2D.createTranslation( - -worldPosX - origin.x, - -worldPosY - origin.y - ); - this._tempMat = Matrix2D.createScale(scale.x, scale.y); - this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); - this._tempMat = Matrix2D.createRotation(rotation); - this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); - this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY); - this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); - var topLeft = new Vector2(worldPosX, worldPosY); - var topRight = new Vector2(worldPosX + width, worldPosY); - var bottomLeft = new Vector2(worldPosX, worldPosY + height); - var bottomRight = new Vector2(worldPosX + width, worldPosY + height); - topLeft = Vector2Ext.transformR(topLeft, this._transformMat); - topRight = Vector2Ext.transformR(topRight, this._transformMat); - bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat); - bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat); - var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); - var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); - var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); - var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); - this.location = new Vector2(minX, minY); - this.width = maxX - minX; - this.height = maxY - minY; - } - }; - Rectangle.rectEncompassingPoints = function (points) { - var minX = Number.POSITIVE_INFINITY; - var minY = Number.POSITIVE_INFINITY; - var maxX = Number.NEGATIVE_INFINITY; - var maxY = Number.NEGATIVE_INFINITY; - for (var i = 0; i < points.length; i++) { - var pt = points[i]; - if (pt.x < minX) { - minX = pt.x; - } - if (pt.x > maxX) { - maxX = pt.x; - } - if (pt.y < minY) { - minY = pt.y; - } - if (pt.y > maxY) { - maxY = pt.y; - } - } - return this.fromMinMax(minX, minY, maxX, maxY); - }; - return Rectangle; -})(); + function Rectangle(x, y, width, height) { + this.x = x ? x : 0; + this.y = y ? y : 0; + this.width = width ? width : 0; + this.height = height ? height : 0; + } + Object.defineProperty(Rectangle.prototype, "left", { + get: function () { + return this.x; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "right", { + get: function () { + return this.x + this.width; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "top", { + get: function () { + return this.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "bottom", { + get: function () { + return this.y + this.height; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "center", { + get: function () { + return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "location", { + get: function () { + return new Vector2(this.x, this.y); + }, + set: function (value) { + this.x = value.x; + this.y = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "size", { + get: function () { + return new Vector2(this.width, this.height); + }, + set: function (value) { + this.width = value.x; + this.height = value.y; + }, + enumerable: true, + configurable: true + }); + Rectangle.prototype.intersects = function (value) { + return value.left < this.right && + this.left < value.right && + value.top < this.bottom && + this.top < value.bottom; + }; + Rectangle.prototype.contains = function (value) { + return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && + (this.y <= value.y)) && + (value.y < (this.y + this.height))); + }; + Rectangle.prototype.containsRect = function (value) { + return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && + (this.y <= value.y)) && + (value.y < (this.y + this.height))); + }; + Rectangle.prototype.getHalfSize = function () { + return new Vector2(this.width * 0.5, this.height * 0.5); + }; + Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { + return new Rectangle(minX, minY, maxX - minX, maxY - minY); + }; + Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { + var edgeNormal = new Vector2(0, 0); + var res = new Vector2(0, 0); + res.x = MathHelper.clamp(point.x, this.left, this.right); + res.y = MathHelper.clamp(point.y, this.top, this.bottom); + if (this.contains(res)) { + var dl = res.x - this.left; + var dr = this.right - res.x; + var dt = res.y - this.top; + var db = this.bottom - res.y; + var min = Math.min(dl, dr, dt, db); + if (min == dt) { + res.y = this.top; + edgeNormal.y = -1; + } + else if (min == db) { + res.y = this.bottom; + edgeNormal.y = 1; + } + else if (min == dl) { + res.x = this.left; + edgeNormal.x = -1; + } + else { + res.x = this.right; + edgeNormal.x = 1; + } + } + else { + if (res.x == this.left) { + edgeNormal.x = -1; + } + if (res.x == this.right) { + edgeNormal.x = 1; + } + if (res.y == this.top) { + edgeNormal.y = -1; + } + if (res.y == this.bottom) { + edgeNormal.y = 1; + } + } + return { res: res, edgeNormal: edgeNormal }; + }; + Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) { + if (rotation == 0) { + this.x = parentPosition.x + position.x - origin.x * scale.x; + this.y = parentPosition.y + position.y - origin.y * scale.y; + this.width = width * scale.x; + this.height = height * scale.y; + } + else { + var worldPosX = parentPosition.x + position.x; + var worldPosY = parentPosition.y + position.y; + this._transformMat = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y); + this._tempMat = Matrix2D.createScale(scale.x, scale.y); + this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); + this._tempMat = Matrix2D.createRotation(rotation); + this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); + this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY); + this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); + var topLeft = new Vector2(worldPosX, worldPosY); + var topRight = new Vector2(worldPosX + width, worldPosY); + var bottomLeft = new Vector2(worldPosX, worldPosY + height); + var bottomRight = new Vector2(worldPosX + width, worldPosY + height); + topLeft = Vector2Ext.transformR(topLeft, this._transformMat); + topRight = Vector2Ext.transformR(topRight, this._transformMat); + bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat); + bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat); + var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + this.location = new Vector2(minX, minY); + this.width = maxX - minX; + this.height = maxY - minY; + } + }; + Rectangle.rectEncompassingPoints = function (points) { + var minX = Number.POSITIVE_INFINITY; + var minY = Number.POSITIVE_INFINITY; + var maxX = Number.NEGATIVE_INFINITY; + var maxY = Number.NEGATIVE_INFINITY; + for (var i = 0; i < points.length; i++) { + var pt = points[i]; + if (pt.x < minX) { + minX = pt.x; + } + if (pt.x > maxX) { + maxX = pt.x; + } + if (pt.y < minY) { + minY = pt.y; + } + if (pt.y > maxY) { + maxY = pt.y; + } + } + return this.fromMinMax(minX, minY, maxX, maxY); + }; + return Rectangle; +}()); var Vector2 = (function () { - function Vector2(x, y) { - this.x = 0; - this.y = 0; - this.x = x ? x : 0; - this.y = y ? y : this.x; - } - Object.defineProperty(Vector2, "zero", { - get: function () { - return Vector2.zeroVector2; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Vector2, "one", { - get: function () { - return Vector2.unitVector2; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Vector2, "unitX", { - get: function () { - return Vector2.unitXVector; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Vector2, "unitY", { - get: function () { - return Vector2.unitYVector; - }, - enumerable: true, - configurable: true, - }); - Vector2.add = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x + value2.x; - result.y = value1.y + value2.y; - return result; - }; - Vector2.divide = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x / value2.x; - result.y = value1.y / value2.y; - return result; - }; - Vector2.multiply = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - }; - Vector2.subtract = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - }; - Vector2.prototype.normalize = function () { - var val = 1 / Math.sqrt(this.x * this.x + this.y * this.y); - this.x *= val; - this.y *= val; - }; - Vector2.prototype.length = function () { - return Math.sqrt(this.x * this.x + this.y * this.y); - }; - Vector2.prototype.round = function () { - return new Vector2(Math.round(this.x), Math.round(this.y)); - }; - Vector2.normalize = function (value) { - var val = 1 / Math.sqrt(value.x * value.x + value.y * value.y); - value.x *= val; - value.y *= val; - return value; - }; - Vector2.dot = function (value1, value2) { - return value1.x * value2.x + value1.y * value2.y; - }; - Vector2.distanceSquared = function (value1, value2) { - var v1 = value1.x - value2.x, - v2 = value1.y - value2.y; - return v1 * v1 + v2 * v2; - }; - Vector2.clamp = function (value1, min, max) { - return new Vector2( - MathHelper.clamp(value1.x, min.x, max.x), - MathHelper.clamp(value1.y, min.y, max.y) - ); - }; - Vector2.lerp = function (value1, value2, amount) { - return new Vector2( - MathHelper.lerp(value1.x, value2.x, amount), - MathHelper.lerp(value1.y, value2.y, amount) - ); - }; - Vector2.transform = function (position, matrix) { - return new Vector2( - position.x * matrix.m11 + position.y * matrix.m21, - position.x * matrix.m12 + position.y * matrix.m22 - ); - }; - Vector2.distance = function (value1, value2) { - var v1 = value1.x - value2.x, - v2 = value1.y - value2.y; - return Math.sqrt(v1 * v1 + v2 * v2); - }; - Vector2.negate = function (value) { - var result = new Vector2(); - result.x = -value.x; - result.y = -value.y; - return result; - }; - Vector2.unitYVector = new Vector2(0, 1); - Vector2.unitXVector = new Vector2(1, 0); - Vector2.unitVector2 = new Vector2(1, 1); - Vector2.zeroVector2 = new Vector2(0, 0); - return Vector2; -})(); + function Vector2(x, y) { + this.x = 0; + this.y = 0; + this.x = x ? x : 0; + this.y = y ? y : this.x; + } + Object.defineProperty(Vector2, "zero", { + get: function () { + return Vector2.zeroVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "one", { + get: function () { + return Vector2.unitVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitX", { + get: function () { + return Vector2.unitXVector; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitY", { + get: function () { + return Vector2.unitYVector; + }, + enumerable: true, + configurable: true + }); + Vector2.add = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x + value2.x; + result.y = value1.y + value2.y; + return result; + }; + Vector2.divide = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x / value2.x; + result.y = value1.y / value2.y; + return result; + }; + Vector2.multiply = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x * value2.x; + result.y = value1.y * value2.y; + return result; + }; + Vector2.subtract = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x - value2.x; + result.y = value1.y - value2.y; + return result; + }; + Vector2.prototype.normalize = function () { + var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); + this.x *= val; + this.y *= val; + }; + Vector2.prototype.length = function () { + return Math.sqrt((this.x * this.x) + (this.y * this.y)); + }; + Vector2.prototype.round = function () { + return new Vector2(Math.round(this.x), Math.round(this.y)); + }; + Vector2.normalize = function (value) { + var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); + value.x *= val; + value.y *= val; + return value; + }; + Vector2.dot = function (value1, value2) { + return (value1.x * value2.x) + (value1.y * value2.y); + }; + Vector2.distanceSquared = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return (v1 * v1) + (v2 * v2); + }; + Vector2.clamp = function (value1, min, max) { + return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y)); + }; + Vector2.lerp = function (value1, value2, amount) { + return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount)); + }; + Vector2.transform = function (position, matrix) { + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + }; + Vector2.distance = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return Math.sqrt((v1 * v1) + (v2 * v2)); + }; + Vector2.negate = function (value) { + var result = new Vector2(); + result.x = -value.x; + result.y = -value.y; + return result; + }; + Vector2.unitYVector = new Vector2(0, 1); + Vector2.unitXVector = new Vector2(1, 0); + Vector2.unitVector2 = new Vector2(1, 1); + Vector2.zeroVector2 = new Vector2(0, 0); + return Vector2; +}()); var Vector3 = (function () { - function Vector3(x, y, z) { - this.x = x; - this.y = y; - this.z = z; - } - return Vector3; -})(); -var ColliderTriggerHelper = (function () { - function ColliderTriggerHelper(entity) { - this._activeTriggerIntersections = []; - this._previousTriggerIntersections = []; - this._tempTriggerList = []; - this._entity = entity; - } - ColliderTriggerHelper.prototype.update = function () { - var colliders = this._entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - var neighbors = Physics.boxcastBroadphase( - collider.bounds, - collider.collidesWithLayers - ); - var _loop_5 = function (j) { - var neighbor = neighbors[j]; - if (!collider.isTrigger && !neighbor.isTrigger) return "continue"; - if (collider.overlaps(neighbor)) { - var pair_1 = new Pair(collider, neighbor); - var shouldReportTriggerEvent = - this_1._activeTriggerIntersections.findIndex(function (value) { - return ( - value.first == pair_1.first && value.second == pair_1.second - ); - }) == -1 && - this_1._previousTriggerIntersections.findIndex(function (value) { - return ( - value.first == pair_1.first && value.second == pair_1.second - ); - }) == -1; - if (shouldReportTriggerEvent) - this_1.notifyTriggerListeners(pair_1, true); - if (!this_1._activeTriggerIntersections.contains(pair_1)) - this_1._activeTriggerIntersections.push(pair_1); - } - }; - var this_1 = this; - for (var j = 0; j < neighbors.length; j++) { - _loop_5(j); - } + function Vector3(x, y, z) { + this.x = x; + this.y = y; + this.z = z; } - ListPool.free(colliders); - this.checkForExitedColliders(); - }; - ColliderTriggerHelper.prototype.checkForExitedColliders = function () { - var _this = this; - var _loop_6 = function (i) { - var index = this_2._previousTriggerIntersections.findIndex(function ( - value - ) { - if ( - value.first == _this._activeTriggerIntersections[i].first && - value.second == _this._activeTriggerIntersections[i].second - ) - return true; - return false; - }); - if (index != -1) this_2._previousTriggerIntersections.removeAt(index); + return Vector3; +}()); +var ColliderTriggerHelper = (function () { + function ColliderTriggerHelper(entity) { + this._activeTriggerIntersections = []; + this._previousTriggerIntersections = []; + this._tempTriggerList = []; + this._entity = entity; + } + ColliderTriggerHelper.prototype.update = function () { + var colliders = this._entity.getComponents(Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + var neighbors = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); + var _loop_5 = function (j) { + var neighbor = neighbors[j]; + if (!collider.isTrigger && !neighbor.isTrigger) + return "continue"; + if (collider.overlaps(neighbor)) { + var pair_1 = new Pair(collider, neighbor); + var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1; + if (shouldReportTriggerEvent) + this_1.notifyTriggerListeners(pair_1, true); + if (!this_1._activeTriggerIntersections.contains(pair_1)) + this_1._activeTriggerIntersections.push(pair_1); + } + }; + var this_1 = this; + for (var j = 0; j < neighbors.length; j++) { + _loop_5(j); + } + } + ListPool.free(colliders); + this.checkForExitedColliders(); }; - var this_2 = this; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - _loop_6(i); - } - for (var i = 0; i < this._previousTriggerIntersections.length; i++) { - this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); - } - this._previousTriggerIntersections.length = 0; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - if ( - !this._previousTriggerIntersections.contains( - this._activeTriggerIntersections[i] - ) - ) { - this._previousTriggerIntersections.push( - this._activeTriggerIntersections[i] - ); - } - } - this._activeTriggerIntersections.length = 0; - }; - ColliderTriggerHelper.prototype.notifyTriggerListeners = function ( - collisionPair, - isEntering - ) { - collisionPair.first.entity.getComponents( - "ITriggerListener", - this._tempTriggerList - ); - for (var i = 0; i < this._tempTriggerList.length; i++) { - if (isEntering) { - this._tempTriggerList[i].onTriggerEnter( - collisionPair.second, - collisionPair.first - ); - } else { - this._tempTriggerList[i].onTriggerExit( - collisionPair.second, - collisionPair.first - ); - } - this._tempTriggerList.length = 0; - if (collisionPair.second.entity) { - collisionPair.second.entity.getComponents( - "ITriggerListener", - this._tempTriggerList - ); - for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { - if (isEntering) { - this._tempTriggerList[i_2].onTriggerEnter( - collisionPair.first, - collisionPair.second - ); - } else { - this._tempTriggerList[i_2].onTriggerExit( - collisionPair.first, - collisionPair.second - ); - } - } - this._tempTriggerList.length = 0; - } - } - }; - return ColliderTriggerHelper; -})(); + ColliderTriggerHelper.prototype.checkForExitedColliders = function () { + var _this = this; + var _loop_6 = function (i) { + var index = this_2._previousTriggerIntersections.findIndex(function (value) { + if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second) + return true; + return false; + }); + if (index != -1) + this_2._previousTriggerIntersections.removeAt(index); + }; + var this_2 = this; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + _loop_6(i); + } + for (var i = 0; i < this._previousTriggerIntersections.length; i++) { + this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); + } + this._previousTriggerIntersections.length = 0; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) { + this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); + } + } + this._activeTriggerIntersections.length = 0; + }; + ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) { + collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + if (isEntering) { + this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); + } + else { + this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); + } + this._tempTriggerList.length = 0; + if (collisionPair.second.entity) { + collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { + if (isEntering) { + this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second); + } + else { + this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second); + } + } + this._tempTriggerList.length = 0; + } + } + }; + return ColliderTriggerHelper; +}()); var PointSectors; (function (PointSectors) { - PointSectors[(PointSectors["center"] = 0)] = "center"; - PointSectors[(PointSectors["top"] = 1)] = "top"; - PointSectors[(PointSectors["bottom"] = 2)] = "bottom"; - PointSectors[(PointSectors["topLeft"] = 9)] = "topLeft"; - PointSectors[(PointSectors["topRight"] = 5)] = "topRight"; - PointSectors[(PointSectors["left"] = 8)] = "left"; - PointSectors[(PointSectors["right"] = 4)] = "right"; - PointSectors[(PointSectors["bottomLeft"] = 10)] = "bottomLeft"; - PointSectors[(PointSectors["bottomRight"] = 6)] = "bottomRight"; + PointSectors[PointSectors["center"] = 0] = "center"; + PointSectors[PointSectors["top"] = 1] = "top"; + PointSectors[PointSectors["bottom"] = 2] = "bottom"; + PointSectors[PointSectors["topLeft"] = 9] = "topLeft"; + PointSectors[PointSectors["topRight"] = 5] = "topRight"; + PointSectors[PointSectors["left"] = 8] = "left"; + PointSectors[PointSectors["right"] = 4] = "right"; + PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft"; + PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight"; })(PointSectors || (PointSectors = {})); var Collisions = (function () { - function Collisions() {} - Collisions.isLineToLine = function (a1, a2, b1, b2) { - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) return false; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) return false; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) return false; - return true; - }; - Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { - var intersection = new Vector2(0, 0); - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) return intersection; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) return intersection; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) return intersection; - intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); - return intersection; - }; - Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); - }; - Collisions.isCircleToCircle = function ( - circleCenter1, - circleRadius1, - circleCenter2, - circleRadius2 - ) { - return ( - Vector2.distanceSquared(circleCenter1, circleCenter2) < - (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2) - ); - }; - Collisions.isCircleToLine = function ( - circleCenter, - radius, - lineFrom, - lineTo - ) { - return ( - Vector2.distanceSquared( - circleCenter, - this.closestPointOnLine(lineFrom, lineTo, circleCenter) - ) < - radius * radius - ); - }; - Collisions.isCircleToPoint = function (circleCenter, radius, point) { - return Vector2.distanceSquared(circleCenter, point) < radius * radius; - }; - Collisions.isRectToCircle = function (rect, cPosition, cRadius) { - var ew = rect.width * 0.5; - var eh = rect.height * 0.5; - var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); - var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); - return vx * vx + vy * vy < cRadius * cRadius; - }; - Collisions.isRectToLine = function (rect, lineFrom, lineTo) { - var fromSector = this.getSector( - rect.x, - rect.y, - rect.width, - rect.height, - lineFrom - ); - var toSector = this.getSector( - rect.x, - rect.y, - rect.width, - rect.height, - lineTo - ); - if (fromSector == PointSectors.center || toSector == PointSectors.center) { - return true; - } else if ((fromSector & toSector) != 0) { - return false; - } else { - var both = fromSector | toSector; - var edgeFrom = void 0; - var edgeTo = void 0; - if ((both & PointSectors.top) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - if ((both & PointSectors.bottom) != 0) { - edgeFrom = new Vector2(rect.x, rect.y + rect.height); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - if ((both & PointSectors.left) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - if ((both & PointSectors.right) != 0) { - edgeFrom = new Vector2(rect.x + rect.width, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - } - return false; - }; - Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { - return ( - point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH - ); - }; - Collisions.getSector = function (rX, rY, rW, rH, point) { - var sector = PointSectors.center; - if (point.x < rX) sector |= PointSectors.left; - else if (point.x >= rX + rW) sector |= PointSectors.right; - if (point.y < rY) sector |= PointSectors.top; - else if (point.y >= rY + rH) sector |= PointSectors.bottom; - return sector; - }; - return Collisions; -})(); -var Physics = (function () { - function Physics() {} - Physics.reset = function () { - this._spatialHash = new SpatialHash(this.spatialHashCellSize); - }; - Physics.clear = function () { - this._spatialHash.clear(); - }; - Physics.overlapCircleAll = function (center, randius, results, layerMask) { - if (layerMask === void 0) { - layerMask = -1; - } - return this._spatialHash.overlapCircle(center, randius, results, layerMask); - }; - Physics.boxcastBroadphase = function (rect, layerMask) { - if (layerMask === void 0) { - layerMask = this.allLayers; - } - return this._spatialHash.aabbBroadphase(rect, null, layerMask); - }; - Physics.boxcastBroadphaseExcludingSelf = function ( - collider, - rect, - layerMask - ) { - if (layerMask === void 0) { - layerMask = this.allLayers; - } - return this._spatialHash.aabbBroadphase(rect, collider, layerMask); - }; - Physics.addCollider = function (collider) { - Physics._spatialHash.register(collider); - }; - Physics.removeCollider = function (collider) { - Physics._spatialHash.remove(collider); - }; - Physics.updateCollider = function (collider) { - this._spatialHash.remove(collider); - this._spatialHash.register(collider); - }; - Physics.spatialHashCellSize = 100; - Physics.allLayers = -1; - return Physics; -})(); -var Shape = (function () { - function Shape() {} - return Shape; -})(); -var Polygon = (function (_super) { - __extends(Polygon, _super); - function Polygon(points, isBox) { - var _this = _super.call(this) || this; - _this.isUnrotated = true; - _this._areEdgeNormalsDirty = true; - _this.setPoints(points); - _this.isBox = isBox; - return _this; - } - Object.defineProperty(Polygon.prototype, "edgeNormals", { - get: function () { - if (this._areEdgeNormalsDirty) this.buildEdgeNormals(); - return this._edgeNormals; - }, - enumerable: true, - configurable: true, - }); - Polygon.prototype.buildEdgeNormals = function () { - var totalEdges = this.isBox ? 2 : this.points.length; - if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) - this._edgeNormals = new Array(totalEdges); - var p2; - for (var i = 0; i < totalEdges; i++) { - var p1 = this.points[i]; - if (i + 1 >= this.points.length) p2 = this.points[0]; - else p2 = this.points[i + 1]; - var perp = Vector2Ext.perpendicular(p1, p2); - perp = Vector2.normalize(perp); - this._edgeNormals[i] = perp; - } - }; - Polygon.prototype.setPoints = function (points) { - this.points = points; - this.recalculateCenterAndEdgeNormals(); - this._originalPoints = []; - for (var i = 0; i < this.points.length; i++) { - this._originalPoints.push(this.points[i]); - } - }; - Polygon.prototype.collidesWithShape = function (other) { - var result = new CollisionResult(); - if (other instanceof Polygon) { - return ShapeCollisions.polygonToPolygon(this, other); - } - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); - return result; - } - return null; - } - throw new Error("overlaps of Polygon to " + other + " are not supported"); - }; - Polygon.prototype.recalculateCenterAndEdgeNormals = function () { - this._polygonCenter = Polygon.findPolygonCenter(this.points); - this._areEdgeNormalsDirty = true; - }; - Polygon.prototype.overlaps = function (other) { - var result; - if (other instanceof Polygon) - return ShapeCollisions.polygonToPolygon(this, other); - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); + function Collisions() { + } + Collisions.isLineToLine = function (a1, a2, b1, b2) { + var b = Vector2.subtract(a2, a1); + var d = Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return false; + var c = Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return false; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return false; return true; - } - return false; - } - throw new Error("overlaps of Pologon to " + other + " are not supported"); - }; - Polygon.findPolygonCenter = function (points) { - var x = 0, - y = 0; - for (var i = 0; i < points.length; i++) { - x += points[i].x; - y += points[i].y; - } - return new Vector2(x / points.length, y / points.length); - }; - Polygon.getClosestPointOnPolygonToPoint = function (points, point) { - var distanceSquared = Number.MAX_VALUE; - var edgeNormal = new Vector2(0, 0); - var closestPoint = new Vector2(0, 0); - var tempDistanceSquared; - for (var i = 0; i < points.length; i++) { - var j = i + 1; - if (j == points.length) j = 0; - var closest = ShapeCollisions.closestPointOnLine( - points[i], - points[j], - point - ); - tempDistanceSquared = Vector2.distanceSquared(point, closest); - if (tempDistanceSquared < distanceSquared) { - distanceSquared = tempDistanceSquared; - closestPoint = closest; - var line = Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; - } - } - edgeNormal = Vector2.normalize(edgeNormal); - return { - closestPoint: closestPoint, - distanceSquared: distanceSquared, - edgeNormal: edgeNormal, - }; - }; - Polygon.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToPoly(point, this); - }; - Polygon.prototype.containsPoint = function (point) { - point = Vector2.subtract(point, this.position); - var isInside = false; - for ( - var i = 0, j = this.points.length - 1; - i < this.points.length; - j = i++ - ) { - if ( - this.points[i].y > point.y != this.points[j].y > point.y && - point.x < - ((this.points[j].x - this.points[i].x) * - (point.y - this.points[i].y)) / - (this.points[j].y - this.points[i].y) + - this.points[i].x - ) { - isInside = !isInside; - } - } - return isInside; - }; - Polygon.buildSymmertricalPolygon = function (vertCount, radius) { - var verts = new Array(vertCount); - for (var i = 0; i < vertCount; i++) { - var a = 2 * Math.PI * (i / vertCount); - verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); + }; + Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { + var intersection = new Vector2(0, 0); + var b = Vector2.subtract(a2, a1); + var d = Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return intersection; + var c = Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return intersection; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return intersection; + intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); + return intersection; + }; + Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = Vector2.subtract(lineB, lineA); + var w = Vector2.subtract(closestTo, lineA); + var t = Vector2.dot(w, v) / Vector2.dot(v, v); + t = MathHelper.clamp(t, 0, 1); + return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); + }; + Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) { + return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); + }; + Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) { + return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; + }; + Collisions.isCircleToPoint = function (circleCenter, radius, point) { + return Vector2.distanceSquared(circleCenter, point) < radius * radius; + }; + Collisions.isRectToCircle = function (rect, cPosition, cRadius) { + var ew = rect.width * 0.5; + var eh = rect.height * 0.5; + var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); + var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); + return vx * vx + vy * vy < cRadius * cRadius; + }; + Collisions.isRectToLine = function (rect, lineFrom, lineTo) { + var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); + var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); + if (fromSector == PointSectors.center || toSector == PointSectors.center) { + return true; + } + else if ((fromSector & toSector) != 0) { + return false; + } + else { + var both = fromSector | toSector; + var edgeFrom = void 0; + var edgeTo = void 0; + if ((both & PointSectors.top) != 0) { + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x + rect.width, rect.y); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.bottom) != 0) { + edgeFrom = new Vector2(rect.x, rect.y + rect.height); + edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.left) != 0) { + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.right) != 0) { + edgeFrom = new Vector2(rect.x + rect.width, rect.y); + edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + } + return false; + }; + Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { + return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; + }; + Collisions.getSector = function (rX, rY, rW, rH, point) { + var sector = PointSectors.center; + if (point.x < rX) + sector |= PointSectors.left; + else if (point.x >= rX + rW) + sector |= PointSectors.right; + if (point.y < rY) + sector |= PointSectors.top; + else if (point.y >= rY + rH) + sector |= PointSectors.bottom; + return sector; + }; + return Collisions; +}()); +var Physics = (function () { + function Physics() { } - return verts; - }; - Polygon.prototype.recalculateBounds = function (collider) { - this.center = collider.localOffset; - if (collider.shouldColliderScaleAndRotationWithTransform) { - var hasUnitScale = true; - var tempMat = void 0; - var combinedMatrix = Matrix2D.createTranslation( - -this._polygonCenter.x, - -this._polygonCenter.y - ); - if (collider.entity.scale != Vector2.one) { - tempMat = Matrix2D.createScale( - collider.entity.scale.x, - collider.entity.scale.y - ); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - hasUnitScale = false; - var scaledOffset = Vector2.multiply( - collider.localOffset, - collider.entity.scale - ); - this.center = scaledOffset; - } - if (collider.entity.rotation != 0) { - tempMat = Matrix2D.createRotation(collider.entity.rotation); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - var offsetAngle = - Math.atan2(collider.localOffset.y, collider.localOffset.x) * - MathHelper.Rad2Deg; - var offsetLength = hasUnitScale - ? collider._localOffsetLength - : Vector2.multiply( - collider.localOffset, - collider.entity.scale - ).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - offsetLength, - MathHelper.toDegrees(collider.entity.rotation) + offsetAngle - ); - } - tempMat = Matrix2D.createTranslation( - this._polygonCenter.x, - this._polygonCenter.y - ); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.rotation == 0; - if (collider._isRotationDirty) this._areEdgeNormalsDirty = true; + Physics.reset = function () { + this._spatialHash = new SpatialHash(this.spatialHashCellSize); + }; + Physics.clear = function () { + this._spatialHash.clear(); + }; + Physics.overlapCircleAll = function (center, randius, results, layerMask) { + if (layerMask === void 0) { layerMask = -1; } + return this._spatialHash.overlapCircle(center, randius, results, layerMask); + }; + Physics.boxcastBroadphase = function (rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + return this._spatialHash.aabbBroadphase(rect, null, layerMask); + }; + Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + return this._spatialHash.aabbBroadphase(rect, collider, layerMask); + }; + Physics.addCollider = function (collider) { + Physics._spatialHash.register(collider); + }; + Physics.removeCollider = function (collider) { + Physics._spatialHash.remove(collider); + }; + Physics.updateCollider = function (collider) { + this._spatialHash.remove(collider); + this._spatialHash.register(collider); + }; + Physics.spatialHashCellSize = 100; + Physics.allLayers = -1; + return Physics; +}()); +var Shape = (function () { + function Shape() { } - this.position = Vector2.add(collider.entity.position, this.center); - this.bounds = Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = Vector2.add(this.bounds.location, this.position); - }; - return Polygon; -})(Shape); + return Shape; +}()); +var Polygon = (function (_super) { + __extends(Polygon, _super); + function Polygon(points, isBox) { + var _this = _super.call(this) || this; + _this.isUnrotated = true; + _this._areEdgeNormalsDirty = true; + _this.setPoints(points); + _this.isBox = isBox; + return _this; + } + Object.defineProperty(Polygon.prototype, "edgeNormals", { + get: function () { + if (this._areEdgeNormalsDirty) + this.buildEdgeNormals(); + return this._edgeNormals; + }, + enumerable: true, + configurable: true + }); + Polygon.prototype.buildEdgeNormals = function () { + var totalEdges = this.isBox ? 2 : this.points.length; + if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) + this._edgeNormals = new Array(totalEdges); + var p2; + for (var i = 0; i < totalEdges; i++) { + var p1 = this.points[i]; + if (i + 1 >= this.points.length) + p2 = this.points[0]; + else + p2 = this.points[i + 1]; + var perp = Vector2Ext.perpendicular(p1, p2); + perp = Vector2.normalize(perp); + this._edgeNormals[i] = perp; + } + }; + Polygon.prototype.setPoints = function (points) { + this.points = points; + this.recalculateCenterAndEdgeNormals(); + this._originalPoints = []; + for (var i = 0; i < this.points.length; i++) { + this._originalPoints.push(this.points[i]); + } + }; + Polygon.prototype.collidesWithShape = function (other) { + var result = new CollisionResult(); + if (other instanceof Polygon) { + return ShapeCollisions.polygonToPolygon(this, other); + } + if (other instanceof Circle) { + result = ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return result; + } + return null; + } + throw new Error("overlaps of Polygon to " + other + " are not supported"); + }; + Polygon.prototype.recalculateCenterAndEdgeNormals = function () { + this._polygonCenter = Polygon.findPolygonCenter(this.points); + this._areEdgeNormalsDirty = true; + }; + Polygon.prototype.overlaps = function (other) { + var result; + if (other instanceof Polygon) + return ShapeCollisions.polygonToPolygon(this, other); + if (other instanceof Circle) { + result = ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return true; + } + return false; + } + throw new Error("overlaps of Pologon to " + other + " are not supported"); + }; + Polygon.findPolygonCenter = function (points) { + var x = 0, y = 0; + for (var i = 0; i < points.length; i++) { + x += points[i].x; + y += points[i].y; + } + return new Vector2(x / points.length, y / points.length); + }; + Polygon.getClosestPointOnPolygonToPoint = function (points, point) { + var distanceSquared = Number.MAX_VALUE; + var edgeNormal = new Vector2(0, 0); + var closestPoint = new Vector2(0, 0); + var tempDistanceSquared; + for (var i = 0; i < points.length; i++) { + var j = i + 1; + if (j == points.length) + j = 0; + var closest = ShapeCollisions.closestPointOnLine(points[i], points[j], point); + tempDistanceSquared = Vector2.distanceSquared(point, closest); + if (tempDistanceSquared < distanceSquared) { + distanceSquared = tempDistanceSquared; + closestPoint = closest; + var line = Vector2.subtract(points[j], points[i]); + edgeNormal.x = -line.y; + edgeNormal.y = line.x; + } + } + edgeNormal = Vector2.normalize(edgeNormal); + return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + }; + Polygon.prototype.pointCollidesWithShape = function (point) { + return ShapeCollisions.pointToPoly(point, this); + }; + Polygon.prototype.containsPoint = function (point) { + point = Vector2.subtract(point, this.position); + var isInside = false; + for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { + if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && + (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + + this.points[i].x)) { + isInside = !isInside; + } + } + return isInside; + }; + Polygon.buildSymmertricalPolygon = function (vertCount, radius) { + var verts = new Array(vertCount); + for (var i = 0; i < vertCount; i++) { + var a = 2 * Math.PI * (i / vertCount); + verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); + } + return verts; + }; + Polygon.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotationWithTransform) { + var hasUnitScale = true; + var tempMat = void 0; + var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); + if (collider.entity.scale != Vector2.one) { + tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); + combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); + hasUnitScale = false; + var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); + this.center = scaledOffset; + } + if (collider.entity.rotation != 0) { + tempMat = Matrix2D.createRotation(collider.entity.rotation); + combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); + } + tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); + combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); + Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); + this.isUnrotated = collider.entity.rotation == 0; + if (collider._isRotationDirty) + this._areEdgeNormalsDirty = true; + } + this.position = Vector2.add(collider.entity.position, this.center); + this.bounds = Rectangle.rectEncompassingPoints(this.points); + this.bounds.location = Vector2.add(this.bounds.location, this.position); + }; + return Polygon; +}(Shape)); var Box = (function (_super) { - __extends(Box, _super); - function Box(width, height) { - var _this = _super.call(this, Box.buildBox(width, height), true) || this; - _this.width = width; - _this.height = height; - return _this; - } - Box.buildBox = function (width, height) { - var halfWidth = width / 2; - var halfHeight = height / 2; - var verts = new Array(4); - verts[0] = new Vector2(-halfWidth, -halfHeight); - verts[1] = new Vector2(halfWidth, -halfHeight); - verts[2] = new Vector2(halfWidth, halfHeight); - verts[3] = new Vector2(-halfWidth, halfHeight); - return verts; - }; - Box.prototype.updateBox = function (width, height) { - this.width = width; - this.height = height; - var halfWidth = width / 2; - var halfHeight = height / 2; - this.points[0] = new Vector2(-halfWidth, -halfHeight); - this.points[1] = new Vector2(halfWidth, -halfHeight); - this.points[2] = new Vector2(halfWidth, halfHeight); - this.points[3] = new Vector2(-halfWidth, halfHeight); - for (var i = 0; i < this.points.length; i++) - this._originalPoints[i] = this.points[i]; - }; - Box.prototype.containsPoint = function (point) { - if (this.isUnrotated) return this.bounds.contains(point); - return _super.prototype.containsPoint.call(this, point); - }; - return Box; -})(Polygon); + __extends(Box, _super); + function Box(width, height) { + var _this = _super.call(this, Box.buildBox(width, height), true) || this; + _this.width = width; + _this.height = height; + return _this; + } + Box.buildBox = function (width, height) { + var halfWidth = width / 2; + var halfHeight = height / 2; + var verts = new Array(4); + verts[0] = new Vector2(-halfWidth, -halfHeight); + verts[1] = new Vector2(halfWidth, -halfHeight); + verts[2] = new Vector2(halfWidth, halfHeight); + verts[3] = new Vector2(-halfWidth, halfHeight); + return verts; + }; + Box.prototype.updateBox = function (width, height) { + this.width = width; + this.height = height; + var halfWidth = width / 2; + var halfHeight = height / 2; + this.points[0] = new Vector2(-halfWidth, -halfHeight); + this.points[1] = new Vector2(halfWidth, -halfHeight); + this.points[2] = new Vector2(halfWidth, halfHeight); + this.points[3] = new Vector2(-halfWidth, halfHeight); + for (var i = 0; i < this.points.length; i++) + this._originalPoints[i] = this.points[i]; + }; + Box.prototype.containsPoint = function (point) { + if (this.isUnrotated) + return this.bounds.contains(point); + return _super.prototype.containsPoint.call(this, point); + }; + return Box; +}(Polygon)); var Circle = (function (_super) { - __extends(Circle, _super); - function Circle(radius) { - var _this = _super.call(this) || this; - _this.radius = radius; - _this._originalRadius = radius; - return _this; - } - Circle.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToCircle(point, this); - }; - Circle.prototype.collidesWithShape = function (other) { - if (other instanceof Box && other.isUnrotated) { - return ShapeCollisions.circleToBox(this, other); - } - if (other instanceof Circle) { - return ShapeCollisions.circleToCircle(this, other); - } - if (other instanceof Polygon) { - return ShapeCollisions.circleToPolygon(this, other); - } - throw new Error("Collisions of Circle to " + other + " are not supported"); - }; - Circle.prototype.recalculateBounds = function (collider) { - this.center = collider.localOffset; - if (collider.shouldColliderScaleAndRotationWithTransform) { - var scale = collider.entity.scale; - var hasUnitScale = scale.x == 1 && scale.y == 1; - var maxScale = Math.max(scale.x, scale.y); - this.radius = this._originalRadius * maxScale; - if (collider.entity.rotation != 0) { - var offsetAngle = - Math.atan2(collider.localOffset.y, collider.localOffset.x) * - MathHelper.Rad2Deg; - var offsetLength = hasUnitScale - ? collider._localOffsetLength - : Vector2.multiply( - collider.localOffset, - collider.entity.scale - ).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - offsetLength, - MathHelper.toDegrees(collider.entity.rotation) + offsetAngle - ); - } - } - this.position = Vector2.add(collider.entity.position, this.center); - this.bounds = new Rectangle( - this.position.x - this.radius, - this.position.y - this.radius, - this.radius * 2, - this.radius * 2 - ); - }; - Circle.prototype.overlaps = function (other) { - if (other instanceof Box && other.isUnrotated) - return Collisions.isRectToCircle( - other.bounds, - this.position, - this.radius - ); - if (other instanceof Circle) - return Collisions.isCircleToCircle( - this.position, - this.radius, - other.position, - other.radius - ); - if (other instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, other); - throw new Error("overlaps of circle to " + other + " are not supported"); - }; - return Circle; -})(Shape); + __extends(Circle, _super); + function Circle(radius) { + var _this = _super.call(this) || this; + _this.radius = radius; + _this._originalRadius = radius; + return _this; + } + Circle.prototype.pointCollidesWithShape = function (point) { + return ShapeCollisions.pointToCircle(point, this); + }; + Circle.prototype.collidesWithShape = function (other) { + if (other instanceof Box && other.isUnrotated) { + return ShapeCollisions.circleToBox(this, other); + } + if (other instanceof Circle) { + return ShapeCollisions.circleToCircle(this, other); + } + if (other instanceof Polygon) { + return ShapeCollisions.circleToPolygon(this, other); + } + throw new Error("Collisions of Circle to " + other + " are not supported"); + }; + Circle.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotationWithTransform) { + var scale = collider.entity.scale; + var hasUnitScale = scale.x == 1 && scale.y == 1; + var maxScale = Math.max(scale.x, scale.y); + this.radius = this._originalRadius * maxScale; + if (collider.entity.rotation != 0) { + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); + } + } + this.position = Vector2.add(collider.entity.position, this.center); + this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); + }; + Circle.prototype.overlaps = function (other) { + if (other instanceof Box && other.isUnrotated) + return Collisions.isRectToCircle(other.bounds, this.position, this.radius); + if (other instanceof Circle) + return Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); + if (other instanceof Polygon) + return ShapeCollisions.circleToPolygon(this, other); + throw new Error("overlaps of circle to " + other + " are not supported"); + }; + return Circle; +}(Shape)); var CollisionResult = (function () { - function CollisionResult() {} - CollisionResult.prototype.invertResult = function () { - this.minimumTranslationVector = Vector2.negate( - this.minimumTranslationVector - ); - this.normal = Vector2.negate(this.normal); - }; - return CollisionResult; -})(); -var ShapeCollisions = (function () { - function ShapeCollisions() {} - ShapeCollisions.polygonToPolygon = function (first, second) { - var result = new CollisionResult(); - var isIntersecting = true; - var firstEdges = first.edgeNormals; - var secondEdges = second.edgeNormals; - var minIntervalDistance = Number.POSITIVE_INFINITY; - var translationAxis = new Vector2(); - var polygonOffset = Vector2.subtract(first.position, second.position); - var axis; - for ( - var edgeIndex = 0; - edgeIndex < firstEdges.length + secondEdges.length; - edgeIndex++ - ) { - if (edgeIndex < firstEdges.length) { - axis = firstEdges[edgeIndex]; - } else { - axis = secondEdges[edgeIndex - firstEdges.length]; - } - var minA = 0; - var minB = 0; - var maxA = 0; - var maxB = 0; - var intervalDist = 0; - var ta = this.getInterval(axis, first, minA, maxA); - minA = ta.min; - minB = ta.max; - var tb = this.getInterval(axis, second, minB, maxB); - minB = tb.min; - maxB = tb.max; - var relativeIntervalOffset = Vector2.dot(polygonOffset, axis); - minA += relativeIntervalOffset; - maxA += relativeIntervalOffset; - intervalDist = this.intervalDistance(minA, maxA, minB, maxB); - if (intervalDist > 0) isIntersecting = false; - if (!isIntersecting) return null; - intervalDist = Math.abs(intervalDist); - if (intervalDist < minIntervalDistance) { - minIntervalDistance = intervalDist; - translationAxis = axis; - if (Vector2.dot(translationAxis, polygonOffset) < 0) - translationAxis = new Vector2(-translationAxis); - } - } - result.normal = translationAxis; - result.minimumTranslationVector = Vector2.multiply( - new Vector2(-translationAxis), - new Vector2(minIntervalDistance) - ); - return result; - }; - ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { - if (minA < minB) return minB - maxA; - return minA - minB; - }; - ShapeCollisions.getInterval = function (axis, polygon, min, max) { - var dot = Vector2.dot(polygon.points[0], axis); - min = max = dot; - for (var i = 1; i < polygon.points.length; i++) { - dot = Vector2.dot(polygon.points[i], axis); - if (dot < min) { - min = dot; - } else if (dot > max) { - max = dot; - } - } - return { min: min, max: max }; - }; - ShapeCollisions.circleToPolygon = function (circle, polygon) { - var result = new CollisionResult(); - var poly2Circle = Vector2.subtract(circle.position, polygon.position); - var gpp = Polygon.getClosestPointOnPolygonToPoint( - polygon.points, - poly2Circle - ); - var closestPoint = gpp.closestPoint; - var distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - var circleCenterInsidePoly = polygon.containsPoint(circle.position); - if ( - distanceSquared > circle.radius * circle.radius && - !circleCenterInsidePoly - ) - return null; - var mtv; - if (circleCenterInsidePoly) { - mtv = Vector2.multiply( - result.normal, - new Vector2(Math.sqrt(distanceSquared) - circle.radius) - ); - } else { - if (distanceSquared == 0) { - mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); - } else { - var distance = Math.sqrt(distanceSquared); - mtv = Vector2.multiply( - new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), - new Vector2((circle.radius - distanceSquared) / distance) - ); - } - } - result.minimumTranslationVector = mtv; - result.point = Vector2.add(closestPoint, polygon.position); - return result; - }; - ShapeCollisions.circleToBox = function (circle, box) { - var result = new CollisionResult(); - var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint( - circle.position - ).res; - if (box.containsPoint(circle.position)) { - result.point = closestPointOnBounds; - var safePlace = Vector2.add( - closestPointOnBounds, - Vector2.subtract(result.normal, new Vector2(circle.radius)) - ); - result.minimumTranslationVector = Vector2.subtract( - circle.position, - safePlace - ); - return result; - } - var sqrDistance = Vector2.distanceSquared( - closestPointOnBounds, - circle.position - ); - if (sqrDistance == 0) { - result.minimumTranslationVector = Vector2.multiply( - result.normal, - new Vector2(circle.radius) - ); - } else if (sqrDistance <= circle.radius * circle.radius) { - result.normal = Vector2.subtract(circle.position, closestPointOnBounds); - var depth = result.normal.length() - circle.radius; - result.normal = Vector2Ext.normalize(result.normal); - result.minimumTranslationVector = Vector2.multiply( - new Vector2(depth), - result.normal - ); - return result; - } - return null; - }; - ShapeCollisions.pointToCircle = function (point, circle) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared(point, circle.position); - var sumOfRadii = 1 + circle.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize( - Vector2.subtract(point, circle.position) - ); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply( - new Vector2(-depth, -depth), - result.normal - ); - result.point = Vector2.add( - circle.position, - Vector2.multiply( - result.normal, - new Vector2(circle.radius, circle.radius) - ) - ); - return result; + function CollisionResult() { } - return null; - }; - ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); - }; - ShapeCollisions.pointToPoly = function (point, poly) { - var result = new CollisionResult(); - if (poly.containsPoint(point)) { - var distanceSquared = void 0; - var gpp = Polygon.getClosestPointOnPolygonToPoint( - poly.points, - Vector2.subtract(point, poly.position) - ); - var closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - result.minimumTranslationVector = Vector2.multiply( - result.normal, - new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared)) - ); - result.point = Vector2.add(closestPoint, poly.position); - return result; - } - return null; - }; - ShapeCollisions.circleToCircle = function (first, second) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared( - first.position, - second.position - ); - var sumOfRadii = first.radius + second.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize( - Vector2.subtract(first.position, second.position) - ); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply( - new Vector2(-depth), - result.normal - ); - result.point = Vector2.add( - second.position, - Vector2.multiply(result.normal, new Vector2(second.radius)) - ); - return result; - } - return null; - }; - return ShapeCollisions; -})(); + CollisionResult.prototype.invertResult = function () { + this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector); + this.normal = Vector2.negate(this.normal); + }; + return CollisionResult; +}()); +var ShapeCollisions = (function () { + function ShapeCollisions() { + } + ShapeCollisions.polygonToPolygon = function (first, second) { + var result = new CollisionResult(); + var isIntersecting = true; + var firstEdges = first.edgeNormals; + var secondEdges = second.edgeNormals; + var minIntervalDistance = Number.POSITIVE_INFINITY; + var translationAxis = new Vector2(); + var polygonOffset = Vector2.subtract(first.position, second.position); + var axis; + for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { + if (edgeIndex < firstEdges.length) { + axis = firstEdges[edgeIndex]; + } + else { + axis = secondEdges[edgeIndex - firstEdges.length]; + } + var minA = 0; + var minB = 0; + var maxA = 0; + var maxB = 0; + var intervalDist = 0; + var ta = this.getInterval(axis, first, minA, maxA); + minA = ta.min; + minB = ta.max; + var tb = this.getInterval(axis, second, minB, maxB); + minB = tb.min; + maxB = tb.max; + var relativeIntervalOffset = Vector2.dot(polygonOffset, axis); + minA += relativeIntervalOffset; + maxA += relativeIntervalOffset; + intervalDist = this.intervalDistance(minA, maxA, minB, maxB); + if (intervalDist > 0) + isIntersecting = false; + if (!isIntersecting) + return null; + intervalDist = Math.abs(intervalDist); + if (intervalDist < minIntervalDistance) { + minIntervalDistance = intervalDist; + translationAxis = axis; + if (Vector2.dot(translationAxis, polygonOffset) < 0) + translationAxis = new Vector2(-translationAxis); + } + } + result.normal = translationAxis; + result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis), new Vector2(minIntervalDistance)); + return result; + }; + ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { + if (minA < minB) + return minB - maxA; + return minA - minB; + }; + ShapeCollisions.getInterval = function (axis, polygon, min, max) { + var dot = Vector2.dot(polygon.points[0], axis); + min = max = dot; + for (var i = 1; i < polygon.points.length; i++) { + dot = Vector2.dot(polygon.points[i], axis); + if (dot < min) { + min = dot; + } + else if (dot > max) { + max = dot; + } + } + return { min: min, max: max }; + }; + ShapeCollisions.circleToPolygon = function (circle, polygon) { + var result = new CollisionResult(); + var poly2Circle = Vector2.subtract(circle.position, polygon.position); + var gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); + var closestPoint = gpp.closestPoint; + var distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + var circleCenterInsidePoly = polygon.containsPoint(circle.position); + if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) + return null; + var mtv; + if (circleCenterInsidePoly) { + mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared) - circle.radius)); + } + else { + if (distanceSquared == 0) { + mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); + } + else { + var distance = Math.sqrt(distanceSquared); + mtv = Vector2.multiply(new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), new Vector2((circle.radius - distanceSquared) / distance)); + } + } + result.minimumTranslationVector = mtv; + result.point = Vector2.add(closestPoint, polygon.position); + return result; + }; + ShapeCollisions.circleToBox = function (circle, box) { + var result = new CollisionResult(); + var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; + if (box.containsPoint(circle.position)) { + result.point = closestPointOnBounds; + var safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); + result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); + return result; + } + var sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); + if (sqrDistance == 0) { + result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius)); + } + else if (sqrDistance <= circle.radius * circle.radius) { + result.normal = Vector2.subtract(circle.position, closestPointOnBounds); + var depth = result.normal.length() - circle.radius; + result.normal = Vector2Ext.normalize(result.normal); + result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); + return result; + } + return null; + }; + ShapeCollisions.pointToCircle = function (point, circle) { + var result = new CollisionResult(); + var distanceSquared = Vector2.distanceSquared(point, circle.position); + var sumOfRadii = 1 + circle.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = Vector2.normalize(Vector2.subtract(point, circle.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal); + result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius))); + return result; + } + return null; + }; + ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = Vector2.subtract(lineB, lineA); + var w = Vector2.subtract(closestTo, lineA); + var t = Vector2.dot(w, v) / Vector2.dot(v, v); + t = MathHelper.clamp(t, 0, 1); + return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); + }; + ShapeCollisions.pointToPoly = function (point, poly) { + var result = new CollisionResult(); + if (poly.containsPoint(point)) { + var distanceSquared = void 0; + var gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position)); + var closestPoint = gpp.closestPoint; + distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); + result.point = Vector2.add(closestPoint, poly.position); + return result; + } + return null; + }; + ShapeCollisions.circleToCircle = function (first, second) { + var result = new CollisionResult(); + var distanceSquared = Vector2.distanceSquared(first.position, second.position); + var sumOfRadii = first.radius + second.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal); + result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius))); + return result; + } + return null; + }; + return ShapeCollisions; +}()); var SpatialHash = (function () { - function SpatialHash(cellSize) { - if (cellSize === void 0) { - cellSize = 100; - } - this.gridBounds = new Rectangle(); - this._tempHashSet = []; - this._cellDict = new NumberDictionary(); - this._cellSize = cellSize; - this._inverseCellSize = 1 / this._cellSize; - this._raycastParser = new RaycastResultParser(); - } - SpatialHash.prototype.remove = function (collider) { - var bounds = collider.registeredPhysicsBounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) - console.error( - "removing Collider [" + - collider + - "] from a cell that it is not present in" - ); - else cell.remove(collider); - } - } - }; - SpatialHash.prototype.register = function (collider) { - var bounds = collider.bounds; - collider.registeredPhysicsBounds = bounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) { - this.gridBounds = RectangleExt.union(this.gridBounds, p1); - } - if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) { - this.gridBounds = RectangleExt.union(this.gridBounds, p2); - } - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var c = this.cellAtPosition(x, y, true); - c.push(collider); - } - } - }; - SpatialHash.prototype.clear = function () { - this._cellDict.clear(); - }; - SpatialHash.prototype.overlapCircle = function ( - circleCenter, - radius, - results, - layerMask - ) { - var bounds = new Rectangle( - circleCenter.x - radius, - circleCenter.y - radius, - radius * 2, - radius * 2 - ); - this._overlapTestCircle.radius = radius; - this._overlapTestCircle.position = circleCenter; - var resultCounter = 0; - var potentials = this.aabbBroadphase(bounds, null, layerMask); - for (var i = 0; i < potentials.length; i++) { - var collider = potentials[i]; - if (collider instanceof BoxCollider) { - results[resultCounter] = collider; - resultCounter++; - } else { - throw new Error( - "overlapCircle against this collider type is not implemented!" - ); - } - if (resultCounter == results.length) return resultCounter; - } - return resultCounter; - }; - SpatialHash.prototype.aabbBroadphase = function ( - bounds, - excludeCollider, - layerMask - ) { - this._tempHashSet.length = 0; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) continue; - for (var i = 0; i < cell.length; i++) { - var collider = cell[i]; - if ( - collider == excludeCollider || - !Flags.isFlagSet(layerMask, collider.physicsLayer) - ) - continue; - if (bounds.intersects(collider.bounds)) { - if (this._tempHashSet.indexOf(collider) == -1) - this._tempHashSet.push(collider); - } - } - } - } - return this._tempHashSet; - }; - SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { - if (createCellIfEmpty === void 0) { - createCellIfEmpty = false; - } - var cell = this._cellDict.tryGetValue(x, y); - if (!cell) { - if (createCellIfEmpty) { - cell = []; - this._cellDict.add(x, y, cell); - } - } - return cell; - }; - SpatialHash.prototype.cellCoords = function (x, y) { - return new Point( - Math.floor(x * this._inverseCellSize), - Math.floor(y * this._inverseCellSize) - ); - }; - return SpatialHash; -})(); + function SpatialHash(cellSize) { + if (cellSize === void 0) { cellSize = 100; } + this.gridBounds = new Rectangle(); + this._tempHashSet = []; + this._cellDict = new NumberDictionary(); + this._cellSize = cellSize; + this._inverseCellSize = 1 / this._cellSize; + this._raycastParser = new RaycastResultParser(); + } + SpatialHash.prototype.remove = function (collider) { + var bounds = collider.registeredPhysicsBounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) + console.error("removing Collider [" + collider + "] from a cell that it is not present in"); + else + cell.remove(collider); + } + } + }; + SpatialHash.prototype.register = function (collider) { + var bounds = collider.bounds; + collider.registeredPhysicsBounds = bounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) { + this.gridBounds = RectangleExt.union(this.gridBounds, p1); + } + if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) { + this.gridBounds = RectangleExt.union(this.gridBounds, p2); + } + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var c = this.cellAtPosition(x, y, true); + c.push(collider); + } + } + }; + SpatialHash.prototype.clear = function () { + this._cellDict.clear(); + }; + SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { + var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); + this._overlapTestCircle.radius = radius; + this._overlapTestCircle.position = circleCenter; + var resultCounter = 0; + var potentials = this.aabbBroadphase(bounds, null, layerMask); + for (var i = 0; i < potentials.length; i++) { + var collider = potentials[i]; + if (collider instanceof BoxCollider) { + results[resultCounter] = collider; + resultCounter++; + } + else { + throw new Error("overlapCircle against this collider type is not implemented!"); + } + if (resultCounter == results.length) + return resultCounter; + } + return resultCounter; + }; + SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) { + this._tempHashSet.length = 0; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) + continue; + for (var i = 0; i < cell.length; i++) { + var collider = cell[i]; + if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer)) + continue; + if (bounds.intersects(collider.bounds)) { + if (this._tempHashSet.indexOf(collider) == -1) + this._tempHashSet.push(collider); + } + } + } + } + return this._tempHashSet; + }; + SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { + if (createCellIfEmpty === void 0) { createCellIfEmpty = false; } + var cell = this._cellDict.tryGetValue(x, y); + if (!cell) { + if (createCellIfEmpty) { + cell = []; + this._cellDict.add(x, y, cell); + } + } + return cell; + }; + SpatialHash.prototype.cellCoords = function (x, y) { + return new Point(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); + }; + return SpatialHash; +}()); var RaycastResultParser = (function () { - function RaycastResultParser() {} - return RaycastResultParser; -})(); + function RaycastResultParser() { + } + return RaycastResultParser; +}()); var NumberDictionary = (function () { - function NumberDictionary() { - this._store = new Map(); - } - NumberDictionary.prototype.getKey = function (x, y) { - return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); - }; - NumberDictionary.prototype.intToUint = function (i) { - if (i >= 0) return i; - else return 4294967296 + i; - }; - NumberDictionary.prototype.add = function (x, y, list) { - this._store.set(this.getKey(x, y), list); - }; - NumberDictionary.prototype.remove = function (obj) { - this._store.forEach(function (list) { - if (list.contains(obj)) list.remove(obj); - }); - }; - NumberDictionary.prototype.tryGetValue = function (x, y) { - return this._store.get(this.getKey(x, y)); - }; - NumberDictionary.prototype.clear = function () { - this._store.clear(); - }; - return NumberDictionary; -})(); -var ContentManager = (function () { - function ContentManager() { - this.loadedAssets = new Map(); - } - ContentManager.prototype.loadRes = function (name, local) { - var _this = this; - if (local === void 0) { - local = true; + function NumberDictionary() { + this._store = new Map(); } - return new Promise(function (resolve, reject) { - var res = _this.loadedAssets.get(name); - if (res) { - resolve(res); - return; - } - if (local) { - RES.getResAsync(name) - .then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }) - .catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } else { - RES.getResByUrl(name) - .then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }) - .catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } - }); - }; - ContentManager.prototype.dispose = function () { - this.loadedAssets.forEach(function (value) { - var assetsToRemove = value; - assetsToRemove.dispose(); - }); - this.loadedAssets.clear(); - }; - return ContentManager; -})(); + NumberDictionary.prototype.getKey = function (x, y) { + return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); + }; + NumberDictionary.prototype.intToUint = function (i) { + if (i >= 0) + return i; + else + return 4294967296 + i; + }; + NumberDictionary.prototype.add = function (x, y, list) { + this._store.set(this.getKey(x, y), list); + }; + NumberDictionary.prototype.remove = function (obj) { + this._store.forEach(function (list) { + if (list.contains(obj)) + list.remove(obj); + }); + }; + NumberDictionary.prototype.tryGetValue = function (x, y) { + return this._store.get(this.getKey(x, y)); + }; + NumberDictionary.prototype.clear = function () { + this._store.clear(); + }; + return NumberDictionary; +}()); +var ContentManager = (function () { + function ContentManager() { + this.loadedAssets = new Map(); + } + ContentManager.prototype.loadRes = function (name, local) { + var _this = this; + if (local === void 0) { local = true; } + return new Promise(function (resolve, reject) { + var res = _this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } + if (local) { + RES.getResAsync(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + else { + RES.getResByUrl(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }); + }; + ContentManager.prototype.dispose = function () { + this.loadedAssets.forEach(function (value) { + var assetsToRemove = value; + assetsToRemove.dispose(); + }); + this.loadedAssets.clear(); + }; + return ContentManager; +}()); var Emitter = (function () { - function Emitter() { - this._messageTable = new Map(); - } - Emitter.prototype.addObserver = function (eventType, handler) { - var list = this._messageTable.get(eventType); - if (!list) { - list = []; - this._messageTable.set(eventType, list); - } - if (list.contains(handler)) console.warn("您试图添加相同的观察者两次"); - list.push(handler); - }; - Emitter.prototype.removeObserver = function (eventType, handler) { - this._messageTable.get(eventType).remove(handler); - }; - Emitter.prototype.emit = function (eventType, data) { - var list = this._messageTable.get(eventType); - if (list) { - for (var i = list.length - 1; i >= 0; i--) list[i](data); - } - }; - return Emitter; -})(); + function Emitter() { + this._messageTable = new Map(); + } + Emitter.prototype.addObserver = function (eventType, handler) { + var list = this._messageTable.get(eventType); + if (!list) { + list = []; + this._messageTable.set(eventType, list); + } + if (list.contains(handler)) + console.warn("您试图添加相同的观察者两次"); + list.push(handler); + }; + Emitter.prototype.removeObserver = function (eventType, handler) { + this._messageTable.get(eventType).remove(handler); + }; + Emitter.prototype.emit = function (eventType, data) { + var list = this._messageTable.get(eventType); + if (list) { + for (var i = list.length - 1; i >= 0; i--) + list[i](data); + } + }; + return Emitter; +}()); var GlobalManager = (function () { - function GlobalManager() {} - Object.defineProperty(GlobalManager.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true, - }); - GlobalManager.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); - } else { - this.onDisabled(); - } - } - }; - GlobalManager.prototype.onEnabled = function () {}; - GlobalManager.prototype.onDisabled = function () {}; - GlobalManager.prototype.update = function () {}; - GlobalManager.registerGlobalManager = function (manager) { - this.globalManagers.push(manager); - manager.enabled = true; - }; - GlobalManager.unregisterGlobalManager = function (manager) { - this.globalManagers.remove(manager); - manager.enabled = false; - }; - GlobalManager.getGlobalManager = function (type) { - for (var i = 0; i < this.globalManagers.length; i++) { - if (this.globalManagers[i] instanceof type) return this.globalManagers[i]; + function GlobalManager() { } - return null; - }; - GlobalManager.globalManagers = []; - return GlobalManager; -})(); + Object.defineProperty(GlobalManager.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + GlobalManager.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } + } + }; + GlobalManager.prototype.onEnabled = function () { }; + GlobalManager.prototype.onDisabled = function () { }; + GlobalManager.prototype.update = function () { }; + GlobalManager.registerGlobalManager = function (manager) { + this.globalManagers.push(manager); + manager.enabled = true; + }; + GlobalManager.unregisterGlobalManager = function (manager) { + this.globalManagers.remove(manager); + manager.enabled = false; + }; + GlobalManager.getGlobalManager = function (type) { + for (var i = 0; i < this.globalManagers.length; i++) { + if (this.globalManagers[i] instanceof type) + return this.globalManagers[i]; + } + return null; + }; + GlobalManager.globalManagers = []; + return GlobalManager; +}()); var TouchState = (function () { - function TouchState() { - this.x = 0; - this.y = 0; - this.touchPoint = -1; - this.touchDown = false; - } - Object.defineProperty(TouchState.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - enumerable: true, - configurable: true, - }); - TouchState.prototype.reset = function () { - this.x = 0; - this.y = 0; - this.touchDown = false; - this.touchPoint = -1; - }; - return TouchState; -})(); + function TouchState() { + this.x = 0; + this.y = 0; + this.touchPoint = -1; + this.touchDown = false; + } + Object.defineProperty(TouchState.prototype, "position", { + get: function () { + return new Vector2(this.x, this.y); + }, + enumerable: true, + configurable: true + }); + TouchState.prototype.reset = function () { + this.x = 0; + this.y = 0; + this.touchDown = false; + this.touchPoint = -1; + }; + return TouchState; +}()); var Input = (function () { - function Input() {} - Object.defineProperty(Input, "touchPosition", { - get: function () { - if (!this._gameTouchs[0]) return Vector2.zero; - return this._gameTouchs[0].position; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "maxSupportedTouch", { - get: function () { - return this._stage.maxTouches; - }, - set: function (value) { - this._stage.maxTouches = value; - this.initTouchCache(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "resolutionScale", { - get: function () { - return this._resolutionScale; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "totalTouchCount", { - get: function () { - return this._totalTouchCount; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "gameTouchs", { - get: function () { - return this._gameTouchs; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "touchPositionDelta", { - get: function () { - var delta = Vector2.subtract( - this.touchPosition, - this._previousTouchState.position - ); - if (delta.length() > 0) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - return delta; - }, - enumerable: true, - configurable: true, - }); - Input.initialize = function (stage) { - if (this._init) return; - this._init = true; - this._stage = stage; - this._stage.addEventListener( - egret.TouchEvent.TOUCH_BEGIN, - this.touchBegin, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_MOVE, - this.touchMove, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_END, - this.touchEnd, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_CANCEL, - this.touchEnd, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, - this.touchEnd, - this - ); - this.initTouchCache(); - }; - Input.initTouchCache = function () { - this._totalTouchCount = 0; - this._touchIndex = 0; - this._gameTouchs.length = 0; - for (var i = 0; i < this.maxSupportedTouch; i++) { - this._gameTouchs.push(new TouchState()); + function Input() { } - }; - Input.touchBegin = function (evt) { - if (this._touchIndex < this.maxSupportedTouch) { - this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; - this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; - this._gameTouchs[this._touchIndex].x = evt.stageX; - this._gameTouchs[this._touchIndex].y = evt.stageY; - if (this._touchIndex == 0) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - this._touchIndex++; - this._totalTouchCount++; - } - }; - Input.touchMove = function (evt) { - if (evt.touchPointID == this._gameTouchs[0].touchPoint) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - var touchIndex = this._gameTouchs.findIndex(function (touch) { - return touch.touchPoint == evt.touchPointID; + Object.defineProperty(Input, "touchPosition", { + get: function () { + if (!this._gameTouchs[0]) + return Vector2.zero; + return this._gameTouchs[0].position; + }, + enumerable: true, + configurable: true }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.x = evt.stageX; - touchData.y = evt.stageY; - } - }; - Input.touchEnd = function (evt) { - var touchIndex = this._gameTouchs.findIndex(function (touch) { - return touch.touchPoint == evt.touchPointID; + Object.defineProperty(Input, "maxSupportedTouch", { + get: function () { + return this._stage.maxTouches; + }, + set: function (value) { + this._stage.maxTouches = value; + this.initTouchCache(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "resolutionScale", { + get: function () { + return this._resolutionScale; + }, + enumerable: true, + configurable: true }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.reset(); - if (touchIndex == 0) this._previousTouchState.reset(); - this._totalTouchCount--; - if (this.totalTouchCount == 0) { + Object.defineProperty(Input, "totalTouchCount", { + get: function () { + return this._totalTouchCount; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "gameTouchs", { + get: function () { + return this._gameTouchs; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "touchPositionDelta", { + get: function () { + var delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position); + if (delta.length() > 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + return delta; + }, + enumerable: true, + configurable: true + }); + Input.initialize = function (stage) { + if (this._init) + return; + this._init = true; + this._stage = stage; + this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); + this.initTouchCache(); + }; + Input.initTouchCache = function () { + this._totalTouchCount = 0; this._touchIndex = 0; - } - } - }; - Input.setpreviousTouchState = function (touchState) { - this._previousTouchState = new TouchState(); - this._previousTouchState.x = touchState.position.x; - this._previousTouchState.y = touchState.position.y; - this._previousTouchState.touchPoint = touchState.touchPoint; - this._previousTouchState.touchDown = touchState.touchDown; - }; - Input.scaledPosition = function (position) { - var scaledPos = new Vector2( - position.x - this._resolutionOffset.x, - position.y - this._resolutionOffset.y - ); - return Vector2.multiply(scaledPos, this.resolutionScale); - }; - Input._init = false; - Input._previousTouchState = new TouchState(); - Input._gameTouchs = []; - Input._resolutionOffset = new Vector2(); - Input._resolutionScale = Vector2.one; - Input._touchIndex = 0; - Input._totalTouchCount = 0; - return Input; -})(); + this._gameTouchs.length = 0; + for (var i = 0; i < this.maxSupportedTouch; i++) { + this._gameTouchs.push(new TouchState()); + } + }; + Input.touchBegin = function (evt) { + if (this._touchIndex < this.maxSupportedTouch) { + this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; + this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; + this._gameTouchs[this._touchIndex].x = evt.stageX; + this._gameTouchs[this._touchIndex].y = evt.stageY; + if (this._touchIndex == 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + this._touchIndex++; + this._totalTouchCount++; + } + }; + Input.touchMove = function (evt) { + if (evt.touchPointID == this._gameTouchs[0].touchPoint) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.x = evt.stageX; + touchData.y = evt.stageY; + } + }; + Input.touchEnd = function (evt) { + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.reset(); + if (touchIndex == 0) + this._previousTouchState.reset(); + this._totalTouchCount--; + if (this.totalTouchCount == 0) { + this._touchIndex = 0; + } + } + }; + Input.setpreviousTouchState = function (touchState) { + this._previousTouchState = new TouchState(); + this._previousTouchState.x = touchState.position.x; + this._previousTouchState.y = touchState.position.y; + this._previousTouchState.touchPoint = touchState.touchPoint; + this._previousTouchState.touchDown = touchState.touchDown; + }; + Input.scaledPosition = function (position) { + var scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); + return Vector2.multiply(scaledPos, this.resolutionScale); + }; + Input._init = false; + Input._previousTouchState = new TouchState(); + Input._gameTouchs = []; + Input._resolutionOffset = new Vector2(); + Input._resolutionScale = Vector2.one; + Input._touchIndex = 0; + Input._totalTouchCount = 0; + return Input; +}()); var ListPool = (function () { - function ListPool() {} - ListPool.warmCache = function (cacheCount) { - cacheCount -= this._objectQueue.length; - if (cacheCount > 0) { - for (var i = 0; i < cacheCount; i++) { - this._objectQueue.unshift([]); - } + function ListPool() { } - }; - ListPool.trimCache = function (cacheCount) { - while (cacheCount > this._objectQueue.length) this._objectQueue.shift(); - }; - ListPool.clearCache = function () { - this._objectQueue.length = 0; - }; - ListPool.obtain = function () { - if (this._objectQueue.length > 0) return this._objectQueue.shift(); - return []; - }; - ListPool.free = function (obj) { - this._objectQueue.unshift(obj); - obj.length = 0; - }; - ListPool._objectQueue = []; - return ListPool; -})(); + ListPool.warmCache = function (cacheCount) { + cacheCount -= this._objectQueue.length; + if (cacheCount > 0) { + for (var i = 0; i < cacheCount; i++) { + this._objectQueue.unshift([]); + } + } + }; + ListPool.trimCache = function (cacheCount) { + while (cacheCount > this._objectQueue.length) + this._objectQueue.shift(); + }; + ListPool.clearCache = function () { + this._objectQueue.length = 0; + }; + ListPool.obtain = function () { + if (this._objectQueue.length > 0) + return this._objectQueue.shift(); + return []; + }; + ListPool.free = function (obj) { + this._objectQueue.unshift(obj); + obj.length = 0; + }; + ListPool._objectQueue = []; + return ListPool; +}()); var Pair = (function () { - function Pair(first, second) { - this.first = first; - this.second = second; - } - Pair.prototype.clear = function () { - this.first = this.second = null; - }; - Pair.prototype.equals = function (other) { - return this.first == other.first && this.second == other.second; - }; - return Pair; -})(); + function Pair(first, second) { + this.first = first; + this.second = second; + } + Pair.prototype.clear = function () { + this.first = this.second = null; + }; + Pair.prototype.equals = function (other) { + return this.first == other.first && this.second == other.second; + }; + return Pair; +}()); var RectangleExt = (function () { - function RectangleExt() {} - RectangleExt.union = function (first, point) { - var rect = new Rectangle(point.x, point.y, 0, 0); - return this.unionR(first, rect); - }; - RectangleExt.unionR = function (value1, value2) { - var result = new Rectangle(); - result.x = Math.min(value1.x, value2.x); - result.y = Math.min(value1.y, value2.y); - result.width = Math.max(value1.right, value2.right) - result.x; - result.height = Math.max(value1.bottom, value2.bottom) - result.y; - return result; - }; - return RectangleExt; -})(); -var Triangulator = (function () { - function Triangulator() { - this.triangleIndices = []; - this._triPrev = new Array(12); - this._triNext = new Array(12); - } - Triangulator.prototype.triangulate = function (points, arePointsCCW) { - if (arePointsCCW === void 0) { - arePointsCCW = true; + function RectangleExt() { } - var count = points.length; - this.initialize(count); - var iterations = 0; - var index = 0; - while (count > 3 && iterations < 500) { - iterations++; - var isEar = true; - var a = points[this._triPrev[index]]; - var b = points[index]; - var c = points[this._triNext[index]]; - if (Vector2Ext.isTriangleCCW(a, b, c)) { - var k = this._triNext[this._triNext[index]]; - do { - if (Triangulator.testPointTriangle(points[k], a, b, c)) { - isEar = false; - break; - } - k = this._triNext[k]; - } while (k != this._triPrev[index]); - } else { - isEar = false; - } - if (isEar) { + RectangleExt.union = function (first, point) { + var rect = new Rectangle(point.x, point.y, 0, 0); + return this.unionR(first, rect); + }; + RectangleExt.unionR = function (value1, value2) { + var result = new Rectangle(); + result.x = Math.min(value1.x, value2.x); + result.y = Math.min(value1.y, value2.y); + result.width = Math.max(value1.right, value2.right) - result.x; + result.height = Math.max(value1.bottom, value2.bottom) - result.y; + return result; + }; + return RectangleExt; +}()); +var Triangulator = (function () { + function Triangulator() { + this.triangleIndices = []; + this._triPrev = new Array(12); + this._triNext = new Array(12); + } + Triangulator.prototype.triangulate = function (points, arePointsCCW) { + if (arePointsCCW === void 0) { arePointsCCW = true; } + var count = points.length; + this.initialize(count); + var iterations = 0; + var index = 0; + while (count > 3 && iterations < 500) { + iterations++; + var isEar = true; + var a = points[this._triPrev[index]]; + var b = points[index]; + var c = points[this._triNext[index]]; + if (Vector2Ext.isTriangleCCW(a, b, c)) { + var k = this._triNext[this._triNext[index]]; + do { + if (Triangulator.testPointTriangle(points[k], a, b, c)) { + isEar = false; + break; + } + k = this._triNext[k]; + } while (k != this._triPrev[index]); + } + else { + isEar = false; + } + if (isEar) { + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); + this._triNext[this._triPrev[index]] = this._triNext[index]; + this._triPrev[this._triNext[index]] = this._triPrev[index]; + count--; + index = this._triPrev[index]; + } + else { + index = this._triNext[index]; + } + } this.triangleIndices.push(this._triPrev[index]); this.triangleIndices.push(index); this.triangleIndices.push(this._triNext[index]); - this._triNext[this._triPrev[index]] = this._triNext[index]; - this._triPrev[this._triNext[index]] = this._triPrev[index]; - count--; - index = this._triPrev[index]; - } else { - index = this._triNext[index]; - } - } - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); - if (!arePointsCCW) this.triangleIndices.reverse(); - }; - Triangulator.prototype.initialize = function (count) { - this.triangleIndices.length = 0; - if (this._triNext.length < count) { - this._triNext.reverse(); - this._triNext = new Array(Math.max(this._triNext.length * 2, count)); - } - if (this._triPrev.length < count) { - this._triPrev.reverse(); - this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); - } - for (var i = 0; i < count; i++) { - this._triPrev[i] = i - 1; - this._triNext[i] = i + 1; - } - this._triPrev[0] = count - 1; - this._triNext[count - 1] = 0; - }; - Triangulator.testPointTriangle = function (point, a, b, c) { - if ( - Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0 - ) - return false; - if ( - Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0 - ) - return false; - if ( - Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0 - ) - return false; - return true; - }; - return Triangulator; -})(); + if (!arePointsCCW) + this.triangleIndices.reverse(); + }; + Triangulator.prototype.initialize = function (count) { + this.triangleIndices.length = 0; + if (this._triNext.length < count) { + this._triNext.reverse(); + this._triNext = new Array(Math.max(this._triNext.length * 2, count)); + } + if (this._triPrev.length < count) { + this._triPrev.reverse(); + this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); + } + for (var i = 0; i < count; i++) { + this._triPrev[i] = i - 1; + this._triNext[i] = i + 1; + } + this._triPrev[0] = count - 1; + this._triNext[count - 1] = 0; + }; + Triangulator.testPointTriangle = function (point, a, b, c) { + if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0) + return false; + if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0) + return false; + if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0) + return false; + return true; + }; + return Triangulator; +}()); var Vector2Ext = (function () { - function Vector2Ext() {} - Vector2Ext.isTriangleCCW = function (a, center, c) { - return ( - this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0 - ); - }; - Vector2Ext.cross = function (u, v) { - return u.y * v.x - u.x * v.y; - }; - Vector2Ext.perpendicular = function (first, second) { - return new Vector2(-1 * (second.y - first.y), second.x - first.x); - }; - Vector2Ext.normalize = function (vec) { - var magnitude = Math.sqrt(vec.x * vec.x + vec.y * vec.y); - if (magnitude > MathHelper.Epsilon) { - vec = Vector2.divide(vec, new Vector2(magnitude)); - } else { - vec.x = vec.y = 0; - } - return vec; - }; - Vector2Ext.transformA = function ( - sourceArray, - sourceIndex, - matrix, - destinationArray, - destinationIndex, - length - ) { - for (var i = 0; i < length; i++) { - var position = sourceArray[sourceIndex + i]; - var destination = destinationArray[destinationIndex + i]; - destination.x = - position.x * matrix.m11 + position.y * matrix.m21 + matrix.m31; - destination.y = - position.x * matrix.m12 + position.y * matrix.m22 + matrix.m32; - destinationArray[destinationIndex + i] = destination; + function Vector2Ext() { } - }; - Vector2Ext.transformR = function (position, matrix) { - var x = position.x * matrix.m11 + position.y * matrix.m21 + matrix.m31; - var y = position.x * matrix.m12 + position.y * matrix.m22 + matrix.m32; - return new Vector2(x, y); - }; - Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { - this.transformA( - sourceArray, - 0, - matrix, - destinationArray, - 0, - sourceArray.length - ); - }; - Vector2Ext.round = function (vec) { - return new Vector2(Math.round(vec.x), Math.round(vec.y)); - }; - return Vector2Ext; -})(); + Vector2Ext.isTriangleCCW = function (a, center, c) { + return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; + }; + Vector2Ext.cross = function (u, v) { + return u.y * v.x - u.x * v.y; + }; + Vector2Ext.perpendicular = function (first, second) { + return new Vector2(-1 * (second.y - first.y), second.x - first.x); + }; + Vector2Ext.normalize = function (vec) { + var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); + if (magnitude > MathHelper.Epsilon) { + vec = Vector2.divide(vec, new Vector2(magnitude)); + } + else { + vec.x = vec.y = 0; + } + return vec; + }; + Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) { + for (var i = 0; i < length; i++) { + var position = sourceArray[sourceIndex + i]; + var destination = destinationArray[destinationIndex + i]; + destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + destinationArray[destinationIndex + i] = destination; + } + }; + Vector2Ext.transformR = function (position, matrix) { + var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + return new Vector2(x, y); + }; + Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { + this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); + }; + Vector2Ext.round = function (vec) { + return new Vector2(Math.round(vec.x), Math.round(vec.y)); + }; + return Vector2Ext; +}()); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 48790482..37478306 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1,5250 +1 @@ -(window.framework = {}), - (window.__extends = - (this && this.__extends) || - (function () { - var t = - Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && - function (t, e) { - t.__proto__ = e; - }) || - function (t, e) { - for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]); - }; - return function (e, n) { - function i() { - this.constructor = e; - } - t(e, n), - (e.prototype = - null === n - ? Object.create(n) - : ((i.prototype = n.prototype), new i())); - }; - })()); -var __awaiter = - (this && this.__awaiter) || - function (t, e, n, i) { - return new (n || (n = Promise))(function (o, r) { - function s(t) { - try { - h(i.next(t)); - } catch (t) { - r(t); - } - } - function a(t) { - try { - h(i.throw(t)); - } catch (t) { - r(t); - } - } - function h(t) { - t.done - ? o(t.value) - : new n(function (e) { - e(t.value); - }).then(s, a); - } - h((i = i.apply(t, e || [])).next()); - }); - }, - __generator = - (this && this.__generator) || - function (t, e) { - var n, - i, - o, - r, - s = { - label: 0, - sent: function () { - if (1 & o[0]) throw o[1]; - return o[1]; - }, - trys: [], - ops: [], - }; - return ( - (r = { next: a(0), throw: a(1), return: a(2) }), - "function" == typeof Symbol && - (r[Symbol.iterator] = function () { - return this; - }), - r - ); - function a(r) { - return function (a) { - return (function (r) { - if (n) throw new TypeError("Generator is already executing."); - for (; s; ) - try { - if ( - ((n = 1), - i && - (o = - 2 & r[0] - ? i.return - : r[0] - ? i.throw || ((o = i.return) && o.call(i), 0) - : i.next) && - !(o = o.call(i, r[1])).done) - ) - return o; - switch (((i = 0), o && (r = [2 & r[0], o.value]), r[0])) { - case 0: - case 1: - o = r; - break; - case 4: - return s.label++, { value: r[1], done: !1 }; - case 5: - s.label++, (i = r[1]), (r = [0]); - continue; - case 7: - (r = s.ops.pop()), s.trys.pop(); - continue; - default: - if ( - !(o = (o = s.trys).length > 0 && o[o.length - 1]) && - (6 === r[0] || 2 === r[0]) - ) { - s = 0; - continue; - } - if (3 === r[0] && (!o || (r[1] > o[0] && r[1] < o[3]))) { - s.label = r[1]; - break; - } - if (6 === r[0] && s.label < o[1]) { - (s.label = o[1]), (o = r); - break; - } - if (o && s.label < o[2]) { - (s.label = o[2]), s.ops.push(r); - break; - } - o[2] && s.ops.pop(), s.trys.pop(); - continue; - } - r = e.call(t, s); - } catch (t) { - (r = [6, t]), (i = 0); - } finally { - n = o = 0; - } - if (5 & r[0]) throw r[1]; - return { value: r[0] ? r[1] : void 0, done: !0 }; - })([r, a]); - }; - } - }; -(Array.prototype.findIndex = function (t) { - return (function (t, e) { - for (var n = 0, i = t.length; n < i; n++) - if (e.call(arguments[2], t[n], n, t)) return n; - return -1; - })(this, t); -}), - (Array.prototype.any = function (t) { - return (function (t, e) { - return t.findIndex(e) > -1; - })(this, t); - }), - (Array.prototype.firstOrDefault = function (t) { - return (function (t, e) { - var n = t.findIndex(e); - return -1 == n ? null : t[n]; - })(this, t); - }), - (Array.prototype.find = function (t) { - return (function (t, e) { - return t.firstOrDefault(e); - })(this, t); - }), - (Array.prototype.where = function (t) { - return (function (t, e) { - if ("function" == typeof t.reduce) - return t.reduce(function (n, i, o) { - return e.call(arguments[2], i, o, t) && n.push(i), n; - }, []); - for (var n = [], i = 0, o = t.length; i < o; i++) { - var r = t[i]; - e.call(arguments[2], r, i, t) && n.push(r); - } - return n; - })(this, t); - }), - (Array.prototype.count = function (t) { - return (function (t, e) { - return t.where(e).length; - })(this, t); - }), - (Array.prototype.findAll = function (t) { - return (function (t, e) { - return t.where(e); - })(this, t); - }), - (Array.prototype.contains = function (t) { - return (function (t, e) { - for (var n = 0, i = t.length; n < i; n++) if (t[n] == e) return !0; - return !1; - })(this, t); - }), - (Array.prototype.removeAll = function (t) { - !(function (t, e) { - var n; - do { - (n = t.findIndex(e)) >= 0 && t.splice(n, 1); - } while (n >= 0); - })(this, t); - }), - (Array.prototype.remove = function (t) { - return (function (t, e) { - var n = t.findIndex(function (t) { - return t === e; - }); - return n >= 0 && (t.splice(n, 1), !0); - })(this, t); - }), - (Array.prototype.removeAt = function (t) { - return (function (t, e) { - t.splice(e, 1); - })(this, t); - }), - (Array.prototype.removeRange = function (t, e) { - return (function (t, e, n) { - t.splice(e, n); - })(this, t, e); - }), - (Array.prototype.select = function (t) { - return (function (t, e) { - if ("function" == typeof t.reduce) - return t.reduce(function (n, i, o) { - return n.push(e.call(arguments[2], i, o, t)), n; - }, []); - for (var n = [], i = 0, o = t.length; i < o; i++) - n.push(e.call(arguments[2], t[i], i, t)); - return n; - })(this, t); - }), - (Array.prototype.orderBy = function (t, e) { - return (function (t, e, n) { - return ( - t.sort(function (t, i) { - var o = e(t), - r = e(i); - return n ? n(o, r) : o > r ? 1 : -1; - }), - t - ); - })(this, t, e); - }), - (Array.prototype.orderByDescending = function (t, e) { - return (function (t, e, n) { - return ( - t.sort(function (t, i) { - var o = e(t), - r = e(i); - return n ? -n(o, r) : o < r ? 1 : -1; - }), - t - ); - })(this, t, e); - }), - (Array.prototype.groupBy = function (t) { - return (function (t, e) { - if ("function" == typeof t.reduce) { - var n = []; - return t.reduce(function (i, o, r) { - var s = JSON.stringify(e.call(arguments[1], o, r, t)), - a = n.findIndex(function (t) { - return t === s; - }); - return ( - a < 0 && (a = n.push(s) - 1), i[a] || (i[a] = []), i[a].push(o), i - ); - }, []); - } - for ( - var i = [], - o = [], - r = function (n, r) { - var a = JSON.stringify(e.call(s[1], t[n], n, t)), - h = o.findIndex(function (t) { - return t === a; - }); - h < 0 && (h = o.push(a) - 1), i[h] || (i[h] = []), i[h].push(t[n]); - }, - s = arguments, - a = 0, - h = t.length; - a < h; - a++ - ) - r(a); - return i; - })(this, t); - }), - (Array.prototype.sum = function (t) { - return (function (t, e) { - for (var n, i = 0, o = t.length; i < o; i++) - 0 == i - ? (n = e ? e.call(arguments[2], t[i], i, t) : t[i]) - : (n += e ? e.call(arguments[2], t[i], i, t) : t[i]); - return n; - })(this, t); - }); -var DirtyType, - ComponentTransform, - PriorityQueueNode = (function () { - return function () { - (this.priority = 0), (this.insertionIndex = 0), (this.queueIndex = 0); - }; - })(), - AStarPathfinder = (function () { - function t() {} - return ( - (t.search = function (t, e, n) { - var i = this, - o = !1, - r = new Map(); - r.set(e, e); - var s = new Map(), - a = new PriorityQueue(1e3); - a.enqueue(new AStarNode(e), 0), s.set(e, 0); - for ( - var h = function () { - var e = a.dequeue(); - if (JSON.stringify(e.data) == JSON.stringify(n)) - return (o = !0), "break"; - t.getNeighbors(e.data).forEach(function (o) { - var h = s.get(e.data) + t.cost(e.data, o); - if (!i.hasKey(s, o) || h < s.get(o)) { - s.set(o, h); - var c = h + t.heuristic(o, n); - a.enqueue(new AStarNode(o), c), r.set(o, e.data); - } - }); - }; - a.count > 0; - - ) { - if ("break" === h()) break; - } - return o ? this.recontructPath(r, e, n) : null; - }), - (t.hasKey = function (t, e) { - for (var n, i = t.keys(); !(n = i.next()).done; ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return !0; - return !1; - }), - (t.getKey = function (t, e) { - for ( - var n, i, o = t.keys(), r = t.values(); - (n = o.next()), (i = r.next()), !n.done; - - ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return i.value; - return null; - }), - (t.recontructPath = function (t, e, n) { - var i = [], - o = n; - for (i.push(n); o != e; ) (o = this.getKey(t, o)), i.push(o); - return i.reverse(), i; - }), - t - ); - })(), - AStarNode = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.data = e), n; - } - return __extends(e, t), e; - })(PriorityQueueNode), - AstarGridGraph = (function () { - function t(t, e) { - (this.dirs = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]), - (this.walls = []), - (this.weightedNodes = []), - (this.defaultWeight = 1), - (this.weightedNodeWeight = 5), - (this._neighbors = new Array(4)), - (this._width = t), - (this._height = e); - } - return ( - (t.prototype.isNodeInBounds = function (t) { - return 0 <= t.x && t.x < this._width && 0 <= t.y && t.y < this._height; - }), - (t.prototype.isNodePassable = function (t) { - return !this.walls.firstOrDefault(function (e) { - return JSON.stringify(e) == JSON.stringify(t); - }); - }), - (t.prototype.search = function (t, e) { - return AStarPathfinder.search(this, t, e); - }), - (t.prototype.getNeighbors = function (t) { - var e = this; - return ( - (this._neighbors.length = 0), - this.dirs.forEach(function (n) { - var i = new Point(t.x + n.x, t.y + n.y); - e.isNodeInBounds(i) && e.isNodePassable(i) && e._neighbors.push(i); - }), - this._neighbors - ); - }), - (t.prototype.cost = function (t, e) { - return this.weightedNodes.find(function (t) { - return JSON.stringify(t) == JSON.stringify(e); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }), - (t.prototype.heuristic = function (t, e) { - return Math.abs(t.x - e.x) + Math.abs(t.y - e.y); - }), - t - ); - })(), - PriorityQueue = (function () { - function t(t) { - (this._numNodes = 0), - (this._nodes = new Array(t + 1)), - (this._numNodesEverEnqueued = 0); - } - return ( - (t.prototype.clear = function () { - this._nodes.splice(1, this._numNodes), (this._numNodes = 0); - }), - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._numNodes; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.contains = function (t) { - return this._nodes[t.queueIndex] == t; - }), - (t.prototype.enqueue = function (t, e) { - (t.priority = e), - this._numNodes++, - (this._nodes[this._numNodes] = t), - (t.queueIndex = this._numNodes), - (t.insertionIndex = this._numNodesEverEnqueued++), - this.cascadeUp(this._nodes[this._numNodes]); - }), - (t.prototype.dequeue = function () { - var t = this._nodes[1]; - return this.remove(t), t; - }), - (t.prototype.remove = function (t) { - if (t.queueIndex == this._numNodes) - return (this._nodes[this._numNodes] = null), void this._numNodes--; - var e = this._nodes[this._numNodes]; - this.swap(t, e), - delete this._nodes[this._numNodes], - this._numNodes--, - this.onNodeUpdated(e); - }), - (t.prototype.isValidQueue = function () { - for (var t = 1; t < this._nodes.length; t++) - if (this._nodes[t]) { - var e = 2 * t; - if ( - e < this._nodes.length && - this._nodes[e] && - this.hasHigherPriority(this._nodes[e], this._nodes[t]) - ) - return !1; - var n = e + 1; - if ( - n < this._nodes.length && - this._nodes[n] && - this.hasHigherPriority(this._nodes[n], this._nodes[t]) - ) - return !1; - } - return !0; - }), - (t.prototype.onNodeUpdated = function (t) { - var e = Math.floor(t.queueIndex / 2), - n = this._nodes[e]; - e > 0 && this.hasHigherPriority(t, n) - ? this.cascadeUp(t) - : this.cascadeDown(t); - }), - (t.prototype.cascadeDown = function (t) { - for (var e, n = t.queueIndex; ; ) { - e = t; - var i = 2 * n; - if (i > this._numNodes) { - (t.queueIndex = n), (this._nodes[n] = t); - break; - } - var o = this._nodes[i]; - this.hasHigherPriority(o, e) && (e = o); - var r = i + 1; - if (r <= this._numNodes) { - var s = this._nodes[r]; - this.hasHigherPriority(s, e) && (e = s); - } - if (e == t) { - (t.queueIndex = n), (this._nodes[n] = t); - break; - } - this._nodes[n] = e; - var a = e.queueIndex; - (e.queueIndex = n), (n = a); - } - }), - (t.prototype.cascadeUp = function (t) { - for (var e = Math.floor(t.queueIndex / 2); e >= 1; ) { - var n = this._nodes[e]; - if (this.hasHigherPriority(n, t)) break; - this.swap(t, n), (e = Math.floor(t.queueIndex / 2)); - } - }), - (t.prototype.swap = function (t, e) { - (this._nodes[t.queueIndex] = e), (this._nodes[e.queueIndex] = t); - var n = t.queueIndex; - (t.queueIndex = e.queueIndex), (e.queueIndex = n); - }), - (t.prototype.hasHigherPriority = function (t, e) { - return ( - t.priority < e.priority || - (t.priority == e.priority && t.insertionIndex < e.insertionIndex) - ); - }), - t - ); - })(), - BreadthFirstPathfinder = (function () { - function t() {} - return ( - (t.search = function (t, e, n) { - var i = this, - o = !1, - r = []; - r.unshift(e); - var s = new Map(); - s.set(e, e); - for ( - var a = function () { - var e = r.shift(); - if (JSON.stringify(e) == JSON.stringify(n)) - return (o = !0), "break"; - t.getNeighbors(e).forEach(function (t) { - i.hasKey(s, t) || (r.unshift(t), s.set(t, e)); - }); - }; - r.length > 0; - - ) { - if ("break" === a()) break; - } - return o ? AStarPathfinder.recontructPath(s, e, n) : null; - }), - (t.hasKey = function (t, e) { - for (var n, i = t.keys(); !(n = i.next()).done; ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return !0; - return !1; - }), - t - ); - })(), - UnweightedGraph = (function () { - function t() { - this.edges = new Map(); - } - return ( - (t.prototype.addEdgesForNode = function (t, e) { - return this.edges.set(t, e), this; - }), - (t.prototype.getNeighbors = function (t) { - return this.edges.get(t); - }), - t - ); - })(), - Point = (function () { - return function (t, e) { - (this.x = t || 0), (this.y = e || this.x); - }; - })(), - UnweightedGridGraph = (function () { - function t(e, n, i) { - void 0 === i && (i = !1), - (this.walls = []), - (this._neighbors = new Array(4)), - (this._width = e), - (this._hegiht = n), - (this._dirs = i ? t.COMPASS_DIRS : t.CARDINAL_DIRS); - } - return ( - (t.prototype.isNodeInBounds = function (t) { - return 0 <= t.x && t.x < this._width && 0 <= t.y && t.y < this._hegiht; - }), - (t.prototype.isNodePassable = function (t) { - return !this.walls.firstOrDefault(function (e) { - return JSON.stringify(e) == JSON.stringify(t); - }); - }), - (t.prototype.getNeighbors = function (t) { - var e = this; - return ( - (this._neighbors.length = 0), - this._dirs.forEach(function (n) { - var i = new Point(t.x + n.x, t.y + n.y); - e.isNodeInBounds(i) && e.isNodePassable(i) && e._neighbors.push(i); - }), - this._neighbors - ); - }), - (t.prototype.search = function (t, e) { - return BreadthFirstPathfinder.search(this, t, e); - }), - (t.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, -1), - ]), - (t.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]), - t - ); - })(), - WeightedGridGraph = (function () { - function t(e, n, i) { - void 0 === i && (i = !1), - (this.walls = []), - (this.weightedNodes = []), - (this.defaultWeight = 1), - (this.weightedNodeWeight = 5), - (this._neighbors = new Array(4)), - (this._width = e), - (this._height = n), - (this._dirs = i ? t.COMPASS_DIRS : t.CARDINAL_DIRS); - } - return ( - (t.prototype.isNodeInBounds = function (t) { - return 0 <= t.x && t.x < this._width && 0 <= t.y && t.y < this._height; - }), - (t.prototype.isNodePassable = function (t) { - return !this.walls.firstOrDefault(function (e) { - return JSON.stringify(e) == JSON.stringify(t); - }); - }), - (t.prototype.search = function (t, e) { - return WeightedPathfinder.search(this, t, e); - }), - (t.prototype.getNeighbors = function (t) { - var e = this; - return ( - (this._neighbors.length = 0), - this._dirs.forEach(function (n) { - var i = new Point(t.x + n.x, t.y + n.y); - e.isNodeInBounds(i) && e.isNodePassable(i) && e._neighbors.push(i); - }), - this._neighbors - ); - }), - (t.prototype.cost = function (t, e) { - return this.weightedNodes.find(function (t) { - return JSON.stringify(t) == JSON.stringify(e); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }), - (t.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]), - (t.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]), - t - ); - })(), - WeightedNode = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.data = e), n; - } - return __extends(e, t), e; - })(PriorityQueueNode), - WeightedPathfinder = (function () { - function t() {} - return ( - (t.search = function (t, e, n) { - var i = this, - o = !1, - r = new Map(); - r.set(e, e); - var s = new Map(), - a = new PriorityQueue(1e3); - a.enqueue(new WeightedNode(e), 0), s.set(e, 0); - for ( - var h = function () { - var e = a.dequeue(); - if (JSON.stringify(e.data) == JSON.stringify(n)) - return (o = !0), "break"; - t.getNeighbors(e.data).forEach(function (n) { - var o = s.get(e.data) + t.cost(e.data, n); - if (!i.hasKey(s, n) || o < s.get(n)) { - s.set(n, o); - var h = o; - a.enqueue(new WeightedNode(n), h), r.set(n, e.data); - } - }); - }; - a.count > 0; - - ) { - if ("break" === h()) break; - } - return o ? this.recontructPath(r, e, n) : null; - }), - (t.hasKey = function (t, e) { - for (var n, i = t.keys(); !(n = i.next()).done; ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return !0; - return !1; - }), - (t.getKey = function (t, e) { - for ( - var n, i, o = t.keys(), r = t.values(); - (n = o.next()), (i = r.next()), !n.done; - - ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return i.value; - return null; - }), - (t.recontructPath = function (t, e, n) { - var i = [], - o = n; - for (i.push(n); o != e; ) (o = this.getKey(t, o)), i.push(o); - return i.reverse(), i; - }), - t - ); - })(), - DebugDefaults = (function () { - function t() {} - return (t.verletParticle = 14431326), (t.verletConstraintEdge = 4406838), t; - })(), - Component = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return (e._enabled = !0), (e.updateInterval = 1), e; - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "enabled", { - get: function () { - return this.entity - ? this.entity.enabled && this._enabled - : this._enabled; - }, - set: function (t) { - this.setEnabled(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setEnabled = function (t) { - return ( - this._enabled != t && - ((this._enabled = t), - this._enabled ? this.onEnabled() : this.onDisabled()), - this - ); - }), - (e.prototype.initialize = function () {}), - (e.prototype.onAddedToEntity = function () {}), - (e.prototype.onRemovedFromEntity = function () {}), - (e.prototype.onEnabled = function () {}), - (e.prototype.onDisabled = function () {}), - (e.prototype.onEntityTransformChanged = function (t) {}), - (e.prototype.update = function () {}), - (e.prototype.debugRender = function () {}), - (e.prototype.registerComponent = function () { - this.entity.componentBits.set( - ComponentTypeManager.getIndexFor(this), - !1 - ), - this.entity.scene.entityProcessors.onComponentAdded(this.entity); - }), - (e.prototype.deregisterComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)), - this.entity.scene.entityProcessors.onComponentRemoved(this.entity); - }), - e - ); - })(egret.DisplayObjectContainer), - Entity = (function (t) { - function e(n) { - var i = t.call(this) || this; - return ( - (i._position = Vector2.zero), - (i._updateOrder = 0), - (i._enabled = !0), - (i._tag = 0), - (i.name = n), - (i.components = new ComponentList(i)), - (i.id = e._idGenerator++), - (i.componentBits = new BitSet()), - i - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "position", { - get: function () { - return this._position; - }, - set: function (t) { - this._position = t; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "scale", { - get: function () { - return new Vector2(this.scaleX, this.scaleY); - }, - set: function (t) { - (this.scaleX = t.x), (this.scaleY = t.y); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (t) { - this.setEnabled(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setEnabled = function (t) { - return this._enabled != t && (this._enabled = t), this; - }), - Object.defineProperty(e.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (t) { - this.setTag(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "stage", { - get: function () { - return this.scene ? this.scene.stage : null; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (t) { - this.setUpdateOrder(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.roundPosition = function () { - this.position = Vector2Ext.round(this.position); - }), - (e.prototype.setUpdateOrder = function (t) { - if (this._updateOrder != t) - return (this._updateOrder = t), this.scene, this; - }), - (e.prototype.setTag = function (t) { - return ( - this._tag != t && - (this.scene && this.scene.entities.removeFromTagList(this), - (this._tag = t), - this.scene && this.scene.entities.addToTagList(this)), - this - ); - }), - (e.prototype.attachToScene = function (t) { - (this.scene = t), - t.entities.add(this), - this.components.registerAllComponents(); - for (var e = 0; e < this.numChildren; e++) - this.getChildAt(e).entity.attachToScene(t); - }), - (e.prototype.detachFromScene = function () { - this.scene.entities.remove(this), - this.components.deregisterAllComponents(); - for (var t = 0; t < this.numChildren; t++) - this.getChildAt(t).entity.detachFromScene(); - }), - (e.prototype.addComponent = function (t) { - return ( - (t.entity = this), - this.components.add(t), - this.addChild(t), - t.initialize(), - t - ); - }), - (e.prototype.hasComponent = function (t) { - return null != this.components.getComponent(t, !1); - }), - (e.prototype.getOrCreateComponent = function (t) { - var e = this.components.getComponent(t, !0); - return e || (e = this.addComponent(t)), e; - }), - (e.prototype.getComponent = function (t) { - return this.components.getComponent(t, !1); - }), - (e.prototype.getComponents = function (t, e) { - return this.components.getComponents(t, e); - }), - (e.prototype.removeComponentForType = function (t) { - var e = this.getComponent(t); - return !!e && (this.removeComponent(e), !0); - }), - (e.prototype.removeComponent = function (t) { - this.components.remove(t); - }), - (e.prototype.removeAllComponents = function () { - for (var t = 0; t < this.components.count; t++) - this.removeComponent(this.components.buffer[t]); - }), - (e.prototype.update = function () { - this.components.update(); - }), - (e.prototype.onAddedToScene = function () {}), - (e.prototype.onRemovedFromScene = function () { - this._isDestoryed && this.components.removeAllComponents(); - }), - (e.prototype.onTransformChanged = function (t) { - this.components.onEntityTransformChanged(t); - }), - (e.prototype.destroy = function () { - (this._isDestoryed = !0), - this.scene.entities.remove(this), - this.removeChildren(); - for (var t = this.numChildren - 1; t >= 0; t--) { - this.getChildAt(t).entity.destroy(); - } - }), - e - ); - })(egret.DisplayObjectContainer), - Scene = (function (t) { - function e() { - var e = t.call(this) || this; - return ( - (e.enablePostProcessing = !0), - (e._renderers = []), - (e._postProcessors = []), - (e.entityProcessors = new EntityProcessorList()), - (e.renderableComponents = new RenderableComponentList()), - (e.entities = new EntityList(e)), - (e.content = new ContentManager()), - (e.width = SceneManager.stage.stageWidth), - (e.height = SceneManager.stage.stageHeight), - e.addEventListener(egret.Event.ACTIVATE, e.onActive, e), - e.addEventListener(egret.Event.DEACTIVATE, e.onDeactive, e), - e - ); - } - return ( - __extends(e, t), - (e.prototype.createEntity = function (t) { - var e = new Entity(t); - return (e.position = new Vector2(0, 0)), this.addEntity(e); - }), - (e.prototype.addEntity = function (t) { - this.entities.add(t), (t.scene = this), this.addChild(t); - for (var e = 0; e < t.numChildren; e++) - this.addEntity(t.getChildAt(e).entity); - return t; - }), - (e.prototype.destroyAllEntities = function () { - for (var t = 0; t < this.entities.count; t++) - this.entities.buffer[t].destroy(); - }), - (e.prototype.findEntity = function (t) { - return this.entities.findEntity(t); - }), - (e.prototype.addEntityProcessor = function (t) { - return (t.scene = this), this.entityProcessors.add(t), t; - }), - (e.prototype.removeEntityProcessor = function (t) { - this.entityProcessors.remove(t); - }), - (e.prototype.getEntityProcessor = function () { - return this.entityProcessors.getProcessor(); - }), - (e.prototype.addRenderer = function (t) { - return ( - this._renderers.push(t), - this._renderers.sort(), - t.onAddedToScene(this), - t - ); - }), - (e.prototype.getRenderer = function (t) { - for (var e = 0; e < this._renderers.length; e++) - if (this._renderers[e] instanceof t) return this._renderers[e]; - return null; - }), - (e.prototype.removeRenderer = function (t) { - this._renderers.remove(t), t.unload(); - }), - (e.prototype.begin = function () { - SceneManager.sceneTransition - ? SceneManager.stage.addChildAt( - this, - SceneManager.stage.numChildren - 1 - ) - : SceneManager.stage.addChild(this), - 0 == this._renderers.length && - (this.addRenderer(new DefaultRenderer()), - console.warn( - "场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染" - )), - (this.camera = this.createEntity("camera").getOrCreateComponent( - new Camera() - )), - Physics.reset(), - this.entityProcessors && this.entityProcessors.begin(), - this.camera.onSceneSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ), - (this._didSceneBegin = !0), - this.onStart(); - }), - (e.prototype.end = function () { - (this._didSceneBegin = !1), - this.removeEventListener( - egret.Event.DEACTIVATE, - this.onDeactive, - this - ), - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - for (var t = 0; t < this._renderers.length; t++) - this._renderers[t].unload(); - for (t = 0; t < this._postProcessors.length; t++) - this._postProcessors[t].unload(); - this.entities.removeAllEntities(), - this.removeChildren(), - Physics.clear(), - (this.camera = null), - this.content.dispose(), - this.entityProcessors && this.entityProcessors.end(), - this.unload(); - }), - (e.prototype.onStart = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (t) { - return [2]; - }); - }); - }), - (e.prototype.onActive = function () {}), - (e.prototype.onDeactive = function () {}), - (e.prototype.unload = function () {}), - (e.prototype.update = function () { - this.entities.updateLists(), - this.entityProcessors && this.entityProcessors.update(), - this.entities.update(), - this.entityProcessors && this.entityProcessors.lateUpdate(), - this.renderableComponents.updateList(); - }), - (e.prototype.postRender = function () { - var t = 0; - if (this.enablePostProcessing) - for (var e = 0; e < this._postProcessors.length; e++) - if (this._postProcessors[e].enable) { - MathHelper.isEven(t); - t++, this._postProcessors[e].process(); - } - }), - (e.prototype.render = function () { - for (var t = 0; t < this._renderers.length; t++) - this._renderers[t].render(this); - }), - (e.prototype.addPostProcessor = function (t) { - return ( - this._postProcessors.push(t), - this._postProcessors.sort(), - t.onAddedToScene(this), - this._didSceneBegin && - t.onSceneBackBufferSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ), - t - ); - }), - e - ); - })(egret.DisplayObjectContainer), - SceneManager = (function () { - function t(e) { - e.addEventListener(egret.Event.ENTER_FRAME, t.update, this), - (t.stage = e), - t.initialize(e); - } - return ( - Object.defineProperty(t, "scene", { - get: function () { - return this._scene; - }, - set: function (t) { - if (!t) throw new Error("场景不能为空"); - null == this._scene - ? ((this._scene = t), this._scene.begin()) - : (this._nextScene = t); - }, - enumerable: !0, - configurable: !0, - }), - (t.initialize = function (t) { - Input.initialize(t); - }), - (t.update = function () { - if ((Time.update(egret.getTimer()), t._scene)) { - for (var e = GlobalManager.globalManagers.length - 1; e >= 0; e--) - GlobalManager.globalManagers[e].enabled && - GlobalManager.globalManagers[e].update(); - if ( - ((t.sceneTransition && - (!t.sceneTransition || - (t.sceneTransition.loadsNewScene && - !t.sceneTransition.isNewSceneLoaded))) || - t._scene.update(), - t._nextScene) - ) { - t._scene.end(); - for (e = 0; e < t._scene.entities.buffer.length; e++) { - t._scene.entities.buffer[e].destroy(); - } - (t._scene = t._nextScene), (t._nextScene = null), t._scene.begin(); - } - } - t.render(); - }), - (t.render = function () { - this.sceneTransition - ? (this.sceneTransition.preRender(), - this._scene && !this.sceneTransition.hasPreviousSceneRender - ? (this._scene.render(), - this._scene.postRender(), - this.sceneTransition.onBeginTransition()) - : this.sceneTransition && - (this._scene && - this.sceneTransition.isNewSceneLoaded && - (this._scene.render(), this._scene.postRender()), - this.sceneTransition.render())) - : this._scene && (this._scene.render(), this._scene.postRender()); - }), - (t.startSceneTransition = function (t) { - if (!this.sceneTransition) return (this.sceneTransition = t), t; - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - }), - t - ); - })(); -!(function (t) { - (t[(t.clean = 0)] = "clean"), - (t[(t.positionDirty = 1)] = "positionDirty"), - (t[(t.scaleDirty = 2)] = "scaleDirty"), - (t[(t.rotationDirty = 3)] = "rotationDirty"); -})(DirtyType || (DirtyType = {})), - (function (t) { - (t[(t.position = 0)] = "position"), - (t[(t.scale = 1)] = "scale"), - (t[(t.rotation = 2)] = "rotation"); - })(ComponentTransform || (ComponentTransform = {})); -var CameraStyle, - Transform = (function () { - function t(t) { - (this._localRotation = 0), - (this._worldTransform = Matrix2D.identity), - (this._worldToLocalTransform = Matrix2D.identity), - (this._worldInverseTransform = Matrix2D.identity), - (this._rotation = 0), - (this.entity = t), - (this._scale = this._localScale = Vector2.one), - (this._children = []); - } - return ( - Object.defineProperty(t.prototype, "childCount", { - get: function () { - return this._children.length; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.getChild = function (t) { - return this._children[t]; - }), - Object.defineProperty(t.prototype, "worldInverseTransform", { - get: function () { - return ( - this.updateTransform(), - this._worldInverseDirty && - ((this._worldInverseTransform = Matrix2D.invert( - this._worldTransform, - this._worldInverseTransform - )), - (this._worldInverseDirty = !1)), - this._worldInverseTransform - ); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localToWorldTransform", { - get: function () { - return this.updateTransform(), this._worldTransform; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "worldToLocalTransform", { - get: function () { - return ( - this._worldToLocalDirty && - (this.parent - ? (this.parent.updateTransform(), - (this._worldToLocalTransform = Matrix2D.invert( - this.parent._worldTransform, - this._worldToLocalTransform - ))) - : (this._worldInverseTransform = new Matrix2D()), - (this._worldToLocalDirty = !1)), - this._worldToLocalTransform - ); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "parent", { - get: function () { - return this._parent; - }, - set: function (t) { - this.setParent(t); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.setParent = function (t) { - return this._parent == t - ? this - : (this._parent && this._parent._children.remove(this), - t && t._children.push(this), - (this._parent = t), - this); - }), - Object.defineProperty(t.prototype, "rotation", { - get: function () { - return this.updateTransform(), this._rotation; - }, - set: function (t) { - this.setRotation(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localRotation", { - get: function () { - return this.updateTransform(), this._localRotation; - }, - set: function (t) { - this.setLocalRotation(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "position", { - get: function () { - return ( - this.updateTransform(), - this._positionDirty && - (this.parent - ? (this.parent.updateTransform(), - (this._position = Vector2Ext.transformR( - this._localPosition, - this.parent._worldTransform - ))) - : (this._position = this._localPosition), - (this._positionDirty = !1)), - this._position - ); - }, - set: function (t) { - this.setPosition(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localPosition", { - get: function () { - return this.updateTransform(), this._localPosition; - }, - set: function (t) { - this.setLocalPosition(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "scale", { - get: function () { - return this.updateTransform(), this._scale; - }, - set: function (t) { - this.setScale(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localScale", { - get: function () { - return this.updateTransform(), this._localScale; - }, - set: function (t) { - this.setLocalScale(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._rotation); - }, - set: function (t) { - this.setRotation(MathHelper.toRadians(t)); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localRotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._localRotation); - }, - set: function (t) { - this.localRotation = MathHelper.toRadians(t); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.setLocalScale = function (t) { - return ( - (this._localScale = t), - (this._localDirty = this._positionDirty = this._localScaleDirty = !0), - this.setDirty(DirtyType.scaleDirty), - this - ); - }), - (t.prototype.setScale = function (t) { - return ( - (this._scale = t), - this.parent - ? (this.localScale = Vector2.divide(t, this.parent._scale)) - : (this.localScale = t), - this - ); - }), - (t.prototype.setLocalRotationDegrees = function (t) { - return this.setLocalRotation(MathHelper.toRadians(t)); - }), - (t.prototype.setLocalRotation = function (t) { - return ( - (this._localRotation = t), - (this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = !0), - this.setDirty(DirtyType.rotationDirty), - this - ); - }), - (t.prototype.setRotation = function (t) { - return ( - (this._rotation = t), - this.parent - ? (this.localRotation = this.parent.rotation + t) - : (this.localRotation = t), - this - ); - }), - (t.prototype.setRotationDegrees = function (t) { - return this.setRotation(MathHelper.toRadians(t)); - }), - (t.prototype.setLocalPosition = function (t) { - return t == this._localPosition - ? this - : ((this._localPosition = t), - (this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = !0), - this.setDirty(DirtyType.positionDirty), - this); - }), - (t.prototype.setPosition = function (t) { - return t == this._position - ? this - : ((this._position = t), - this.parent - ? (this.localPosition = Vector2.transform( - this._position, - this._worldToLocalTransform - )) - : (this.localPosition = t), - (this._positionDirty = !1), - this); - }), - (t.prototype.setDirty = function (t) { - if (0 == (this._hierachyDirty & t)) { - switch (((this._hierachyDirty |= t), t)) { - case DirtyType.positionDirty: - this.entity.onTransformChanged(ComponentTransform.position); - break; - case DirtyType.rotationDirty: - this.entity.onTransformChanged(ComponentTransform.rotation); - break; - case DirtyType.scaleDirty: - this.entity.onTransformChanged(ComponentTransform.scale); - } - null == this._children && (this._children = []); - for (var e = 0; e < this._children.length; e++) - this._children[e].setDirty(t); - } - }), - (t.prototype.roundPosition = function () { - this.position = this._position.round(); - }), - (t.prototype.updateTransform = function () { - this._hierachyDirty != DirtyType.clean && - (this.parent && this.parent.updateTransform(), - this._localDirty && - (this._localPositionDirty && - ((this._translationMatrix = Matrix2D.createTranslation( - this._localPosition.x, - this._localPosition.y - )), - (this._localPositionDirty = !1)), - this._localRotationDirty && - ((this._rotationMatrix = Matrix2D.createRotation( - this._localRotation - )), - (this._localRotationDirty = !1)), - this._localScaleDirty && - ((this._scaleMatrix = Matrix2D.createScale( - this._localScale.x, - this._localScale.y - )), - (this._localScaleDirty = !1)), - (this._localTransform = Matrix2D.multiply( - this._scaleMatrix, - this._rotationMatrix - )), - (this._localTransform = Matrix2D.multiply( - this._localTransform, - this._translationMatrix - )), - this.parent || - ((this._worldTransform = this._localTransform), - (this._rotation = this._localRotation), - (this._scale = this._localScale), - (this._worldInverseDirty = !0)), - (this._localDirty = !1)), - this.parent && - ((this._worldTransform = Matrix2D.multiply( - this._localTransform, - this.parent._worldTransform - )), - (this._rotation = this._localRotation + this.parent._rotation), - (this._scale = Vector2.multiply( - this.parent._scale, - this._localScale - )), - (this._worldInverseDirty = !0)), - (this._worldToLocalDirty = !0), - (this._positionDirty = !0), - (this._hierachyDirty = DirtyType.clean)); - }), - t - ); - })(), - Camera = (function (t) { - function e() { - var e = t.call(this) || this; - return ( - (e._origin = Vector2.zero), - (e._minimumZoom = 0.3), - (e._maximumZoom = 3), - (e.followLerp = 0.1), - (e.deadzone = new Rectangle()), - (e.focusOffset = new Vector2()), - (e.mapLockEnabled = !1), - (e.mapSize = new Vector2()), - (e._worldSpaceDeadZone = new Rectangle()), - (e._desiredPositionDelta = new Vector2()), - (e.cameraStyle = CameraStyle.lockOn), - (e.width = SceneManager.stage.stageWidth), - (e.height = SceneManager.stage.stageHeight), - e.setZoom(0), - e - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "zoom", { - get: function () { - return 0 == this._zoom - ? 1 - : this._zoom < 1 - ? MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0) - : MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); - }, - set: function (t) { - this.setZoom(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "minimumZoom", { - get: function () { - return this._minimumZoom; - }, - set: function (t) { - this.setMinimumZoom(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "maximumZoom", { - get: function () { - return this._maximumZoom; - }, - set: function (t) { - this.setMaximumZoom(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (t) { - this._origin != t && (this._origin = t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "position", { - get: function () { - return this.entity.position; - }, - set: function (t) { - this.entity.position = t; - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.onSceneSizeChanged = function (t, e) { - var n = this._origin; - (this.origin = new Vector2(t / 2, e / 2)), - (this.entity.position = Vector2.add( - this.entity.position, - Vector2.subtract(this._origin, n) - )); - }), - (e.prototype.setMinimumZoom = function (t) { - return ( - this._zoom < t && (this._zoom = this.minimumZoom), - (this._minimumZoom = t), - this - ); - }), - (e.prototype.setMaximumZoom = function (t) { - return ( - this._zoom > t && (this._zoom = t), (this._maximumZoom = t), this - ); - }), - (e.prototype.setZoom = function (t) { - var e = MathHelper.clamp(t, -1, 1); - return ( - (this._zoom = - 0 == e - ? 1 - : e < 0 - ? MathHelper.map(e, -1, 0, this._minimumZoom, 1) - : MathHelper.map(e, 0, 1, 1, this._maximumZoom)), - (SceneManager.scene.scaleX = this._zoom), - (SceneManager.scene.scaleY = this._zoom), - this - ); - }), - (e.prototype.setRotation = function (t) { - return (SceneManager.scene.rotation = t), this; - }), - (e.prototype.setPosition = function (t) { - return (this.entity.position = t), this; - }), - (e.prototype.follow = function (t, e) { - void 0 === e && (e = CameraStyle.cameraWindow), - (this.targetEntity = t), - (this.cameraStyle = e); - var n = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - switch (this.cameraStyle) { - case CameraStyle.cameraWindow: - var i = n.width / 6, - o = n.height / 3; - this.deadzone = new Rectangle( - (n.width - i) / 2, - (n.height - o) / 2, - i, - o - ); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle(n.width / 2, n.height / 2, 10, 10); - } - }), - (e.prototype.update = function () { - var t = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - e = Vector2.multiply( - new Vector2(t.width, t.height), - new Vector2(0.5) - ); - (this._worldSpaceDeadZone.x = - this.position.x - e.x + this.deadzone.x + this.focusOffset.x), - (this._worldSpaceDeadZone.y = - this.position.y - e.y + this.deadzone.y + this.focusOffset.y), - (this._worldSpaceDeadZone.width = this.deadzone.width), - (this._worldSpaceDeadZone.height = this.deadzone.height), - this.targetEntity && this.updateFollow(), - (this.position = Vector2.lerp( - this.position, - Vector2.add(this.position, this._desiredPositionDelta), - this.followLerp - )), - this.entity.roundPosition(), - this.mapLockEnabled && - ((this.position = this.clampToMapSize(this.position)), - this.entity.roundPosition()); - }), - (e.prototype.clampToMapSize = function (t) { - var e = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - n = Vector2.multiply( - new Vector2(e.width, e.height), - new Vector2(0.5) - ), - i = new Vector2(this.mapSize.x - n.x, this.mapSize.y - n.y); - return Vector2.clamp(t, n, i); - }), - (e.prototype.updateFollow = function () { - if ( - ((this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0), - this.cameraStyle == CameraStyle.lockOn) - ) { - var t = this.targetEntity.position.x, - e = this.targetEntity.position.y; - this._worldSpaceDeadZone.x > t - ? (this._desiredPositionDelta.x = t - this._worldSpaceDeadZone.x) - : this._worldSpaceDeadZone.x < t && - (this._desiredPositionDelta.x = t - this._worldSpaceDeadZone.x), - this._worldSpaceDeadZone.y < e - ? (this._desiredPositionDelta.y = e - this._worldSpaceDeadZone.y) - : this._worldSpaceDeadZone.y > e && - (this._desiredPositionDelta.y = e - this._worldSpaceDeadZone.y); - } else { - if ( - !this._targetCollider && - ((this._targetCollider = this.targetEntity.getComponent(Collider)), - !this._targetCollider) - ) - return; - var n = this.targetEntity.getComponent(Collider).bounds; - this._worldSpaceDeadZone.containsRect(n) || - (this._worldSpaceDeadZone.left > n.left - ? (this._desiredPositionDelta.x = - n.left - this._worldSpaceDeadZone.left) - : this._worldSpaceDeadZone.right < n.right && - (this._desiredPositionDelta.x = - n.right - this._worldSpaceDeadZone.right), - this._worldSpaceDeadZone.bottom < n.bottom - ? (this._desiredPositionDelta.y = - n.bottom - this._worldSpaceDeadZone.bottom) - : this._worldSpaceDeadZone.top > n.top && - (this._desiredPositionDelta.y = - n.top - this._worldSpaceDeadZone.top)); - } - }), - e - ); - })(Component); -!(function (t) { - (t[(t.lockOn = 0)] = "lockOn"), (t[(t.cameraWindow = 1)] = "cameraWindow"); -})(CameraStyle || (CameraStyle = {})); -var PointSectors, - ComponentPool = (function () { - function t(t) { - (this._type = t), (this._cache = []); - } - return ( - (t.prototype.obtain = function () { - try { - return this._cache.length > 0 - ? this._cache.shift() - : new this._type(); - } catch (t) { - throw new Error(this._type + t); - } - }), - (t.prototype.free = function (t) { - t.reset(), this._cache.push(t); - }), - t - ); - })(), - Mesh = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.initialize = function () {}), - (e.prototype.setVertPosition = function (t) { - (!this._verts || this._verts.length != t.length) && - (this._verts = new Array(t.length)); - for (var e = 0; e < this._verts.length; e++) - this._verts[e] = new VertexPosition(t[e]); - return this; - }), - (e.prototype.setTriangles = function (t) { - return ( - (this._primitiveCount = t.length / 3), (this._triangles = t), this - ); - }), - (e.prototype.recalculateBounds = function () { - this._topLeftVertPosition = new Vector2( - Number.MAX_VALUE, - Number.MAX_VALUE - ); - for ( - var t = new Vector2(Number.MIN_VALUE, Number.MIN_VALUE), e = 0; - e < this._verts.length; - e++ - ) - (this._topLeftVertPosition.x = Math.min( - this._topLeftVertPosition.x, - this._verts[e].position.x - )), - (this._topLeftVertPosition.y = Math.min( - this._topLeftVertPosition.y, - this._verts[e].position.y - )), - (t.x = Math.max(t.x, this._verts[e].position.x)), - (t.y = Math.max(t.y, this._verts[e].position.y)); - return ( - (this._width = t.x - this._topLeftVertPosition.x), - (this._height = t.y - this._topLeftVertPosition.y), - this - ); - }), - (e.prototype.render = function () {}), - e - ); - })(Component), - VertexPosition = (function () { - return function (t) { - this.position = t; - }; - })(), - PolygonMesh = (function (t) { - function e(e, n) { - void 0 === n && (n = !0); - var i = t.call(this) || this, - o = new Triangulator(); - return ( - o.triangulate(e, n), - i.setVertPosition(e), - i.setTriangles(o.triangleIndices), - i.recalculateBounds(), - i - ); - } - return __extends(e, t), e; - })(Mesh), - PooledComponent = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return __extends(e, t), e; - })(Component), - RenderableComponent = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return ( - (e._areBoundsDirty = !0), - (e._bounds = new Rectangle()), - (e._localOffset = Vector2.zero), - (e.color = 0), - e - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "width", { - get: function () { - return this.getWidth(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "height", { - get: function () { - return this.getHeight(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "isVisible", { - get: function () { - return this._isVisible; - }, - set: function (t) { - (this._isVisible = t), - this._isVisible ? this.onBecameVisible() : this.onBecameInvisible(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "bounds", { - get: function () { - return new Rectangle( - this.getBounds().x, - this.getBounds().y, - this.getBounds().width, - this.getBounds().height - ); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.getWidth = function () { - return this.bounds.width; - }), - (e.prototype.getHeight = function () { - return this.bounds.height; - }), - (e.prototype.onBecameVisible = function () {}), - (e.prototype.onBecameInvisible = function () {}), - (e.prototype.isVisibleFromCamera = function (t) { - return ( - (this.isVisible = t.getBounds().intersects(this.getBounds())), - this.isVisible - ); - }), - (e.prototype.onEntityTransformChanged = function (t) { - this._areBoundsDirty = !0; - }), - e - ); - })(PooledComponent), - ScreenSpaceCamera = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return __extends(e, t), (e.prototype.updateMatrixes = function () {}), e; - })(Camera), - Sprite = (function () { - return function (t, e, n) { - void 0 === e && - (e = new Rectangle(0, 0, t.textureWidth, t.textureHeight)), - void 0 === n && (n = e.getHalfSize()), - (this.uvs = new Rectangle()), - (this.texture2D = t), - (this.sourceRect = e), - (this.center = new Vector2(0.5 * e.width, 0.5 * e.height)), - (this.origin = n); - var i = 1 / t.textureWidth, - o = 1 / t.textureHeight; - (this.uvs.x = e.x * i), - (this.uvs.y = e.y * o), - (this.uvs.width = e.width * i), - (this.uvs.height = e.height * o); - }; - })(), - SpriteRenderer = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (t) { - this.setOrigin(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setOrigin = function (t) { - return this._origin != t && (this._origin = t), this; - }), - (e.prototype.setSprite = function (t) { - return ( - this.removeChildren(), - (this._sprite = t), - this._sprite && (this._origin = this._sprite.origin), - (this._bitmap = new egret.Bitmap(t.texture2D)), - this.addChild(this._bitmap), - this - ); - }), - (e.prototype.setColor = function (t) { - var e = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - (e[0] = Math.floor(t / 256 / 256) / 255), - (e[6] = Math.floor((t / 256) % 256) / 255), - (e[12] = (t % 256) / 255); - var n = new egret.ColorMatrixFilter(e); - return (this.filters = [n]), this; - }), - (e.prototype.isVisibleFromCamera = function (t) { - return ( - (this.isVisible = new Rectangle( - 0, - 0, - this.stage.stageWidth, - this.stage.stageHeight - ).intersects(this.bounds)), - (this.visible = this.isVisible), - this.isVisible - ); - }), - (e.prototype.render = function (t) { - (this.x = - this.entity.position.x - this.origin.x - t.position.x + t.origin.x), - (this.y = - this.entity.position.y - this.origin.y - t.position.y + t.origin.y); - }), - (e.prototype.onRemovedFromEntity = function () { - this.parent && this.parent.removeChild(this); - }), - (e.prototype.reset = function () {}), - e - ); - })(RenderableComponent), - Mover = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onAddedToEntity = function () { - this._triggerHelper = new ColliderTriggerHelper(this.entity); - }), - (e.prototype.calculateMovement = function (t) { - var e = new CollisionResult(); - if (!this.entity.getComponent(Collider) || !this._triggerHelper) - return null; - for ( - var n = this.entity.getComponents(Collider), i = 0; - i < n.length; - i++ - ) { - var o = n[i]; - if (!o.isTrigger) { - var r = o.bounds; - (r.x += t.x), (r.y += t.y); - for ( - var s = Physics.boxcastBroadphaseExcludingSelf( - o, - r, - o.collidesWithLayers - ), - a = 0; - a < s.length; - a++ - ) { - var h = s[a]; - if (!h.isTrigger) { - var c = o.collidesWith(h, t); - c && - ((t = Vector2.subtract(t, c.minimumTranslationVector)), - c.collider && (e = c)); - } - } - } - } - return ListPool.free(n), e; - }), - (e.prototype.applyMovement = function (t) { - (this.entity.position = Vector2.add(this.entity.position, t)), - this._triggerHelper && this._triggerHelper.update(); - }), - (e.prototype.move = function (t) { - var e = this.calculateMovement(t); - return this.applyMovement(t), e; - }), - e - ); - })(Component), - Collider = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return ( - (e.physicsLayer = 1), - (e.shouldColliderScaleAndRotationWithTransform = !0), - (e.collidesWithLayers = Physics.allLayers), - (e._isPositionDirty = !0), - (e._isRotationDirty = !0), - (e._localOffset = new Vector2(0, 0)), - e - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "bounds", { - get: function () { - return ( - (this._isPositionDirty || this._isRotationDirty) && - (this.shape.recalculateBounds(this), - (this._isPositionDirty = this._isRotationDirty = !1)), - this.shape.bounds - ); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "localOffset", { - get: function () { - return this._localOffset; - }, - set: function (t) { - this.setLocalOffset(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setLocalOffset = function (t) { - this._localOffset != t && - (this.unregisterColliderWithPhysicsSystem(), - (this._localOffset = t), - (this._localOffsetLength = this._localOffset.length()), - (this._isPositionDirty = !0), - this.registerColliderWithPhysicsSystem()); - }), - (e.prototype.registerColliderWithPhysicsSystem = function () { - this._isParentEntityAddedToScene && - !this._isColliderRegistered && - (Physics.addCollider(this), (this._isColliderRegistered = !0)); - }), - (e.prototype.unregisterColliderWithPhysicsSystem = function () { - this._isParentEntityAddedToScene && - this._isColliderRegistered && - Physics.removeCollider(this), - (this._isColliderRegistered = !1); - }), - (e.prototype.overlaps = function (t) { - return this.shape.overlaps(t.shape); - }), - (e.prototype.collidesWith = function (t, e) { - var n = this.shape.position; - this.shape.position = Vector2.add(this.shape.position, e); - var i = this.shape.collidesWithShape(t.shape); - return i && (i.collider = t), (this.shape.position = n), i; - }), - (e.prototype.onAddedToEntity = function () { - if (this._colliderRequiresAutoSizing) { - this instanceof BoxCollider || - console.error( - "Only box and circle colliders can be created automatically" - ); - var t = this.entity.getComponent(RenderableComponent); - if (t) { - var e = t.bounds, - n = e.width / this.entity.scale.x, - i = e.height / this.entity.scale.y; - if (this instanceof BoxCollider) { - (this.width = n), - (this.height = i), - (this.localOffset = Vector2.subtract( - e.center, - this.entity.position - )); - } - } - } - (this._isParentEntityAddedToScene = !0), - this.registerColliderWithPhysicsSystem(); - }), - (e.prototype.onRemovedFromEntity = function () { - this.unregisterColliderWithPhysicsSystem(), - (this._isParentEntityAddedToScene = !1); - }), - (e.prototype.onEntityTransformChanged = function (t) { - switch (t) { - case ComponentTransform.position: - case ComponentTransform.scale: - this._isPositionDirty = !0; - break; - case ComponentTransform.rotation: - this._isRotationDirty = !0; - } - this._isColliderRegistered && Physics.updateCollider(this); - }), - (e.prototype.onEnabled = function () { - this.registerColliderWithPhysicsSystem(), - (this._isPositionDirty = this._isRotationDirty = !0); - }), - (e.prototype.onDisabled = function () { - this.unregisterColliderWithPhysicsSystem(); - }), - e - ); - })(Component), - BoxCollider = (function (t) { - function e() { - var e = t.call(this) || this; - return (e.shape = new Box(1, 1)), (e._colliderRequiresAutoSizing = !0), e; - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "width", { - get: function () { - return this.shape.width; - }, - set: function (t) { - this.setWidth(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setWidth = function (t) { - this._colliderRequiresAutoSizing = !1; - var e = this.shape; - return ( - t != e.width && - (e.updateBox(t, e.height), - (this._isPositionDirty = !0), - this.entity && - this._isParentEntityAddedToScene && - Physics.updateCollider(this)), - this - ); - }), - Object.defineProperty(e.prototype, "height", { - get: function () { - return this.shape.height; - }, - set: function (t) { - this.setHeight(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setHeight = function (t) { - this._colliderRequiresAutoSizing = !1; - var e = this.shape; - t != e.height && - (e.updateBox(e.width, t), - (this._isPositionDirty = !0), - this.entity && - this._isParentEntityAddedToScene && - Physics.updateCollider(this)); - }), - (e.prototype.setSize = function (t, e) { - this._colliderRequiresAutoSizing = !1; - var n = this.shape; - return ( - (t == n.width && e == n.height) || - (n.updateBox(t, e), - (this._isPositionDirty = !0), - this.entity && - this._isParentEntityAddedToScene && - Physics.updateCollider(this)), - this - ); - }), - e - ); - })(Collider), - EntitySystem = (function () { - function t(t) { - (this._entities = []), (this._matcher = t || Matcher.empty()); - } - return ( - Object.defineProperty(t.prototype, "matcher", { - get: function () { - return this._matcher; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "scene", { - get: function () { - return this._scene; - }, - set: function (t) { - (this._scene = t), (this._entities = []); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.initialize = function () {}), - (t.prototype.onChanged = function (t) { - var e = this._entities.contains(t), - n = this._matcher.IsIntersted(t); - n && !e ? this.add(t) : !n && e && this.remove(t); - }), - (t.prototype.add = function (t) { - this._entities.push(t), this.onAdded(t); - }), - (t.prototype.onAdded = function (t) {}), - (t.prototype.remove = function (t) { - this._entities.remove(t), this.onRemoved(t); - }), - (t.prototype.onRemoved = function (t) {}), - (t.prototype.update = function () { - this.begin(), this.process(this._entities); - }), - (t.prototype.lateUpdate = function () { - this.lateProcess(this._entities), this.end(); - }), - (t.prototype.begin = function () {}), - (t.prototype.process = function (t) {}), - (t.prototype.lateProcess = function (t) {}), - (t.prototype.end = function () {}), - t - ); - })(), - EntityProcessingSystem = (function (t) { - function e(e) { - return t.call(this, e) || this; - } - return ( - __extends(e, t), - (e.prototype.lateProcessEntity = function (t) {}), - (e.prototype.process = function (t) { - var e = this; - t.forEach(function (t) { - return e.processEntity(t); - }); - }), - (e.prototype.lateProcess = function (t) { - var e = this; - t.forEach(function (t) { - return e.lateProcessEntity(t); - }); - }), - e - ); - })(EntitySystem), - PassiveSystem = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onChanged = function (t) {}), - (e.prototype.process = function (t) { - this.begin(), this.end(); - }), - e - ); - })(EntitySystem), - ProcessingSystem = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onChanged = function (t) {}), - (e.prototype.process = function (t) { - this.begin(), this.processSystem(), this.end(); - }), - e - ); - })(EntitySystem), - BitSet = (function () { - function t(e) { - void 0 === e && (e = 64); - var n = e >> 6; - 0 != (e & t.LONG_MASK) && n++, (this._bits = new Array(n)); - } - return ( - (t.prototype.and = function (t) { - for ( - var e, n = Math.min(this._bits.length, t._bits.length), i = 0; - i < n; - ++i - ) - this._bits[i] &= t._bits[i]; - for (; e < this._bits.length; ) this._bits[e++] = 0; - }), - (t.prototype.andNot = function (t) { - for (var e = Math.min(this._bits.length, t._bits.length); --e >= 0; ) - this._bits[e] &= ~t._bits[e]; - }), - (t.prototype.cardinality = function () { - for (var t = 0, e = this._bits.length - 1; e >= 0; e--) { - var n = this._bits[e]; - if (0 != n) - if (-1 != n) { - var i = - ((n = - (((n = - ((n >> 1) & 0x5555555555555400) + - (0x5555555555555400 & n)) >> - 2) & - 0x3333333333333400) + - (0x3333333333333400 & n)) >> - 32) + - n; - t += - (((i = - (((i = ((i >> 4) & 252645135) + (252645135 & i)) >> 8) & - 16711935) + - (16711935 & i)) >> - 16) & - 65535) + - (65535 & i); - } else t += 64; - } - return t; - }), - (t.prototype.clear = function (t) { - if (null != t) { - var e = t >> 6; - this.ensure(e), (this._bits[e] &= ~(1 << t)); - } else for (var n = 0; n < this._bits.length; n++) this._bits[n] = 0; - }), - (t.prototype.ensure = function (t) { - if (t >= this._bits.length) { - var e = new Number[t + 1](); - (e = this._bits.copyWithin(0, 0, this._bits.length)), - (this._bits = e); - } - }), - (t.prototype.get = function (t) { - var e = t >> 6; - return !(e >= this._bits.length) && 0 != (this._bits[e] & (1 << t)); - }), - (t.prototype.intersects = function (t) { - for (var e = Math.min(this._bits.length, t._bits.length); --e >= 0; ) - if (0 != (this._bits[e] & t._bits[e])) return !0; - return !1; - }), - (t.prototype.isEmpty = function () { - for (var t = this._bits.length - 1; t >= 0; t--) - if (this._bits[t]) return !1; - return !0; - }), - (t.prototype.nextSetBit = function (t) { - for (var e = t >> 6, n = 1 << t; e < this._bits.length; ) { - var i = this._bits[e]; - do { - if (0 != (i & n)) return t; - (n <<= 1), t++; - } while (0 != n); - (n = 1), e++; - } - return -1; - }), - (t.prototype.set = function (t, e) { - if ((void 0 === e && (e = !0), e)) { - var n = t >> 6; - this.ensure(n), (this._bits[n] |= 1 << t); - } else this.clear(t); - }), - (t.LONG_MASK = 63), - t - ); - })(), - ComponentList = (function () { - function t(t) { - (this._components = []), - (this._componentsToAdd = []), - (this._componentsToRemove = []), - (this._tempBufferList = []), - (this._entity = t); - } - return ( - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.add = function (t) { - this._componentsToAdd.push(t); - }), - (t.prototype.remove = function (t) { - this._componentsToAdd.contains(t) - ? this._componentsToAdd.remove(t) - : this._componentsToRemove.push(t); - }), - (t.prototype.removeAllComponents = function () { - for (var t = 0; t < this._components.length; t++) - this.handleRemove(this._components[t]); - (this._components.length = 0), - (this._componentsToAdd.length = 0), - (this._componentsToRemove.length = 0); - }), - (t.prototype.deregisterAllComponents = function () { - for (var t = 0; t < this._components.length; t++) { - var e = this._components[t]; - e instanceof RenderableComponent && - this._entity.scene.renderableComponents.remove(e), - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(e), - !1 - ), - this._entity.scene.entityProcessors.onComponentRemoved( - this._entity - ); - } - }), - (t.prototype.registerAllComponents = function () { - for (var t = 0; t < this._components.length; t++) { - var e = this._components[t]; - e instanceof RenderableComponent && - this._entity.scene.renderableComponents.add(e), - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(e)), - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - } - }), - (t.prototype.updateLists = function () { - if (this._componentsToRemove.length > 0) { - for (var t = 0; t < this._componentsToRemove.length; t++) - this.handleRemove(this._componentsToRemove[t]), - this._components.remove(this._componentsToRemove[t]); - this._componentsToRemove.length = 0; - } - if (this._componentsToAdd.length > 0) { - t = 0; - for (var e = this._componentsToAdd.length; t < e; t++) { - (n = this._componentsToAdd[t]) instanceof RenderableComponent && - this._entity.scene.renderableComponents.add(n), - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(n) - ), - this._entity.scene.entityProcessors.onComponentAdded( - this._entity - ), - this._components.push(n), - this._tempBufferList.push(n); - } - this._componentsToAdd.length = 0; - for (t = 0; t < this._tempBufferList.length; t++) { - var n; - (n = this._tempBufferList[t]).onAddedToEntity(), - n.enabled && n.onEnabled(); - } - this._tempBufferList.length = 0; - } - }), - (t.prototype.handleRemove = function (t) { - t instanceof RenderableComponent && - this._entity.scene.renderableComponents.remove(t), - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(t), - !1 - ), - this._entity.scene.entityProcessors.onComponentRemoved(this._entity), - t.onRemovedFromEntity(), - (t.entity = null); - }), - (t.prototype.getComponent = function (t, e) { - for (var n = 0; n < this._components.length; n++) { - if ((i = this._components[n]) instanceof t) return i; - } - if (!e) - for (n = 0; n < this._componentsToAdd.length; n++) { - var i; - if ((i = this._componentsToAdd[n]) instanceof t) return i; - } - return null; - }), - (t.prototype.getComponents = function (t, e) { - e || (e = []); - for (var n = 0; n < this._components.length; n++) { - var i = this._components[n]; - "string" == typeof t - ? egret.is(i, t) && e.push(i) - : i instanceof t && e.push(i); - } - for (n = 0; n < this._componentsToAdd.length; n++) { - i = this._componentsToAdd[n]; - "string" == typeof t - ? egret.is(i, t) && e.push(i) - : i instanceof t && e.push(i); - } - return e; - }), - (t.prototype.update = function () { - this.updateLists(); - for (var t = 0; t < this._components.length; t++) { - var e = this._components[t]; - !e.enabled || - (1 != e.updateInterval && - Time.frameCount % e.updateInterval != 0) || - e.update(); - } - }), - (t.prototype.onEntityTransformChanged = function (t) { - for (var e = 0; e < this._components.length; e++) - this._components[e].enabled && - this._components[e].onEntityTransformChanged(t); - for (e = 0; e < this._componentsToAdd.length; e++) - this._componentsToAdd[e].enabled && - this._componentsToAdd[e].onEntityTransformChanged(t); - }), - t - ); - })(), - ComponentTypeManager = (function () { - function t() {} - return ( - (t.add = function (t) { - this._componentTypesMask.has(t) || - (this._componentTypesMask[t] = this._componentTypesMask.size); - }), - (t.getIndexFor = function (t) { - var e = -1; - return ( - this._componentTypesMask.has(t) || - (this.add(t), (e = this._componentTypesMask.get(t))), - e - ); - }), - (t._componentTypesMask = new Map()), - t - ); - })(), - EntityList = (function () { - function t(t) { - (this._entitiesToRemove = []), - (this._entitiesToAdded = []), - (this._tempEntityList = []), - (this._entities = []), - (this._entityDict = new Map()), - (this._unsortedTags = []), - (this.scene = t); - } - return ( - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._entities.length; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "buffer", { - get: function () { - return this._entities; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.add = function (t) { - -1 == this._entitiesToAdded.indexOf(t) && this._entitiesToAdded.push(t); - }), - (t.prototype.remove = function (t) { - this._entitiesToAdded.contains(t) - ? this._entitiesToAdded.remove(t) - : this._entitiesToRemove.contains(t) || - this._entitiesToRemove.push(t); - }), - (t.prototype.findEntity = function (t) { - for (var e = 0; e < this._entities.length; e++) - if (this._entities[e].name == t) return this._entities[e]; - return this._entitiesToAdded.firstOrDefault(function (e) { - return e.name == t; - }); - }), - (t.prototype.getTagList = function (t) { - var e = this._entityDict.get(t); - return ( - e || ((e = []), this._entityDict.set(t, e)), this._entityDict.get(t) - ); - }), - (t.prototype.addToTagList = function (t) { - var e = this.getTagList(t.tag); - e.contains(t) || (e.push(t), this._unsortedTags.push(t.tag)); - }), - (t.prototype.removeFromTagList = function (t) { - var e = this._entityDict.get(t.tag); - e && e.remove(t); - }), - (t.prototype.update = function () { - for (var t = 0; t < this._entities.length; t++) { - var e = this._entities[t]; - e.enabled && e.update(); - } - }), - (t.prototype.removeAllEntities = function () { - (this._entitiesToAdded.length = 0), this.updateLists(); - for (var t = 0; t < this._entities.length; t++) - (this._entities[t]._isDestoryed = !0), - this._entities[t].onRemovedFromScene(), - (this._entities[t].scene = null); - (this._entities.length = 0), this._entityDict.clear(); - }), - (t.prototype.updateLists = function () { - var t = this; - if (this._entitiesToRemove.length > 0) { - var e = this._entitiesToRemove; - (this._entitiesToRemove = this._tempEntityList), - (this._tempEntityList = e), - this._tempEntityList.forEach(function (e) { - t._entities.remove(e), - (e.scene = null), - t.scene.entityProcessors.onEntityRemoved(e); - }), - (this._tempEntityList.length = 0); - } - if (this._entitiesToAdded.length > 0) { - e = this._entitiesToAdded; - (this._entitiesToAdded = this._tempEntityList), - (this._tempEntityList = e), - this._tempEntityList.forEach(function (e) { - t._entities.contains(e) || - (t._entities.push(e), - (e.scene = t.scene), - t.scene.entityProcessors.onEntityAdded(e)); - }), - this._tempEntityList.forEach(function (t) { - return t.onAddedToScene(); - }), - (this._tempEntityList.length = 0); - } - this._unsortedTags.length > 0 && - (this._unsortedTags.forEach(function (e) { - t._entityDict.get(e).sort(); - }), - (this._unsortedTags.length = 0)); - }), - t - ); - })(), - EntityProcessorList = (function () { - function t() { - this._processors = []; - } - return ( - (t.prototype.add = function (t) { - this._processors.push(t); - }), - (t.prototype.remove = function (t) { - this._processors.remove(t); - }), - (t.prototype.onComponentAdded = function (t) { - this.notifyEntityChanged(t); - }), - (t.prototype.onComponentRemoved = function (t) { - this.notifyEntityChanged(t); - }), - (t.prototype.onEntityAdded = function (t) { - this.notifyEntityChanged(t); - }), - (t.prototype.onEntityRemoved = function (t) { - this.removeFromProcessors(t); - }), - (t.prototype.notifyEntityChanged = function (t) { - for (var e = 0; e < this._processors.length; e++) - this._processors[e].onChanged(t); - }), - (t.prototype.removeFromProcessors = function (t) { - for (var e = 0; e < this._processors.length; e++) - this._processors[e].remove(t); - }), - (t.prototype.begin = function () {}), - (t.prototype.update = function () { - for (var t = 0; t < this._processors.length; t++) - this._processors[t].update(); - }), - (t.prototype.lateUpdate = function () { - for (var t = 0; t < this._processors.length; t++) - this._processors[t].lateUpdate(); - }), - (t.prototype.end = function () {}), - (t.prototype.getProcessor = function () { - for (var t = 0; t < this._processors.length; t++) { - var e = this._processors[t]; - if (e instanceof EntitySystem) return e; - } - return null; - }), - t - ); - })(), - Matcher = (function () { - function t() { - (this.allSet = new BitSet()), - (this.exclusionSet = new BitSet()), - (this.oneSet = new BitSet()); - } - return ( - (t.empty = function () { - return new t(); - }), - (t.prototype.getAllSet = function () { - return this.allSet; - }), - (t.prototype.getExclusionSet = function () { - return this.exclusionSet; - }), - (t.prototype.getOneSet = function () { - return this.oneSet; - }), - (t.prototype.IsIntersted = function (t) { - if (!this.allSet.isEmpty()) - for ( - var e = this.allSet.nextSetBit(0); - e >= 0; - e = this.allSet.nextSetBit(e + 1) - ) - if (!t.componentBits.get(e)) return !1; - return ( - !( - !this.exclusionSet.isEmpty() && - this.exclusionSet.intersects(t.componentBits) - ) && - !(!this.oneSet.isEmpty() && !this.oneSet.intersects(t.componentBits)) - ); - }), - (t.prototype.all = function () { - for (var t = this, e = [], n = 0; n < arguments.length; n++) - e[n] = arguments[n]; - return ( - e.forEach(function (e) { - t.allSet.set(ComponentTypeManager.getIndexFor(e)); - }), - this - ); - }), - (t.prototype.exclude = function () { - for (var t = this, e = [], n = 0; n < arguments.length; n++) - e[n] = arguments[n]; - return ( - e.forEach(function (e) { - t.exclusionSet.set(ComponentTypeManager.getIndexFor(e)); - }), - this - ); - }), - (t.prototype.one = function () { - for (var t = this, e = [], n = 0; n < arguments.length; n++) - e[n] = arguments[n]; - return ( - e.forEach(function (e) { - t.oneSet.set(ComponentTypeManager.getIndexFor(e)); - }), - this - ); - }), - t - ); - })(), - RenderableComponentList = (function () { - function t() { - this._components = []; - } - return ( - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.add = function (t) { - this._components.push(t); - }), - (t.prototype.remove = function (t) { - this._components.remove(t); - }), - (t.prototype.updateList = function () {}), - t - ); - })(), - Time = (function () { - function t() {} - return ( - (t.update = function (t) { - var e = (t - this._lastTime) / 1e3; - (this.deltaTime = e * this.timeScale), - (this.unscaledDeltaTime = e), - this.frameCount++, - (this._lastTime = t); - }), - (t.deltaTime = 0), - (t.timeScale = 1), - (t.frameCount = 0), - (t._lastTime = 0), - t - ); - })(), - GraphicsCapabilities = (function () { - function t() {} - return ( - (t.prototype.initialize = function (t) { - this.platformInitialize(t); - }), - (t.prototype.platformInitialize = function (t) { - var e = new egret.sys.RenderBuffer().context.getInstance(); - (this.supportsNonPowerOfTwo = !1), - (this.supportsTextureFilterAnisotropic = - null != e.getExtension("EXT_texture_filter_anisotropic")), - (this.supportsDepth24 = !0), - (this.supportsPackedDepthStencil = !0), - (this.supportsDepthNonLinear = !1), - (this.supportsTextureMaxLevel = !0), - (this.supportsS3tc = - null != e.getExtension("WEBGL_compressed_texture_s3tc") || - null != e.getExtension("WEBGL_compressed_texture_s3tc_srgb")), - (this.supportsDxt1 = this.supportsS3tc), - (this.supportsPvrtc = !1), - (this.supportsAtitc = - null != e.getExtension("WEBGL_compressed_texture_astc")), - (this.supportsFramebufferObjectARB = !1); - }), - t - ); - })(), - GraphicsDevice = (function () { - return function () { - (this.graphicsCapabilities = new GraphicsCapabilities()), - this.graphicsCapabilities.initialize(this); - }; - })(), - Viewport = (function () { - function t(t, e, n, i) { - (this._x = t), - (this._y = e), - (this._width = n), - (this._height = i), - (this._minDepth = 0), - (this._maxDepth = 1); - } - return ( - Object.defineProperty(t.prototype, "aspectRatio", { - get: function () { - return 0 != this._height && 0 != this._width - ? this._width / this._height - : 0; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "bounds", { - get: function () { - return new Rectangle(this._x, this._y, this._width, this._height); - }, - set: function (t) { - (this._x = t.x), - (this._y = t.y), - (this._width = t.width), - (this._height = t.height); - }, - enumerable: !0, - configurable: !0, - }), - t - ); - })(), - GraphicsResource = (function () { - return function () {}; - })(), - GaussianBlurEffect = (function (t) { - function e() { - return ( - t.call(this, PostProcessor.default_vert, e.blur_frag, { - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight, - }) || this - ); - } - return ( - __extends(e, t), - (e.blur_frag = - "precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}"), - e - ); - })(egret.CustomFilter), - PolygonLightEffect = (function (t) { - function e() { - return t.call(this, e.vertSrc, e.fragmentSrc) || this; - } - return ( - __extends(e, t), - (e.vertSrc = - "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}"), - (e.fragmentSrc = - "precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}"), - e - ); - })(egret.CustomFilter), - PostProcessor = (function () { - function t(t) { - void 0 === t && (t = null), (this.enable = !0), (this.effect = t); - } - return ( - (t.prototype.onAddedToScene = function (t) { - (this.scene = t), - (this.shape = new egret.Shape()), - this.shape.graphics.beginFill(16777215, 1), - this.shape.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - this.shape.graphics.endFill(), - t.addChild(this.shape); - }), - (t.prototype.process = function () { - this.drawFullscreenQuad(); - }), - (t.prototype.onSceneBackBufferSizeChanged = function (t, e) {}), - (t.prototype.drawFullscreenQuad = function () { - this.scene.filters = [this.effect]; - }), - (t.prototype.unload = function () { - this.effect && (this.effect = null), - this.scene.removeChild(this.shape), - (this.scene = null); - }), - (t.default_vert = - "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}"), - t - ); - })(), - BloomSettings = (function () { - function t(t, e, n, i, o, r) { - (this.threshold = t), - (this.blurAmount = e), - (this.intensity = n), - (this.baseIntensity = i), - (this.saturation = o), - (this.baseStaturation = r); - } - return ( - (t.presetSettings = [ - new t(0.1, 0.6, 2, 1, 1, 0), - new t(0, 3, 1, 1, 1, 1), - new t(0.5, 8, 2, 1, 0, 1), - new t(0.25, 8, 1.3, 1, 1, 0), - new t(0, 2, 1, 0.1, 1, 1), - new t(0.5, 2, 1, 1, 1, 1), - ]), - t - ); - })(), - GaussianBlurPostProcessor = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onAddedToScene = function (e) { - t.prototype.onAddedToScene.call(this, e), - (this.effect = new GaussianBlurEffect()); - }), - e - ); - })(PostProcessor), - Renderer = (function () { - function t() {} - return ( - (t.prototype.onAddedToScene = function (t) {}), - (t.prototype.beginRender = function (t) {}), - (t.prototype.unload = function () {}), - (t.prototype.renderAfterStateCheck = function (t, e) { - t.render(e); - }), - t - ); - })(), - DefaultRenderer = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.render = function (t) { - var e = this.camera ? this.camera : t.camera; - this.beginRender(e); - for (var n = 0; n < t.renderableComponents.count; n++) { - var i = t.renderableComponents.buffer[n]; - i.enabled && - i.isVisibleFromCamera(e) && - this.renderAfterStateCheck(i, e); - } - }), - e - ); - })(Renderer), - ScreenSpaceRenderer = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return __extends(e, t), (e.prototype.render = function (t) {}), e; - })(Renderer), - PolyLight = (function (t) { - function e(e, n, i) { - var o = t.call(this) || this; - return ( - (o._indices = []), - (o.radius = e), - (o.power = i), - (o.color = n), - o.computeTriangleIndices(), - o - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "radius", { - get: function () { - return this._radius; - }, - set: function (t) { - this.setRadius(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.computeTriangleIndices = function (t) { - void 0 === t && (t = 20), (this._indices.length = 0); - for (var e = 0; e < t; e += 2) - this._indices.push(0), - this._indices.push(e + 2), - this._indices.push(e + 1); - }), - (e.prototype.setRadius = function (t) { - t != this._radius && ((this._radius = t), (this._areBoundsDirty = !0)); - }), - (e.prototype.render = function (t) {}), - (e.prototype.reset = function () {}), - e - ); - })(RenderableComponent), - SceneTransition = (function () { - function t(t) { - (this.sceneLoadAction = t), (this.loadsNewScene = null != t); - } - return ( - Object.defineProperty(t.prototype, "hasPreviousSceneRender", { - get: function () { - return ( - !!this._hasPreviousSceneRender || - ((this._hasPreviousSceneRender = !0), !1) - ); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.preRender = function () {}), - (t.prototype.render = function () {}), - (t.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (t) { - switch (t.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - return t.sent(), this.transitionComplete(), [2]; - } - }); - }); - }), - (t.prototype.transitionComplete = function () { - (SceneManager.sceneTransition = null), - this.onTransitionCompleted && this.onTransitionCompleted(); - }), - (t.prototype.loadNextScene = function () { - return __awaiter(this, void 0, void 0, function () { - var t; - return __generator(this, function (e) { - switch (e.label) { - case 0: - return ( - this.onScreenObscured && this.onScreenObscured(), - this.loadsNewScene || (this.isNewSceneLoaded = !0), - (t = SceneManager), - [4, this.sceneLoadAction()] - ); - case 1: - return (t.scene = e.sent()), (this.isNewSceneLoaded = !0), [2]; - } - }); - }); - }), - (t.prototype.tickEffectProgressProperty = function (t, e, n, i) { - return ( - void 0 === i && (i = !1), - new Promise(function (o) { - var r = i ? 1 : 0, - s = i ? 0 : 1; - egret.Tween.get(t.uniforms) - .set({ _progress: r }) - .to({ _progress: s }, 1e3 * e, n) - .call(function () { - o(); - }); - }) - ); - }), - t - ); - })(), - FadeTransition = (function (t) { - function e(e) { - var n = t.call(this, e) || this; - return ( - (n.fadeToColor = 0), - (n.fadeOutDuration = 0.4), - (n.fadeEaseType = egret.Ease.quadInOut), - (n.delayBeforeFadeInDuration = 0.1), - (n._alpha = 0), - (n._mask = new egret.Shape()), - n - ); - } - return ( - __extends(e, t), - (e.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - var t = this; - return __generator(this, function (e) { - return ( - this._mask.graphics.beginFill(this.fadeToColor, 1), - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - this._mask.graphics.endFill(), - SceneManager.stage.addChild(this._mask), - egret.Tween.get(this) - .to( - { _alpha: 1 }, - 1e3 * this.fadeOutDuration, - this.fadeEaseType - ) - .call(function () { - return __awaiter(t, void 0, void 0, function () { - return __generator(this, function (t) { - switch (t.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - return t.sent(), [2]; - } - }); - }); - }) - .wait(this.delayBeforeFadeInDuration) - .call(function () { - egret.Tween.get(t) - .to({ _alpha: 0 }, 1e3 * t.fadeOutDuration, t.fadeEaseType) - .call(function () { - t.transitionComplete(), - SceneManager.stage.removeChild(t._mask); - }); - }), - [2] - ); - }); - }); - }), - (e.prototype.render = function () { - this._mask.graphics.clear(), - this._mask.graphics.beginFill(this.fadeToColor, this._alpha), - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - this._mask.graphics.endFill(); - }), - e - ); - })(SceneTransition), - WindTransition = (function (t) { - function e(e) { - var n = t.call(this, e) || this; - (n.duration = 1), (n.easeType = egret.Ease.quadOut); - return ( - (n._windEffect = new egret.CustomFilter( - "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}", - "precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float _progress;\nuniform float _size;\nuniform float _windSegments;\nvoid main(void) {\nvec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\nfloat x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\nfloat r = x - floor(x);\nfloat m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\nvec4 fg = texture2D(uSampler, vTextureCoord);\ngl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n}", - { _progress: 0, _size: 0.3, _windSegments: 100 } - )), - (n._mask = new egret.Shape()), - n._mask.graphics.beginFill(16777215, 1), - n._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - n._mask.graphics.endFill(), - (n._mask.filters = [n._windEffect]), - SceneManager.stage.addChild(n._mask), - n - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "windSegments", { - set: function (t) { - this._windEffect.uniforms._windSegments = t; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "size", { - set: function (t) { - this._windEffect.uniforms._size = t; - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (t) { - switch (t.label) { - case 0: - return ( - this.loadNextScene(), - [ - 4, - this.tickEffectProgressProperty( - this._windEffect, - this.duration, - this.easeType - ), - ] - ); - case 1: - return ( - t.sent(), - this.transitionComplete(), - SceneManager.stage.removeChild(this._mask), - [2] - ); - } - }); - }); - }), - e - ); - })(SceneTransition), - BaseView = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.init = function () {}), - (e.prototype.show = function (t) {}), - (e.prototype.refreshData = function (t) { - this._data = t; - }), - (e.prototype.refreshView = function () {}), - (e.prototype.close = function () {}), - (e.prototype.destroy = function () { - for ( - this.parent && this.parent.removeChild(this); - this.numChildren > 0; - - ) - this.removeChildAt(0); - }), - e - ); - })(egret.DisplayObjectContainer), - BaseFuiView = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.name = e), n; - } - return __extends(e, t), e; - })(BaseView), - BaseSingle = (function () { - function t() {} - return ( - (t.getInstance = function () { - return ( - null == this._instance && (this._instance = new this()), - this._instance - ); - }), - (t.prototype.clearFuiObj = function (t) { - return ( - !!t && - (egret.Tween.removeTweens(t.displayObject), - t.displayObject && - t.displayObject.parent && - t.displayObject.parent.removeChild(t.displayObject), - t.dispose(), - (t = null), - !0) - ); - }), - t - ); - })(), - ViewManager = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return (e._openDic = []), e; - } - return ( - __extends(e, t), - (e.prototype.refreshView = function (t, e) { - var n = this.getView(t); - n && (n.refreshData(e), n.refreshView()); - }), - (e.prototype.openView = function (t, e, n) { - var i = this.getView(t); - if ((i || (i = new t()), this.existView(t))) - return i.refreshData(e), void i.refreshView(); - this._openDic.push(i); - }), - (e.prototype.getView = function (t) { - return this._openDic.firstOrDefault(function (e) { - return e instanceof t; - }); - }), - (e.prototype.existView = function (t) { - return ( - -1 != - this._openDic.findIndex(function (e) { - return e instanceof t; - }) - ); - }), - e - ); - })(BaseSingle), - Flags = (function () { - function t() {} - return ( - (t.isFlagSet = function (t, e) { - return 0 != (t & e); - }), - (t.isUnshiftedFlagSet = function (t, e) { - return 0 != (t & (e = 1 << e)); - }), - (t.setFlagExclusive = function (t, e) { - return 1 << e; - }), - (t.setFlag = function (t, e) { - return t | (1 << e); - }), - (t.unsetFlag = function (t, e) { - return t & ~(e = 1 << e); - }), - (t.invertFlags = function (t) { - return ~t; - }), - t - ); - })(), - MathHelper = (function () { - function t() {} - return ( - (t.toDegrees = function (t) { - return 57.29577951308232 * t; - }), - (t.toRadians = function (t) { - return 0.017453292519943295 * t; - }), - (t.map = function (t, e, n, i, o) { - return i + ((t - e) * (o - i)) / (n - e); - }), - (t.lerp = function (t, e, n) { - return t + (e - t) * n; - }), - (t.clamp = function (t, e, n) { - return t < e ? e : t > n ? n : t; - }), - (t.pointOnCirlce = function (e, n, i) { - var o = t.toRadians(i); - return new Vector2(Math.cos(o) * o + e.x, Math.sin(o) * o + e.y); - }), - (t.isEven = function (t) { - return t % 2 == 0; - }), - (t.Epsilon = 1e-5), - (t.Rad2Deg = 57.29578), - (t.Deg2Rad = 0.0174532924), - t - ); - })(), - Matrix2D = (function () { - function t(t, e, n, i, o, r) { - (this.m11 = 0), - (this.m12 = 0), - (this.m21 = 0), - (this.m22 = 0), - (this.m31 = 0), - (this.m32 = 0), - (this.m11 = t || 1), - (this.m12 = e || 0), - (this.m21 = n || 0), - (this.m22 = i || 1), - (this.m31 = o || 0), - (this.m32 = r || 0); - } - return ( - Object.defineProperty(t, "identity", { - get: function () { - return t._identity; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "translation", { - get: function () { - return new Vector2(this.m31, this.m32); - }, - set: function (t) { - (this.m31 = t.x), (this.m32 = t.y); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "rotation", { - get: function () { - return Math.atan2(this.m21, this.m11); - }, - set: function (t) { - var e = Math.cos(t), - n = Math.sin(t); - (this.m11 = e), (this.m12 = n), (this.m21 = -n), (this.m22 = e); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this.rotation); - }, - set: function (t) { - this.rotation = MathHelper.toRadians(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "scale", { - get: function () { - return new Vector2(this.m11, this.m22); - }, - set: function (t) { - (this.m11 = t.x), (this.m12 = t.y); - }, - enumerable: !0, - configurable: !0, - }), - (t.add = function (t, e) { - return ( - (t.m11 += e.m11), - (t.m12 += e.m12), - (t.m21 += e.m21), - (t.m22 += e.m22), - (t.m31 += e.m31), - (t.m32 += e.m32), - t - ); - }), - (t.divide = function (t, e) { - return ( - (t.m11 /= e.m11), - (t.m12 /= e.m12), - (t.m21 /= e.m21), - (t.m22 /= e.m22), - (t.m31 /= e.m31), - (t.m32 /= e.m32), - t - ); - }), - (t.multiply = function (e, n) { - var i = new t(), - o = e.m11 * n.m11 + e.m12 * n.m21, - r = e.m11 * n.m12 + e.m12 * n.m22, - s = e.m21 * n.m11 + e.m22 * n.m21, - a = e.m21 * n.m12 + e.m22 * n.m22, - h = e.m31 * n.m11 + e.m32 * n.m21 + n.m31, - c = e.m31 * n.m12 + e.m32 * n.m22 + n.m32; - return ( - (i.m11 = o), - (i.m12 = r), - (i.m21 = s), - (i.m22 = a), - (i.m31 = h), - (i.m32 = c), - i - ); - }), - (t.multiplyTranslation = function (e, n, i) { - var o = t.createTranslation(n, i); - return t.multiply(e, o); - }), - (t.prototype.determinant = function () { - return this.m11 * this.m22 - this.m12 * this.m21; - }), - (t.invert = function (e, n) { - void 0 === n && (n = new t()); - var i = 1 / e.determinant(); - return ( - (n.m11 = e.m22 * i), - (n.m12 = -e.m12 * i), - (n.m21 = -e.m21 * i), - (n.m22 = e.m11 * i), - (n.m31 = (e.m32 * e.m21 - e.m31 * e.m22) * i), - (n.m32 = -(e.m32 * e.m11 - e.m31 * e.m12) * i), - n - ); - }), - (t.createTranslation = function (e, n, i) { - return ( - ((i = i || new t()).m11 = 1), - (i.m12 = 0), - (i.m21 = 0), - (i.m22 = 1), - (i.m31 = e), - (i.m32 = n), - i - ); - }), - (t.createRotation = function (e, n) { - n = new t(); - var i = Math.cos(e), - o = Math.sin(e); - return (n.m11 = i), (n.m12 = o), (n.m21 = -o), (n.m22 = i), n; - }), - (t.createScale = function (e, n, i) { - return ( - void 0 === i && (i = new t()), - (i.m11 = e), - (i.m12 = 0), - (i.m21 = 0), - (i.m22 = n), - (i.m31 = 0), - (i.m32 = 0), - i - ); - }), - (t.prototype.toEgretMatrix = function () { - return new egret.Matrix( - this.m11, - this.m12, - this.m21, - this.m22, - this.m31, - this.m32 - ); - }), - (t._identity = new t(1, 0, 0, 1, 0, 0)), - t - ); - })(), - Rectangle = (function () { - function t(t, e, n, i) { - (this.x = t || 0), - (this.y = e || 0), - (this.width = n || 0), - (this.height = i || 0); - } - return ( - Object.defineProperty(t.prototype, "left", { - get: function () { - return this.x; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "right", { - get: function () { - return this.x + this.width; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "top", { - get: function () { - return this.y; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "bottom", { - get: function () { - return this.y + this.height; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "center", { - get: function () { - return new Vector2(this.x + this.width / 2, this.y + this.height / 2); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "location", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (t) { - (this.x = t.x), (this.y = t.y); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "size", { - get: function () { - return new Vector2(this.width, this.height); - }, - set: function (t) { - (this.width = t.x), (this.height = t.y); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.intersects = function (t) { - return ( - t.left < this.right && - this.left < t.right && - t.top < this.bottom && - this.top < t.bottom - ); - }), - (t.prototype.contains = function (t) { - return ( - this.x <= t.x && - t.x < this.x + this.width && - this.y <= t.y && - t.y < this.y + this.height - ); - }), - (t.prototype.containsRect = function (t) { - return ( - this.x <= t.x && - t.x < this.x + this.width && - this.y <= t.y && - t.y < this.y + this.height - ); - }), - (t.prototype.getHalfSize = function () { - return new Vector2(0.5 * this.width, 0.5 * this.height); - }), - (t.fromMinMax = function (e, n, i, o) { - return new t(e, n, i - e, o - n); - }), - (t.prototype.getClosestPointOnRectangleBorderToPoint = function (t) { - var e = new Vector2(0, 0), - n = new Vector2(0, 0); - if ( - ((n.x = MathHelper.clamp(t.x, this.left, this.right)), - (n.y = MathHelper.clamp(t.y, this.top, this.bottom)), - this.contains(n)) - ) { - var i = n.x - this.left, - o = this.right - n.x, - r = n.y - this.top, - s = this.bottom - n.y, - a = Math.min(i, o, r, s); - a == r - ? ((n.y = this.top), (e.y = -1)) - : a == s - ? ((n.y = this.bottom), (e.y = 1)) - : a == i - ? ((n.x = this.left), (e.x = -1)) - : ((n.x = this.right), (e.x = 1)); - } else - n.x == this.left && (e.x = -1), - n.x == this.right && (e.x = 1), - n.y == this.top && (e.y = -1), - n.y == this.bottom && (e.y = 1); - return { res: n, edgeNormal: e }; - }), - (t.prototype.calculateBounds = function (t, e, n, i, o, r, s) { - if (0 == o) - (this.x = t.x + e.x - n.x * i.x), - (this.y = t.y + e.y - n.y * i.y), - (this.width = r * i.x), - (this.height = s * i.y); - else { - var a = t.x + e.x, - h = t.y + e.y; - (this._transformMat = Matrix2D.createTranslation(-a - n.x, -h - n.y)), - (this._tempMat = Matrix2D.createScale(i.x, i.y)), - (this._transformMat = Matrix2D.multiply( - this._transformMat, - this._tempMat - )), - (this._tempMat = Matrix2D.createRotation(o)), - (this._transformMat = Matrix2D.multiply( - this._transformMat, - this._tempMat - )), - (this._tempMat = Matrix2D.createTranslation(a, h)), - (this._transformMat = Matrix2D.multiply( - this._transformMat, - this._tempMat - )); - var c = new Vector2(a, h), - u = new Vector2(a + r, h), - l = new Vector2(a, h + s), - p = new Vector2(a + r, h + s); - (c = Vector2Ext.transformR(c, this._transformMat)), - (u = Vector2Ext.transformR(u, this._transformMat)), - (l = Vector2Ext.transformR(l, this._transformMat)), - (p = Vector2Ext.transformR(p, this._transformMat)); - var f = Math.min(c.x, p.x, u.x, l.x), - d = Math.max(c.x, p.x, u.x, l.x), - y = Math.min(c.y, p.y, u.y, l.y), - g = Math.max(c.y, p.y, u.y, l.y); - (this.location = new Vector2(f, y)), - (this.width = d - f), - (this.height = g - y); - } - }), - (t.rectEncompassingPoints = function (t) { - for ( - var e = Number.POSITIVE_INFINITY, - n = Number.POSITIVE_INFINITY, - i = Number.NEGATIVE_INFINITY, - o = Number.NEGATIVE_INFINITY, - r = 0; - r < t.length; - r++ - ) { - var s = t[r]; - s.x < e && (e = s.x), - s.x > i && (i = s.x), - s.y < n && (n = s.y), - s.y > o && (o = s.y); - } - return this.fromMinMax(e, n, i, o); - }), - t - ); - })(), - Vector2 = (function () { - function t(t, e) { - (this.x = 0), (this.y = 0), (this.x = t || 0), (this.y = e || this.x); - } - return ( - Object.defineProperty(t, "zero", { - get: function () { - return t.zeroVector2; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "one", { - get: function () { - return t.unitVector2; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "unitX", { - get: function () { - return t.unitXVector; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "unitY", { - get: function () { - return t.unitYVector; - }, - enumerable: !0, - configurable: !0, - }), - (t.add = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x + n.x), (i.y = e.y + n.y), i; - }), - (t.divide = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x / n.x), (i.y = e.y / n.y), i; - }), - (t.multiply = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x * n.x), (i.y = e.y * n.y), i; - }), - (t.subtract = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x - n.x), (i.y = e.y - n.y), i; - }), - (t.prototype.normalize = function () { - var t = 1 / Math.sqrt(this.x * this.x + this.y * this.y); - (this.x *= t), (this.y *= t); - }), - (t.prototype.length = function () { - return Math.sqrt(this.x * this.x + this.y * this.y); - }), - (t.prototype.round = function () { - return new t(Math.round(this.x), Math.round(this.y)); - }), - (t.normalize = function (t) { - var e = 1 / Math.sqrt(t.x * t.x + t.y * t.y); - return (t.x *= e), (t.y *= e), t; - }), - (t.dot = function (t, e) { - return t.x * e.x + t.y * e.y; - }), - (t.distanceSquared = function (t, e) { - var n = t.x - e.x, - i = t.y - e.y; - return n * n + i * i; - }), - (t.clamp = function (e, n, i) { - return new t( - MathHelper.clamp(e.x, n.x, i.x), - MathHelper.clamp(e.y, n.y, i.y) - ); - }), - (t.lerp = function (e, n, i) { - return new t( - MathHelper.lerp(e.x, n.x, i), - MathHelper.lerp(e.y, n.y, i) - ); - }), - (t.transform = function (e, n) { - return new t(e.x * n.m11 + e.y * n.m21, e.x * n.m12 + e.y * n.m22); - }), - (t.distance = function (t, e) { - var n = t.x - e.x, - i = t.y - e.y; - return Math.sqrt(n * n + i * i); - }), - (t.negate = function (e) { - var n = new t(); - return (n.x = -e.x), (n.y = -e.y), n; - }), - (t.unitYVector = new t(0, 1)), - (t.unitXVector = new t(1, 0)), - (t.unitVector2 = new t(1, 1)), - (t.zeroVector2 = new t(0, 0)), - t - ); - })(), - Vector3 = (function () { - return function (t, e, n) { - (this.x = t), (this.y = e), (this.z = n); - }; - })(), - ColliderTriggerHelper = (function () { - function t(t) { - (this._activeTriggerIntersections = []), - (this._previousTriggerIntersections = []), - (this._tempTriggerList = []), - (this._entity = t); - } - return ( - (t.prototype.update = function () { - for ( - var t = this._entity.getComponents(Collider), e = 0; - e < t.length; - e++ - ) - for ( - var n = t[e], - i = Physics.boxcastBroadphase(n.bounds, n.collidesWithLayers), - o = function (t) { - var e = i[t]; - if (!n.isTrigger && !e.isTrigger) return "continue"; - if (n.overlaps(e)) { - var o = new Pair(n, e); - -1 == - r._activeTriggerIntersections.findIndex(function (t) { - return t.first == o.first && t.second == o.second; - }) && - -1 == - r._previousTriggerIntersections.findIndex(function (t) { - return t.first == o.first && t.second == o.second; - }) && - r.notifyTriggerListeners(o, !0), - r._activeTriggerIntersections.contains(o) || - r._activeTriggerIntersections.push(o); - } - }, - r = this, - s = 0; - s < i.length; - s++ - ) - o(s); - ListPool.free(t), this.checkForExitedColliders(); - }), - (t.prototype.checkForExitedColliders = function () { - for ( - var t = this, - e = function (e) { - var i = n._previousTriggerIntersections.findIndex(function (n) { - return ( - n.first == t._activeTriggerIntersections[e].first && - n.second == t._activeTriggerIntersections[e].second - ); - }); - -1 != i && n._previousTriggerIntersections.removeAt(i); - }, - n = this, - i = 0; - i < this._activeTriggerIntersections.length; - i++ - ) - e(i); - for (i = 0; i < this._previousTriggerIntersections.length; i++) - this.notifyTriggerListeners( - this._previousTriggerIntersections[i], - !1 - ); - this._previousTriggerIntersections.length = 0; - for (i = 0; i < this._activeTriggerIntersections.length; i++) - this._previousTriggerIntersections.contains( - this._activeTriggerIntersections[i] - ) || - this._previousTriggerIntersections.push( - this._activeTriggerIntersections[i] - ); - this._activeTriggerIntersections.length = 0; - }), - (t.prototype.notifyTriggerListeners = function (t, e) { - t.first.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var n = 0; n < this._tempTriggerList.length; n++) - if ( - (e - ? this._tempTriggerList[n].onTriggerEnter(t.second, t.first) - : this._tempTriggerList[n].onTriggerExit(t.second, t.first), - (this._tempTriggerList.length = 0), - t.second.entity) - ) { - t.second.entity.getComponents( - "ITriggerListener", - this._tempTriggerList - ); - for (var i = 0; i < this._tempTriggerList.length; i++) - e - ? this._tempTriggerList[i].onTriggerEnter(t.first, t.second) - : this._tempTriggerList[i].onTriggerExit(t.first, t.second); - this._tempTriggerList.length = 0; - } - }), - t - ); - })(); -!(function (t) { - (t[(t.center = 0)] = "center"), - (t[(t.top = 1)] = "top"), - (t[(t.bottom = 2)] = "bottom"), - (t[(t.topLeft = 9)] = "topLeft"), - (t[(t.topRight = 5)] = "topRight"), - (t[(t.left = 8)] = "left"), - (t[(t.right = 4)] = "right"), - (t[(t.bottomLeft = 10)] = "bottomLeft"), - (t[(t.bottomRight = 6)] = "bottomRight"); -})(PointSectors || (PointSectors = {})); -var Collisions = (function () { - function t() {} - return ( - (t.isLineToLine = function (t, e, n, i) { - var o = Vector2.subtract(e, t), - r = Vector2.subtract(i, n), - s = o.x * r.y - o.y * r.x; - if (0 == s) return !1; - var a = Vector2.subtract(n, t), - h = (a.x * r.y - a.y * r.x) / s; - if (h < 0 || h > 1) return !1; - var c = (a.x * o.y - a.y * o.x) / s; - return !(c < 0 || c > 1); - }), - (t.lineToLineIntersection = function (t, e, n, i) { - var o = new Vector2(0, 0), - r = Vector2.subtract(e, t), - s = Vector2.subtract(i, n), - a = r.x * s.y - r.y * s.x; - if (0 == a) return o; - var h = Vector2.subtract(n, t), - c = (h.x * s.y - h.y * s.x) / a; - if (c < 0 || c > 1) return o; - var u = (h.x * r.y - h.y * r.x) / a; - return u < 0 || u > 1 - ? o - : (o = Vector2.add(t, new Vector2(c * r.x, c * r.y))); - }), - (t.closestPointOnLine = function (t, e, n) { - var i = Vector2.subtract(e, t), - o = Vector2.subtract(n, t), - r = Vector2.dot(o, i) / Vector2.dot(i, i); - return ( - (r = MathHelper.clamp(r, 0, 1)), - Vector2.add(t, new Vector2(i.x * r, i.y * r)) - ); - }), - (t.isCircleToCircle = function (t, e, n, i) { - return Vector2.distanceSquared(t, n) < (e + i) * (e + i); - }), - (t.isCircleToLine = function (t, e, n, i) { - return ( - Vector2.distanceSquared(t, this.closestPointOnLine(n, i, t)) < e * e - ); - }), - (t.isCircleToPoint = function (t, e, n) { - return Vector2.distanceSquared(t, n) < e * e; - }), - (t.isRectToCircle = function (t, e, n) { - var i = 0.5 * t.width, - o = 0.5 * t.height, - r = Math.max(0, Math.max(e.x - t.x) - i), - s = Math.max(0, Math.max(e.y - t.y) - o); - return r * r + s * s < n * n; - }), - (t.isRectToLine = function (t, e, n) { - var i = this.getSector(t.x, t.y, t.width, t.height, e), - o = this.getSector(t.x, t.y, t.width, t.height, n); - if (i == PointSectors.center || o == PointSectors.center) return !0; - if (0 != (i & o)) return !1; - var r = i | o, - s = void 0, - a = void 0; - return ( - !( - 0 == (r & PointSectors.top) || - ((s = new Vector2(t.x, t.y)), - (a = new Vector2(t.x + t.width, t.y)), - !this.isLineToLine(s, a, e, n)) - ) || - !( - 0 == (r & PointSectors.bottom) || - ((s = new Vector2(t.x, t.y + t.height)), - (a = new Vector2(t.x + t.width, t.y + t.height)), - !this.isLineToLine(s, a, e, n)) - ) || - !( - 0 == (r & PointSectors.left) || - ((s = new Vector2(t.x, t.y)), - (a = new Vector2(t.x, t.y + t.height)), - !this.isLineToLine(s, a, e, n)) - ) || - !( - 0 == (r & PointSectors.right) || - ((s = new Vector2(t.x + t.width, t.y)), - (a = new Vector2(t.x + t.width, t.y + t.height)), - !this.isLineToLine(s, a, e, n)) - ) - ); - }), - (t.isRectToPoint = function (t, e, n, i, o) { - return o.x >= t && o.y >= e && o.x < t + n && o.y < e + i; - }), - (t.getSector = function (t, e, n, i, o) { - var r = PointSectors.center; - return ( - o.x < t - ? (r |= PointSectors.left) - : o.x >= t + n && (r |= PointSectors.right), - o.y < e - ? (r |= PointSectors.top) - : o.y >= e + i && (r |= PointSectors.bottom), - r - ); - }), - t - ); - })(), - Physics = (function () { - function t() {} - return ( - (t.reset = function () { - this._spatialHash = new SpatialHash(this.spatialHashCellSize); - }), - (t.clear = function () { - this._spatialHash.clear(); - }), - (t.overlapCircleAll = function (t, e, n, i) { - return ( - void 0 === i && (i = -1), this._spatialHash.overlapCircle(t, e, n, i) - ); - }), - (t.boxcastBroadphase = function (t, e) { - return ( - void 0 === e && (e = this.allLayers), - this._spatialHash.aabbBroadphase(t, null, e) - ); - }), - (t.boxcastBroadphaseExcludingSelf = function (t, e, n) { - return ( - void 0 === n && (n = this.allLayers), - this._spatialHash.aabbBroadphase(e, t, n) - ); - }), - (t.addCollider = function (e) { - t._spatialHash.register(e); - }), - (t.removeCollider = function (e) { - t._spatialHash.remove(e); - }), - (t.updateCollider = function (t) { - this._spatialHash.remove(t), this._spatialHash.register(t); - }), - (t.spatialHashCellSize = 100), - (t.allLayers = -1), - t - ); - })(), - Shape = (function () { - return function () {}; - })(), - Polygon = (function (t) { - function e(e, n) { - var i = t.call(this) || this; - return ( - (i.isUnrotated = !0), - (i._areEdgeNormalsDirty = !0), - i.setPoints(e), - (i.isBox = n), - i - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "edgeNormals", { - get: function () { - return ( - this._areEdgeNormalsDirty && this.buildEdgeNormals(), - this._edgeNormals - ); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.buildEdgeNormals = function () { - var t, - e = this.isBox ? 2 : this.points.length; - (null != this._edgeNormals && this._edgeNormals.length == e) || - (this._edgeNormals = new Array(e)); - for (var n = 0; n < e; n++) { - var i = this.points[n]; - t = n + 1 >= this.points.length ? this.points[0] : this.points[n + 1]; - var o = Vector2Ext.perpendicular(i, t); - (o = Vector2.normalize(o)), (this._edgeNormals[n] = o); - } - }), - (e.prototype.setPoints = function (t) { - (this.points = t), - this.recalculateCenterAndEdgeNormals(), - (this._originalPoints = []); - for (var e = 0; e < this.points.length; e++) - this._originalPoints.push(this.points[e]); - }), - (e.prototype.collidesWithShape = function (t) { - var n = new CollisionResult(); - if (t instanceof e) return ShapeCollisions.polygonToPolygon(this, t); - if (t instanceof Circle) - return (n = ShapeCollisions.circleToPolygon(t, this)) - ? (n.invertResult(), n) - : null; - throw new Error("overlaps of Polygon to " + t + " are not supported"); - }), - (e.prototype.recalculateCenterAndEdgeNormals = function () { - (this._polygonCenter = e.findPolygonCenter(this.points)), - (this._areEdgeNormalsDirty = !0); - }), - (e.prototype.overlaps = function (t) { - var n; - if (t instanceof e) return ShapeCollisions.polygonToPolygon(this, t); - if (t instanceof Circle) - return ( - !!(n = ShapeCollisions.circleToPolygon(t, this)) && - (n.invertResult(), !0) - ); - throw new Error("overlaps of Pologon to " + t + " are not supported"); - }), - (e.findPolygonCenter = function (t) { - for (var e = 0, n = 0, i = 0; i < t.length; i++) - (e += t[i].x), (n += t[i].y); - return new Vector2(e / t.length, n / t.length); - }), - (e.getClosestPointOnPolygonToPoint = function (t, e) { - for ( - var n, - i = Number.MAX_VALUE, - o = new Vector2(0, 0), - r = new Vector2(0, 0), - s = 0; - s < t.length; - s++ - ) { - var a = s + 1; - a == t.length && (a = 0); - var h = ShapeCollisions.closestPointOnLine(t[s], t[a], e); - if ((n = Vector2.distanceSquared(e, h)) < i) { - (i = n), (r = h); - var c = Vector2.subtract(t[a], t[s]); - (o.x = -c.y), (o.y = c.x); - } - } - return { - closestPoint: r, - distanceSquared: i, - edgeNormal: (o = Vector2.normalize(o)), - }; - }), - (e.prototype.pointCollidesWithShape = function (t) { - return ShapeCollisions.pointToPoly(t, this); - }), - (e.prototype.containsPoint = function (t) { - t = Vector2.subtract(t, this.position); - for ( - var e = !1, n = 0, i = this.points.length - 1; - n < this.points.length; - i = n++ - ) - this.points[n].y > t.y != this.points[i].y > t.y && - t.x < - ((this.points[i].x - this.points[n].x) * - (t.y - this.points[n].y)) / - (this.points[i].y - this.points[n].y) + - this.points[n].x && - (e = !e); - return e; - }), - (e.buildSymmertricalPolygon = function (t, e) { - for (var n = new Array(t), i = 0; i < t; i++) { - var o = 2 * Math.PI * (i / t); - n[i] = new Vector2(Math.cos(o), Math.sin(o) * e); - } - return n; - }), - (e.prototype.recalculateBounds = function (t) { - if ( - ((this.center = t.localOffset), - t.shouldColliderScaleAndRotationWithTransform) - ) { - var e = !0, - n = void 0, - i = Matrix2D.createTranslation( - -this._polygonCenter.x, - -this._polygonCenter.y - ); - if (t.entity.scale != Vector2.one) { - (n = Matrix2D.createScale(t.entity.scale.x, t.entity.scale.y)), - (i = Matrix2D.multiply(i, n)), - (e = !1); - var o = Vector2.multiply(t.localOffset, t.entity.scale); - this.center = o; - } - if (0 != t.entity.rotation) { - (n = Matrix2D.createRotation(t.entity.rotation)), - (i = Matrix2D.multiply(i, n)); - var r = - Math.atan2(t.localOffset.y, t.localOffset.x) * - MathHelper.Rad2Deg, - s = e - ? t._localOffsetLength - : Vector2.multiply(t.localOffset, t.entity.scale).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - s, - MathHelper.toDegrees(t.entity.rotation) + r - ); - } - (n = Matrix2D.createTranslation( - this._polygonCenter.x, - this._polygonCenter.y - )), - (i = Matrix2D.multiply(i, n)), - Vector2Ext.transform(this._originalPoints, i, this.points), - (this.isUnrotated = 0 == t.entity.rotation), - t._isRotationDirty && (this._areEdgeNormalsDirty = !0); - } - (this.position = Vector2.add(t.entity.position, this.center)), - (this.bounds = Rectangle.rectEncompassingPoints(this.points)), - (this.bounds.location = Vector2.add( - this.bounds.location, - this.position - )); - }), - e - ); - })(Shape), - Box = (function (t) { - function e(n, i) { - var o = t.call(this, e.buildBox(n, i), !0) || this; - return (o.width = n), (o.height = i), o; - } - return ( - __extends(e, t), - (e.buildBox = function (t, e) { - var n = t / 2, - i = e / 2, - o = new Array(4); - return ( - (o[0] = new Vector2(-n, -i)), - (o[1] = new Vector2(n, -i)), - (o[2] = new Vector2(n, i)), - (o[3] = new Vector2(-n, i)), - o - ); - }), - (e.prototype.updateBox = function (t, e) { - (this.width = t), (this.height = e); - var n = t / 2, - i = e / 2; - (this.points[0] = new Vector2(-n, -i)), - (this.points[1] = new Vector2(n, -i)), - (this.points[2] = new Vector2(n, i)), - (this.points[3] = new Vector2(-n, i)); - for (var o = 0; o < this.points.length; o++) - this._originalPoints[o] = this.points[o]; - }), - (e.prototype.containsPoint = function (e) { - return this.isUnrotated - ? this.bounds.contains(e) - : t.prototype.containsPoint.call(this, e); - }), - e - ); - })(Polygon), - Circle = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.radius = e), (n._originalRadius = e), n; - } - return ( - __extends(e, t), - (e.prototype.pointCollidesWithShape = function (t) { - return ShapeCollisions.pointToCircle(t, this); - }), - (e.prototype.collidesWithShape = function (t) { - if (t instanceof Box && t.isUnrotated) - return ShapeCollisions.circleToBox(this, t); - if (t instanceof e) return ShapeCollisions.circleToCircle(this, t); - if (t instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, t); - throw new Error("Collisions of Circle to " + t + " are not supported"); - }), - (e.prototype.recalculateBounds = function (t) { - if ( - ((this.center = t.localOffset), - t.shouldColliderScaleAndRotationWithTransform) - ) { - var e = t.entity.scale, - n = 1 == e.x && 1 == e.y, - i = Math.max(e.x, e.y); - if ( - ((this.radius = this._originalRadius * i), 0 != t.entity.rotation) - ) { - var o = - Math.atan2(t.localOffset.y, t.localOffset.x) * - MathHelper.Rad2Deg, - r = n - ? t._localOffsetLength - : Vector2.multiply(t.localOffset, t.entity.scale).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - r, - MathHelper.toDegrees(t.entity.rotation) + o - ); - } - } - (this.position = Vector2.add(t.entity.position, this.center)), - (this.bounds = new Rectangle( - this.position.x - this.radius, - this.position.y - this.radius, - 2 * this.radius, - 2 * this.radius - )); - }), - (e.prototype.overlaps = function (t) { - if (t instanceof Box && t.isUnrotated) - return Collisions.isRectToCircle( - t.bounds, - this.position, - this.radius - ); - if (t instanceof e) - return Collisions.isCircleToCircle( - this.position, - this.radius, - t.position, - t.radius - ); - if (t instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, t); - throw new Error("overlaps of circle to " + t + " are not supported"); - }), - e - ); - })(Shape), - CollisionResult = (function () { - function t() {} - return ( - (t.prototype.invertResult = function () { - (this.minimumTranslationVector = Vector2.negate( - this.minimumTranslationVector - )), - (this.normal = Vector2.negate(this.normal)); - }), - t - ); - })(), - ShapeCollisions = (function () { - function t() {} - return ( - (t.polygonToPolygon = function (t, e) { - for ( - var n, - i = new CollisionResult(), - o = !0, - r = t.edgeNormals, - s = e.edgeNormals, - a = Number.POSITIVE_INFINITY, - h = new Vector2(), - c = Vector2.subtract(t.position, e.position), - u = 0; - u < r.length + s.length; - u++ - ) { - n = u < r.length ? r[u] : s[u - r.length]; - var l = 0, - p = 0, - f = 0, - d = 0, - y = 0, - g = this.getInterval(n, t, l, f); - (l = g.min), (p = g.max); - var m = this.getInterval(n, e, p, d); - (p = m.min), (d = m.max); - var _ = Vector2.dot(c, n); - if ( - ((l += _), - (f += _), - (y = this.intervalDistance(l, f, p, d)) > 0 && (o = !1), - !o) - ) - return null; - (y = Math.abs(y)) < a && - ((a = y), (h = n), Vector2.dot(h, c) < 0 && (h = new Vector2(-h))); - } - return ( - (i.normal = h), - (i.minimumTranslationVector = Vector2.multiply( - new Vector2(-h), - new Vector2(a) - )), - i - ); - }), - (t.intervalDistance = function (t, e, n, i) { - return t < n ? n - e : t - n; - }), - (t.getInterval = function (t, e, n, i) { - var o = Vector2.dot(e.points[0], t); - n = i = o; - for (var r = 1; r < e.points.length; r++) - (o = Vector2.dot(e.points[r], t)) < n ? (n = o) : o > i && (i = o); - return { min: n, max: i }; - }), - (t.circleToPolygon = function (t, e) { - var n = new CollisionResult(), - i = Vector2.subtract(t.position, e.position), - o = Polygon.getClosestPointOnPolygonToPoint(e.points, i), - r = o.closestPoint, - s = o.distanceSquared; - n.normal = o.edgeNormal; - var a, - h = e.containsPoint(t.position); - if (s > t.radius * t.radius && !h) return null; - if (h) - a = Vector2.multiply(n.normal, new Vector2(Math.sqrt(s) - t.radius)); - else if (0 == s) a = Vector2.multiply(n.normal, new Vector2(t.radius)); - else { - var c = Math.sqrt(s); - a = Vector2.multiply( - new Vector2(-Vector2.subtract(i, r)), - new Vector2((t.radius - s) / c) - ); - } - return ( - (n.minimumTranslationVector = a), - (n.point = Vector2.add(r, e.position)), - n - ); - }), - (t.circleToBox = function (t, e) { - var n = new CollisionResult(), - i = e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res; - if (e.containsPoint(t.position)) { - n.point = i; - var o = Vector2.add( - i, - Vector2.subtract(n.normal, new Vector2(t.radius)) - ); - return ( - (n.minimumTranslationVector = Vector2.subtract(t.position, o)), n - ); - } - var r = Vector2.distanceSquared(i, t.position); - if (0 == r) - n.minimumTranslationVector = Vector2.multiply( - n.normal, - new Vector2(t.radius) - ); - else if (r <= t.radius * t.radius) { - n.normal = Vector2.subtract(t.position, i); - var s = n.normal.length() - t.radius; - return ( - (n.normal = Vector2Ext.normalize(n.normal)), - (n.minimumTranslationVector = Vector2.multiply( - new Vector2(s), - n.normal - )), - n - ); - } - return null; - }), - (t.pointToCircle = function (t, e) { - var n = new CollisionResult(), - i = Vector2.distanceSquared(t, e.position), - o = 1 + e.radius; - if (i < o * o) { - n.normal = Vector2.normalize(Vector2.subtract(t, e.position)); - var r = o - Math.sqrt(i); - return ( - (n.minimumTranslationVector = Vector2.multiply( - new Vector2(-r, -r), - n.normal - )), - (n.point = Vector2.add( - e.position, - Vector2.multiply(n.normal, new Vector2(e.radius, e.radius)) - )), - n - ); - } - return null; - }), - (t.closestPointOnLine = function (t, e, n) { - var i = Vector2.subtract(e, t), - o = Vector2.subtract(n, t), - r = Vector2.dot(o, i) / Vector2.dot(i, i); - return ( - (r = MathHelper.clamp(r, 0, 1)), - Vector2.add(t, Vector2.multiply(i, new Vector2(r, r))) - ); - }), - (t.pointToPoly = function (t, e) { - var n = new CollisionResult(); - if (e.containsPoint(t)) { - var i, - o = Polygon.getClosestPointOnPolygonToPoint( - e.points, - Vector2.subtract(t, e.position) - ), - r = o.closestPoint; - return ( - (i = o.distanceSquared), - (n.normal = o.edgeNormal), - (n.minimumTranslationVector = Vector2.multiply( - n.normal, - new Vector2(Math.sqrt(i), Math.sqrt(i)) - )), - (n.point = Vector2.add(r, e.position)), - n - ); - } - return null; - }), - (t.circleToCircle = function (t, e) { - var n = new CollisionResult(), - i = Vector2.distanceSquared(t.position, e.position), - o = t.radius + e.radius; - if (i < o * o) { - n.normal = Vector2.normalize( - Vector2.subtract(t.position, e.position) - ); - var r = o - Math.sqrt(i); - return ( - (n.minimumTranslationVector = Vector2.multiply( - new Vector2(-r), - n.normal - )), - (n.point = Vector2.add( - e.position, - Vector2.multiply(n.normal, new Vector2(e.radius)) - )), - n - ); - } - return null; - }), - t - ); - })(), - SpatialHash = (function () { - function t(t) { - void 0 === t && (t = 100), - (this.gridBounds = new Rectangle()), - (this._tempHashSet = []), - (this._cellDict = new NumberDictionary()), - (this._cellSize = t), - (this._inverseCellSize = 1 / this._cellSize), - (this._raycastParser = new RaycastResultParser()); - } - return ( - (t.prototype.remove = function (t) { - for ( - var e = t.registeredPhysicsBounds, - n = this.cellCoords(e.x, e.y), - i = this.cellCoords(e.right, e.bottom), - o = n.x; - o <= i.x; - o++ - ) - for (var r = n.y; r <= i.y; r++) { - var s = this.cellAtPosition(o, r); - s - ? s.remove(t) - : console.error( - "removing Collider [" + - t + - "] from a cell that it is not present in" - ); - } - }), - (t.prototype.register = function (t) { - var e = t.bounds; - t.registeredPhysicsBounds = e; - var n = this.cellCoords(e.x, e.y), - i = this.cellCoords(e.right, e.bottom); - this.gridBounds.contains(new Vector2(n.x, n.y)) || - (this.gridBounds = RectangleExt.union(this.gridBounds, n)), - this.gridBounds.contains(new Vector2(i.x, i.y)) || - (this.gridBounds = RectangleExt.union(this.gridBounds, i)); - for (var o = n.x; o <= i.x; o++) - for (var r = n.y; r <= i.y; r++) { - this.cellAtPosition(o, r, !0).push(t); - } - }), - (t.prototype.clear = function () { - this._cellDict.clear(); - }), - (t.prototype.overlapCircle = function (t, e, n, i) { - var o = new Rectangle(t.x - e, t.y - e, 2 * e, 2 * e); - (this._overlapTestCircle.radius = e), - (this._overlapTestCircle.position = t); - for ( - var r = 0, s = this.aabbBroadphase(o, null, i), a = 0; - a < s.length; - a++ - ) { - var h = s[a]; - if (!(h instanceof BoxCollider)) - throw new Error( - "overlapCircle against this collider type is not implemented!" - ); - if (((n[r] = h), ++r == n.length)) return r; - } - return r; - }), - (t.prototype.aabbBroadphase = function (t, e, n) { - this._tempHashSet.length = 0; - for ( - var i = this.cellCoords(t.x, t.y), - o = this.cellCoords(t.right, t.bottom), - r = i.x; - r <= o.x; - r++ - ) - for (var s = i.y; s <= o.y; s++) { - var a = this.cellAtPosition(r, s); - if (a) - for (var h = 0; h < a.length; h++) { - var c = a[h]; - c != e && - Flags.isFlagSet(n, c.physicsLayer) && - t.intersects(c.bounds) && - -1 == this._tempHashSet.indexOf(c) && - this._tempHashSet.push(c); - } - } - return this._tempHashSet; - }), - (t.prototype.cellAtPosition = function (t, e, n) { - void 0 === n && (n = !1); - var i = this._cellDict.tryGetValue(t, e); - return i || (n && ((i = []), this._cellDict.add(t, e, i))), i; - }), - (t.prototype.cellCoords = function (t, e) { - return new Point( - Math.floor(t * this._inverseCellSize), - Math.floor(e * this._inverseCellSize) - ); - }), - t - ); - })(), - RaycastResultParser = (function () { - return function () {}; - })(), - NumberDictionary = (function () { - function t() { - this._store = new Map(); - } - return ( - (t.prototype.getKey = function (t, e) { - return Long.fromNumber(t) - .shiftLeft(32) - .or(this.intToUint(e)) - .toString(); - }), - (t.prototype.intToUint = function (t) { - return t >= 0 ? t : 4294967296 + t; - }), - (t.prototype.add = function (t, e, n) { - this._store.set(this.getKey(t, e), n); - }), - (t.prototype.remove = function (t) { - this._store.forEach(function (e) { - e.contains(t) && e.remove(t); - }); - }), - (t.prototype.tryGetValue = function (t, e) { - return this._store.get(this.getKey(t, e)); - }), - (t.prototype.clear = function () { - this._store.clear(); - }), - t - ); - })(), - ContentManager = (function () { - function t() { - this.loadedAssets = new Map(); - } - return ( - (t.prototype.loadRes = function (t, e) { - var n = this; - return ( - void 0 === e && (e = !0), - new Promise(function (i, o) { - var r = n.loadedAssets.get(t); - r - ? i(r) - : e - ? RES.getResAsync(t) - .then(function (e) { - n.loadedAssets.set(t, e), i(e); - }) - .catch(function (e) { - console.error("资源加载错误:", t, e), o(e); - }) - : RES.getResByUrl(t) - .then(function (e) { - n.loadedAssets.set(t, e), i(e); - }) - .catch(function (e) { - console.error("资源加载错误:", t, e), o(e); - }); - }) - ); - }), - (t.prototype.dispose = function () { - this.loadedAssets.forEach(function (t) { - t.dispose(); - }), - this.loadedAssets.clear(); - }), - t - ); - })(), - Emitter = (function () { - function t() { - this._messageTable = new Map(); - } - return ( - (t.prototype.addObserver = function (t, e) { - var n = this._messageTable.get(t); - n || ((n = []), this._messageTable.set(t, n)), - n.contains(e) && console.warn("您试图添加相同的观察者两次"), - n.push(e); - }), - (t.prototype.removeObserver = function (t, e) { - this._messageTable.get(t).remove(e); - }), - (t.prototype.emit = function (t, e) { - var n = this._messageTable.get(t); - if (n) for (var i = n.length - 1; i >= 0; i--) n[i](e); - }), - t - ); - })(), - GlobalManager = (function () { - function t() {} - return ( - Object.defineProperty(t.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (t) { - this.setEnabled(t); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.setEnabled = function (t) { - this._enabled != t && - ((this._enabled = t), - this._enabled ? this.onEnabled() : this.onDisabled()); - }), - (t.prototype.onEnabled = function () {}), - (t.prototype.onDisabled = function () {}), - (t.prototype.update = function () {}), - (t.registerGlobalManager = function (t) { - this.globalManagers.push(t), (t.enabled = !0); - }), - (t.unregisterGlobalManager = function (t) { - this.globalManagers.remove(t), (t.enabled = !1); - }), - (t.getGlobalManager = function (t) { - for (var e = 0; e < this.globalManagers.length; e++) - if (this.globalManagers[e] instanceof t) - return this.globalManagers[e]; - return null; - }), - (t.globalManagers = []), - t - ); - })(), - TouchState = (function () { - function t() { - (this.x = 0), (this.y = 0), (this.touchPoint = -1), (this.touchDown = !1); - } - return ( - Object.defineProperty(t.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.reset = function () { - (this.x = 0), - (this.y = 0), - (this.touchDown = !1), - (this.touchPoint = -1); - }), - t - ); - })(), - Input = (function () { - function t() {} - return ( - Object.defineProperty(t, "touchPosition", { - get: function () { - return this._gameTouchs[0] - ? this._gameTouchs[0].position - : Vector2.zero; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "maxSupportedTouch", { - get: function () { - return this._stage.maxTouches; - }, - set: function (t) { - (this._stage.maxTouches = t), this.initTouchCache(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "resolutionScale", { - get: function () { - return this._resolutionScale; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "totalTouchCount", { - get: function () { - return this._totalTouchCount; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "gameTouchs", { - get: function () { - return this._gameTouchs; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "touchPositionDelta", { - get: function () { - var t = Vector2.subtract( - this.touchPosition, - this._previousTouchState.position - ); - return ( - t.length() > 0 && this.setpreviousTouchState(this._gameTouchs[0]), t - ); - }, - enumerable: !0, - configurable: !0, - }), - (t.initialize = function (t) { - this._init || - ((this._init = !0), - (this._stage = t), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_BEGIN, - this.touchBegin, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_MOVE, - this.touchMove, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_END, - this.touchEnd, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_CANCEL, - this.touchEnd, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, - this.touchEnd, - this - ), - this.initTouchCache()); - }), - (t.initTouchCache = function () { - (this._totalTouchCount = 0), - (this._touchIndex = 0), - (this._gameTouchs.length = 0); - for (var t = 0; t < this.maxSupportedTouch; t++) - this._gameTouchs.push(new TouchState()); - }), - (t.touchBegin = function (t) { - this._touchIndex < this.maxSupportedTouch && - ((this._gameTouchs[this._touchIndex].touchPoint = t.touchPointID), - (this._gameTouchs[this._touchIndex].touchDown = t.touchDown), - (this._gameTouchs[this._touchIndex].x = t.stageX), - (this._gameTouchs[this._touchIndex].y = t.stageY), - 0 == this._touchIndex && - this.setpreviousTouchState(this._gameTouchs[0]), - this._touchIndex++, - this._totalTouchCount++); - }), - (t.touchMove = function (t) { - t.touchPointID == this._gameTouchs[0].touchPoint && - this.setpreviousTouchState(this._gameTouchs[0]); - var e = this._gameTouchs.findIndex(function (e) { - return e.touchPoint == t.touchPointID; - }); - if (-1 != e) { - var n = this._gameTouchs[e]; - (n.x = t.stageX), (n.y = t.stageY); - } - }), - (t.touchEnd = function (t) { - var e = this._gameTouchs.findIndex(function (e) { - return e.touchPoint == t.touchPointID; - }); - -1 != e && - (this._gameTouchs[e].reset(), - 0 == e && this._previousTouchState.reset(), - this._totalTouchCount--, - 0 == this.totalTouchCount && (this._touchIndex = 0)); - }), - (t.setpreviousTouchState = function (t) { - (this._previousTouchState = new TouchState()), - (this._previousTouchState.x = t.position.x), - (this._previousTouchState.y = t.position.y), - (this._previousTouchState.touchPoint = t.touchPoint), - (this._previousTouchState.touchDown = t.touchDown); - }), - (t.scaledPosition = function (t) { - var e = new Vector2( - t.x - this._resolutionOffset.x, - t.y - this._resolutionOffset.y - ); - return Vector2.multiply(e, this.resolutionScale); - }), - (t._init = !1), - (t._previousTouchState = new TouchState()), - (t._gameTouchs = []), - (t._resolutionOffset = new Vector2()), - (t._resolutionScale = Vector2.one), - (t._touchIndex = 0), - (t._totalTouchCount = 0), - t - ); - })(), - ListPool = (function () { - function t() {} - return ( - (t.warmCache = function (t) { - if ((t -= this._objectQueue.length) > 0) - for (var e = 0; e < t; e++) this._objectQueue.unshift([]); - }), - (t.trimCache = function (t) { - for (; t > this._objectQueue.length; ) this._objectQueue.shift(); - }), - (t.clearCache = function () { - this._objectQueue.length = 0; - }), - (t.obtain = function () { - return this._objectQueue.length > 0 ? this._objectQueue.shift() : []; - }), - (t.free = function (t) { - this._objectQueue.unshift(t), (t.length = 0); - }), - (t._objectQueue = []), - t - ); - })(), - Pair = (function () { - function t(t, e) { - (this.first = t), (this.second = e); - } - return ( - (t.prototype.clear = function () { - this.first = this.second = null; - }), - (t.prototype.equals = function (t) { - return this.first == t.first && this.second == t.second; - }), - t - ); - })(), - RectangleExt = (function () { - function t() {} - return ( - (t.union = function (t, e) { - var n = new Rectangle(e.x, e.y, 0, 0); - return this.unionR(t, n); - }), - (t.unionR = function (t, e) { - var n = new Rectangle(); - return ( - (n.x = Math.min(t.x, e.x)), - (n.y = Math.min(t.y, e.y)), - (n.width = Math.max(t.right, e.right) - n.x), - (n.height = Math.max(t.bottom, e.bottom) - n.y), - n - ); - }), - t - ); - })(), - Triangulator = (function () { - function t() { - (this.triangleIndices = []), - (this._triPrev = new Array(12)), - (this._triNext = new Array(12)); - } - return ( - (t.prototype.triangulate = function (e, n) { - void 0 === n && (n = !0); - var i = e.length; - this.initialize(i); - for (var o = 0, r = 0; i > 3 && o < 500; ) { - o++; - var s = !0, - a = e[this._triPrev[r]], - h = e[r], - c = e[this._triNext[r]]; - if (Vector2Ext.isTriangleCCW(a, h, c)) { - var u = this._triNext[this._triNext[r]]; - do { - if (t.testPointTriangle(e[u], a, h, c)) { - s = !1; - break; - } - u = this._triNext[u]; - } while (u != this._triPrev[r]); - } else s = !1; - s - ? (this.triangleIndices.push(this._triPrev[r]), - this.triangleIndices.push(r), - this.triangleIndices.push(this._triNext[r]), - (this._triNext[this._triPrev[r]] = this._triNext[r]), - (this._triPrev[this._triNext[r]] = this._triPrev[r]), - i--, - (r = this._triPrev[r])) - : (r = this._triNext[r]); - } - this.triangleIndices.push(this._triPrev[r]), - this.triangleIndices.push(r), - this.triangleIndices.push(this._triNext[r]), - n || this.triangleIndices.reverse(); - }), - (t.prototype.initialize = function (t) { - (this.triangleIndices.length = 0), - this._triNext.length < t && - (this._triNext.reverse(), - (this._triNext = new Array(Math.max(2 * this._triNext.length, t)))), - this._triPrev.length < t && - (this._triPrev.reverse(), - (this._triPrev = new Array(Math.max(2 * this._triPrev.length, t)))); - for (var e = 0; e < t; e++) - (this._triPrev[e] = e - 1), (this._triNext[e] = e + 1); - (this._triPrev[0] = t - 1), (this._triNext[t - 1] = 0); - }), - (t.testPointTriangle = function (t, e, n, i) { - return ( - !( - Vector2Ext.cross(Vector2.subtract(t, e), Vector2.subtract(n, e)) < 0 - ) && - !( - Vector2Ext.cross(Vector2.subtract(t, n), Vector2.subtract(i, n)) < 0 - ) && - !( - Vector2Ext.cross(Vector2.subtract(t, i), Vector2.subtract(e, i)) < 0 - ) - ); - }), - t - ); - })(), - Vector2Ext = (function () { - function t() {} - return ( - (t.isTriangleCCW = function (t, e, n) { - return this.cross(Vector2.subtract(e, t), Vector2.subtract(n, e)) < 0; - }), - (t.cross = function (t, e) { - return t.y * e.x - t.x * e.y; - }), - (t.perpendicular = function (t, e) { - return new Vector2(-1 * (e.y - t.y), e.x - t.x); - }), - (t.normalize = function (t) { - var e = Math.sqrt(t.x * t.x + t.y * t.y); - return ( - e > MathHelper.Epsilon - ? (t = Vector2.divide(t, new Vector2(e))) - : (t.x = t.y = 0), - t - ); - }), - (t.transformA = function (t, e, n, i, o, r) { - for (var s = 0; s < r; s++) { - var a = t[e + s], - h = i[o + s]; - (h.x = a.x * n.m11 + a.y * n.m21 + n.m31), - (h.y = a.x * n.m12 + a.y * n.m22 + n.m32), - (i[o + s] = h); - } - }), - (t.transformR = function (t, e) { - var n = t.x * e.m11 + t.y * e.m21 + e.m31, - i = t.x * e.m12 + t.y * e.m22 + e.m32; - return new Vector2(n, i); - }), - (t.transform = function (t, e, n) { - this.transformA(t, 0, e, n, 0, t.length); - }), - (t.round = function (t) { - return new Vector2(Math.round(t.x), Math.round(t.y)); - }), - t - ); - })(); +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{h(i.next(t))}catch(t){r(t)}}function a(t){try{h(i.throw(t))}catch(t){r(t)}}function h(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,a)}h((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(n){var i=t.call(this)||this;return i._position=Vector2.zero,i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.scaleX=t.x,this.scaleY=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer),Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,o=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*o,this.uvs.width=e.width*i,this.uvs.height=e.height*o}}(),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),e.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t),this},e.prototype.setSprite=function(t){return this.removeChildren(),this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this._bitmap=new egret.Bitmap(t.texture2D),this.addChild(this._bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=this.entity.position.x-this.origin.x-t.position.x+t.origin.x,this.y=this.entity.position.y-this.origin.y-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n0;)this.removeChildAt(0)},e}(egret.DisplayObjectContainer),BaseFuiView=function(t){function e(e){var n=t.call(this)||this;return n.name=e,n}return __extends(e,t),e}(BaseView),BaseSingle=function(){function t(){}return t.getInstance=function(){return null==this._instance&&(this._instance=new this),this._instance},t.prototype.clearFuiObj=function(t){return!!t&&(egret.Tween.removeTweens(t.displayObject),t.displayObject&&t.displayObject.parent&&t.displayObject.parent.removeChild(t.displayObject),t.dispose(),t=null,!0)},t}(),ViewManager=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._openDic=[],e}return __extends(e,t),e.prototype.refreshView=function(t,e){var n=this.getView(t);n&&(n.refreshData(e),n.refreshView())},e.prototype.openView=function(t,e,n){var i=this.getView(t);if(i||(i=new t),this.existView(t))return i.refreshData(e),void i.refreshView();this._openDic.push(i)},e.prototype.getView=function(t){return this._openDic.firstOrDefault(function(e){return e instanceof t})},e.prototype.existView=function(t){return-1!=this._openDic.findIndex(function(e){return e instanceof t})},e}(BaseSingle),Flags=function(){function t(){}return t.isFlagSet=function(t,e){return 0!=(t&e)},t.isUnshiftedFlagSet=function(t,e){return 0!=(t&(e=1<n?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=h,i.m32=c,i},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return(i=i||new t).m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,n,i){this.x=t||0,this.y=e||0,this.width=n||0,this.height=i||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(g=Math.abs(g))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/c))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s(Mover); + if (!this.spriteRenderer) + this.spriteRenderer = this.entity.getComponent(SpriteRenderer); + if (!this.mover) return; + if (!SpriteRenderer) + return; + if (this.down){ let camera = SceneManager.scene.camera; - this.mover.move(Input.touchPositionDelta); - console.log(Input.touchPositionDelta); + let moveLeft: number = 0; + let moveRight: number = 0; + let speed = 200; + let worldPos = Input.touchPosition; + if (worldPos.x < this.spriteRenderer.x){ + moveLeft = -1; + } else if(worldPos.x > this.spriteRenderer.x){ + moveLeft = 1; + } + + if (worldPos.y < this.spriteRenderer.y){ + moveRight = -1; + } else if(worldPos.y > this.spriteRenderer.y){ + moveRight = 1; + } + this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime)); } } } \ No newline at end of file diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 2439ff38..8b2f6efb 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -150,7 +150,6 @@ declare abstract class Component extends egret.DisplayObjectContainer { onRemovedFromEntity(): void; onEnabled(): void; onDisabled(): void; - onEntityTransformChanged(comp: ComponentTransform): void; update(): void; debugRender(): void; registerComponent(): void; @@ -193,7 +192,6 @@ declare class Entity extends egret.DisplayObjectContainer { update(): void; onAddedToScene(): void; onRemovedFromScene(): void; - onTransformChanged(comp: ComponentTransform): void; destroy(): void; } declare class Scene extends egret.DisplayObjectContainer { @@ -240,70 +238,6 @@ declare class SceneManager { static render(): void; static startSceneTransition(sceneTransition: T): T; } -declare enum DirtyType { - clean = 0, - positionDirty = 1, - scaleDirty = 2, - rotationDirty = 3 -} -declare enum ComponentTransform { - position = 0, - scale = 1, - rotation = 2 -} -declare class Transform { - readonly entity: Entity; - private _children; - private _parent; - private _localPosition; - private _localRotation; - private _localScale; - private _translationMatrix; - private _rotationMatrix; - private _scaleMatrix; - private _worldTransform; - private _worldToLocalTransform; - private _worldInverseTransform; - private _rotation; - private _position; - private _scale; - private _localTransform; - private _hierachyDirty; - private _localDirty; - private _localPositionDirty; - private _localScaleDirty; - private _localRotationDirty; - private _positionDirty; - private _worldToLocalDirty; - private _worldInverseDirty; - readonly childCount: number; - constructor(entity: Entity); - getChild(index: number): Transform; - readonly worldInverseTransform: Matrix2D; - readonly localToWorldTransform: Matrix2D; - readonly worldToLocalTransform: Matrix2D; - parent: Transform; - setParent(parent: Transform): this; - rotation: number; - localRotation: number; - position: Vector2; - localPosition: Vector2; - scale: Vector2; - localScale: Vector2; - rotationDegrees: number; - localRotationDegrees: number; - setLocalScale(scale: Vector2): this; - setScale(scale: Vector2): this; - setLocalRotationDegrees(degrees: number): this; - setLocalRotation(radians: number): this; - setRotation(radians: number): this; - setRotationDegrees(degrees: number): this; - setLocalPosition(localPosition: Vector2): this; - setPosition(position: Vector2): this; - setDirty(dirtyFlagType: DirtyType): void; - roundPosition(): void; - updateTransform(): void; -} declare class Camera extends Component { private _zoom; private _origin; @@ -347,26 +281,6 @@ declare class ComponentPool { obtain(): T; free(component: T): void; } -declare class Mesh extends Component { - private _verts; - private _primitiveCount; - private _triangles; - private _topLeftVertPosition; - private _width; - private _height; - initialize(): void; - setVertPosition(positions: Vector2[]): this; - setTriangles(triangles: number[]): this; - recalculateBounds(): this; - render(): void; -} -declare class VertexPosition { - position: Vector2; - constructor(position: Vector2); -} -declare class PolygonMesh extends Mesh { - constructor(points: Vector2[], arePointsCCW?: boolean); -} declare abstract class PooledComponent extends Component { abstract reset(): any; } @@ -386,10 +300,15 @@ declare abstract class RenderableComponent extends PooledComponent implements IR protected onBecameInvisible(): void; abstract render(camera: Camera): any; isVisibleFromCamera(camera: Camera): boolean; - onEntityTransformChanged(comp: ComponentTransform): void; } -declare class ScreenSpaceCamera extends Camera { - protected updateMatrixes(): void; +declare class Mesh extends RenderableComponent { + private _mesh; + constructor(); + setTexture(texture: egret.Texture): Mesh; + onAddedToEntity(): void; + onRemovedFromEntity(): void; + render(camera: Camera): void; + reset(): void; } declare class Sprite { texture2D: egret.Texture; @@ -446,7 +365,6 @@ declare abstract class Collider extends Component { collidesWith(collider: Collider, motion: Vector2): CollisionResult; onAddedToEntity(): void; onRemovedFromEntity(): void; - onEntityTransformChanged(comp: ComponentTransform): void; onEnabled(): void; onDisabled(): void; } @@ -528,7 +446,6 @@ declare class ComponentList { getComponent(type: any, onlyReturnInitializedComponents: boolean): T; getComponents(typeName: string | any, components?: any): any; update(): void; - onEntityTransformChanged(comp: any): void; } declare class ComponentTypeManager { private static _componentTypesMask; @@ -632,8 +549,6 @@ declare class Viewport { bounds: Rectangle; constructor(x: number, y: number, width: number, height: number); } -declare abstract class GraphicsResource { -} declare class GaussianBlurEffect extends egret.CustomFilter { private static blur_frag; constructor(); @@ -656,16 +571,6 @@ declare class PostProcessor { protected drawFullscreenQuad(): void; unload(): void; } -declare class BloomSettings { - readonly threshold: any; - readonly blurAmount: any; - readonly intensity: any; - readonly baseIntensity: any; - readonly saturation: any; - readonly baseStaturation: any; - constructor(bloomThreshold: number, blurAmount: number, bloomIntensity: number, baseIntensity: number, bloomSaturation: number, baseSaturation: number); - static presetSettings: BloomSettings[]; -} declare class GaussianBlurPostProcessor extends PostProcessor { onAddedToScene(scene: Scene): void; } diff --git a/source/bin/framework.js b/source/bin/framework.js index d970796c..0f65d055 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1,5859 +1,4858 @@ -var __extends = - (this && this.__extends) || - (function () { - var extendStatics = - Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && - function (d, b) { - d.__proto__ = b; - }) || - function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - }; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { - extendStatics(d, b); - function __() { - this.constructor = d; - } - d.prototype = - b === null - ? Object.create(b) - : ((__.prototype = b.prototype), new __()); - }; - })(); -var __awaiter = - (this && this.__awaiter) || - function (thisArg, _arguments, P, generator) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { - try { - step(generator.next(value)); - } catch (e) { - reject(e); - } - } - function rejected(value) { - try { - step(generator["throw"](value)); - } catch (e) { - reject(e); - } - } - function step(result) { - result.done - ? resolve(result.value) - : new P(function (resolve) { - resolve(result.value); - }).then(fulfilled, rejected); - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); }); - }; -var __generator = - (this && this.__generator) || - function (thisArg, body) { - var _ = { - label: 0, - sent: function () { - if (t[0] & 1) throw t[1]; - return t[1]; - }, - trys: [], - ops: [], - }, - f, - y, - t, - g; - return ( - (g = { next: verb(0), throw: verb(1), return: verb(2) }), - typeof Symbol === "function" && - (g[Symbol.iterator] = function () { - return this; - }), - g - ); - function verb(n) { - return function (v) { - return step([n, v]); - }; - } +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) - try { - if ( - ((f = 1), - y && - (t = - op[0] & 2 - ? y["return"] - : op[0] - ? y["throw"] || ((t = y["return"]) && t.call(y), 0) - : y.next) && - !(t = t.call(y, op[1])).done) - ) - return t; - if (((y = 0), t)) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: - case 1: - t = op; - break; - case 4: - _.label++; - return { value: op[1], done: false }; - case 5: - _.label++; - y = op[1]; - op = [0]; - continue; - case 7: - op = _.ops.pop(); - _.trys.pop(); - continue; - default: - if ( - !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && - (op[0] === 6 || op[0] === 2) - ) { - _ = 0; - continue; - } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { - _.label = op[1]; - break; - } - if (op[0] === 6 && _.label < t[1]) { - _.label = t[1]; - t = op; - break; - } - if (t && _.label < t[2]) { - _.label = t[2]; - _.ops.push(op); - break; - } - if (t[2]) _.ops.pop(); - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } catch (e) { - op = [6, e]; - y = 0; - } finally { - f = t = 0; - } - if (op[0] & 5) throw op[1]; - return { value: op[0] ? op[1] : void 0, done: true }; + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } - }; +}; Array.prototype.findIndex = function (predicate) { - function findIndex(array, predicate) { - for (var i = 0, len = array.length; i < len; i++) { - if (predicate.call(arguments[2], array[i], i, array)) { - return i; - } + function findIndex(array, predicate) { + for (var i = 0, len = array.length; i < len; i++) { + if (predicate.call(arguments[2], array[i], i, array)) { + return i; + } + } + return -1; } - return -1; - } - return findIndex(this, predicate); + return findIndex(this, predicate); }; Array.prototype.any = function (predicate) { - function any(array, predicate) { - return array.findIndex(predicate) > -1; - } - return any(this, predicate); + function any(array, predicate) { + return array.findIndex(predicate) > -1; + } + return any(this, predicate); }; Array.prototype.firstOrDefault = function (predicate) { - function firstOrDefault(array, predicate) { - var index = array.findIndex(predicate); - return index == -1 ? null : array[index]; - } - return firstOrDefault(this, predicate); + function firstOrDefault(array, predicate) { + var index = array.findIndex(predicate); + return index == -1 ? null : array[index]; + } + return firstOrDefault(this, predicate); }; Array.prototype.find = function (predicate) { - function find(array, predicate) { - return array.firstOrDefault(predicate); - } - return find(this, predicate); + function find(array, predicate) { + return array.firstOrDefault(predicate); + } + return find(this, predicate); }; Array.prototype.where = function (predicate) { - function where(array, predicate) { - if (typeof array.reduce === "function") { - return array.reduce(function (ret, element, index) { - if (predicate.call(arguments[2], element, index, array)) { - ret.push(element); + function where(array, predicate) { + if (typeof (array.reduce) === "function") { + return array.reduce(function (ret, element, index) { + if (predicate.call(arguments[2], element, index, array)) { + ret.push(element); + } + return ret; + }, []); + } + else { + var ret = []; + for (var i = 0, len = array.length; i < len; i++) { + var element = array[i]; + if (predicate.call(arguments[2], element, i, array)) { + ret.push(element); + } + } + return ret; } - return ret; - }, []); - } else { - var ret = []; - for (var i = 0, len = array.length; i < len; i++) { - var element = array[i]; - if (predicate.call(arguments[2], element, i, array)) { - ret.push(element); - } - } - return ret; } - } - return where(this, predicate); + return where(this, predicate); }; Array.prototype.count = function (predicate) { - function count(array, predicate) { - return array.where(predicate).length; - } - return count(this, predicate); + function count(array, predicate) { + return array.where(predicate).length; + } + return count(this, predicate); }; Array.prototype.findAll = function (predicate) { - function findAll(array, predicate) { - return array.where(predicate); - } - return findAll(this, predicate); + function findAll(array, predicate) { + return array.where(predicate); + } + return findAll(this, predicate); }; Array.prototype.contains = function (value) { - function contains(array, value) { - for (var i = 0, len = array.length; i < len; i++) { - if (array[i] == value) { - return true; - } + function contains(array, value) { + for (var i = 0, len = array.length; i < len; i++) { + if (array[i] == value) { + return true; + } + } + return false; } - return false; - } - return contains(this, value); + return contains(this, value); }; Array.prototype.removeAll = function (predicate) { - function removeAll(array, predicate) { - var index; - do { - index = array.findIndex(predicate); - if (index >= 0) { - array.splice(index, 1); - } - } while (index >= 0); - } - removeAll(this, predicate); + function removeAll(array, predicate) { + var index; + do { + index = array.findIndex(predicate); + if (index >= 0) { + array.splice(index, 1); + } + } while (index >= 0); + } + removeAll(this, predicate); }; Array.prototype.remove = function (element) { - function remove(array, element) { - var index = array.findIndex(function (x) { - return x === element; - }); - if (index >= 0) { - array.splice(index, 1); - return true; - } else { - return false; + function remove(array, element) { + var index = array.findIndex(function (x) { + return x === element; + }); + if (index >= 0) { + array.splice(index, 1); + return true; + } + else { + return false; + } } - } - return remove(this, element); + return remove(this, element); }; Array.prototype.removeAt = function (index) { - function removeAt(array, index) { - array.splice(index, 1); - } - return removeAt(this, index); + function removeAt(array, index) { + array.splice(index, 1); + } + return removeAt(this, index); }; Array.prototype.removeRange = function (index, count) { - function removeRange(array, index, count) { - array.splice(index, count); - } - return removeRange(this, index, count); + function removeRange(array, index, count) { + array.splice(index, count); + } + return removeRange(this, index, count); }; Array.prototype.select = function (selector) { - function select(array, selector) { - if (typeof array.reduce === "function") { - return array.reduce(function (ret, element, index) { - ret.push(selector.call(arguments[2], element, index, array)); - return ret; - }, []); - } else { - var ret = []; - for (var i = 0, len = array.length; i < len; i++) { - ret.push(selector.call(arguments[2], array[i], i, array)); - } - return ret; + function select(array, selector) { + if (typeof (array.reduce) === "function") { + return array.reduce(function (ret, element, index) { + ret.push(selector.call(arguments[2], element, index, array)); + return ret; + }, []); + } + else { + var ret = []; + for (var i = 0, len = array.length; i < len; i++) { + ret.push(selector.call(arguments[2], array[i], i, array)); + } + return ret; + } } - } - return select(this, selector); + return select(this, selector); }; Array.prototype.orderBy = function (keySelector, comparer) { - function orderBy(array, keySelector, comparer) { - array.sort(function (x, y) { - var v1 = keySelector(x); - var v2 = keySelector(y); - if (comparer) { - return comparer(v1, v2); - } else { - return v1 > v2 ? 1 : -1; - } - }); - return array; - } - return orderBy(this, keySelector, comparer); + function orderBy(array, keySelector, comparer) { + array.sort(function (x, y) { + var v1 = keySelector(x); + var v2 = keySelector(y); + if (comparer) { + return comparer(v1, v2); + } + else { + return (v1 > v2) ? 1 : -1; + } + }); + return array; + } + return orderBy(this, keySelector, comparer); }; Array.prototype.orderByDescending = function (keySelector, comparer) { - function orderByDescending(array, keySelector, comparer) { - array.sort(function (x, y) { - var v1 = keySelector(x); - var v2 = keySelector(y); - if (comparer) { - return -comparer(v1, v2); - } else { - return v1 < v2 ? 1 : -1; - } - }); - return array; - } - return orderByDescending(this, keySelector, comparer); + function orderByDescending(array, keySelector, comparer) { + array.sort(function (x, y) { + var v1 = keySelector(x); + var v2 = keySelector(y); + if (comparer) { + return -comparer(v1, v2); + } + else { + return (v1 < v2) ? 1 : -1; + } + }); + return array; + } + return orderByDescending(this, keySelector, comparer); }; Array.prototype.groupBy = function (keySelector) { - function groupBy(array, keySelector) { - if (typeof array.reduce === "function") { - var keys_1 = []; - return array.reduce(function (groups, element, index) { - var key = JSON.stringify( - keySelector.call(arguments[1], element, index, array) - ); - var index2 = keys_1.findIndex(function (x) { - return x === key; - }); - if (index2 < 0) { - index2 = keys_1.push(key) - 1; - } - if (!groups[index2]) { - groups[index2] = []; - } - groups[index2].push(element); - return groups; - }, []); - } else { - var groups = []; - var keys = []; - var _loop_1 = function (i, len) { - var key = JSON.stringify( - keySelector.call(arguments_1[1], array[i], i, array) - ); - var index = keys.findIndex(function (x) { - return x === key; - }); - if (index < 0) { - index = keys.push(key) - 1; - } - if (!groups[index]) { - groups[index] = []; - } - groups[index].push(array[i]); - }; - var arguments_1 = arguments; - for (var i = 0, len = array.length; i < len; i++) { - _loop_1(i, len); - } - return groups; + function groupBy(array, keySelector) { + if (typeof (array.reduce) === "function") { + var keys_1 = []; + return array.reduce(function (groups, element, index) { + var key = JSON.stringify(keySelector.call(arguments[1], element, index, array)); + var index2 = keys_1.findIndex(function (x) { return x === key; }); + if (index2 < 0) { + index2 = keys_1.push(key) - 1; + } + if (!groups[index2]) { + groups[index2] = []; + } + groups[index2].push(element); + return groups; + }, []); + } + else { + var groups = []; + var keys = []; + var _loop_1 = function (i, len) { + var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array)); + var index = keys.findIndex(function (x) { return x === key; }); + if (index < 0) { + index = keys.push(key) - 1; + } + if (!groups[index]) { + groups[index] = []; + } + groups[index].push(array[i]); + }; + var arguments_1 = arguments; + for (var i = 0, len = array.length; i < len; i++) { + _loop_1(i, len); + } + return groups; + } } - } - return groupBy(this, keySelector); + return groupBy(this, keySelector); }; Array.prototype.sum = function (selector) { - function sum(array, selector) { - var ret; - for (var i = 0, len = array.length; i < len; i++) { - if (i == 0) { - if (selector) { - ret = selector.call(arguments[2], array[i], i, array); - } else { - ret = array[i]; - } - } else { - if (selector) { - ret += selector.call(arguments[2], array[i], i, array); - } else { - ret += array[i]; - } - } + function sum(array, selector) { + var ret; + for (var i = 0, len = array.length; i < len; i++) { + if (i == 0) { + if (selector) { + ret = selector.call(arguments[2], array[i], i, array); + } + else { + ret = array[i]; + } + } + else { + if (selector) { + ret += selector.call(arguments[2], array[i], i, array); + } + else { + ret += array[i]; + } + } + } + return ret; } - return ret; - } - return sum(this, selector); + return sum(this, selector); }; var PriorityQueueNode = (function () { - function PriorityQueueNode() { - this.priority = 0; - this.insertionIndex = 0; - this.queueIndex = 0; - } - return PriorityQueueNode; -})(); -var AStarPathfinder = (function () { - function AStarPathfinder() {} - AStarPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new AStarNode(start), 0); - costSoFar.set(start, 0); - var _loop_2 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = - costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priority = newCost + graph.heuristic(next, goal); - frontier.enqueue(new AStarNode(next), priority); - cameFrom.set(next, current.data); - } - }); - }; - while (frontier.count > 0) { - var state_1 = _loop_2(); - if (state_1 === "break") break; - } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - AStarPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (((r = iterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return true; + function PriorityQueueNode() { + this.priority = 0; + this.insertionIndex = 0; + this.queueIndex = 0; } - return false; - }; - AStarPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (((r = iterator.next()), (v = valueIterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return v.value; - } - return null; - }; - AStarPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return AStarPathfinder; -})(); + return PriorityQueueNode; +}()); +var AStarPathfinder = (function () { + function AStarPathfinder() { + } + AStarPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new PriorityQueue(1000); + frontier.enqueue(new AStarNode(start), 0); + costSoFar.set(start, 0); + var _loop_2 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priority = newCost + graph.heuristic(next, goal); + frontier.enqueue(new AStarNode(next), priority); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_1 = _loop_2(); + if (state_1 === "break") + break; + } + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; + }; + AStarPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + AStarPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + AStarPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return AStarPathfinder; +}()); var AStarNode = (function (_super) { - __extends(AStarNode, _super); - function AStarNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return AStarNode; -})(PriorityQueueNode); + __extends(AStarNode, _super); + function AStarNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return AStarNode; +}(PriorityQueueNode)); var AstarGridGraph = (function () { - function AstarGridGraph(width, height) { - this.dirs = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]; - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - } - AstarGridGraph.prototype.isNodeInBounds = function (node) { - return ( - 0 <= node.x && - node.x < this._width && - 0 <= node.y && - node.y < this._height - ); - }; - AstarGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { - return JSON.stringify(wall) == JSON.stringify(node); - }); - }; - AstarGridGraph.prototype.search = function (start, goal) { - return AStarPathfinder.search(this, start, goal); - }; - AstarGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this.dirs.forEach(function (dir) { - var next = new Point(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - AstarGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (p) { - return JSON.stringify(p) == JSON.stringify(to); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }; - AstarGridGraph.prototype.heuristic = function (node, goal) { - return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); - }; - return AstarGridGraph; -})(); + function AstarGridGraph(width, height) { + this.dirs = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, 1) + ]; + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; + } + AstarGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + AstarGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + AstarGridGraph.prototype.search = function (start, goal) { + return AStarPathfinder.search(this, start, goal); + }; + AstarGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this.dirs.forEach(function (dir) { + var next = new Point(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + AstarGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + AstarGridGraph.prototype.heuristic = function (node, goal) { + return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); + }; + return AstarGridGraph; +}()); var PriorityQueue = (function () { - function PriorityQueue(maxNodes) { - this._numNodes = 0; - this._nodes = new Array(maxNodes + 1); - this._numNodesEverEnqueued = 0; - } - PriorityQueue.prototype.clear = function () { - this._nodes.splice(1, this._numNodes); - this._numNodes = 0; - }; - Object.defineProperty(PriorityQueue.prototype, "count", { - get: function () { - return this._numNodes; - }, - enumerable: true, - configurable: true, - }); - PriorityQueue.prototype.contains = function (node) { - return this._nodes[node.queueIndex] == node; - }; - PriorityQueue.prototype.enqueue = function (node, priority) { - node.priority = priority; - this._numNodes++; - this._nodes[this._numNodes] = node; - node.queueIndex = this._numNodes; - node.insertionIndex = this._numNodesEverEnqueued++; - this.cascadeUp(this._nodes[this._numNodes]); - }; - PriorityQueue.prototype.dequeue = function () { - var returnMe = this._nodes[1]; - this.remove(returnMe); - return returnMe; - }; - PriorityQueue.prototype.remove = function (node) { - if (node.queueIndex == this._numNodes) { - this._nodes[this._numNodes] = null; - this._numNodes--; - return; - } - var formerLastNode = this._nodes[this._numNodes]; - this.swap(node, formerLastNode); - delete this._nodes[this._numNodes]; - this._numNodes--; - this.onNodeUpdated(formerLastNode); - }; - PriorityQueue.prototype.isValidQueue = function () { - for (var i = 1; i < this._nodes.length; i++) { - if (this._nodes[i]) { - var childLeftIndex = 2 * i; - if ( - childLeftIndex < this._nodes.length && - this._nodes[childLeftIndex] && - this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i]) - ) - return false; - var childRightIndex = childLeftIndex + 1; - if ( - childRightIndex < this._nodes.length && - this._nodes[childRightIndex] && - this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i]) - ) - return false; - } - } - return true; - }; - PriorityQueue.prototype.onNodeUpdated = function (node) { - var parentIndex = Math.floor(node.queueIndex / 2); - var parentNode = this._nodes[parentIndex]; - if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { - this.cascadeUp(node); - } else { - this.cascadeDown(node); - } - }; - PriorityQueue.prototype.cascadeDown = function (node) { - var newParent; - var finalQueueIndex = node.queueIndex; - while (true) { - newParent = node; - var childLeftIndex = 2 * finalQueueIndex; - if (childLeftIndex > this._numNodes) { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - var childLeft = this._nodes[childLeftIndex]; - if (this.hasHigherPriority(childLeft, newParent)) { - newParent = childLeft; - } - var childRightIndex = childLeftIndex + 1; - if (childRightIndex <= this._numNodes) { - var childRight = this._nodes[childRightIndex]; - if (this.hasHigherPriority(childRight, newParent)) { - newParent = childRight; - } - } - if (newParent != node) { - this._nodes[finalQueueIndex] = newParent; - var temp = newParent.queueIndex; - newParent.queueIndex = finalQueueIndex; - finalQueueIndex = temp; - } else { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - } - }; - PriorityQueue.prototype.cascadeUp = function (node) { - var parent = Math.floor(node.queueIndex / 2); - while (parent >= 1) { - var parentNode = this._nodes[parent]; - if (this.hasHigherPriority(parentNode, node)) break; - this.swap(node, parentNode); - parent = Math.floor(node.queueIndex / 2); - } - }; - PriorityQueue.prototype.swap = function (node1, node2) { - this._nodes[node1.queueIndex] = node2; - this._nodes[node2.queueIndex] = node1; - var temp = node1.queueIndex; - node1.queueIndex = node2.queueIndex; - node2.queueIndex = temp; - }; - PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { - return ( - higher.priority < lower.priority || - (higher.priority == lower.priority && - higher.insertionIndex < lower.insertionIndex) - ); - }; - return PriorityQueue; -})(); + function PriorityQueue(maxNodes) { + this._numNodes = 0; + this._nodes = new Array(maxNodes + 1); + this._numNodesEverEnqueued = 0; + } + PriorityQueue.prototype.clear = function () { + this._nodes.splice(1, this._numNodes); + this._numNodes = 0; + }; + Object.defineProperty(PriorityQueue.prototype, "count", { + get: function () { + return this._numNodes; + }, + enumerable: true, + configurable: true + }); + PriorityQueue.prototype.contains = function (node) { + return (this._nodes[node.queueIndex] == node); + }; + PriorityQueue.prototype.enqueue = function (node, priority) { + node.priority = priority; + this._numNodes++; + this._nodes[this._numNodes] = node; + node.queueIndex = this._numNodes; + node.insertionIndex = this._numNodesEverEnqueued++; + this.cascadeUp(this._nodes[this._numNodes]); + }; + PriorityQueue.prototype.dequeue = function () { + var returnMe = this._nodes[1]; + this.remove(returnMe); + return returnMe; + }; + PriorityQueue.prototype.remove = function (node) { + if (node.queueIndex == this._numNodes) { + this._nodes[this._numNodes] = null; + this._numNodes--; + return; + } + var formerLastNode = this._nodes[this._numNodes]; + this.swap(node, formerLastNode); + delete this._nodes[this._numNodes]; + this._numNodes--; + this.onNodeUpdated(formerLastNode); + }; + PriorityQueue.prototype.isValidQueue = function () { + for (var i = 1; i < this._nodes.length; i++) { + if (this._nodes[i]) { + var childLeftIndex = 2 * i; + if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && + this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) + return false; + var childRightIndex = childLeftIndex + 1; + if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && + this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) + return false; + } + } + return true; + }; + PriorityQueue.prototype.onNodeUpdated = function (node) { + var parentIndex = Math.floor(node.queueIndex / 2); + var parentNode = this._nodes[parentIndex]; + if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { + this.cascadeUp(node); + } + else { + this.cascadeDown(node); + } + }; + PriorityQueue.prototype.cascadeDown = function (node) { + var newParent; + var finalQueueIndex = node.queueIndex; + while (true) { + newParent = node; + var childLeftIndex = 2 * finalQueueIndex; + if (childLeftIndex > this._numNodes) { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } + var childLeft = this._nodes[childLeftIndex]; + if (this.hasHigherPriority(childLeft, newParent)) { + newParent = childLeft; + } + var childRightIndex = childLeftIndex + 1; + if (childRightIndex <= this._numNodes) { + var childRight = this._nodes[childRightIndex]; + if (this.hasHigherPriority(childRight, newParent)) { + newParent = childRight; + } + } + if (newParent != node) { + this._nodes[finalQueueIndex] = newParent; + var temp = newParent.queueIndex; + newParent.queueIndex = finalQueueIndex; + finalQueueIndex = temp; + } + else { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } + } + }; + PriorityQueue.prototype.cascadeUp = function (node) { + var parent = Math.floor(node.queueIndex / 2); + while (parent >= 1) { + var parentNode = this._nodes[parent]; + if (this.hasHigherPriority(parentNode, node)) + break; + this.swap(node, parentNode); + parent = Math.floor(node.queueIndex / 2); + } + }; + PriorityQueue.prototype.swap = function (node1, node2) { + this._nodes[node1.queueIndex] = node2; + this._nodes[node2.queueIndex] = node1; + var temp = node1.queueIndex; + node1.queueIndex = node2.queueIndex; + node2.queueIndex = temp; + }; + PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { + return (higher.priority < lower.priority || + (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); + }; + return PriorityQueue; +}()); var BreadthFirstPathfinder = (function () { - function BreadthFirstPathfinder() {} - BreadthFirstPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var frontier = []; - frontier.unshift(start); - var cameFrom = new Map(); - cameFrom.set(start, start); - var _loop_3 = function () { - var current = frontier.shift(); - if (JSON.stringify(current) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current).forEach(function (next) { - if (!_this.hasKey(cameFrom, next)) { - frontier.unshift(next); - cameFrom.set(next, current); - } - }); - }; - while (frontier.length > 0) { - var state_2 = _loop_3(); - if (state_2 === "break") break; - } - return foundPath - ? AStarPathfinder.recontructPath(cameFrom, start, goal) - : null; - }; - BreadthFirstPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (((r = iterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return true; - } - return false; - }; - return BreadthFirstPathfinder; -})(); + function BreadthFirstPathfinder() { + } + BreadthFirstPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var frontier = []; + frontier.unshift(start); + var cameFrom = new Map(); + cameFrom.set(start, start); + var _loop_3 = function () { + var current = frontier.shift(); + if (JSON.stringify(current) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current).forEach(function (next) { + if (!_this.hasKey(cameFrom, next)) { + frontier.unshift(next); + cameFrom.set(next, current); + } + }); + }; + while (frontier.length > 0) { + var state_2 = _loop_3(); + if (state_2 === "break") + break; + } + return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null; + }; + BreadthFirstPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + return BreadthFirstPathfinder; +}()); var UnweightedGraph = (function () { - function UnweightedGraph() { - this.edges = new Map(); - } - UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { - this.edges.set(node, edges); - return this; - }; - UnweightedGraph.prototype.getNeighbors = function (node) { - return this.edges.get(node); - }; - return UnweightedGraph; -})(); + function UnweightedGraph() { + this.edges = new Map(); + } + UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { + this.edges.set(node, edges); + return this; + }; + UnweightedGraph.prototype.getNeighbors = function (node) { + return this.edges.get(node); + }; + return UnweightedGraph; +}()); var Point = (function () { - function Point(x, y) { - this.x = x ? x : 0; - this.y = y ? y : this.x; - } - return Point; -})(); -var UnweightedGridGraph = (function () { - function UnweightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { - allowDiagonalSearch = false; + function Point(x, y) { + this.x = x ? x : 0; + this.y = y ? y : this.x; } - this.walls = []; - this._neighbors = new Array(4); - this._width = width; - this._hegiht = height; - this._dirs = allowDiagonalSearch - ? UnweightedGridGraph.COMPASS_DIRS - : UnweightedGridGraph.CARDINAL_DIRS; - } - UnweightedGridGraph.prototype.isNodeInBounds = function (node) { - return ( - 0 <= node.x && - node.x < this._width && - 0 <= node.y && - node.y < this._hegiht - ); - }; - UnweightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { - return JSON.stringify(wall) == JSON.stringify(node); - }); - }; - UnweightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Point(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - UnweightedGridGraph.prototype.search = function (start, goal) { - return BreadthFirstPathfinder.search(this, start, goal); - }; - UnweightedGridGraph.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, -1), - ]; - UnweightedGridGraph.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]; - return UnweightedGridGraph; -})(); + return Point; +}()); +var UnweightedGridGraph = (function () { + function UnweightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this._neighbors = new Array(4); + this._width = width; + this._hegiht = height; + this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; + } + UnweightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; + }; + UnweightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + UnweightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new Point(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + UnweightedGridGraph.prototype.search = function (start, goal) { + return BreadthFirstPathfinder.search(this, start, goal); + }; + UnweightedGridGraph.CARDINAL_DIRS = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, -1) + ]; + UnweightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return UnweightedGridGraph; +}()); var WeightedGridGraph = (function () { - function WeightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { - allowDiagonalSearch = false; - } - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - this._dirs = allowDiagonalSearch - ? WeightedGridGraph.COMPASS_DIRS - : WeightedGridGraph.CARDINAL_DIRS; - } - WeightedGridGraph.prototype.isNodeInBounds = function (node) { - return ( - 0 <= node.x && - node.x < this._width && - 0 <= node.y && - node.y < this._height - ); - }; - WeightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { - return JSON.stringify(wall) == JSON.stringify(node); - }); - }; - WeightedGridGraph.prototype.search = function (start, goal) { - return WeightedPathfinder.search(this, start, goal); - }; - WeightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Point(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - WeightedGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (t) { - return JSON.stringify(t) == JSON.stringify(to); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }; - WeightedGridGraph.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]; - WeightedGridGraph.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]; - return WeightedGridGraph; -})(); + function WeightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; + this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; + } + WeightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + WeightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + WeightedGridGraph.prototype.search = function (start, goal) { + return WeightedPathfinder.search(this, start, goal); + }; + WeightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new Point(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + WeightedGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + WeightedGridGraph.CARDINAL_DIRS = [ + new Point(1, 0), + new Point(0, -1), + new Point(-1, 0), + new Point(0, 1) + ]; + WeightedGridGraph.COMPASS_DIRS = [ + new Point(1, 0), + new Point(1, -1), + new Point(0, -1), + new Point(-1, -1), + new Point(-1, 0), + new Point(-1, 1), + new Point(0, 1), + new Point(1, 1), + ]; + return WeightedGridGraph; +}()); var WeightedNode = (function (_super) { - __extends(WeightedNode, _super); - function WeightedNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return WeightedNode; -})(PriorityQueueNode); + __extends(WeightedNode, _super); + function WeightedNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return WeightedNode; +}(PriorityQueueNode)); var WeightedPathfinder = (function () { - function WeightedPathfinder() {} - WeightedPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new WeightedNode(start), 0); - costSoFar.set(start, 0); - var _loop_4 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = - costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priprity = newCost; - frontier.enqueue(new WeightedNode(next), priprity); - cameFrom.set(next, current.data); - } - }); - }; - while (frontier.count > 0) { - var state_3 = _loop_4(); - if (state_3 === "break") break; - } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - WeightedPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (((r = iterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return true; - } - return false; - }; - WeightedPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (((r = iterator.next()), (v = valueIterator.next()), !r.done)) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) return v.value; - } - return null; - }; - WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return WeightedPathfinder; -})(); + function WeightedPathfinder() { + } + WeightedPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new PriorityQueue(1000); + frontier.enqueue(new WeightedNode(start), 0); + costSoFar.set(start, 0); + var _loop_4 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priprity = newCost; + frontier.enqueue(new WeightedNode(next), priprity); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_3 = _loop_4(); + if (state_3 === "break") + break; + } + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; + }; + WeightedPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + WeightedPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return WeightedPathfinder; +}()); var DebugDefaults = (function () { - function DebugDefaults() {} - DebugDefaults.verletParticle = 0xdc345e; - DebugDefaults.verletConstraintEdge = 0x433e36; - return DebugDefaults; -})(); -var Component = (function (_super) { - __extends(Component, _super); - function Component() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this._enabled = true; - _this.updateInterval = 1; - return _this; - } - Object.defineProperty(Component.prototype, "enabled", { - get: function () { - return this.entity ? this.entity.enabled && this._enabled : this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true, - }); - Component.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); - } else { - this.onDisabled(); - } + function DebugDefaults() { } - return this; - }; - Component.prototype.initialize = function () {}; - Component.prototype.onAddedToEntity = function () {}; - Component.prototype.onRemovedFromEntity = function () {}; - Component.prototype.onEnabled = function () {}; - Component.prototype.onDisabled = function () {}; - Component.prototype.onEntityTransformChanged = function (comp) {}; - Component.prototype.update = function () {}; - Component.prototype.debugRender = function () {}; - Component.prototype.registerComponent = function () { - this.entity.componentBits.set( - ComponentTypeManager.getIndexFor(this), - false - ); - this.entity.scene.entityProcessors.onComponentAdded(this.entity); - }; - Component.prototype.deregisterComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)); - this.entity.scene.entityProcessors.onComponentRemoved(this.entity); - }; - return Component; -})(egret.DisplayObjectContainer); + DebugDefaults.verletParticle = 0xDC345E; + DebugDefaults.verletConstraintEdge = 0x433E36; + return DebugDefaults; +}()); +var Component = (function (_super) { + __extends(Component, _super); + function Component() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._enabled = true; + _this.updateInterval = 1; + return _this; + } + Object.defineProperty(Component.prototype, "enabled", { + get: function () { + return this.entity ? this.entity.enabled && this._enabled : this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Component.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } + } + return this; + }; + Component.prototype.initialize = function () { + }; + Component.prototype.onAddedToEntity = function () { + }; + Component.prototype.onRemovedFromEntity = function () { + }; + Component.prototype.onEnabled = function () { + }; + Component.prototype.onDisabled = function () { + }; + Component.prototype.update = function () { + }; + Component.prototype.debugRender = function () { + }; + Component.prototype.registerComponent = function () { + this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false); + this.entity.scene.entityProcessors.onComponentAdded(this.entity); + }; + Component.prototype.deregisterComponent = function () { + this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)); + this.entity.scene.entityProcessors.onComponentRemoved(this.entity); + }; + return Component; +}(egret.DisplayObjectContainer)); var Entity = (function (_super) { - __extends(Entity, _super); - function Entity(name) { - var _this = _super.call(this) || this; - _this._position = Vector2.zero; - _this._updateOrder = 0; - _this._enabled = true; - _this._tag = 0; - _this.name = name; - _this.components = new ComponentList(_this); - _this.id = Entity._idGenerator++; - _this.componentBits = new BitSet(); - return _this; - } - Object.defineProperty(Entity.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "position", { - get: function () { - return this._position; - }, - set: function (value) { - this._position = value; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "scale", { - get: function () { - return new Vector2(this.scaleX, this.scaleY); - }, - set: function (value) { - this.scaleX = value.x; - this.scaleY = value.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true, - }); - Entity.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - } - return this; - }; - Object.defineProperty(Entity.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (value) { - this.setTag(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "stage", { - get: function () { - if (!this.scene) return null; - return this.scene.stage; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Entity.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (value) { - this.setUpdateOrder(value); - }, - enumerable: true, - configurable: true, - }); - Entity.prototype.roundPosition = function () { - this.position = Vector2Ext.round(this.position); - }; - Entity.prototype.setUpdateOrder = function (updateOrder) { - if (this._updateOrder != updateOrder) { - this._updateOrder = updateOrder; - if (this.scene) { - } - return this; - } - }; - Entity.prototype.setTag = function (tag) { - if (this._tag != tag) { - if (this.scene) { - this.scene.entities.removeFromTagList(this); - } - this._tag = tag; - if (this.scene) { - this.scene.entities.addToTagList(this); - } - } - return this; - }; - Entity.prototype.attachToScene = function (newScene) { - this.scene = newScene; - newScene.entities.add(this); - this.components.registerAllComponents(); - for (var i = 0; i < this.numChildren; i++) { - this.getChildAt(i).entity.attachToScene(newScene); - } - }; - Entity.prototype.detachFromScene = function () { - this.scene.entities.remove(this); - this.components.deregisterAllComponents(); - for (var i = 0; i < this.numChildren; i++) - this.getChildAt(i).entity.detachFromScene(); - }; - Entity.prototype.addComponent = function (component) { - component.entity = this; - this.components.add(component); - this.addChild(component); - component.initialize(); - return component; - }; - Entity.prototype.hasComponent = function (type) { - return this.components.getComponent(type, false) != null; - }; - Entity.prototype.getOrCreateComponent = function (type) { - var comp = this.components.getComponent(type, true); - if (!comp) { - comp = this.addComponent(type); - } - return comp; - }; - Entity.prototype.getComponent = function (type) { - return this.components.getComponent(type, false); - }; - Entity.prototype.getComponents = function (typeName, componentList) { - return this.components.getComponents(typeName, componentList); - }; - Entity.prototype.removeComponentForType = function (type) { - var comp = this.getComponent(type); - if (comp) { - this.removeComponent(comp); - return true; - } - return false; - }; - Entity.prototype.removeComponent = function (component) { - this.components.remove(component); - }; - Entity.prototype.removeAllComponents = function () { - for (var i = 0; i < this.components.count; i++) { - this.removeComponent(this.components.buffer[i]); - } - }; - Entity.prototype.update = function () { - this.components.update(); - }; - Entity.prototype.onAddedToScene = function () {}; - Entity.prototype.onRemovedFromScene = function () { - if (this._isDestoryed) this.components.removeAllComponents(); - }; - Entity.prototype.onTransformChanged = function (comp) { - this.components.onEntityTransformChanged(comp); - }; - Entity.prototype.destroy = function () { - this._isDestoryed = true; - this.scene.entities.remove(this); - this.removeChildren(); - for (var i = this.numChildren - 1; i >= 0; i--) { - var child = this.getChildAt(i); - child.entity.destroy(); - } - }; - return Entity; -})(egret.DisplayObjectContainer); -var Scene = (function (_super) { - __extends(Scene, _super); - function Scene() { - var _this = _super.call(this) || this; - _this.enablePostProcessing = true; - _this._renderers = []; - _this._postProcessors = []; - _this.entityProcessors = new EntityProcessorList(); - _this.renderableComponents = new RenderableComponentList(); - _this.entities = new EntityList(_this); - _this.content = new ContentManager(); - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); - _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); - return _this; - } - Scene.prototype.createEntity = function (name) { - var entity = new Entity(name); - entity.position = new Vector2(0, 0); - return this.addEntity(entity); - }; - Scene.prototype.addEntity = function (entity) { - this.entities.add(entity); - entity.scene = this; - this.addChild(entity); - for (var i = 0; i < entity.numChildren; i++) - this.addEntity(entity.getChildAt(i).entity); - return entity; - }; - Scene.prototype.destroyAllEntities = function () { - for (var i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destroy(); - } - }; - Scene.prototype.findEntity = function (name) { - return this.entities.findEntity(name); - }; - Scene.prototype.addEntityProcessor = function (processor) { - processor.scene = this; - this.entityProcessors.add(processor); - return processor; - }; - Scene.prototype.removeEntityProcessor = function (processor) { - this.entityProcessors.remove(processor); - }; - Scene.prototype.getEntityProcessor = function () { - return this.entityProcessors.getProcessor(); - }; - Scene.prototype.addRenderer = function (renderer) { - this._renderers.push(renderer); - this._renderers.sort(); - renderer.onAddedToScene(this); - return renderer; - }; - Scene.prototype.getRenderer = function (type) { - for (var i = 0; i < this._renderers.length; i++) { - if (this._renderers[i] instanceof type) return this._renderers[i]; - } - return null; - }; - Scene.prototype.removeRenderer = function (renderer) { - this._renderers.remove(renderer); - renderer.unload(); - }; - Scene.prototype.begin = function () { - if (SceneManager.sceneTransition) { - SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); - } else { - SceneManager.stage.addChild(this); - } - if (this._renderers.length == 0) { - this.addRenderer(new DefaultRenderer()); - console.warn( - "场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染" - ); - } - this.camera = this.createEntity("camera").getOrCreateComponent( - new Camera() - ); - Physics.reset(); - if (this.entityProcessors) this.entityProcessors.begin(); - this.camera.onSceneSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ); - this._didSceneBegin = true; - this.onStart(); - }; - Scene.prototype.end = function () { - this._didSceneBegin = false; - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].unload(); - } - for (var i = 0; i < this._postProcessors.length; i++) { - this._postProcessors[i].unload(); - } - this.entities.removeAllEntities(); - this.removeChildren(); - Physics.clear(); - this.camera = null; - this.content.dispose(); - if (this.entityProcessors) this.entityProcessors.end(); - this.unload(); - }; - Scene.prototype.onStart = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2]; - }); + __extends(Entity, _super); + function Entity(name) { + var _this = _super.call(this) || this; + _this._position = Vector2.zero; + _this._updateOrder = 0; + _this._enabled = true; + _this._tag = 0; + _this.name = name; + _this.components = new ComponentList(_this); + _this.id = Entity._idGenerator++; + _this.componentBits = new BitSet(); + return _this; + } + Object.defineProperty(Entity.prototype, "isDestoryed", { + get: function () { + return this._isDestoryed; + }, + enumerable: true, + configurable: true }); - }; - Scene.prototype.onActive = function () {}; - Scene.prototype.onDeactive = function () {}; - Scene.prototype.unload = function () {}; - Scene.prototype.update = function () { - this.entities.updateLists(); - if (this.entityProcessors) this.entityProcessors.update(); - this.entities.update(); - if (this.entityProcessors) this.entityProcessors.lateUpdate(); - this.renderableComponents.updateList(); - }; - Scene.prototype.postRender = function () { - var enabledCounter = 0; - if (this.enablePostProcessing) { - for (var i = 0; i < this._postProcessors.length; i++) { - if (this._postProcessors[i].enable) { - var isEven = MathHelper.isEven(enabledCounter); - enabledCounter++; - this._postProcessors[i].process(); - } - } - } - }; - Scene.prototype.render = function () { - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].render(this); - } - }; - Scene.prototype.addPostProcessor = function (postProcessor) { - this._postProcessors.push(postProcessor); - this._postProcessors.sort(); - postProcessor.onAddedToScene(this); - if (this._didSceneBegin) { - postProcessor.onSceneBackBufferSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ); - } - return postProcessor; - }; - return Scene; -})(egret.DisplayObjectContainer); -var SceneManager = (function () { - function SceneManager(stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - SceneManager.stage = stage; - SceneManager.initialize(stage); - } - Object.defineProperty(SceneManager, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - if (!value) throw new Error("场景不能为空"); - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - } else { - this._nextScene = value; - } - }, - enumerable: true, - configurable: true, - }); - SceneManager.initialize = function (stage) { - Input.initialize(stage); - }; - SceneManager.update = function () { - Time.update(egret.getTimer()); - if (SceneManager._scene) { - for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } - if ( - !SceneManager.sceneTransition || - (SceneManager.sceneTransition && - (!SceneManager.sceneTransition.loadsNewScene || - SceneManager.sceneTransition.isNewSceneLoaded)) - ) { - SceneManager._scene.update(); - } - if (SceneManager._nextScene) { - SceneManager._scene.end(); - for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { - var entity = SceneManager._scene.entities.buffer[i]; - entity.destroy(); - } - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._scene.begin(); - } - } - SceneManager.render(); - }; - SceneManager.render = function () { - if (this.sceneTransition) { - this.sceneTransition.preRender(); - if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { - this._scene.render(); - this._scene.postRender(); - } - this.sceneTransition.render(); - } - } else if (this._scene) { - this._scene.render(); - this._scene.postRender(); - } - }; - SceneManager.startSceneTransition = function (sceneTransition) { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; - } - this.sceneTransition = sceneTransition; - return sceneTransition; - }; - return SceneManager; -})(); -var DirtyType; -(function (DirtyType) { - DirtyType[(DirtyType["clean"] = 0)] = "clean"; - DirtyType[(DirtyType["positionDirty"] = 1)] = "positionDirty"; - DirtyType[(DirtyType["scaleDirty"] = 2)] = "scaleDirty"; - DirtyType[(DirtyType["rotationDirty"] = 3)] = "rotationDirty"; -})(DirtyType || (DirtyType = {})); -var ComponentTransform; -(function (ComponentTransform) { - ComponentTransform[(ComponentTransform["position"] = 0)] = "position"; - ComponentTransform[(ComponentTransform["scale"] = 1)] = "scale"; - ComponentTransform[(ComponentTransform["rotation"] = 2)] = "rotation"; -})(ComponentTransform || (ComponentTransform = {})); -var Transform = (function () { - function Transform(entity) { - this._localRotation = 0; - this._worldTransform = Matrix2D.identity; - this._worldToLocalTransform = Matrix2D.identity; - this._worldInverseTransform = Matrix2D.identity; - this._rotation = 0; - this.entity = entity; - this._scale = this._localScale = Vector2.one; - this._children = []; - } - Object.defineProperty(Transform.prototype, "childCount", { - get: function () { - return this._children.length; - }, - enumerable: true, - configurable: true, - }); - Transform.prototype.getChild = function (index) { - return this._children[index]; - }; - Object.defineProperty(Transform.prototype, "worldInverseTransform", { - get: function () { - this.updateTransform(); - if (this._worldInverseDirty) { - this._worldInverseTransform = Matrix2D.invert( - this._worldTransform, - this._worldInverseTransform - ); - this._worldInverseDirty = false; - } - return this._worldInverseTransform; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localToWorldTransform", { - get: function () { - this.updateTransform(); - return this._worldTransform; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "worldToLocalTransform", { - get: function () { - if (this._worldToLocalDirty) { - if (!this.parent) { - this._worldInverseTransform = new Matrix2D(); - } else { - this.parent.updateTransform(); - this._worldToLocalTransform = Matrix2D.invert( - this.parent._worldTransform, - this._worldToLocalTransform - ); - } - this._worldToLocalDirty = false; - } - return this._worldToLocalTransform; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "parent", { - get: function () { - return this._parent; - }, - set: function (value) { - this.setParent(value); - }, - enumerable: true, - configurable: true, - }); - Transform.prototype.setParent = function (parent) { - if (this._parent == parent) return this; - if (this._parent) this._parent._children.remove(this); - if (parent) parent._children.push(this); - this._parent = parent; - return this; - }; - Object.defineProperty(Transform.prototype, "rotation", { - get: function () { - this.updateTransform(); - return this._rotation; - }, - set: function (value) { - this.setRotation(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localRotation", { - get: function () { - this.updateTransform(); - return this._localRotation; - }, - set: function (value) { - this.setLocalRotation(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "position", { - get: function () { - this.updateTransform(); - if (this._positionDirty) { - if (!this.parent) { - this._position = this._localPosition; - } else { - this.parent.updateTransform(); - this._position = Vector2Ext.transformR( - this._localPosition, - this.parent._worldTransform - ); - } - this._positionDirty = false; - } - return this._position; - }, - set: function (value) { - this.setPosition(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localPosition", { - get: function () { - this.updateTransform(); - return this._localPosition; - }, - set: function (value) { - this.setLocalPosition(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "scale", { - get: function () { - this.updateTransform(); - return this._scale; - }, - set: function (value) { - this.setScale(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localScale", { - get: function () { - this.updateTransform(); - return this._localScale; - }, - set: function (value) { - this.setLocalScale(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._rotation); - }, - set: function (value) { - this.setRotation(MathHelper.toRadians(value)); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Transform.prototype, "localRotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._localRotation); - }, - set: function (value) { - this.localRotation = MathHelper.toRadians(value); - }, - enumerable: true, - configurable: true, - }); - Transform.prototype.setLocalScale = function (scale) { - this._localScale = scale; - this._localDirty = this._positionDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.scaleDirty); - return this; - }; - Transform.prototype.setScale = function (scale) { - this._scale = scale; - if (this.parent) { - this.localScale = Vector2.divide(scale, this.parent._scale); - } else { - this.localScale = scale; - } - return this; - }; - Transform.prototype.setLocalRotationDegrees = function (degrees) { - return this.setLocalRotation(MathHelper.toRadians(degrees)); - }; - Transform.prototype.setLocalRotation = function (radians) { - this._localRotation = radians; - this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.rotationDirty); - return this; - }; - Transform.prototype.setRotation = function (radians) { - this._rotation = radians; - if (this.parent) { - this.localRotation = this.parent.rotation + radians; - } else { - this.localRotation = radians; - } - return this; - }; - Transform.prototype.setRotationDegrees = function (degrees) { - return this.setRotation(MathHelper.toRadians(degrees)); - }; - Transform.prototype.setLocalPosition = function (localPosition) { - if (localPosition == this._localPosition) return this; - this._localPosition = localPosition; - this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.positionDirty); - return this; - }; - Transform.prototype.setPosition = function (position) { - if (position == this._position) return this; - this._position = position; - if (this.parent) { - this.localPosition = Vector2.transform( - this._position, - this._worldToLocalTransform - ); - } else { - this.localPosition = position; - } - this._positionDirty = false; - return this; - }; - Transform.prototype.setDirty = function (dirtyFlagType) { - if ((this._hierachyDirty & dirtyFlagType) == 0) { - this._hierachyDirty |= dirtyFlagType; - switch (dirtyFlagType) { - case DirtyType.positionDirty: - this.entity.onTransformChanged(ComponentTransform.position); - break; - case DirtyType.rotationDirty: - this.entity.onTransformChanged(ComponentTransform.rotation); - break; - case DirtyType.scaleDirty: - this.entity.onTransformChanged(ComponentTransform.scale); - break; - } - if (this._children == null) this._children = []; - for (var i = 0; i < this._children.length; i++) { - this._children[i].setDirty(dirtyFlagType); - } - } - }; - Transform.prototype.roundPosition = function () { - this.position = this._position.round(); - }; - Transform.prototype.updateTransform = function () { - if (this._hierachyDirty != DirtyType.clean) { - if (this.parent) this.parent.updateTransform(); - if (this._localDirty) { - if (this._localPositionDirty) { - this._translationMatrix = Matrix2D.createTranslation( - this._localPosition.x, - this._localPosition.y - ); - this._localPositionDirty = false; - } - if (this._localRotationDirty) { - this._rotationMatrix = Matrix2D.createRotation(this._localRotation); - this._localRotationDirty = false; - } - if (this._localScaleDirty) { - this._scaleMatrix = Matrix2D.createScale( - this._localScale.x, - this._localScale.y - ); - this._localScaleDirty = false; - } - this._localTransform = Matrix2D.multiply( - this._scaleMatrix, - this._rotationMatrix - ); - this._localTransform = Matrix2D.multiply( - this._localTransform, - this._translationMatrix - ); - if (!this.parent) { - this._worldTransform = this._localTransform; - this._rotation = this._localRotation; - this._scale = this._localScale; - this._worldInverseDirty = true; - } - this._localDirty = false; - } - if (this.parent) { - this._worldTransform = Matrix2D.multiply( - this._localTransform, - this.parent._worldTransform - ); - this._rotation = this._localRotation + this.parent._rotation; - this._scale = Vector2.multiply(this.parent._scale, this._localScale); - this._worldInverseDirty = true; - } - this._worldToLocalDirty = true; - this._positionDirty = true; - this._hierachyDirty = DirtyType.clean; - } - }; - return Transform; -})(); -var Camera = (function (_super) { - __extends(Camera, _super); - function Camera() { - var _this = _super.call(this) || this; - _this._origin = Vector2.zero; - _this._minimumZoom = 0.3; - _this._maximumZoom = 3; - _this.followLerp = 0.1; - _this.deadzone = new Rectangle(); - _this.focusOffset = new Vector2(); - _this.mapLockEnabled = false; - _this.mapSize = new Vector2(); - _this._worldSpaceDeadZone = new Rectangle(); - _this._desiredPositionDelta = new Vector2(); - _this.cameraStyle = CameraStyle.lockOn; - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.setZoom(0); - return _this; - } - Object.defineProperty(Camera.prototype, "zoom", { - get: function () { - if (this._zoom == 0) return 1; - if (this._zoom < 1) - return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); - return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); - }, - set: function (value) { - this.setZoom(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "minimumZoom", { - get: function () { - return this._minimumZoom; - }, - set: function (value) { - this.setMinimumZoom(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "maximumZoom", { - get: function () { - return this._maximumZoom; - }, - set: function (value) { - this.setMaximumZoom(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (value) { - if (this._origin != value) { - this._origin = value; - } - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Camera.prototype, "position", { - get: function () { - return this.entity.position; - }, - set: function (value) { - this.entity.position = value; - }, - enumerable: true, - configurable: true, - }); - Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { - var oldOrigin = this._origin; - this.origin = new Vector2(newWidth / 2, newHeight / 2); - this.entity.position = Vector2.add( - this.entity.position, - Vector2.subtract(this._origin, oldOrigin) - ); - }; - Camera.prototype.setMinimumZoom = function (minZoom) { - if (this._zoom < minZoom) this._zoom = this.minimumZoom; - this._minimumZoom = minZoom; - return this; - }; - Camera.prototype.setMaximumZoom = function (maxZoom) { - if (this._zoom > maxZoom) this._zoom = maxZoom; - this._maximumZoom = maxZoom; - return this; - }; - Camera.prototype.setZoom = function (zoom) { - var newZoom = MathHelper.clamp(zoom, -1, 1); - if (newZoom == 0) { - this._zoom = 1; - } else if (newZoom < 0) { - this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); - } else { - this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); - } - SceneManager.scene.scaleX = this._zoom; - SceneManager.scene.scaleY = this._zoom; - return this; - }; - Camera.prototype.setRotation = function (rotation) { - SceneManager.scene.rotation = rotation; - return this; - }; - Camera.prototype.setPosition = function (position) { - this.entity.position = position; - return this; - }; - Camera.prototype.follow = function (targetEntity, cameraStyle) { - if (cameraStyle === void 0) { - cameraStyle = CameraStyle.cameraWindow; - } - this.targetEntity = targetEntity; - this.cameraStyle = cameraStyle; - var cameraBounds = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - switch (this.cameraStyle) { - case CameraStyle.cameraWindow: - var w = cameraBounds.width / 6; - var h = cameraBounds.height / 3; - this.deadzone = new Rectangle( - (cameraBounds.width - w) / 2, - (cameraBounds.height - h) / 2, - w, - h - ); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle( - cameraBounds.width / 2, - cameraBounds.height / 2, - 10, - 10 - ); - break; - } - }; - Camera.prototype.update = function () { - var cameraBounds = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - var halfScreen = Vector2.multiply( - new Vector2(cameraBounds.width, cameraBounds.height), - new Vector2(0.5) - ); - this._worldSpaceDeadZone.x = - this.position.x - halfScreen.x + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = - this.position.y - halfScreen.y + this.deadzone.y + this.focusOffset.y; - this._worldSpaceDeadZone.width = this.deadzone.width; - this._worldSpaceDeadZone.height = this.deadzone.height; - if (this.targetEntity) this.updateFollow(); - this.position = Vector2.lerp( - this.position, - Vector2.add(this.position, this._desiredPositionDelta), - this.followLerp - ); - this.entity.roundPosition(); - if (this.mapLockEnabled) { - this.position = this.clampToMapSize(this.position); - this.entity.roundPosition(); - } - }; - Camera.prototype.clampToMapSize = function (position) { - var cameraBounds = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - var halfScreen = Vector2.multiply( - new Vector2(cameraBounds.width, cameraBounds.height), - new Vector2(0.5) - ); - var cameraMax = new Vector2( - this.mapSize.x - halfScreen.x, - this.mapSize.y - halfScreen.y - ); - return Vector2.clamp(position, halfScreen, cameraMax); - }; - Camera.prototype.updateFollow = function () { - this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; - if (this.cameraStyle == CameraStyle.lockOn) { - var targetX = this.targetEntity.position.x; - var targetY = this.targetEntity.position.y; - if (this._worldSpaceDeadZone.x > targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - else if (this._worldSpaceDeadZone.x < targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - if (this._worldSpaceDeadZone.y < targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - else if (this._worldSpaceDeadZone.y > targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - } else { - if (!this._targetCollider) { - this._targetCollider = this.targetEntity.getComponent(Collider); - if (!this._targetCollider) return; - } - var targetBounds = this.targetEntity.getComponent(Collider).bounds; - if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { - if (this._worldSpaceDeadZone.left > targetBounds.left) - this._desiredPositionDelta.x = - targetBounds.left - this._worldSpaceDeadZone.left; - else if (this._worldSpaceDeadZone.right < targetBounds.right) - this._desiredPositionDelta.x = - targetBounds.right - this._worldSpaceDeadZone.right; - if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) - this._desiredPositionDelta.y = - targetBounds.bottom - this._worldSpaceDeadZone.bottom; - else if (this._worldSpaceDeadZone.top > targetBounds.top) - this._desiredPositionDelta.y = - targetBounds.top - this._worldSpaceDeadZone.top; - } - } - }; - return Camera; -})(Component); -var CameraStyle; -(function (CameraStyle) { - CameraStyle[(CameraStyle["lockOn"] = 0)] = "lockOn"; - CameraStyle[(CameraStyle["cameraWindow"] = 1)] = "cameraWindow"; + Object.defineProperty(Entity.prototype, "position", { + get: function () { + return this._position; + }, + set: function (value) { + this._position = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "scale", { + get: function () { + return new Vector2(this.scaleX, this.scaleY); + }, + set: function (value) { + this.scaleX = value.x; + this.scaleY = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Entity.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + } + return this; + }; + Object.defineProperty(Entity.prototype, "tag", { + get: function () { + return this._tag; + }, + set: function (value) { + this.setTag(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "stage", { + get: function () { + if (!this.scene) + return null; + return this.scene.stage; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "updateOrder", { + get: function () { + return this._updateOrder; + }, + set: function (value) { + this.setUpdateOrder(value); + }, + enumerable: true, + configurable: true + }); + Entity.prototype.roundPosition = function () { + this.position = Vector2Ext.round(this.position); + }; + Entity.prototype.setUpdateOrder = function (updateOrder) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; + if (this.scene) { + } + return this; + } + }; + Entity.prototype.setTag = function (tag) { + if (this._tag != tag) { + if (this.scene) { + this.scene.entities.removeFromTagList(this); + } + this._tag = tag; + if (this.scene) { + this.scene.entities.addToTagList(this); + } + } + return this; + }; + Entity.prototype.attachToScene = function (newScene) { + this.scene = newScene; + newScene.entities.add(this); + this.components.registerAllComponents(); + for (var i = 0; i < this.numChildren; i++) { + this.getChildAt(i).entity.attachToScene(newScene); + } + }; + Entity.prototype.detachFromScene = function () { + this.scene.entities.remove(this); + this.components.deregisterAllComponents(); + for (var i = 0; i < this.numChildren; i++) + this.getChildAt(i).entity.detachFromScene(); + }; + Entity.prototype.addComponent = function (component) { + component.entity = this; + this.components.add(component); + this.addChild(component); + component.initialize(); + return component; + }; + Entity.prototype.hasComponent = function (type) { + return this.components.getComponent(type, false) != null; + }; + Entity.prototype.getOrCreateComponent = function (type) { + var comp = this.components.getComponent(type, true); + if (!comp) { + comp = this.addComponent(type); + } + return comp; + }; + Entity.prototype.getComponent = function (type) { + return this.components.getComponent(type, false); + }; + Entity.prototype.getComponents = function (typeName, componentList) { + return this.components.getComponents(typeName, componentList); + }; + Entity.prototype.removeComponentForType = function (type) { + var comp = this.getComponent(type); + if (comp) { + this.removeComponent(comp); + return true; + } + return false; + }; + Entity.prototype.removeComponent = function (component) { + this.components.remove(component); + }; + Entity.prototype.removeAllComponents = function () { + for (var i = 0; i < this.components.count; i++) { + this.removeComponent(this.components.buffer[i]); + } + }; + Entity.prototype.update = function () { + this.components.update(); + }; + Entity.prototype.onAddedToScene = function () { + }; + Entity.prototype.onRemovedFromScene = function () { + if (this._isDestoryed) + this.components.removeAllComponents(); + }; + Entity.prototype.destroy = function () { + this._isDestoryed = true; + this.scene.entities.remove(this); + this.removeChildren(); + for (var i = this.numChildren - 1; i >= 0; i--) { + var child = this.getChildAt(i); + child.entity.destroy(); + } + }; + return Entity; +}(egret.DisplayObjectContainer)); +var Scene = (function (_super) { + __extends(Scene, _super); + function Scene() { + var _this = _super.call(this) || this; + _this.enablePostProcessing = true; + _this._renderers = []; + _this._postProcessors = []; + _this.entityProcessors = new EntityProcessorList(); + _this.renderableComponents = new RenderableComponentList(); + _this.entities = new EntityList(_this); + _this.content = new ContentManager(); + _this.width = SceneManager.stage.stageWidth; + _this.height = SceneManager.stage.stageHeight; + _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); + _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); + return _this; + } + Scene.prototype.createEntity = function (name) { + var entity = new Entity(name); + entity.position = new Vector2(0, 0); + return this.addEntity(entity); + }; + Scene.prototype.addEntity = function (entity) { + this.entities.add(entity); + entity.scene = this; + this.addChild(entity); + for (var i = 0; i < entity.numChildren; i++) + this.addEntity(entity.getChildAt(i).entity); + return entity; + }; + Scene.prototype.destroyAllEntities = function () { + for (var i = 0; i < this.entities.count; i++) { + this.entities.buffer[i].destroy(); + } + }; + Scene.prototype.findEntity = function (name) { + return this.entities.findEntity(name); + }; + Scene.prototype.addEntityProcessor = function (processor) { + processor.scene = this; + this.entityProcessors.add(processor); + return processor; + }; + Scene.prototype.removeEntityProcessor = function (processor) { + this.entityProcessors.remove(processor); + }; + Scene.prototype.getEntityProcessor = function () { + return this.entityProcessors.getProcessor(); + }; + Scene.prototype.addRenderer = function (renderer) { + this._renderers.push(renderer); + this._renderers.sort(); + renderer.onAddedToScene(this); + return renderer; + }; + Scene.prototype.getRenderer = function (type) { + for (var i = 0; i < this._renderers.length; i++) { + if (this._renderers[i] instanceof type) + return this._renderers[i]; + } + return null; + }; + Scene.prototype.removeRenderer = function (renderer) { + this._renderers.remove(renderer); + renderer.unload(); + }; + Scene.prototype.begin = function () { + if (SceneManager.sceneTransition) { + SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); + } + else { + SceneManager.stage.addChild(this); + } + if (this._renderers.length == 0) { + this.addRenderer(new DefaultRenderer()); + console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); + } + this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); + Physics.reset(); + if (this.entityProcessors) + this.entityProcessors.begin(); + this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + this._didSceneBegin = true; + this.onStart(); + }; + Scene.prototype.end = function () { + this._didSceneBegin = false; + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].unload(); + } + for (var i = 0; i < this._postProcessors.length; i++) { + this._postProcessors[i].unload(); + } + this.entities.removeAllEntities(); + this.removeChildren(); + Physics.clear(); + this.camera = null; + this.content.dispose(); + if (this.entityProcessors) + this.entityProcessors.end(); + this.unload(); + }; + Scene.prototype.onStart = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2]; + }); + }); + }; + Scene.prototype.onActive = function () { + }; + Scene.prototype.onDeactive = function () { + }; + Scene.prototype.unload = function () { }; + Scene.prototype.update = function () { + this.entities.updateLists(); + if (this.entityProcessors) + this.entityProcessors.update(); + this.entities.update(); + if (this.entityProcessors) + this.entityProcessors.lateUpdate(); + this.renderableComponents.updateList(); + }; + Scene.prototype.postRender = function () { + var enabledCounter = 0; + if (this.enablePostProcessing) { + for (var i = 0; i < this._postProcessors.length; i++) { + if (this._postProcessors[i].enable) { + var isEven = MathHelper.isEven(enabledCounter); + enabledCounter++; + this._postProcessors[i].process(); + } + } + } + }; + Scene.prototype.render = function () { + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].render(this); + } + }; + Scene.prototype.addPostProcessor = function (postProcessor) { + this._postProcessors.push(postProcessor); + this._postProcessors.sort(); + postProcessor.onAddedToScene(this); + if (this._didSceneBegin) { + postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + } + return postProcessor; + }; + return Scene; +}(egret.DisplayObjectContainer)); +var SceneManager = (function () { + function SceneManager(stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); + SceneManager.stage = stage; + SceneManager.initialize(stage); + } + Object.defineProperty(SceneManager, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + if (!value) + throw new Error("场景不能为空"); + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + } + else { + this._nextScene = value; + } + }, + enumerable: true, + configurable: true + }); + SceneManager.initialize = function (stage) { + Input.initialize(stage); + }; + SceneManager.update = function () { + Time.update(egret.getTimer()); + if (SceneManager._scene) { + for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (GlobalManager.globalManagers[i].enabled) + GlobalManager.globalManagers[i].update(); + } + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + SceneManager._scene.update(); + } + if (SceneManager._nextScene) { + SceneManager._scene.end(); + for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { + var entity = SceneManager._scene.entities.buffer[i]; + entity.destroy(); + } + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + SceneManager._scene.begin(); + } + } + SceneManager.render(); + }; + SceneManager.render = function () { + if (this.sceneTransition) { + this.sceneTransition.preRender(); + if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { + this._scene.render(); + this._scene.postRender(); + this.sceneTransition.onBeginTransition(); + } + else if (this.sceneTransition) { + if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + this.sceneTransition.render(); + } + } + else if (this._scene) { + this._scene.render(); + this._scene.postRender(); + } + }; + SceneManager.startSceneTransition = function (sceneTransition) { + if (this.sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } + this.sceneTransition = sceneTransition; + return sceneTransition; + }; + return SceneManager; +}()); +var Camera = (function (_super) { + __extends(Camera, _super); + function Camera() { + var _this = _super.call(this) || this; + _this._origin = Vector2.zero; + _this._minimumZoom = 0.3; + _this._maximumZoom = 3; + _this.followLerp = 0.1; + _this.deadzone = new Rectangle(); + _this.focusOffset = new Vector2(); + _this.mapLockEnabled = false; + _this.mapSize = new Vector2(); + _this._worldSpaceDeadZone = new Rectangle(); + _this._desiredPositionDelta = new Vector2(); + _this.cameraStyle = CameraStyle.lockOn; + _this.width = SceneManager.stage.stageWidth; + _this.height = SceneManager.stage.stageHeight; + _this.setZoom(0); + return _this; + } + Object.defineProperty(Camera.prototype, "zoom", { + get: function () { + if (this._zoom == 0) + return 1; + if (this._zoom < 1) + return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); + return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); + }, + set: function (value) { + this.setZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "minimumZoom", { + get: function () { + return this._minimumZoom; + }, + set: function (value) { + this.setMinimumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "maximumZoom", { + get: function () { + return this._maximumZoom; + }, + set: function (value) { + this.setMaximumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + if (this._origin != value) { + this._origin = value; + } + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "position", { + get: function () { + return this.entity.position; + }, + set: function (value) { + this.entity.position = value; + }, + enumerable: true, + configurable: true + }); + Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { + var oldOrigin = this._origin; + this.origin = new Vector2(newWidth / 2, newHeight / 2); + this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); + }; + Camera.prototype.setMinimumZoom = function (minZoom) { + if (this._zoom < minZoom) + this._zoom = this.minimumZoom; + this._minimumZoom = minZoom; + return this; + }; + Camera.prototype.setMaximumZoom = function (maxZoom) { + if (this._zoom > maxZoom) + this._zoom = maxZoom; + this._maximumZoom = maxZoom; + return this; + }; + Camera.prototype.setZoom = function (zoom) { + var newZoom = MathHelper.clamp(zoom, -1, 1); + if (newZoom == 0) { + this._zoom = 1; + } + else if (newZoom < 0) { + this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); + } + else { + this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); + } + SceneManager.scene.scaleX = this._zoom; + SceneManager.scene.scaleY = this._zoom; + return this; + }; + Camera.prototype.setRotation = function (rotation) { + SceneManager.scene.rotation = rotation; + return this; + }; + Camera.prototype.setPosition = function (position) { + this.entity.position = position; + return this; + }; + Camera.prototype.follow = function (targetEntity, cameraStyle) { + if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; } + this.targetEntity = targetEntity; + this.cameraStyle = cameraStyle; + var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + switch (this.cameraStyle) { + case CameraStyle.cameraWindow: + var w = cameraBounds.width / 6; + var h = cameraBounds.height / 3; + this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h); + break; + case CameraStyle.lockOn: + this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10); + break; + } + }; + Camera.prototype.update = function () { + var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.width = this.deadzone.width; + this._worldSpaceDeadZone.height = this.deadzone.height; + if (this.targetEntity) + this.updateFollow(); + this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); + this.entity.roundPosition(); + if (this.mapLockEnabled) { + this.position = this.clampToMapSize(this.position); + this.entity.roundPosition(); + } + }; + Camera.prototype.clampToMapSize = function (position) { + var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); + var cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); + return Vector2.clamp(position, halfScreen, cameraMax); + }; + Camera.prototype.updateFollow = function () { + this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; + if (this.cameraStyle == CameraStyle.lockOn) { + var targetX = this.targetEntity.position.x; + var targetY = this.targetEntity.position.y; + if (this._worldSpaceDeadZone.x > targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + else if (this._worldSpaceDeadZone.x < targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + if (this._worldSpaceDeadZone.y < targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + else if (this._worldSpaceDeadZone.y > targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + } + else { + if (!this._targetCollider) { + this._targetCollider = this.targetEntity.getComponent(Collider); + if (!this._targetCollider) + return; + } + var targetBounds = this.targetEntity.getComponent(Collider).bounds; + if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { + if (this._worldSpaceDeadZone.left > targetBounds.left) + this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; + else if (this._worldSpaceDeadZone.right < targetBounds.right) + this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; + if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) + this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; + else if (this._worldSpaceDeadZone.top > targetBounds.top) + this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; + } + } + }; + return Camera; +}(Component)); +var CameraStyle; +(function (CameraStyle) { + CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; + CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; })(CameraStyle || (CameraStyle = {})); var ComponentPool = (function () { - function ComponentPool(typeClass) { - this._type = typeClass; - this._cache = []; - } - ComponentPool.prototype.obtain = function () { - try { - return this._cache.length > 0 ? this._cache.shift() : new this._type(); - } catch (err) { - throw new Error(this._type + err); - } - }; - ComponentPool.prototype.free = function (component) { - component.reset(); - this._cache.push(component); - }; - return ComponentPool; -})(); -var Mesh = (function (_super) { - __extends(Mesh, _super); - function Mesh() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - Mesh.prototype.initialize = function () {}; - Mesh.prototype.setVertPosition = function (positions) { - var createVerts = !this._verts || this._verts.length != positions.length; - if (createVerts) this._verts = new Array(positions.length); - for (var i = 0; i < this._verts.length; i++) { - this._verts[i] = new VertexPosition(positions[i]); + function ComponentPool(typeClass) { + this._type = typeClass; + this._cache = []; } - return this; - }; - Mesh.prototype.setTriangles = function (triangles) { - this._primitiveCount = triangles.length / 3; - this._triangles = triangles; - return this; - }; - Mesh.prototype.recalculateBounds = function () { - this._topLeftVertPosition = new Vector2(Number.MAX_VALUE, Number.MAX_VALUE); - var max = new Vector2(Number.MIN_VALUE, Number.MIN_VALUE); - for (var i = 0; i < this._verts.length; i++) { - this._topLeftVertPosition.x = Math.min( - this._topLeftVertPosition.x, - this._verts[i].position.x - ); - this._topLeftVertPosition.y = Math.min( - this._topLeftVertPosition.y, - this._verts[i].position.y - ); - max.x = Math.max(max.x, this._verts[i].position.x); - max.y = Math.max(max.y, this._verts[i].position.y); - } - this._width = max.x - this._topLeftVertPosition.x; - this._height = max.y - this._topLeftVertPosition.y; - return this; - }; - Mesh.prototype.render = function () {}; - return Mesh; -})(Component); -var VertexPosition = (function () { - function VertexPosition(position) { - this.position = position; - } - return VertexPosition; -})(); -var PolygonMesh = (function (_super) { - __extends(PolygonMesh, _super); - function PolygonMesh(points, arePointsCCW) { - if (arePointsCCW === void 0) { - arePointsCCW = true; - } - var _this = _super.call(this) || this; - var triangulator = new Triangulator(); - triangulator.triangulate(points, arePointsCCW); - _this.setVertPosition(points); - _this.setTriangles(triangulator.triangleIndices); - _this.recalculateBounds(); - return _this; - } - return PolygonMesh; -})(Mesh); + ComponentPool.prototype.obtain = function () { + try { + return this._cache.length > 0 ? this._cache.shift() : new this._type(); + } + catch (err) { + throw new Error(this._type + err); + } + }; + ComponentPool.prototype.free = function (component) { + component.reset(); + this._cache.push(component); + }; + return ComponentPool; +}()); var PooledComponent = (function (_super) { - __extends(PooledComponent, _super); - function PooledComponent() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - return PooledComponent; -})(Component); + __extends(PooledComponent, _super); + function PooledComponent() { + return _super !== null && _super.apply(this, arguments) || this; + } + return PooledComponent; +}(Component)); var RenderableComponent = (function (_super) { - __extends(RenderableComponent, _super); - function RenderableComponent() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this._areBoundsDirty = true; - _this._bounds = new Rectangle(); - _this._localOffset = Vector2.zero; - _this.color = 0x000000; - return _this; - } - Object.defineProperty(RenderableComponent.prototype, "width", { - get: function () { - return this.getWidth(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponent.prototype, "height", { - get: function () { - return this.getHeight(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponent.prototype, "isVisible", { - get: function () { - return this._isVisible; - }, - set: function (value) { - this._isVisible = value; - if (this._isVisible) this.onBecameVisible(); - else this.onBecameInvisible(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponent.prototype, "bounds", { - get: function () { - return new Rectangle( - this.getBounds().x, - this.getBounds().y, - this.getBounds().width, - this.getBounds().height - ); - }, - enumerable: true, - configurable: true, - }); - RenderableComponent.prototype.getWidth = function () { - return this.bounds.width; - }; - RenderableComponent.prototype.getHeight = function () { - return this.bounds.height; - }; - RenderableComponent.prototype.onBecameVisible = function () {}; - RenderableComponent.prototype.onBecameInvisible = function () {}; - RenderableComponent.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = camera.getBounds().intersects(this.getBounds()); - return this.isVisible; - }; - RenderableComponent.prototype.onEntityTransformChanged = function (comp) { - this._areBoundsDirty = true; - }; - return RenderableComponent; -})(PooledComponent); -var ScreenSpaceCamera = (function (_super) { - __extends(ScreenSpaceCamera, _super); - function ScreenSpaceCamera() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - ScreenSpaceCamera.prototype.updateMatrixes = function () {}; - return ScreenSpaceCamera; -})(Camera); + __extends(RenderableComponent, _super); + function RenderableComponent() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._areBoundsDirty = true; + _this._bounds = new Rectangle(); + _this._localOffset = Vector2.zero; + _this.color = 0x000000; + return _this; + } + Object.defineProperty(RenderableComponent.prototype, "width", { + get: function () { + return this.getWidth(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "height", { + get: function () { + return this.getHeight(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "isVisible", { + get: function () { + return this._isVisible; + }, + set: function (value) { + this._isVisible = value; + if (this._isVisible) + this.onBecameVisible(); + else + this.onBecameInvisible(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "bounds", { + get: function () { + return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); + }, + enumerable: true, + configurable: true + }); + RenderableComponent.prototype.getWidth = function () { + return this.bounds.width; + }; + RenderableComponent.prototype.getHeight = function () { + return this.bounds.height; + }; + RenderableComponent.prototype.onBecameVisible = function () { }; + RenderableComponent.prototype.onBecameInvisible = function () { }; + RenderableComponent.prototype.isVisibleFromCamera = function (camera) { + this.isVisible = camera.getBounds().intersects(this.getBounds()); + return this.isVisible; + }; + return RenderableComponent; +}(PooledComponent)); +var Mesh = (function (_super) { + __extends(Mesh, _super); + function Mesh() { + var _this = _super.call(this) || this; + _this._mesh = new egret.Mesh(); + return _this; + } + Mesh.prototype.setTexture = function (texture) { + this._mesh.texture = texture; + return this; + }; + Mesh.prototype.onAddedToEntity = function () { + this.addChild(this._mesh); + }; + Mesh.prototype.onRemovedFromEntity = function () { + this.removeChild(this._mesh); + }; + Mesh.prototype.render = function (camera) { + this.x = this.entity.position.x - camera.position.x + camera.origin.x; + this.y = this.entity.position.y - camera.position.y + camera.origin.y; + }; + Mesh.prototype.reset = function () { + }; + return Mesh; +}(RenderableComponent)); var Sprite = (function () { - function Sprite(texture, sourceRect, origin) { - if (sourceRect === void 0) { - sourceRect = new Rectangle( - 0, - 0, - texture.textureWidth, - texture.textureHeight - ); - } - if (origin === void 0) { - origin = sourceRect.getHalfSize(); - } - this.uvs = new Rectangle(); - this.texture2D = texture; - this.sourceRect = sourceRect; - this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); - this.origin = origin; - var inverseTexW = 1 / texture.textureWidth; - var inverseTexH = 1 / texture.textureHeight; - this.uvs.x = sourceRect.x * inverseTexW; - this.uvs.y = sourceRect.y * inverseTexH; - this.uvs.width = sourceRect.width * inverseTexW; - this.uvs.height = sourceRect.height * inverseTexH; - } - return Sprite; -})(); + function Sprite(texture, sourceRect, origin) { + if (sourceRect === void 0) { sourceRect = new Rectangle(0, 0, texture.textureWidth, texture.textureHeight); } + if (origin === void 0) { origin = sourceRect.getHalfSize(); } + this.uvs = new Rectangle(); + this.texture2D = texture; + this.sourceRect = sourceRect; + this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); + this.origin = origin; + var inverseTexW = 1 / texture.textureWidth; + var inverseTexH = 1 / texture.textureHeight; + this.uvs.x = sourceRect.x * inverseTexW; + this.uvs.y = sourceRect.y * inverseTexH; + this.uvs.width = sourceRect.width * inverseTexW; + this.uvs.height = sourceRect.height * inverseTexH; + } + return Sprite; +}()); var SpriteRenderer = (function (_super) { - __extends(SpriteRenderer, _super); - function SpriteRenderer() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - Object.defineProperty(SpriteRenderer.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (value) { - this.setOrigin(value); - }, - enumerable: true, - configurable: true, - }); - SpriteRenderer.prototype.setOrigin = function (origin) { - if (this._origin != origin) { - this._origin = origin; + __extends(SpriteRenderer, _super); + function SpriteRenderer() { + return _super !== null && _super.apply(this, arguments) || this; } - return this; - }; - SpriteRenderer.prototype.setSprite = function (sprite) { - this.removeChildren(); - this._sprite = sprite; - if (this._sprite) this._origin = this._sprite.origin; - this._bitmap = new egret.Bitmap(sprite.texture2D); - this.addChild(this._bitmap); - return this; - }; - SpriteRenderer.prototype.setColor = function (color) { - var colorMatrix = [ - 1, - 0, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 1, - 0, - 0, - 0, - 0, - 0, - 1, - 0, - ]; - colorMatrix[0] = Math.floor(color / 256 / 256) / 255; - colorMatrix[6] = Math.floor((color / 256) % 256) / 255; - colorMatrix[12] = (color % 256) / 255; - var colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this.filters = [colorFilter]; - return this; - }; - SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = new Rectangle( - 0, - 0, - this.stage.stageWidth, - this.stage.stageHeight - ).intersects(this.bounds); - this.visible = this.isVisible; - return this.isVisible; - }; - SpriteRenderer.prototype.render = function (camera) { - this.x = - this.entity.position.x - - this.origin.x - - camera.position.x + - camera.origin.x; - this.y = - this.entity.position.y - - this.origin.y - - camera.position.y + - camera.origin.y; - }; - SpriteRenderer.prototype.onRemovedFromEntity = function () { - if (this.parent) this.parent.removeChild(this); - }; - SpriteRenderer.prototype.reset = function () {}; - return SpriteRenderer; -})(RenderableComponent); + Object.defineProperty(SpriteRenderer.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + this.setOrigin(value); + }, + enumerable: true, + configurable: true + }); + SpriteRenderer.prototype.setOrigin = function (origin) { + if (this._origin != origin) { + this._origin = origin; + } + return this; + }; + SpriteRenderer.prototype.setSprite = function (sprite) { + this.removeChildren(); + this._sprite = sprite; + if (this._sprite) + this._origin = this._sprite.origin; + this._bitmap = new egret.Bitmap(sprite.texture2D); + this.addChild(this._bitmap); + return this; + }; + SpriteRenderer.prototype.setColor = function (color) { + var colorMatrix = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 + ]; + colorMatrix[0] = Math.floor(color / 256 / 256) / 255; + colorMatrix[6] = Math.floor(color / 256 % 256) / 255; + colorMatrix[12] = color % 256 / 255; + var colorFilter = new egret.ColorMatrixFilter(colorMatrix); + this.filters = [colorFilter]; + return this; + }; + SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { + this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); + this.visible = this.isVisible; + return this.isVisible; + }; + SpriteRenderer.prototype.render = function (camera) { + this.x = this.entity.position.x - this.origin.x - camera.position.x + camera.origin.x; + this.y = this.entity.position.y - this.origin.y - camera.position.y + camera.origin.y; + }; + SpriteRenderer.prototype.onRemovedFromEntity = function () { + if (this.parent) + this.parent.removeChild(this); + }; + SpriteRenderer.prototype.reset = function () { + }; + return SpriteRenderer; +}(RenderableComponent)); var Mover = (function (_super) { - __extends(Mover, _super); - function Mover() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - Mover.prototype.onAddedToEntity = function () { - this._triggerHelper = new ColliderTriggerHelper(this.entity); - }; - Mover.prototype.calculateMovement = function (motion) { - var collisionResult = new CollisionResult(); - if (!this.entity.getComponent(Collider) || !this._triggerHelper) { - return null; - } - var colliders = this.entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - if (collider.isTrigger) continue; - var bounds = collider.bounds; - bounds.x += motion.x; - bounds.y += motion.y; - var neighbors = Physics.boxcastBroadphaseExcludingSelf( - collider, - bounds, - collider.collidesWithLayers - ); - for (var j = 0; j < neighbors.length; j++) { - var neighbor = neighbors[j]; - if (neighbor.isTrigger) continue; - var _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult) { - motion = Vector2.subtract( - motion, - _internalcollisionResult.minimumTranslationVector - ); - if (_internalcollisionResult.collider) { - collisionResult = _internalcollisionResult; - } - } - } + __extends(Mover, _super); + function Mover() { + return _super !== null && _super.apply(this, arguments) || this; } - ListPool.free(colliders); - return collisionResult; - }; - Mover.prototype.applyMovement = function (motion) { - this.entity.position = Vector2.add(this.entity.position, motion); - if (this._triggerHelper) this._triggerHelper.update(); - }; - Mover.prototype.move = function (motion) { - var collisionResult = this.calculateMovement(motion); - this.applyMovement(motion); - return collisionResult; - }; - return Mover; -})(Component); + Mover.prototype.onAddedToEntity = function () { + this._triggerHelper = new ColliderTriggerHelper(this.entity); + }; + Mover.prototype.calculateMovement = function (motion) { + var collisionResult = new CollisionResult(); + if (!this.entity.getComponent(Collider) || !this._triggerHelper) { + return null; + } + var colliders = this.entity.getComponents(Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + if (collider.isTrigger) + continue; + var bounds = collider.bounds; + bounds.x += motion.x; + bounds.y += motion.y; + var neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); + for (var j = 0; j < neighbors.length; j++) { + var neighbor = neighbors[j]; + if (neighbor.isTrigger) + continue; + var _internalcollisionResult = collider.collidesWith(neighbor, motion); + if (_internalcollisionResult) { + motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); + if (_internalcollisionResult.collider) { + collisionResult = _internalcollisionResult; + } + } + } + } + ListPool.free(colliders); + return collisionResult; + }; + Mover.prototype.applyMovement = function (motion) { + this.entity.position = Vector2.add(this.entity.position, motion); + if (this._triggerHelper) + this._triggerHelper.update(); + }; + Mover.prototype.move = function (motion) { + var collisionResult = this.calculateMovement(motion); + this.applyMovement(motion); + return collisionResult; + }; + return Mover; +}(Component)); var Collider = (function (_super) { - __extends(Collider, _super); - function Collider() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this.physicsLayer = 1 << 0; - _this.shouldColliderScaleAndRotationWithTransform = true; - _this.collidesWithLayers = Physics.allLayers; - _this._isPositionDirty = true; - _this._isRotationDirty = true; - _this._localOffset = new Vector2(0, 0); - return _this; - } - Object.defineProperty(Collider.prototype, "bounds", { - get: function () { - if (this._isPositionDirty || this._isRotationDirty) { - this.shape.recalculateBounds(this); - this._isPositionDirty = this._isRotationDirty = false; - } - return this.shape.bounds; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Collider.prototype, "localOffset", { - get: function () { - return this._localOffset; - }, - set: function (value) { - this.setLocalOffset(value); - }, - enumerable: true, - configurable: true, - }); - Collider.prototype.setLocalOffset = function (offset) { - if (this._localOffset != offset) { - this.unregisterColliderWithPhysicsSystem(); - this._localOffset = offset; - this._localOffsetLength = this._localOffset.length(); - this._isPositionDirty = true; - this.registerColliderWithPhysicsSystem(); - } - }; - Collider.prototype.registerColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { - Physics.addCollider(this); - this._isColliderRegistered = true; - } - }; - Collider.prototype.unregisterColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && this._isColliderRegistered) { - Physics.removeCollider(this); - } - this._isColliderRegistered = false; - }; - Collider.prototype.overlaps = function (other) { - return this.shape.overlaps(other.shape); - }; - Collider.prototype.collidesWith = function (collider, motion) { - var oldPosition = this.shape.position; - this.shape.position = Vector2.add(this.shape.position, motion); - var result = this.shape.collidesWithShape(collider.shape); - if (result) result.collider = collider; - this.shape.position = oldPosition; - return result; - }; - Collider.prototype.onAddedToEntity = function () { - if (this._colliderRequiresAutoSizing) { - if (!(this instanceof BoxCollider)) { - console.error( - "Only box and circle colliders can be created automatically" - ); - } - var renderable = this.entity.getComponent(RenderableComponent); - if (renderable) { - var renderbaleBounds = renderable.bounds; - var width = renderbaleBounds.width / this.entity.scale.x; - var height = renderbaleBounds.height / this.entity.scale.y; - if (this instanceof BoxCollider) { - var boxCollider = this; - boxCollider.width = width; - boxCollider.height = height; - this.localOffset = Vector2.subtract( - renderbaleBounds.center, - this.entity.position - ); - } - } - } - this._isParentEntityAddedToScene = true; - this.registerColliderWithPhysicsSystem(); - }; - Collider.prototype.onRemovedFromEntity = function () { - this.unregisterColliderWithPhysicsSystem(); - this._isParentEntityAddedToScene = false; - }; - Collider.prototype.onEntityTransformChanged = function (comp) { - switch (comp) { - case ComponentTransform.position: - this._isPositionDirty = true; - break; - case ComponentTransform.scale: - this._isPositionDirty = true; - break; - case ComponentTransform.rotation: - this._isRotationDirty = true; - break; - } - if (this._isColliderRegistered) Physics.updateCollider(this); - }; - Collider.prototype.onEnabled = function () { - this.registerColliderWithPhysicsSystem(); - this._isPositionDirty = this._isRotationDirty = true; - }; - Collider.prototype.onDisabled = function () { - this.unregisterColliderWithPhysicsSystem(); - }; - return Collider; -})(Component); + __extends(Collider, _super); + function Collider() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.physicsLayer = 1 << 0; + _this.shouldColliderScaleAndRotationWithTransform = true; + _this.collidesWithLayers = Physics.allLayers; + _this._isPositionDirty = true; + _this._isRotationDirty = true; + _this._localOffset = new Vector2(0, 0); + return _this; + } + Object.defineProperty(Collider.prototype, "bounds", { + get: function () { + if (this._isPositionDirty || this._isRotationDirty) { + this.shape.recalculateBounds(this); + this._isPositionDirty = this._isRotationDirty = false; + } + return this.shape.bounds; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "localOffset", { + get: function () { + return this._localOffset; + }, + set: function (value) { + this.setLocalOffset(value); + }, + enumerable: true, + configurable: true + }); + Collider.prototype.setLocalOffset = function (offset) { + if (this._localOffset != offset) { + this.unregisterColliderWithPhysicsSystem(); + this._localOffset = offset; + this._localOffsetLength = this._localOffset.length(); + this._isPositionDirty = true; + this.registerColliderWithPhysicsSystem(); + } + }; + Collider.prototype.registerColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { + Physics.addCollider(this); + this._isColliderRegistered = true; + } + }; + Collider.prototype.unregisterColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && this._isColliderRegistered) { + Physics.removeCollider(this); + } + this._isColliderRegistered = false; + }; + Collider.prototype.overlaps = function (other) { + return this.shape.overlaps(other.shape); + }; + Collider.prototype.collidesWith = function (collider, motion) { + var oldPosition = this.shape.position; + this.shape.position = Vector2.add(this.shape.position, motion); + var result = this.shape.collidesWithShape(collider.shape); + if (result) + result.collider = collider; + this.shape.position = oldPosition; + return result; + }; + Collider.prototype.onAddedToEntity = function () { + if (this._colliderRequiresAutoSizing) { + if (!(this instanceof BoxCollider)) { + console.error("Only box and circle colliders can be created automatically"); + } + var renderable = this.entity.getComponent(RenderableComponent); + if (renderable) { + var renderbaleBounds = renderable.bounds; + var width = renderbaleBounds.width / this.entity.scale.x; + var height = renderbaleBounds.height / this.entity.scale.y; + if (this instanceof BoxCollider) { + var boxCollider = this; + boxCollider.width = width; + boxCollider.height = height; + this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position); + } + } + } + this._isParentEntityAddedToScene = true; + this.registerColliderWithPhysicsSystem(); + }; + Collider.prototype.onRemovedFromEntity = function () { + this.unregisterColliderWithPhysicsSystem(); + this._isParentEntityAddedToScene = false; + }; + Collider.prototype.onEnabled = function () { + this.registerColliderWithPhysicsSystem(); + this._isPositionDirty = this._isRotationDirty = true; + }; + Collider.prototype.onDisabled = function () { + this.unregisterColliderWithPhysicsSystem(); + }; + return Collider; +}(Component)); var BoxCollider = (function (_super) { - __extends(BoxCollider, _super); - function BoxCollider() { - var _this = _super.call(this) || this; - _this.shape = new Box(1, 1); - _this._colliderRequiresAutoSizing = true; - return _this; - } - Object.defineProperty(BoxCollider.prototype, "width", { - get: function () { - return this.shape.width; - }, - set: function (value) { - this.setWidth(value); - }, - enumerable: true, - configurable: true, - }); - BoxCollider.prototype.setWidth = function (width) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width) { - box.updateBox(width, box.height); - this._isPositionDirty = true; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - Object.defineProperty(BoxCollider.prototype, "height", { - get: function () { - return this.shape.height; - }, - set: function (value) { - this.setHeight(value); - }, - enumerable: true, - configurable: true, - }); - BoxCollider.prototype.setHeight = function (height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (height != box.height) { - box.updateBox(box.width, height); - this._isPositionDirty = true; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - }; - BoxCollider.prototype.setSize = function (width, height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width || height != box.height) { - box.updateBox(width, height); - this._isPositionDirty = true; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - return BoxCollider; -})(Collider); -var EntitySystem = (function () { - function EntitySystem(matcher) { - this._entities = []; - this._matcher = matcher ? matcher : Matcher.empty(); - } - Object.defineProperty(EntitySystem.prototype, "matcher", { - get: function () { - return this._matcher; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(EntitySystem.prototype, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - this._scene = value; - this._entities = []; - }, - enumerable: true, - configurable: true, - }); - EntitySystem.prototype.initialize = function () {}; - EntitySystem.prototype.onChanged = function (entity) { - var contains = this._entities.contains(entity); - var interest = this._matcher.IsIntersted(entity); - if (interest && !contains) this.add(entity); - else if (!interest && contains) this.remove(entity); - }; - EntitySystem.prototype.add = function (entity) { - this._entities.push(entity); - this.onAdded(entity); - }; - EntitySystem.prototype.onAdded = function (entity) {}; - EntitySystem.prototype.remove = function (entity) { - this._entities.remove(entity); - this.onRemoved(entity); - }; - EntitySystem.prototype.onRemoved = function (entity) {}; - EntitySystem.prototype.update = function () { - this.begin(); - this.process(this._entities); - }; - EntitySystem.prototype.lateUpdate = function () { - this.lateProcess(this._entities); - this.end(); - }; - EntitySystem.prototype.begin = function () {}; - EntitySystem.prototype.process = function (entities) {}; - EntitySystem.prototype.lateProcess = function (entities) {}; - EntitySystem.prototype.end = function () {}; - return EntitySystem; -})(); -var EntityProcessingSystem = (function (_super) { - __extends(EntityProcessingSystem, _super); - function EntityProcessingSystem(matcher) { - return _super.call(this, matcher) || this; - } - EntityProcessingSystem.prototype.lateProcessEntity = function (entity) {}; - EntityProcessingSystem.prototype.process = function (entities) { - var _this = this; - entities.forEach(function (entity) { - return _this.processEntity(entity); + __extends(BoxCollider, _super); + function BoxCollider() { + var _this = _super.call(this) || this; + _this.shape = new Box(1, 1); + _this._colliderRequiresAutoSizing = true; + return _this; + } + Object.defineProperty(BoxCollider.prototype, "width", { + get: function () { + return this.shape.width; + }, + set: function (value) { + this.setWidth(value); + }, + enumerable: true, + configurable: true }); - }; - EntityProcessingSystem.prototype.lateProcess = function (entities) { - var _this = this; - entities.forEach(function (entity) { - return _this.lateProcessEntity(entity); + BoxCollider.prototype.setWidth = function (width) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width) { + box.updateBox(width, box.height); + this._isPositionDirty = true; + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + return this; + }; + Object.defineProperty(BoxCollider.prototype, "height", { + get: function () { + return this.shape.height; + }, + set: function (value) { + this.setHeight(value); + }, + enumerable: true, + configurable: true }); - }; - return EntityProcessingSystem; -})(EntitySystem); -var PassiveSystem = (function (_super) { - __extends(PassiveSystem, _super); - function PassiveSystem() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - PassiveSystem.prototype.onChanged = function (entity) {}; - PassiveSystem.prototype.process = function (entities) { - this.begin(); - this.end(); - }; - return PassiveSystem; -})(EntitySystem); -var ProcessingSystem = (function (_super) { - __extends(ProcessingSystem, _super); - function ProcessingSystem() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - ProcessingSystem.prototype.onChanged = function (entity) {}; - ProcessingSystem.prototype.process = function (entities) { - this.begin(); - this.processSystem(); - this.end(); - }; - return ProcessingSystem; -})(EntitySystem); -var BitSet = (function () { - function BitSet(nbits) { - if (nbits === void 0) { - nbits = 64; - } - var length = nbits >> 6; - if ((nbits & BitSet.LONG_MASK) != 0) length++; - this._bits = new Array(length); - } - BitSet.prototype.and = function (bs) { - var max = Math.min(this._bits.length, bs._bits.length); - var i; - for (var i_1 = 0; i_1 < max; ++i_1) this._bits[i_1] &= bs._bits[i_1]; - while (i < this._bits.length) this._bits[i++] = 0; - }; - BitSet.prototype.andNot = function (bs) { - var i = Math.min(this._bits.length, bs._bits.length); - while (--i >= 0) this._bits[i] &= ~bs._bits[i]; - }; - BitSet.prototype.cardinality = function () { - var card = 0; - for (var i = this._bits.length - 1; i >= 0; i--) { - var a = this._bits[i]; - if (a == 0) continue; - if (a == -1) { - card += 64; - continue; - } - a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); - a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); - var b = (a >> 32) + a; - b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); - b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); - card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); - } - return card; - }; - BitSet.prototype.clear = function (pos) { - if (pos != undefined) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] &= ~(1 << pos); - } else { - for (var i = 0; i < this._bits.length; i++) this._bits[i] = 0; - } - }; - BitSet.prototype.ensure = function (lastElt) { - if (lastElt >= this._bits.length) { - var nd = new Number[lastElt + 1](); - nd = this._bits.copyWithin(0, 0, this._bits.length); - this._bits = nd; - } - }; - BitSet.prototype.get = function (pos) { - var offset = pos >> 6; - if (offset >= this._bits.length) return false; - return (this._bits[offset] & (1 << pos)) != 0; - }; - BitSet.prototype.intersects = function (set) { - var i = Math.min(this._bits.length, set._bits.length); - while (--i >= 0) { - if ((this._bits[i] & set._bits[i]) != 0) return true; - } - return false; - }; - BitSet.prototype.isEmpty = function () { - for (var i = this._bits.length - 1; i >= 0; i--) { - if (this._bits[i]) return false; + BoxCollider.prototype.setHeight = function (height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (height != box.height) { + box.updateBox(box.width, height); + this._isPositionDirty = true; + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + }; + BoxCollider.prototype.setSize = function (width, height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width || height != box.height) { + box.updateBox(width, height); + this._isPositionDirty = true; + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + return this; + }; + return BoxCollider; +}(Collider)); +var EntitySystem = (function () { + function EntitySystem(matcher) { + this._entities = []; + this._matcher = matcher ? matcher : Matcher.empty(); } - return true; - }; - BitSet.prototype.nextSetBit = function (from) { - var offset = from >> 6; - var mask = 1 << from; - while (offset < this._bits.length) { - var h = this._bits[offset]; - do { - if ((h & mask) != 0) return from; - mask <<= 1; - from++; - } while (mask != 0); - mask = 1; - offset++; + Object.defineProperty(EntitySystem.prototype, "matcher", { + get: function () { + return this._matcher; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(EntitySystem.prototype, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + this._scene = value; + this._entities = []; + }, + enumerable: true, + configurable: true + }); + EntitySystem.prototype.initialize = function () { + }; + EntitySystem.prototype.onChanged = function (entity) { + var contains = this._entities.contains(entity); + var interest = this._matcher.IsIntersted(entity); + if (interest && !contains) + this.add(entity); + else if (!interest && contains) + this.remove(entity); + }; + EntitySystem.prototype.add = function (entity) { + this._entities.push(entity); + this.onAdded(entity); + }; + EntitySystem.prototype.onAdded = function (entity) { + }; + EntitySystem.prototype.remove = function (entity) { + this._entities.remove(entity); + this.onRemoved(entity); + }; + EntitySystem.prototype.onRemoved = function (entity) { + }; + EntitySystem.prototype.update = function () { + this.begin(); + this.process(this._entities); + }; + EntitySystem.prototype.lateUpdate = function () { + this.lateProcess(this._entities); + this.end(); + }; + EntitySystem.prototype.begin = function () { + }; + EntitySystem.prototype.process = function (entities) { + }; + EntitySystem.prototype.lateProcess = function (entities) { + }; + EntitySystem.prototype.end = function () { + }; + return EntitySystem; +}()); +var EntityProcessingSystem = (function (_super) { + __extends(EntityProcessingSystem, _super); + function EntityProcessingSystem(matcher) { + return _super.call(this, matcher) || this; } - return -1; - }; - BitSet.prototype.set = function (pos, value) { - if (value === void 0) { - value = true; + EntityProcessingSystem.prototype.lateProcessEntity = function (entity) { + }; + EntityProcessingSystem.prototype.process = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.processEntity(entity); }); + }; + EntityProcessingSystem.prototype.lateProcess = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.lateProcessEntity(entity); }); + }; + return EntityProcessingSystem; +}(EntitySystem)); +var PassiveSystem = (function (_super) { + __extends(PassiveSystem, _super); + function PassiveSystem() { + return _super !== null && _super.apply(this, arguments) || this; } - if (value) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] |= 1 << pos; - } else { - this.clear(pos); + PassiveSystem.prototype.onChanged = function (entity) { + }; + PassiveSystem.prototype.process = function (entities) { + this.begin(); + this.end(); + }; + return PassiveSystem; +}(EntitySystem)); +var ProcessingSystem = (function (_super) { + __extends(ProcessingSystem, _super); + function ProcessingSystem() { + return _super !== null && _super.apply(this, arguments) || this; } - }; - BitSet.LONG_MASK = 0x3f; - return BitSet; -})(); + ProcessingSystem.prototype.onChanged = function (entity) { + }; + ProcessingSystem.prototype.process = function (entities) { + this.begin(); + this.processSystem(); + this.end(); + }; + return ProcessingSystem; +}(EntitySystem)); +var BitSet = (function () { + function BitSet(nbits) { + if (nbits === void 0) { nbits = 64; } + var length = nbits >> 6; + if ((nbits & BitSet.LONG_MASK) != 0) + length++; + this._bits = new Array(length); + } + BitSet.prototype.and = function (bs) { + var max = Math.min(this._bits.length, bs._bits.length); + var i; + for (var i_1 = 0; i_1 < max; ++i_1) + this._bits[i_1] &= bs._bits[i_1]; + while (i < this._bits.length) + this._bits[i++] = 0; + }; + BitSet.prototype.andNot = function (bs) { + var i = Math.min(this._bits.length, bs._bits.length); + while (--i >= 0) + this._bits[i] &= ~bs._bits[i]; + }; + BitSet.prototype.cardinality = function () { + var card = 0; + for (var i = this._bits.length - 1; i >= 0; i--) { + var a = this._bits[i]; + if (a == 0) + continue; + if (a == -1) { + card += 64; + continue; + } + a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); + a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); + var b = ((a >> 32) + a); + b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); + b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); + card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); + } + return card; + }; + BitSet.prototype.clear = function (pos) { + if (pos != undefined) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] &= ~(1 << pos); + } + else { + for (var i = 0; i < this._bits.length; i++) + this._bits[i] = 0; + } + }; + BitSet.prototype.ensure = function (lastElt) { + if (lastElt >= this._bits.length) { + var nd = new Number[lastElt + 1]; + nd = this._bits.copyWithin(0, 0, this._bits.length); + this._bits = nd; + } + }; + BitSet.prototype.get = function (pos) { + var offset = pos >> 6; + if (offset >= this._bits.length) + return false; + return (this._bits[offset] & (1 << pos)) != 0; + }; + BitSet.prototype.intersects = function (set) { + var i = Math.min(this._bits.length, set._bits.length); + while (--i >= 0) { + if ((this._bits[i] & set._bits[i]) != 0) + return true; + } + return false; + }; + BitSet.prototype.isEmpty = function () { + for (var i = this._bits.length - 1; i >= 0; i--) { + if (this._bits[i]) + return false; + } + return true; + }; + BitSet.prototype.nextSetBit = function (from) { + var offset = from >> 6; + var mask = 1 << from; + while (offset < this._bits.length) { + var h = this._bits[offset]; + do { + if ((h & mask) != 0) + return from; + mask <<= 1; + from++; + } while (mask != 0); + mask = 1; + offset++; + } + return -1; + }; + BitSet.prototype.set = function (pos, value) { + if (value === void 0) { value = true; } + if (value) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] |= 1 << pos; + } + else { + this.clear(pos); + } + }; + BitSet.LONG_MASK = 0x3f; + return BitSet; +}()); var ComponentList = (function () { - function ComponentList(entity) { - this._components = []; - this._componentsToAdd = []; - this._componentsToRemove = []; - this._tempBufferList = []; - this._entity = entity; - } - Object.defineProperty(ComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(ComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true, - }); - ComponentList.prototype.add = function (component) { - this._componentsToAdd.push(component); - }; - ComponentList.prototype.remove = function (component) { - if (this._componentsToAdd.contains(component)) { - this._componentsToAdd.remove(component); - return; - } - this._componentsToRemove.push(component); - }; - ComponentList.prototype.removeAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - this.handleRemove(this._components[i]); - } - this._components.length = 0; - this._componentsToAdd.length = 0; - this._componentsToRemove.length = 0; - }; - ComponentList.prototype.deregisterAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component), - false - ); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - } - }; - ComponentList.prototype.registerAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component) - ); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - } - }; - ComponentList.prototype.updateLists = function () { - if (this._componentsToRemove.length > 0) { - for (var i = 0; i < this._componentsToRemove.length; i++) { - this.handleRemove(this._componentsToRemove[i]); - this._components.remove(this._componentsToRemove[i]); - } - this._componentsToRemove.length = 0; - } - if (this._componentsToAdd.length > 0) { - for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { - var component = this._componentsToAdd[i]; + function ComponentList(entity) { + this._components = []; + this._componentsToAdd = []; + this._componentsToRemove = []; + this._tempBufferList = []; + this._entity = entity; + } + Object.defineProperty(ComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(ComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true + }); + ComponentList.prototype.add = function (component) { + this._componentsToAdd.push(component); + }; + ComponentList.prototype.remove = function (component) { + if (this._componentsToAdd.contains(component)) { + this._componentsToAdd.remove(component); + return; + } + this._componentsToRemove.push(component); + }; + ComponentList.prototype.removeAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + this.handleRemove(this._components[i]); + } + this._components.length = 0; + this._componentsToAdd.length = 0; + this._componentsToRemove.length = 0; + }; + ComponentList.prototype.deregisterAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + } + }; + ComponentList.prototype.registerAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + } + }; + ComponentList.prototype.updateLists = function () { + if (this._componentsToRemove.length > 0) { + for (var i = 0; i < this._componentsToRemove.length; i++) { + this.handleRemove(this._componentsToRemove[i]); + this._components.remove(this._componentsToRemove[i]); + } + this._componentsToRemove.length = 0; + } + if (this._componentsToAdd.length > 0) { + for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + this._components.push(component); + this._tempBufferList.push(component); + } + this._componentsToAdd.length = 0; + for (var i = 0; i < this._tempBufferList.length; i++) { + var component = this._tempBufferList[i]; + component.onAddedToEntity(); + if (component.enabled) { + component.onEnabled(); + } + } + this._tempBufferList.length = 0; + } + }; + ComponentList.prototype.handleRemove = function (component) { if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component) - ); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - this._components.push(component); - this._tempBufferList.push(component); - } - this._componentsToAdd.length = 0; - for (var i = 0; i < this._tempBufferList.length; i++) { - var component = this._tempBufferList[i]; - component.onAddedToEntity(); - if (component.enabled) { - component.onEnabled(); - } - } - this._tempBufferList.length = 0; - } - }; - ComponentList.prototype.handleRemove = function (component) { - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(component), - false - ); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - component.onRemovedFromEntity(); - component.entity = null; - }; - ComponentList.prototype.getComponent = function ( - type, - onlyReturnInitializedComponents - ) { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof type) return component; - } - if (!onlyReturnInitializedComponents) { - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; - if (component instanceof type) return component; - } - } - return null; - }; - ComponentList.prototype.getComponents = function (typeName, components) { - if (!components) components = []; - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (typeof typeName == "string") { - if (egret.is(component, typeName)) { - components.push(component); - } - } else { - if (component instanceof typeName) { - components.push(component); - } - } - } - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; - if (typeof typeName == "string") { - if (egret.is(component, typeName)) { - components.push(component); + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + component.onRemovedFromEntity(); + component.entity = null; + }; + ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof type) + return component; } - } else { - if (component instanceof typeName) { - components.push(component); + if (!onlyReturnInitializedComponents) { + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof type) + return component; + } } - } - } - return components; - }; - ComponentList.prototype.update = function () { - this.updateLists(); - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if ( - component.enabled && - (component.updateInterval == 1 || - Time.frameCount % component.updateInterval == 0) - ) - component.update(); - } - }; - ComponentList.prototype.onEntityTransformChanged = function (comp) { - for (var i = 0; i < this._components.length; i++) { - if (this._components[i].enabled) - this._components[i].onEntityTransformChanged(comp); - } - for (var i = 0; i < this._componentsToAdd.length; i++) { - if (this._componentsToAdd[i].enabled) - this._componentsToAdd[i].onEntityTransformChanged(comp); - } - }; - return ComponentList; -})(); + return null; + }; + ComponentList.prototype.getComponents = function (typeName, components) { + if (!components) + components = []; + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } + } + } + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } + } + } + return components; + }; + ComponentList.prototype.update = function () { + this.updateLists(); + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component.enabled && (component.updateInterval == 1 || Time.frameCount % component.updateInterval == 0)) + component.update(); + } + }; + return ComponentList; +}()); var ComponentTypeManager = (function () { - function ComponentTypeManager() {} - ComponentTypeManager.add = function (type) { - if (!this._componentTypesMask.has(type)) - this._componentTypesMask[type] = this._componentTypesMask.size; - }; - ComponentTypeManager.getIndexFor = function (type) { - var v = -1; - if (!this._componentTypesMask.has(type)) { - this.add(type); - v = this._componentTypesMask.get(type); + function ComponentTypeManager() { } - return v; - }; - ComponentTypeManager._componentTypesMask = new Map(); - return ComponentTypeManager; -})(); + ComponentTypeManager.add = function (type) { + if (!this._componentTypesMask.has(type)) + this._componentTypesMask[type] = this._componentTypesMask.size; + }; + ComponentTypeManager.getIndexFor = function (type) { + var v = -1; + if (!this._componentTypesMask.has(type)) { + this.add(type); + v = this._componentTypesMask.get(type); + } + return v; + }; + ComponentTypeManager._componentTypesMask = new Map(); + return ComponentTypeManager; +}()); var EntityList = (function () { - function EntityList(scene) { - this._entitiesToRemove = []; - this._entitiesToAdded = []; - this._tempEntityList = []; - this._entities = []; - this._entityDict = new Map(); - this._unsortedTags = []; - this.scene = scene; - } - Object.defineProperty(EntityList.prototype, "count", { - get: function () { - return this._entities.length; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(EntityList.prototype, "buffer", { - get: function () { - return this._entities; - }, - enumerable: true, - configurable: true, - }); - EntityList.prototype.add = function (entity) { - if (this._entitiesToAdded.indexOf(entity) == -1) - this._entitiesToAdded.push(entity); - }; - EntityList.prototype.remove = function (entity) { - if (this._entitiesToAdded.contains(entity)) { - this._entitiesToAdded.remove(entity); - return; - } - if (!this._entitiesToRemove.contains(entity)) - this._entitiesToRemove.push(entity); - }; - EntityList.prototype.findEntity = function (name) { - for (var i = 0; i < this._entities.length; i++) { - if (this._entities[i].name == name) return this._entities[i]; - } - return this._entitiesToAdded.firstOrDefault(function (entity) { - return entity.name == name; + function EntityList(scene) { + this._entitiesToRemove = []; + this._entitiesToAdded = []; + this._tempEntityList = []; + this._entities = []; + this._entityDict = new Map(); + this._unsortedTags = []; + this.scene = scene; + } + Object.defineProperty(EntityList.prototype, "count", { + get: function () { + return this._entities.length; + }, + enumerable: true, + configurable: true }); - }; - EntityList.prototype.getTagList = function (tag) { - var list = this._entityDict.get(tag); - if (!list) { - list = []; - this._entityDict.set(tag, list); - } - return this._entityDict.get(tag); - }; - EntityList.prototype.addToTagList = function (entity) { - var list = this.getTagList(entity.tag); - if (!list.contains(entity)) { - list.push(entity); - this._unsortedTags.push(entity.tag); - } - }; - EntityList.prototype.removeFromTagList = function (entity) { - var list = this._entityDict.get(entity.tag); - if (list) { - list.remove(entity); - } - }; - EntityList.prototype.update = function () { - for (var i = 0; i < this._entities.length; i++) { - var entity = this._entities[i]; - if (entity.enabled) entity.update(); - } - }; - EntityList.prototype.removeAllEntities = function () { - this._entitiesToAdded.length = 0; - this.updateLists(); - for (var i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestoryed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; - } - this._entities.length = 0; - this._entityDict.clear(); - }; - EntityList.prototype.updateLists = function () { - var _this = this; - if (this._entitiesToRemove.length > 0) { - var temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - _this._entities.remove(entity); - entity.scene = null; - _this.scene.entityProcessors.onEntityRemoved(entity); - }); - this._tempEntityList.length = 0; - } - if (this._entitiesToAdded.length > 0) { - var temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - if (!_this._entities.contains(entity)) { - _this._entities.push(entity); - entity.scene = _this.scene; - _this.scene.entityProcessors.onEntityAdded(entity); - } - }); - this._tempEntityList.forEach(function (entity) { - return entity.onAddedToScene(); - }); - this._tempEntityList.length = 0; - } - if (this._unsortedTags.length > 0) { - this._unsortedTags.forEach(function (tag) { - _this._entityDict.get(tag).sort(); - }); - this._unsortedTags.length = 0; - } - }; - return EntityList; -})(); + Object.defineProperty(EntityList.prototype, "buffer", { + get: function () { + return this._entities; + }, + enumerable: true, + configurable: true + }); + EntityList.prototype.add = function (entity) { + if (this._entitiesToAdded.indexOf(entity) == -1) + this._entitiesToAdded.push(entity); + }; + EntityList.prototype.remove = function (entity) { + if (this._entitiesToAdded.contains(entity)) { + this._entitiesToAdded.remove(entity); + return; + } + if (!this._entitiesToRemove.contains(entity)) + this._entitiesToRemove.push(entity); + }; + EntityList.prototype.findEntity = function (name) { + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].name == name) + return this._entities[i]; + } + return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; }); + }; + EntityList.prototype.getTagList = function (tag) { + var list = this._entityDict.get(tag); + if (!list) { + list = []; + this._entityDict.set(tag, list); + } + return this._entityDict.get(tag); + }; + EntityList.prototype.addToTagList = function (entity) { + var list = this.getTagList(entity.tag); + if (!list.contains(entity)) { + list.push(entity); + this._unsortedTags.push(entity.tag); + } + }; + EntityList.prototype.removeFromTagList = function (entity) { + var list = this._entityDict.get(entity.tag); + if (list) { + list.remove(entity); + } + }; + EntityList.prototype.update = function () { + for (var i = 0; i < this._entities.length; i++) { + var entity = this._entities[i]; + if (entity.enabled) + entity.update(); + } + }; + EntityList.prototype.removeAllEntities = function () { + this._entitiesToAdded.length = 0; + this.updateLists(); + for (var i = 0; i < this._entities.length; i++) { + this._entities[i]._isDestoryed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + this._entities.length = 0; + this._entityDict.clear(); + }; + EntityList.prototype.updateLists = function () { + var _this = this; + if (this._entitiesToRemove.length > 0) { + var temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + _this._entities.remove(entity); + entity.scene = null; + _this.scene.entityProcessors.onEntityRemoved(entity); + }); + this._tempEntityList.length = 0; + } + if (this._entitiesToAdded.length > 0) { + var temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + if (!_this._entities.contains(entity)) { + _this._entities.push(entity); + entity.scene = _this.scene; + _this.scene.entityProcessors.onEntityAdded(entity); + } + }); + this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); + this._tempEntityList.length = 0; + } + if (this._unsortedTags.length > 0) { + this._unsortedTags.forEach(function (tag) { + _this._entityDict.get(tag).sort(); + }); + this._unsortedTags.length = 0; + } + }; + return EntityList; +}()); var EntityProcessorList = (function () { - function EntityProcessorList() { - this._processors = []; - } - EntityProcessorList.prototype.add = function (processor) { - this._processors.push(processor); - }; - EntityProcessorList.prototype.remove = function (processor) { - this._processors.remove(processor); - }; - EntityProcessorList.prototype.onComponentAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onComponentRemoved = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityRemoved = function (entity) { - this.removeFromProcessors(entity); - }; - EntityProcessorList.prototype.notifyEntityChanged = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].onChanged(entity); - } - }; - EntityProcessorList.prototype.removeFromProcessors = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].remove(entity); - } - }; - EntityProcessorList.prototype.begin = function () {}; - EntityProcessorList.prototype.update = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].update(); - } - }; - EntityProcessorList.prototype.lateUpdate = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].lateUpdate(); + function EntityProcessorList() { + this._processors = []; } - }; - EntityProcessorList.prototype.end = function () {}; - EntityProcessorList.prototype.getProcessor = function () { - for (var i = 0; i < this._processors.length; i++) { - var processor = this._processors[i]; - if (processor instanceof EntitySystem) return processor; - } - return null; - }; - return EntityProcessorList; -})(); + EntityProcessorList.prototype.add = function (processor) { + this._processors.push(processor); + }; + EntityProcessorList.prototype.remove = function (processor) { + this._processors.remove(processor); + }; + EntityProcessorList.prototype.onComponentAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onComponentRemoved = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityRemoved = function (entity) { + this.removeFromProcessors(entity); + }; + EntityProcessorList.prototype.notifyEntityChanged = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].onChanged(entity); + } + }; + EntityProcessorList.prototype.removeFromProcessors = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].remove(entity); + } + }; + EntityProcessorList.prototype.begin = function () { + }; + EntityProcessorList.prototype.update = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].update(); + } + }; + EntityProcessorList.prototype.lateUpdate = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].lateUpdate(); + } + }; + EntityProcessorList.prototype.end = function () { + }; + EntityProcessorList.prototype.getProcessor = function () { + for (var i = 0; i < this._processors.length; i++) { + var processor = this._processors[i]; + if (processor instanceof EntitySystem) + return processor; + } + return null; + }; + return EntityProcessorList; +}()); var Matcher = (function () { - function Matcher() { - this.allSet = new BitSet(); - this.exclusionSet = new BitSet(); - this.oneSet = new BitSet(); - } - Matcher.empty = function () { - return new Matcher(); - }; - Matcher.prototype.getAllSet = function () { - return this.allSet; - }; - Matcher.prototype.getExclusionSet = function () { - return this.exclusionSet; - }; - Matcher.prototype.getOneSet = function () { - return this.oneSet; - }; - Matcher.prototype.IsIntersted = function (e) { - if (!this.allSet.isEmpty()) { - for ( - var i = this.allSet.nextSetBit(0); - i >= 0; - i = this.allSet.nextSetBit(i + 1) - ) { - if (!e.componentBits.get(i)) return false; - } - } - if ( - !this.exclusionSet.isEmpty() && - this.exclusionSet.intersects(e.componentBits) - ) - return false; - if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) - return false; - return true; - }; - Matcher.prototype.all = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + function Matcher() { + this.allSet = new BitSet(); + this.exclusionSet = new BitSet(); + this.oneSet = new BitSet(); } - types.forEach(function (type) { - _this.allSet.set(ComponentTypeManager.getIndexFor(type)); - }); - return this; - }; - Matcher.prototype.exclude = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + Matcher.empty = function () { + return new Matcher(); + }; + Matcher.prototype.getAllSet = function () { + return this.allSet; + }; + Matcher.prototype.getExclusionSet = function () { + return this.exclusionSet; + }; + Matcher.prototype.getOneSet = function () { + return this.oneSet; + }; + Matcher.prototype.IsIntersted = function (e) { + if (!this.allSet.isEmpty()) { + for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { + if (!e.componentBits.get(i)) + return false; + } + } + if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) + return false; + if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) + return false; + return true; + }; + Matcher.prototype.all = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.allSet.set(ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.exclude = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.one = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.oneSet.set(ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + return Matcher; +}()); +var RenderableComponentList = (function () { + function RenderableComponentList() { + this._components = []; } - types.forEach(function (type) { - _this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(RenderableComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true }); - return this; - }; - Matcher.prototype.one = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; - } - types.forEach(function (type) { - _this.oneSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(RenderableComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true }); - return this; - }; - return Matcher; -})(); -var RenderableComponentList = (function () { - function RenderableComponentList() { - this._components = []; - } - Object.defineProperty(RenderableComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(RenderableComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true, - }); - RenderableComponentList.prototype.add = function (component) { - this._components.push(component); - }; - RenderableComponentList.prototype.remove = function (component) { - this._components.remove(component); - }; - RenderableComponentList.prototype.updateList = function () {}; - return RenderableComponentList; -})(); + RenderableComponentList.prototype.add = function (component) { + this._components.push(component); + }; + RenderableComponentList.prototype.remove = function (component) { + this._components.remove(component); + }; + RenderableComponentList.prototype.updateList = function () { + }; + return RenderableComponentList; +}()); var Time = (function () { - function Time() {} - Time.update = function (currentTime) { - var dt = (currentTime - this._lastTime) / 1000; - this.deltaTime = dt * this.timeScale; - this.unscaledDeltaTime = dt; - this.frameCount++; - this._lastTime = currentTime; - }; - Time.deltaTime = 0; - Time.timeScale = 1; - Time.frameCount = 0; - Time._lastTime = 0; - return Time; -})(); + function Time() { + } + ; + Time.update = function (currentTime) { + var dt = (currentTime - this._lastTime) / 1000; + this.deltaTime = dt * this.timeScale; + this.unscaledDeltaTime = dt; + this.frameCount++; + this._lastTime = currentTime; + }; + Time.deltaTime = 0; + Time.timeScale = 1; + Time.frameCount = 0; + Time._lastTime = 0; + return Time; +}()); var GraphicsCapabilities = (function () { - function GraphicsCapabilities() {} - GraphicsCapabilities.prototype.initialize = function (device) { - this.platformInitialize(device); - }; - GraphicsCapabilities.prototype.platformInitialize = function (device) { - var gl = new egret.sys.RenderBuffer().context.getInstance(); - this.supportsNonPowerOfTwo = false; - this.supportsTextureFilterAnisotropic = - gl.getExtension("EXT_texture_filter_anisotropic") != null; - this.supportsDepth24 = true; - this.supportsPackedDepthStencil = true; - this.supportsDepthNonLinear = false; - this.supportsTextureMaxLevel = true; - this.supportsS3tc = - gl.getExtension("WEBGL_compressed_texture_s3tc") != null || - gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null; - this.supportsDxt1 = this.supportsS3tc; - this.supportsPvrtc = false; - this.supportsAtitc = - gl.getExtension("WEBGL_compressed_texture_astc") != null; - this.supportsFramebufferObjectARB = false; - }; - return GraphicsCapabilities; -})(); + function GraphicsCapabilities() { + } + GraphicsCapabilities.prototype.initialize = function (device) { + this.platformInitialize(device); + }; + GraphicsCapabilities.prototype.platformInitialize = function (device) { + var gl = new egret.sys.RenderBuffer().context.getInstance(); + this.supportsNonPowerOfTwo = false; + this.supportsTextureFilterAnisotropic = gl.getExtension("EXT_texture_filter_anisotropic") != null; + this.supportsDepth24 = true; + this.supportsPackedDepthStencil = true; + this.supportsDepthNonLinear = false; + this.supportsTextureMaxLevel = true; + this.supportsS3tc = gl.getExtension("WEBGL_compressed_texture_s3tc") != null || + gl.getExtension("WEBGL_compressed_texture_s3tc_srgb") != null; + this.supportsDxt1 = this.supportsS3tc; + this.supportsPvrtc = false; + this.supportsAtitc = gl.getExtension("WEBGL_compressed_texture_astc") != null; + this.supportsFramebufferObjectARB = false; + }; + return GraphicsCapabilities; +}()); var GraphicsDevice = (function () { - function GraphicsDevice() { - this.graphicsCapabilities = new GraphicsCapabilities(); - this.graphicsCapabilities.initialize(this); - } - return GraphicsDevice; -})(); + function GraphicsDevice() { + this.graphicsCapabilities = new GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); + } + return GraphicsDevice; +}()); var Viewport = (function () { - function Viewport(x, y, width, height) { - this._x = x; - this._y = y; - this._width = width; - this._height = height; - this._minDepth = 0; - this._maxDepth = 1; - } - Object.defineProperty(Viewport.prototype, "aspectRatio", { - get: function () { - if (this._height != 0 && this._width != 0) - return this._width / this._height; - return 0; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Viewport.prototype, "bounds", { - get: function () { - return new Rectangle(this._x, this._y, this._width, this._height); - }, - set: function (value) { - this._x = value.x; - this._y = value.y; - this._width = value.width; - this._height = value.height; - }, - enumerable: true, - configurable: true, - }); - return Viewport; -})(); -var GraphicsResource = (function () { - function GraphicsResource() {} - return GraphicsResource; -})(); + function Viewport(x, y, width, height) { + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } + Object.defineProperty(Viewport.prototype, "aspectRatio", { + get: function () { + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Viewport.prototype, "bounds", { + get: function () { + return new Rectangle(this._x, this._y, this._width, this._height); + }, + set: function (value) { + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + }, + enumerable: true, + configurable: true + }); + return Viewport; +}()); var GaussianBlurEffect = (function (_super) { - __extends(GaussianBlurEffect, _super); - function GaussianBlurEffect() { - return ( - _super.call( - this, - PostProcessor.default_vert, - GaussianBlurEffect.blur_frag, - { - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight, - } - ) || this - ); - } - GaussianBlurEffect.blur_frag = - "precision mediump float;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float screenWidth;\n" + - "uniform float screenHeight;\n" + - "float normpdf(in float x, in float sigma)\n" + - "{\n" + - "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + - "}\n" + - "void main()\n" + - "{\n" + - "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "const int mSize = 11;\n" + - "const int kSize = (mSize - 1)/2;\n" + - "float kernel[mSize];\n" + - "vec3 final_colour = vec3(0.0);\n" + - "float sigma = 7.0;\n" + - "float z = 0.0;\n" + - "for (int j = 0; j <= kSize; ++j)\n" + - "{\n" + - "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + - "}\n" + - "for (int j = 0; j < mSize; ++j)\n" + - "{\n" + - "z += kernel[j];\n" + - "}\n" + - "for (int i = -kSize; i <= kSize; ++i)\n" + - "{\n" + - "for (int j = -kSize; j <= kSize; ++j)\n" + - "{\n" + - "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "}\n}\n" + - "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + - "}"; - return GaussianBlurEffect; -})(egret.CustomFilter); + __extends(GaussianBlurEffect, _super); + function GaussianBlurEffect() { + return _super.call(this, PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { + screenWidth: SceneManager.stage.stageWidth, + screenHeight: SceneManager.stage.stageHeight + }) || this; + } + GaussianBlurEffect.blur_frag = "precision mediump float;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float screenWidth;\n" + + "uniform float screenHeight;\n" + + "float normpdf(in float x, in float sigma)\n" + + "{\n" + + "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + + "}\n" + + "void main()\n" + + "{\n" + + "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "const int mSize = 11;\n" + + "const int kSize = (mSize - 1)/2;\n" + + "float kernel[mSize];\n" + + "vec3 final_colour = vec3(0.0);\n" + + "float sigma = 7.0;\n" + + "float z = 0.0;\n" + + "for (int j = 0; j <= kSize; ++j)\n" + + "{\n" + + "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + + "}\n" + + "for (int j = 0; j < mSize; ++j)\n" + + "{\n" + + "z += kernel[j];\n" + + "}\n" + + "for (int i = -kSize; i <= kSize; ++i)\n" + + "{\n" + + "for (int j = -kSize; j <= kSize; ++j)\n" + + "{\n" + + "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "}\n}\n" + + "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + + "}"; + return GaussianBlurEffect; +}(egret.CustomFilter)); var PolygonLightEffect = (function (_super) { - __extends(PolygonLightEffect, _super); - function PolygonLightEffect() { - return ( - _super.call( - this, - PolygonLightEffect.vertSrc, - PolygonLightEffect.fragmentSrc - ) || this - ); - } - PolygonLightEffect.vertSrc = - "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - PolygonLightEffect.fragmentSrc = - "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + - "#define SAMPLE_COUNT 15\n" + - "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + - "uniform float _sampleWeights[SAMPLE_COUNT];\n" + - "void main(void) {\n" + - "vec4 c = vec4(0, 0, 0, 0);\n" + - "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + - " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + - "gl_FragColor = c;\n" + - "}"; - return PolygonLightEffect; -})(egret.CustomFilter); + __extends(PolygonLightEffect, _super); + function PolygonLightEffect() { + return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this; + } + PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + PolygonLightEffect.fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + + "#define SAMPLE_COUNT 15\n" + + "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + + "uniform float _sampleWeights[SAMPLE_COUNT];\n" + + "void main(void) {\n" + + "vec4 c = vec4(0, 0, 0, 0);\n" + + "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + + " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + + "gl_FragColor = c;\n" + + "}"; + return PolygonLightEffect; +}(egret.CustomFilter)); var PostProcessor = (function () { - function PostProcessor(effect) { - if (effect === void 0) { - effect = null; - } - this.enable = true; - this.effect = effect; - } - PostProcessor.prototype.onAddedToScene = function (scene) { - this.scene = scene; - this.shape = new egret.Shape(); - this.shape.graphics.beginFill(0xffffff, 1); - this.shape.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - this.shape.graphics.endFill(); - scene.addChild(this.shape); - }; - PostProcessor.prototype.process = function () { - this.drawFullscreenQuad(); - }; - PostProcessor.prototype.onSceneBackBufferSizeChanged = function ( - newWidth, - newHeight - ) {}; - PostProcessor.prototype.drawFullscreenQuad = function () { - this.scene.filters = [this.effect]; - }; - PostProcessor.prototype.unload = function () { - if (this.effect) { - this.effect = null; - } - this.scene.removeChild(this.shape); - this.scene = null; - }; - PostProcessor.default_vert = - "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "attribute vec2 aColor;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "varying vec4 vColor;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - "vTextureCoord = aTextureCoord;\n" + - "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + - "}"; - return PostProcessor; -})(); -var BloomSettings = (function () { - function BloomSettings( - bloomThreshold, - blurAmount, - bloomIntensity, - baseIntensity, - bloomSaturation, - baseSaturation - ) { - this.threshold = bloomThreshold; - this.blurAmount = blurAmount; - this.intensity = bloomIntensity; - this.baseIntensity = baseIntensity; - this.saturation = bloomSaturation; - this.baseStaturation = baseSaturation; - } - BloomSettings.presetSettings = [ - new BloomSettings(0.1, 0.6, 2, 1, 1, 0), - new BloomSettings(0, 3, 1, 1, 1, 1), - new BloomSettings(0.5, 8, 2, 1, 0, 1), - new BloomSettings(0.25, 8, 1.3, 1, 1, 0), - new BloomSettings(0, 2, 1, 0.1, 1, 1), - new BloomSettings(0.5, 2, 1, 1, 1, 1), - ]; - return BloomSettings; -})(); + function PostProcessor(effect) { + if (effect === void 0) { effect = null; } + this.enable = true; + this.effect = effect; + } + PostProcessor.prototype.onAddedToScene = function (scene) { + this.scene = scene; + this.shape = new egret.Shape(); + this.shape.graphics.beginFill(0xFFFFFF, 1); + this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this.shape.graphics.endFill(); + scene.addChild(this.shape); + }; + PostProcessor.prototype.process = function () { + this.drawFullscreenQuad(); + }; + PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { }; + PostProcessor.prototype.drawFullscreenQuad = function () { + this.scene.filters = [this.effect]; + }; + PostProcessor.prototype.unload = function () { + if (this.effect) { + this.effect = null; + } + this.scene.removeChild(this.shape); + this.scene = null; + }; + PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "attribute vec2 aColor;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "varying vec4 vColor;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + "vTextureCoord = aTextureCoord;\n" + + "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + + "}"; + return PostProcessor; +}()); var GaussianBlurPostProcessor = (function (_super) { - __extends(GaussianBlurPostProcessor, _super); - function GaussianBlurPostProcessor() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { - _super.prototype.onAddedToScene.call(this, scene); - this.effect = new GaussianBlurEffect(); - }; - return GaussianBlurPostProcessor; -})(PostProcessor); + __extends(GaussianBlurPostProcessor, _super); + function GaussianBlurPostProcessor() { + return _super !== null && _super.apply(this, arguments) || this; + } + GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { + _super.prototype.onAddedToScene.call(this, scene); + this.effect = new GaussianBlurEffect(); + }; + return GaussianBlurPostProcessor; +}(PostProcessor)); var Renderer = (function () { - function Renderer() {} - Renderer.prototype.onAddedToScene = function (scene) {}; - Renderer.prototype.beginRender = function (cam) {}; - Renderer.prototype.unload = function () {}; - Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { - renderable.render(cam); - }; - return Renderer; -})(); -var DefaultRenderer = (function (_super) { - __extends(DefaultRenderer, _super); - function DefaultRenderer() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - DefaultRenderer.prototype.render = function (scene) { - var cam = this.camera ? this.camera : scene.camera; - this.beginRender(cam); - for (var i = 0; i < scene.renderableComponents.count; i++) { - var renderable = scene.renderableComponents.buffer[i]; - if (renderable.enabled && renderable.isVisibleFromCamera(cam)) - this.renderAfterStateCheck(renderable, cam); + function Renderer() { } - }; - return DefaultRenderer; -})(Renderer); + Renderer.prototype.onAddedToScene = function (scene) { }; + Renderer.prototype.beginRender = function (cam) { + }; + Renderer.prototype.unload = function () { }; + Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { + renderable.render(cam); + }; + return Renderer; +}()); +var DefaultRenderer = (function (_super) { + __extends(DefaultRenderer, _super); + function DefaultRenderer() { + return _super !== null && _super.apply(this, arguments) || this; + } + DefaultRenderer.prototype.render = function (scene) { + var cam = this.camera ? this.camera : scene.camera; + this.beginRender(cam); + for (var i = 0; i < scene.renderableComponents.count; i++) { + var renderable = scene.renderableComponents.buffer[i]; + if (renderable.enabled && renderable.isVisibleFromCamera(cam)) + this.renderAfterStateCheck(renderable, cam); + } + }; + return DefaultRenderer; +}(Renderer)); var ScreenSpaceRenderer = (function (_super) { - __extends(ScreenSpaceRenderer, _super); - function ScreenSpaceRenderer() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - ScreenSpaceRenderer.prototype.render = function (scene) {}; - return ScreenSpaceRenderer; -})(Renderer); -var PolyLight = (function (_super) { - __extends(PolyLight, _super); - function PolyLight(radius, color, power) { - var _this = _super.call(this) || this; - _this._indices = []; - _this.radius = radius; - _this.power = power; - _this.color = color; - _this.computeTriangleIndices(); - return _this; - } - Object.defineProperty(PolyLight.prototype, "radius", { - get: function () { - return this._radius; - }, - set: function (value) { - this.setRadius(value); - }, - enumerable: true, - configurable: true, - }); - PolyLight.prototype.computeTriangleIndices = function (totalTris) { - if (totalTris === void 0) { - totalTris = 20; + __extends(ScreenSpaceRenderer, _super); + function ScreenSpaceRenderer() { + return _super !== null && _super.apply(this, arguments) || this; } - this._indices.length = 0; - for (var i = 0; i < totalTris; i += 2) { - this._indices.push(0); - this._indices.push(i + 2); - this._indices.push(i + 1); - } - }; - PolyLight.prototype.setRadius = function (radius) { - if (radius != this._radius) { - this._radius = radius; - this._areBoundsDirty = true; - } - }; - PolyLight.prototype.render = function (camera) {}; - PolyLight.prototype.reset = function () {}; - return PolyLight; -})(RenderableComponent); -var SceneTransition = (function () { - function SceneTransition(sceneLoadAction) { - this.sceneLoadAction = sceneLoadAction; - this.loadsNewScene = sceneLoadAction != null; - } - Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { - get: function () { - if (!this._hasPreviousSceneRender) { - this._hasPreviousSceneRender = true; - return false; - } - return true; - }, - enumerable: true, - configurable: true, - }); - SceneTransition.prototype.preRender = function () {}; - SceneTransition.prototype.render = function () {}; - SceneTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - _a.sent(); - this.transitionComplete(); - return [2]; - } - }); + ScreenSpaceRenderer.prototype.render = function (scene) { + }; + return ScreenSpaceRenderer; +}(Renderer)); +var PolyLight = (function (_super) { + __extends(PolyLight, _super); + function PolyLight(radius, color, power) { + var _this = _super.call(this) || this; + _this._indices = []; + _this.radius = radius; + _this.power = power; + _this.color = color; + _this.computeTriangleIndices(); + return _this; + } + Object.defineProperty(PolyLight.prototype, "radius", { + get: function () { + return this._radius; + }, + set: function (value) { + this.setRadius(value); + }, + enumerable: true, + configurable: true }); - }; - SceneTransition.prototype.transitionComplete = function () { - SceneManager.sceneTransition = null; - if (this.onTransitionCompleted) { - this.onTransitionCompleted(); - } - }; - SceneTransition.prototype.loadNextScene = function () { - return __awaiter(this, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (this.onScreenObscured) this.onScreenObscured(); - if (!this.loadsNewScene) { - this.isNewSceneLoaded = true; + PolyLight.prototype.computeTriangleIndices = function (totalTris) { + if (totalTris === void 0) { totalTris = 20; } + this._indices.length = 0; + for (var i = 0; i < totalTris; i += 2) { + this._indices.push(0); + this._indices.push(i + 2); + this._indices.push(i + 1); + } + }; + PolyLight.prototype.setRadius = function (radius) { + if (radius != this._radius) { + this._radius = radius; + this._areBoundsDirty = true; + } + }; + PolyLight.prototype.render = function (camera) { + }; + PolyLight.prototype.reset = function () { + }; + return PolyLight; +}(RenderableComponent)); +var SceneTransition = (function () { + function SceneTransition(sceneLoadAction) { + this.sceneLoadAction = sceneLoadAction; + this.loadsNewScene = sceneLoadAction != null; + } + Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { + get: function () { + if (!this._hasPreviousSceneRender) { + this._hasPreviousSceneRender = true; + return false; } - _a = SceneManager; - return [4, this.sceneLoadAction()]; - case 1: - _a.scene = _b.sent(); - this.isNewSceneLoaded = true; - return [2]; - } - }); - }); - }; - SceneTransition.prototype.tickEffectProgressProperty = function ( - filter, - duration, - easeType, - reverseDirection - ) { - if (reverseDirection === void 0) { - reverseDirection = false; - } - return new Promise(function (resolve) { - var start = reverseDirection ? 1 : 0; - var end = reverseDirection ? 0 : 1; - egret.Tween.get(filter.uniforms) - .set({ _progress: start }) - .to({ _progress: end }, duration * 1000, easeType) - .call(function () { - resolve(); - }); + return true; + }, + enumerable: true, + configurable: true }); - }; - return SceneTransition; -})(); -var FadeTransition = (function (_super) { - __extends(FadeTransition, _super); - function FadeTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.fadeToColor = 0x000000; - _this.fadeOutDuration = 0.4; - _this.fadeEaseType = egret.Ease.quadInOut; - _this.delayBeforeFadeInDuration = 0.1; - _this._alpha = 0; - _this._mask = new egret.Shape(); - return _this; - } - FadeTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - this._mask.graphics.endFill(); - SceneManager.stage.addChild(this._mask); - egret.Tween.get(this) - .to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) - .call(function () { - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { + SceneTransition.prototype.preRender = function () { }; + SceneTransition.prototype.render = function () { + }; + SceneTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { switch (_a.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - _a.sent(); - return [2]; + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + this.transitionComplete(); + return [2]; } - }); }); - }) - .wait(this.delayBeforeFadeInDuration) - .call(function () { - egret.Tween.get(_this) - .to( - { _alpha: 0 }, - _this.fadeOutDuration * 1000, - _this.fadeEaseType - ) - .call(function () { - _this.transitionComplete(); - SceneManager.stage.removeChild(_this._mask); - }); - }); - return [2]; - }); - }); - }; - FadeTransition.prototype.render = function () { - this._mask.graphics.clear(); - this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - this._mask.graphics.endFill(); - }; - return FadeTransition; -})(SceneTransition); + }); + }; + SceneTransition.prototype.transitionComplete = function () { + SceneManager.sceneTransition = null; + if (this.onTransitionCompleted) { + this.onTransitionCompleted(); + } + }; + SceneTransition.prototype.loadNextScene = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (this.onScreenObscured) + this.onScreenObscured(); + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + } + _a = SceneManager; + return [4, this.sceneLoadAction()]; + case 1: + _a.scene = _b.sent(); + this.isNewSceneLoaded = true; + return [2]; + } + }); + }); + }; + SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) { + if (reverseDirection === void 0) { reverseDirection = false; } + return new Promise(function (resolve) { + var start = reverseDirection ? 1 : 0; + var end = reverseDirection ? 0 : 1; + egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () { + resolve(); + }); + }); + }; + return SceneTransition; +}()); +var FadeTransition = (function (_super) { + __extends(FadeTransition, _super); + function FadeTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.fadeToColor = 0x000000; + _this.fadeOutDuration = 0.4; + _this.fadeEaseType = egret.Ease.quadInOut; + _this.delayBeforeFadeInDuration = 0.1; + _this._alpha = 0; + _this._mask = new egret.Shape(); + return _this; + } + FadeTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + this._mask.graphics.beginFill(this.fadeToColor, 1); + this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + SceneManager.stage.addChild(this._mask); + egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) + .call(function () { return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + return [2]; + } + }); + }); }).wait(this.delayBeforeFadeInDuration).call(function () { + egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { + _this.transitionComplete(); + SceneManager.stage.removeChild(_this._mask); + }); + }); + return [2]; + }); + }); + }; + FadeTransition.prototype.render = function () { + this._mask.graphics.clear(); + this._mask.graphics.beginFill(this.fadeToColor, this._alpha); + this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + }; + return FadeTransition; +}(SceneTransition)); var WindTransition = (function (_super) { - __extends(WindTransition, _super); - function WindTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.duration = 1; - _this.easeType = egret.Ease.quadOut; - var vertexSrc = - "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - var fragmentSrc = - "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float _progress;\n" + - "uniform float _size;\n" + - "uniform float _windSegments;\n" + - "void main(void) {\n" + - "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + - "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + - "float r = x - floor(x);\n" + - "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + - "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + - "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + - "}"; - _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { - _progress: 0, - _size: 0.3, - _windSegments: 100, + __extends(WindTransition, _super); + function WindTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.duration = 1; + _this.easeType = egret.Ease.quadOut; + var vertexSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + var fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float _progress;\n" + + "uniform float _size;\n" + + "uniform float _windSegments;\n" + + "void main(void) {\n" + + "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + + "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + + "float r = x - floor(x);\n" + + "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + + "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + + "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + + "}"; + _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { + _progress: 0, + _size: 0.3, + _windSegments: 100 + }); + _this._mask = new egret.Shape(); + _this._mask.graphics.beginFill(0xFFFFFF, 1); + _this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + _this._mask.graphics.endFill(); + _this._mask.filters = [_this._windEffect]; + SceneManager.stage.addChild(_this._mask); + return _this; + } + Object.defineProperty(WindTransition.prototype, "windSegments", { + set: function (value) { + this._windEffect.uniforms._windSegments = value; + }, + enumerable: true, + configurable: true }); - _this._mask = new egret.Shape(); - _this._mask.graphics.beginFill(0xffffff, 1); - _this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - _this._mask.graphics.endFill(); - _this._mask.filters = [_this._windEffect]; - SceneManager.stage.addChild(_this._mask); - return _this; - } - Object.defineProperty(WindTransition.prototype, "windSegments", { - set: function (value) { - this._windEffect.uniforms._windSegments = value; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(WindTransition.prototype, "size", { - set: function (value) { - this._windEffect.uniforms._size = value; - }, - enumerable: true, - configurable: true, - }); - WindTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.loadNextScene(); - return [ - 4, - this.tickEffectProgressProperty( - this._windEffect, - this.duration, - this.easeType - ), - ]; - case 1: - _a.sent(); - this.transitionComplete(); - SceneManager.stage.removeChild(this._mask); - return [2]; - } - }); + Object.defineProperty(WindTransition.prototype, "size", { + set: function (value) { + this._windEffect.uniforms._size = value; + }, + enumerable: true, + configurable: true }); - }; - return WindTransition; -})(SceneTransition); + WindTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.loadNextScene(); + return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)]; + case 1: + _a.sent(); + this.transitionComplete(); + SceneManager.stage.removeChild(this._mask); + return [2]; + } + }); + }); + }; + return WindTransition; +}(SceneTransition)); var BaseView = (function (_super) { - __extends(BaseView, _super); - function BaseView() { - return (_super !== null && _super.apply(this, arguments)) || this; - } - BaseView.prototype.init = function () {}; - BaseView.prototype.show = function (data) {}; - BaseView.prototype.refreshData = function (data) { - this._data = data; - }; - BaseView.prototype.refreshView = function () {}; - BaseView.prototype.close = function () {}; - BaseView.prototype.destroy = function () { - if (this.parent) { - this.parent.removeChild(this); - } - while (this.numChildren > 0) { - this.removeChildAt(0); + __extends(BaseView, _super); + function BaseView() { + return _super !== null && _super.apply(this, arguments) || this; } - }; - return BaseView; -})(egret.DisplayObjectContainer); + BaseView.prototype.init = function () { + }; + BaseView.prototype.show = function (data) { + }; + BaseView.prototype.refreshData = function (data) { + this._data = data; + }; + BaseView.prototype.refreshView = function () { + }; + BaseView.prototype.close = function () { + }; + BaseView.prototype.destroy = function () { + if (this.parent) { + this.parent.removeChild(this); + } + while (this.numChildren > 0) { + this.removeChildAt(0); + } + }; + return BaseView; +}(egret.DisplayObjectContainer)); var BaseFuiView = (function (_super) { - __extends(BaseFuiView, _super); - function BaseFuiView(name) { - var _this = _super.call(this) || this; - _this.name = name; - return _this; - } - return BaseFuiView; -})(BaseView); + __extends(BaseFuiView, _super); + function BaseFuiView(name) { + var _this = _super.call(this) || this; + _this.name = name; + return _this; + } + return BaseFuiView; +}(BaseView)); var BaseSingle = (function () { - function BaseSingle() {} - BaseSingle.getInstance = function () { - if (this._instance == null) { - this._instance = new this(); + function BaseSingle() { } - return this._instance; - }; - BaseSingle.prototype.clearFuiObj = function (obj) { - if (obj) { - egret.Tween.removeTweens(obj.displayObject); - if (obj.displayObject && obj.displayObject.parent) { - obj.displayObject.parent.removeChild(obj.displayObject); - } - obj.dispose(); - obj = null; - return true; - } - return false; - }; - return BaseSingle; -})(); + BaseSingle.getInstance = function () { + if (this._instance == null) { + this._instance = new this(); + } + return this._instance; + }; + BaseSingle.prototype.clearFuiObj = function (obj) { + if (obj) { + egret.Tween.removeTweens(obj.displayObject); + if (obj.displayObject && obj.displayObject.parent) { + obj.displayObject.parent.removeChild(obj.displayObject); + } + obj.dispose(); + obj = null; + return true; + } + return false; + }; + return BaseSingle; +}()); var ViewManager = (function (_super) { - __extends(ViewManager, _super); - function ViewManager() { - var _this = (_super !== null && _super.apply(this, arguments)) || this; - _this._openDic = []; - return _this; - } - ViewManager.prototype.refreshView = function (viewClass, data) { - var view = this.getView(viewClass); - if (view) { - view.refreshData(data); - view.refreshView(); - } - }; - ViewManager.prototype.openView = function (viewClass, data, complete) { - var newView = this.getView(viewClass); - if (!newView) { - newView = new viewClass(); - } - if (this.existView(viewClass)) { - newView.refreshData(data); - newView.refreshView(); - return; - } - this._openDic.push(newView); - }; - ViewManager.prototype.getView = function (viewClass) { - var result = this._openDic.firstOrDefault(function (a) { - return a instanceof viewClass; - }); - return result; - }; - ViewManager.prototype.existView = function (viewClass) { - return ( - this._openDic.findIndex(function (a) { - return a instanceof viewClass; - }) != -1 - ); - }; - return ViewManager; -})(BaseSingle); + __extends(ViewManager, _super); + function ViewManager() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._openDic = []; + return _this; + } + ViewManager.prototype.refreshView = function (viewClass, data) { + var view = this.getView(viewClass); + if (view) { + view.refreshData(data); + view.refreshView(); + } + }; + ViewManager.prototype.openView = function (viewClass, data, complete) { + var newView = this.getView(viewClass); + if (!newView) { + newView = new viewClass(); + } + if (this.existView(viewClass)) { + newView.refreshData(data); + newView.refreshView(); + return; + } + this._openDic.push(newView); + }; + ViewManager.prototype.getView = function (viewClass) { + var result = this._openDic.firstOrDefault(function (a) { + return a instanceof viewClass; + }); + return result; + }; + ViewManager.prototype.existView = function (viewClass) { + return this._openDic.findIndex(function (a) { + return a instanceof viewClass; + }) != -1; + }; + return ViewManager; +}(BaseSingle)); var Flags = (function () { - function Flags() {} - Flags.isFlagSet = function (self, flag) { - return (self & flag) != 0; - }; - Flags.isUnshiftedFlagSet = function (self, flag) { - flag = 1 << flag; - return (self & flag) != 0; - }; - Flags.setFlagExclusive = function (self, flag) { - return 1 << flag; - }; - Flags.setFlag = function (self, flag) { - return self | (1 << flag); - }; - Flags.unsetFlag = function (self, flag) { - flag = 1 << flag; - return self & ~flag; - }; - Flags.invertFlags = function (self) { - return ~self; - }; - return Flags; -})(); -var MathHelper = (function () { - function MathHelper() {} - MathHelper.toDegrees = function (radians) { - return radians * 57.295779513082320876798154814105; - }; - MathHelper.toRadians = function (degrees) { - return degrees * 0.017453292519943295769236907684886; - }; - MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { - return ( - rightMin + - ((value - leftMin) * (rightMax - rightMin)) / (leftMax - leftMin) - ); - }; - MathHelper.lerp = function (value1, value2, amount) { - return value1 + (value2 - value1) * amount; - }; - MathHelper.clamp = function (value, min, max) { - if (value < min) return min; - if (value > max) return max; - return value; - }; - MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { - var radians = MathHelper.toRadians(angleInDegrees); - return new Vector2( - Math.cos(radians) * radians + circleCenter.x, - Math.sin(radians) * radians + circleCenter.y - ); - }; - MathHelper.isEven = function (value) { - return value % 2 == 0; - }; - MathHelper.Epsilon = 0.00001; - MathHelper.Rad2Deg = 57.29578; - MathHelper.Deg2Rad = 0.0174532924; - return MathHelper; -})(); -var Matrix2D = (function () { - function Matrix2D(m11, m12, m21, m22, m31, m32) { - this.m11 = 0; - this.m12 = 0; - this.m21 = 0; - this.m22 = 0; - this.m31 = 0; - this.m32 = 0; - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; - } - Object.defineProperty(Matrix2D, "identity", { - get: function () { - return Matrix2D._identity; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "translation", { - get: function () { - return new Vector2(this.m31, this.m32); - }, - set: function (value) { - this.m31 = value.x; - this.m32 = value.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "rotation", { - get: function () { - return Math.atan2(this.m21, this.m11); - }, - set: function (value) { - var val1 = Math.cos(value); - var val2 = Math.sin(value); - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this.rotation); - }, - set: function (value) { - this.rotation = MathHelper.toRadians(value); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Matrix2D.prototype, "scale", { - get: function () { - return new Vector2(this.m11, this.m22); - }, - set: function (value) { - this.m11 = value.x; - this.m12 = value.y; - }, - enumerable: true, - configurable: true, - }); - Matrix2D.add = function (matrix1, matrix2) { - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; - return matrix1; - }; - Matrix2D.divide = function (matrix1, matrix2) { - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; - return matrix1; - }; - Matrix2D.multiply = function (matrix1, matrix2) { - var result = new Matrix2D(); - var m11 = matrix1.m11 * matrix2.m11 + matrix1.m12 * matrix2.m21; - var m12 = matrix1.m11 * matrix2.m12 + matrix1.m12 * matrix2.m22; - var m21 = matrix1.m21 * matrix2.m11 + matrix1.m22 * matrix2.m21; - var m22 = matrix1.m21 * matrix2.m12 + matrix1.m22 * matrix2.m22; - var m31 = - matrix1.m31 * matrix2.m11 + matrix1.m32 * matrix2.m21 + matrix2.m31; - var m32 = - matrix1.m31 * matrix2.m12 + matrix1.m32 * matrix2.m22 + matrix2.m32; - result.m11 = m11; - result.m12 = m12; - result.m21 = m21; - result.m22 = m22; - result.m31 = m31; - result.m32 = m32; - return result; - }; - Matrix2D.multiplyTranslation = function (matrix, x, y) { - var trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); - }; - Matrix2D.prototype.determinant = function () { - return this.m11 * this.m22 - this.m12 * this.m21; - }; - Matrix2D.invert = function (matrix, result) { - if (result === void 0) { - result = new Matrix2D(); + function Flags() { } - var det = 1 / matrix.determinant(); - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - return result; - }; - Matrix2D.createTranslation = function (xPosition, yPosition, result) { - result = result ? result : new Matrix2D(); - result.m11 = 1; - result.m12 = 0; - result.m21 = 0; - result.m22 = 1; - result.m31 = xPosition; - result.m32 = yPosition; - return result; - }; - Matrix2D.createRotation = function (radians, result) { - result = new Matrix2D(); - var val1 = Math.cos(radians); - var val2 = Math.sin(radians); - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - return result; - }; - Matrix2D.createScale = function (xScale, yScale, result) { - if (result === void 0) { - result = new Matrix2D(); + Flags.isFlagSet = function (self, flag) { + return (self & flag) != 0; + }; + Flags.isUnshiftedFlagSet = function (self, flag) { + flag = 1 << flag; + return (self & flag) != 0; + }; + Flags.setFlagExclusive = function (self, flag) { + return 1 << flag; + }; + Flags.setFlag = function (self, flag) { + return (self | 1 << flag); + }; + Flags.unsetFlag = function (self, flag) { + flag = 1 << flag; + return (self & (~flag)); + }; + Flags.invertFlags = function (self) { + return ~self; + }; + return Flags; +}()); +var MathHelper = (function () { + function MathHelper() { } - result.m11 = xScale; - result.m12 = 0; - result.m21 = 0; - result.m22 = yScale; - result.m31 = 0; - result.m32 = 0; - return result; - }; - Matrix2D.prototype.toEgretMatrix = function () { - var matrix = new egret.Matrix( - this.m11, - this.m12, - this.m21, - this.m22, - this.m31, - this.m32 - ); - return matrix; - }; - Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); - return Matrix2D; -})(); + MathHelper.toDegrees = function (radians) { + return radians * 57.295779513082320876798154814105; + }; + MathHelper.toRadians = function (degrees) { + return degrees * 0.017453292519943295769236907684886; + }; + MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { + return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); + }; + MathHelper.lerp = function (value1, value2, amount) { + return value1 + (value2 - value1) * amount; + }; + MathHelper.clamp = function (value, min, max) { + if (value < min) + return min; + if (value > max) + return max; + return value; + }; + MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { + var radians = MathHelper.toRadians(angleInDegrees); + return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); + }; + MathHelper.isEven = function (value) { + return value % 2 == 0; + }; + MathHelper.Epsilon = 0.00001; + MathHelper.Rad2Deg = 57.29578; + MathHelper.Deg2Rad = 0.0174532924; + return MathHelper; +}()); +var Matrix2D = (function () { + function Matrix2D(m11, m12, m21, m22, m31, m32) { + this.m11 = 0; + this.m12 = 0; + this.m21 = 0; + this.m22 = 0; + this.m31 = 0; + this.m32 = 0; + this.m11 = m11 ? m11 : 1; + this.m12 = m12 ? m12 : 0; + this.m21 = m21 ? m21 : 0; + this.m22 = m22 ? m22 : 1; + this.m31 = m31 ? m31 : 0; + this.m32 = m32 ? m32 : 0; + } + Object.defineProperty(Matrix2D, "identity", { + get: function () { + return Matrix2D._identity; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "translation", { + get: function () { + return new Vector2(this.m31, this.m32); + }, + set: function (value) { + this.m31 = value.x; + this.m32 = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotation", { + get: function () { + return Math.atan2(this.m21, this.m11); + }, + set: function (value) { + var val1 = Math.cos(value); + var val2 = Math.sin(value); + this.m11 = val1; + this.m12 = val2; + this.m21 = -val2; + this.m22 = val1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { + get: function () { + return MathHelper.toDegrees(this.rotation); + }, + set: function (value) { + this.rotation = MathHelper.toRadians(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "scale", { + get: function () { + return new Vector2(this.m11, this.m22); + }, + set: function (value) { + this.m11 = value.x; + this.m12 = value.y; + }, + enumerable: true, + configurable: true + }); + Matrix2D.add = function (matrix1, matrix2) { + matrix1.m11 += matrix2.m11; + matrix1.m12 += matrix2.m12; + matrix1.m21 += matrix2.m21; + matrix1.m22 += matrix2.m22; + matrix1.m31 += matrix2.m31; + matrix1.m32 += matrix2.m32; + return matrix1; + }; + Matrix2D.divide = function (matrix1, matrix2) { + matrix1.m11 /= matrix2.m11; + matrix1.m12 /= matrix2.m12; + matrix1.m21 /= matrix2.m21; + matrix1.m22 /= matrix2.m22; + matrix1.m31 /= matrix2.m31; + matrix1.m32 /= matrix2.m32; + return matrix1; + }; + Matrix2D.multiply = function (matrix1, matrix2) { + var result = new Matrix2D(); + var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); + var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); + var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); + var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); + var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; + var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; + result.m11 = m11; + result.m12 = m12; + result.m21 = m21; + result.m22 = m22; + result.m31 = m31; + result.m32 = m32; + return result; + }; + Matrix2D.multiplyTranslation = function (matrix, x, y) { + var trans = Matrix2D.createTranslation(x, y); + return Matrix2D.multiply(matrix, trans); + }; + Matrix2D.prototype.determinant = function () { + return this.m11 * this.m22 - this.m12 * this.m21; + }; + Matrix2D.invert = function (matrix, result) { + if (result === void 0) { result = new Matrix2D(); } + var det = 1 / matrix.determinant(); + result.m11 = matrix.m22 * det; + result.m12 = -matrix.m12 * det; + result.m21 = -matrix.m21 * det; + result.m22 = matrix.m11 * det; + result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; + result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; + return result; + }; + Matrix2D.createTranslation = function (xPosition, yPosition, result) { + result = result ? result : new Matrix2D(); + result.m11 = 1; + result.m12 = 0; + result.m21 = 0; + result.m22 = 1; + result.m31 = xPosition; + result.m32 = yPosition; + return result; + }; + Matrix2D.createRotation = function (radians, result) { + result = new Matrix2D(); + var val1 = Math.cos(radians); + var val2 = Math.sin(radians); + result.m11 = val1; + result.m12 = val2; + result.m21 = -val2; + result.m22 = val1; + return result; + }; + Matrix2D.createScale = function (xScale, yScale, result) { + if (result === void 0) { result = new Matrix2D(); } + result.m11 = xScale; + result.m12 = 0; + result.m21 = 0; + result.m22 = yScale; + result.m31 = 0; + result.m32 = 0; + return result; + }; + Matrix2D.prototype.toEgretMatrix = function () { + var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + }; + Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); + return Matrix2D; +}()); var Rectangle = (function () { - function Rectangle(x, y, width, height) { - this.x = x ? x : 0; - this.y = y ? y : 0; - this.width = width ? width : 0; - this.height = height ? height : 0; - } - Object.defineProperty(Rectangle.prototype, "left", { - get: function () { - return this.x; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "right", { - get: function () { - return this.x + this.width; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "top", { - get: function () { - return this.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "bottom", { - get: function () { - return this.y + this.height; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "center", { - get: function () { - return new Vector2(this.x + this.width / 2, this.y + this.height / 2); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "location", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (value) { - this.x = value.x; - this.y = value.y; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Rectangle.prototype, "size", { - get: function () { - return new Vector2(this.width, this.height); - }, - set: function (value) { - this.width = value.x; - this.height = value.y; - }, - enumerable: true, - configurable: true, - }); - Rectangle.prototype.intersects = function (value) { - return ( - value.left < this.right && - this.left < value.right && - value.top < this.bottom && - this.top < value.bottom - ); - }; - Rectangle.prototype.contains = function (value) { - return ( - this.x <= value.x && - value.x < this.x + this.width && - this.y <= value.y && - value.y < this.y + this.height - ); - }; - Rectangle.prototype.containsRect = function (value) { - return ( - this.x <= value.x && - value.x < this.x + this.width && - this.y <= value.y && - value.y < this.y + this.height - ); - }; - Rectangle.prototype.getHalfSize = function () { - return new Vector2(this.width * 0.5, this.height * 0.5); - }; - Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { - return new Rectangle(minX, minY, maxX - minX, maxY - minY); - }; - Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function ( - point - ) { - var edgeNormal = new Vector2(0, 0); - var res = new Vector2(0, 0); - res.x = MathHelper.clamp(point.x, this.left, this.right); - res.y = MathHelper.clamp(point.y, this.top, this.bottom); - if (this.contains(res)) { - var dl = res.x - this.left; - var dr = this.right - res.x; - var dt = res.y - this.top; - var db = this.bottom - res.y; - var min = Math.min(dl, dr, dt, db); - if (min == dt) { - res.y = this.top; - edgeNormal.y = -1; - } else if (min == db) { - res.y = this.bottom; - edgeNormal.y = 1; - } else if (min == dl) { - res.x = this.left; - edgeNormal.x = -1; - } else { - res.x = this.right; - edgeNormal.x = 1; - } - } else { - if (res.x == this.left) { - edgeNormal.x = -1; - } - if (res.x == this.right) { - edgeNormal.x = 1; - } - if (res.y == this.top) { - edgeNormal.y = -1; - } - if (res.y == this.bottom) { - edgeNormal.y = 1; - } - } - return { res: res, edgeNormal: edgeNormal }; - }; - Rectangle.prototype.calculateBounds = function ( - parentPosition, - position, - origin, - scale, - rotation, - width, - height - ) { - if (rotation == 0) { - this.x = parentPosition.x + position.x - origin.x * scale.x; - this.y = parentPosition.y + position.y - origin.y * scale.y; - this.width = width * scale.x; - this.height = height * scale.y; - } else { - var worldPosX = parentPosition.x + position.x; - var worldPosY = parentPosition.y + position.y; - this._transformMat = Matrix2D.createTranslation( - -worldPosX - origin.x, - -worldPosY - origin.y - ); - this._tempMat = Matrix2D.createScale(scale.x, scale.y); - this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); - this._tempMat = Matrix2D.createRotation(rotation); - this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); - this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY); - this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); - var topLeft = new Vector2(worldPosX, worldPosY); - var topRight = new Vector2(worldPosX + width, worldPosY); - var bottomLeft = new Vector2(worldPosX, worldPosY + height); - var bottomRight = new Vector2(worldPosX + width, worldPosY + height); - topLeft = Vector2Ext.transformR(topLeft, this._transformMat); - topRight = Vector2Ext.transformR(topRight, this._transformMat); - bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat); - bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat); - var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); - var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); - var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); - var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); - this.location = new Vector2(minX, minY); - this.width = maxX - minX; - this.height = maxY - minY; - } - }; - Rectangle.rectEncompassingPoints = function (points) { - var minX = Number.POSITIVE_INFINITY; - var minY = Number.POSITIVE_INFINITY; - var maxX = Number.NEGATIVE_INFINITY; - var maxY = Number.NEGATIVE_INFINITY; - for (var i = 0; i < points.length; i++) { - var pt = points[i]; - if (pt.x < minX) { - minX = pt.x; - } - if (pt.x > maxX) { - maxX = pt.x; - } - if (pt.y < minY) { - minY = pt.y; - } - if (pt.y > maxY) { - maxY = pt.y; - } - } - return this.fromMinMax(minX, minY, maxX, maxY); - }; - return Rectangle; -})(); + function Rectangle(x, y, width, height) { + this.x = x ? x : 0; + this.y = y ? y : 0; + this.width = width ? width : 0; + this.height = height ? height : 0; + } + Object.defineProperty(Rectangle.prototype, "left", { + get: function () { + return this.x; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "right", { + get: function () { + return this.x + this.width; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "top", { + get: function () { + return this.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "bottom", { + get: function () { + return this.y + this.height; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "center", { + get: function () { + return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "location", { + get: function () { + return new Vector2(this.x, this.y); + }, + set: function (value) { + this.x = value.x; + this.y = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "size", { + get: function () { + return new Vector2(this.width, this.height); + }, + set: function (value) { + this.width = value.x; + this.height = value.y; + }, + enumerable: true, + configurable: true + }); + Rectangle.prototype.intersects = function (value) { + return value.left < this.right && + this.left < value.right && + value.top < this.bottom && + this.top < value.bottom; + }; + Rectangle.prototype.contains = function (value) { + return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && + (this.y <= value.y)) && + (value.y < (this.y + this.height))); + }; + Rectangle.prototype.containsRect = function (value) { + return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && + (this.y <= value.y)) && + (value.y < (this.y + this.height))); + }; + Rectangle.prototype.getHalfSize = function () { + return new Vector2(this.width * 0.5, this.height * 0.5); + }; + Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { + return new Rectangle(minX, minY, maxX - minX, maxY - minY); + }; + Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { + var edgeNormal = new Vector2(0, 0); + var res = new Vector2(0, 0); + res.x = MathHelper.clamp(point.x, this.left, this.right); + res.y = MathHelper.clamp(point.y, this.top, this.bottom); + if (this.contains(res)) { + var dl = res.x - this.left; + var dr = this.right - res.x; + var dt = res.y - this.top; + var db = this.bottom - res.y; + var min = Math.min(dl, dr, dt, db); + if (min == dt) { + res.y = this.top; + edgeNormal.y = -1; + } + else if (min == db) { + res.y = this.bottom; + edgeNormal.y = 1; + } + else if (min == dl) { + res.x = this.left; + edgeNormal.x = -1; + } + else { + res.x = this.right; + edgeNormal.x = 1; + } + } + else { + if (res.x == this.left) { + edgeNormal.x = -1; + } + if (res.x == this.right) { + edgeNormal.x = 1; + } + if (res.y == this.top) { + edgeNormal.y = -1; + } + if (res.y == this.bottom) { + edgeNormal.y = 1; + } + } + return { res: res, edgeNormal: edgeNormal }; + }; + Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) { + if (rotation == 0) { + this.x = parentPosition.x + position.x - origin.x * scale.x; + this.y = parentPosition.y + position.y - origin.y * scale.y; + this.width = width * scale.x; + this.height = height * scale.y; + } + else { + var worldPosX = parentPosition.x + position.x; + var worldPosY = parentPosition.y + position.y; + this._transformMat = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y); + this._tempMat = Matrix2D.createScale(scale.x, scale.y); + this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); + this._tempMat = Matrix2D.createRotation(rotation); + this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); + this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY); + this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat); + var topLeft = new Vector2(worldPosX, worldPosY); + var topRight = new Vector2(worldPosX + width, worldPosY); + var bottomLeft = new Vector2(worldPosX, worldPosY + height); + var bottomRight = new Vector2(worldPosX + width, worldPosY + height); + topLeft = Vector2Ext.transformR(topLeft, this._transformMat); + topRight = Vector2Ext.transformR(topRight, this._transformMat); + bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat); + bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat); + var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + this.location = new Vector2(minX, minY); + this.width = maxX - minX; + this.height = maxY - minY; + } + }; + Rectangle.rectEncompassingPoints = function (points) { + var minX = Number.POSITIVE_INFINITY; + var minY = Number.POSITIVE_INFINITY; + var maxX = Number.NEGATIVE_INFINITY; + var maxY = Number.NEGATIVE_INFINITY; + for (var i = 0; i < points.length; i++) { + var pt = points[i]; + if (pt.x < minX) { + minX = pt.x; + } + if (pt.x > maxX) { + maxX = pt.x; + } + if (pt.y < minY) { + minY = pt.y; + } + if (pt.y > maxY) { + maxY = pt.y; + } + } + return this.fromMinMax(minX, minY, maxX, maxY); + }; + return Rectangle; +}()); var Vector2 = (function () { - function Vector2(x, y) { - this.x = 0; - this.y = 0; - this.x = x ? x : 0; - this.y = y ? y : this.x; - } - Object.defineProperty(Vector2, "zero", { - get: function () { - return Vector2.zeroVector2; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Vector2, "one", { - get: function () { - return Vector2.unitVector2; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Vector2, "unitX", { - get: function () { - return Vector2.unitXVector; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Vector2, "unitY", { - get: function () { - return Vector2.unitYVector; - }, - enumerable: true, - configurable: true, - }); - Vector2.add = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x + value2.x; - result.y = value1.y + value2.y; - return result; - }; - Vector2.divide = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x / value2.x; - result.y = value1.y / value2.y; - return result; - }; - Vector2.multiply = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - }; - Vector2.subtract = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - }; - Vector2.prototype.normalize = function () { - var val = 1 / Math.sqrt(this.x * this.x + this.y * this.y); - this.x *= val; - this.y *= val; - }; - Vector2.prototype.length = function () { - return Math.sqrt(this.x * this.x + this.y * this.y); - }; - Vector2.prototype.round = function () { - return new Vector2(Math.round(this.x), Math.round(this.y)); - }; - Vector2.normalize = function (value) { - var val = 1 / Math.sqrt(value.x * value.x + value.y * value.y); - value.x *= val; - value.y *= val; - return value; - }; - Vector2.dot = function (value1, value2) { - return value1.x * value2.x + value1.y * value2.y; - }; - Vector2.distanceSquared = function (value1, value2) { - var v1 = value1.x - value2.x, - v2 = value1.y - value2.y; - return v1 * v1 + v2 * v2; - }; - Vector2.clamp = function (value1, min, max) { - return new Vector2( - MathHelper.clamp(value1.x, min.x, max.x), - MathHelper.clamp(value1.y, min.y, max.y) - ); - }; - Vector2.lerp = function (value1, value2, amount) { - return new Vector2( - MathHelper.lerp(value1.x, value2.x, amount), - MathHelper.lerp(value1.y, value2.y, amount) - ); - }; - Vector2.transform = function (position, matrix) { - return new Vector2( - position.x * matrix.m11 + position.y * matrix.m21, - position.x * matrix.m12 + position.y * matrix.m22 - ); - }; - Vector2.distance = function (value1, value2) { - var v1 = value1.x - value2.x, - v2 = value1.y - value2.y; - return Math.sqrt(v1 * v1 + v2 * v2); - }; - Vector2.negate = function (value) { - var result = new Vector2(); - result.x = -value.x; - result.y = -value.y; - return result; - }; - Vector2.unitYVector = new Vector2(0, 1); - Vector2.unitXVector = new Vector2(1, 0); - Vector2.unitVector2 = new Vector2(1, 1); - Vector2.zeroVector2 = new Vector2(0, 0); - return Vector2; -})(); + function Vector2(x, y) { + this.x = 0; + this.y = 0; + this.x = x ? x : 0; + this.y = y ? y : this.x; + } + Object.defineProperty(Vector2, "zero", { + get: function () { + return Vector2.zeroVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "one", { + get: function () { + return Vector2.unitVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitX", { + get: function () { + return Vector2.unitXVector; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitY", { + get: function () { + return Vector2.unitYVector; + }, + enumerable: true, + configurable: true + }); + Vector2.add = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x + value2.x; + result.y = value1.y + value2.y; + return result; + }; + Vector2.divide = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x / value2.x; + result.y = value1.y / value2.y; + return result; + }; + Vector2.multiply = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x * value2.x; + result.y = value1.y * value2.y; + return result; + }; + Vector2.subtract = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x - value2.x; + result.y = value1.y - value2.y; + return result; + }; + Vector2.prototype.normalize = function () { + var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); + this.x *= val; + this.y *= val; + }; + Vector2.prototype.length = function () { + return Math.sqrt((this.x * this.x) + (this.y * this.y)); + }; + Vector2.prototype.round = function () { + return new Vector2(Math.round(this.x), Math.round(this.y)); + }; + Vector2.normalize = function (value) { + var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); + value.x *= val; + value.y *= val; + return value; + }; + Vector2.dot = function (value1, value2) { + return (value1.x * value2.x) + (value1.y * value2.y); + }; + Vector2.distanceSquared = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return (v1 * v1) + (v2 * v2); + }; + Vector2.clamp = function (value1, min, max) { + return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y)); + }; + Vector2.lerp = function (value1, value2, amount) { + return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount)); + }; + Vector2.transform = function (position, matrix) { + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + }; + Vector2.distance = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return Math.sqrt((v1 * v1) + (v2 * v2)); + }; + Vector2.negate = function (value) { + var result = new Vector2(); + result.x = -value.x; + result.y = -value.y; + return result; + }; + Vector2.unitYVector = new Vector2(0, 1); + Vector2.unitXVector = new Vector2(1, 0); + Vector2.unitVector2 = new Vector2(1, 1); + Vector2.zeroVector2 = new Vector2(0, 0); + return Vector2; +}()); var Vector3 = (function () { - function Vector3(x, y, z) { - this.x = x; - this.y = y; - this.z = z; - } - return Vector3; -})(); -var ColliderTriggerHelper = (function () { - function ColliderTriggerHelper(entity) { - this._activeTriggerIntersections = []; - this._previousTriggerIntersections = []; - this._tempTriggerList = []; - this._entity = entity; - } - ColliderTriggerHelper.prototype.update = function () { - var colliders = this._entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - var neighbors = Physics.boxcastBroadphase( - collider.bounds, - collider.collidesWithLayers - ); - var _loop_5 = function (j) { - var neighbor = neighbors[j]; - if (!collider.isTrigger && !neighbor.isTrigger) return "continue"; - if (collider.overlaps(neighbor)) { - var pair_1 = new Pair(collider, neighbor); - var shouldReportTriggerEvent = - this_1._activeTriggerIntersections.findIndex(function (value) { - return ( - value.first == pair_1.first && value.second == pair_1.second - ); - }) == -1 && - this_1._previousTriggerIntersections.findIndex(function (value) { - return ( - value.first == pair_1.first && value.second == pair_1.second - ); - }) == -1; - if (shouldReportTriggerEvent) - this_1.notifyTriggerListeners(pair_1, true); - if (!this_1._activeTriggerIntersections.contains(pair_1)) - this_1._activeTriggerIntersections.push(pair_1); - } - }; - var this_1 = this; - for (var j = 0; j < neighbors.length; j++) { - _loop_5(j); - } + function Vector3(x, y, z) { + this.x = x; + this.y = y; + this.z = z; } - ListPool.free(colliders); - this.checkForExitedColliders(); - }; - ColliderTriggerHelper.prototype.checkForExitedColliders = function () { - var _this = this; - var _loop_6 = function (i) { - var index = this_2._previousTriggerIntersections.findIndex(function ( - value - ) { - if ( - value.first == _this._activeTriggerIntersections[i].first && - value.second == _this._activeTriggerIntersections[i].second - ) - return true; - return false; - }); - if (index != -1) this_2._previousTriggerIntersections.removeAt(index); + return Vector3; +}()); +var ColliderTriggerHelper = (function () { + function ColliderTriggerHelper(entity) { + this._activeTriggerIntersections = []; + this._previousTriggerIntersections = []; + this._tempTriggerList = []; + this._entity = entity; + } + ColliderTriggerHelper.prototype.update = function () { + var colliders = this._entity.getComponents(Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + var neighbors = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); + var _loop_5 = function (j) { + var neighbor = neighbors[j]; + if (!collider.isTrigger && !neighbor.isTrigger) + return "continue"; + if (collider.overlaps(neighbor)) { + var pair_1 = new Pair(collider, neighbor); + var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1; + if (shouldReportTriggerEvent) + this_1.notifyTriggerListeners(pair_1, true); + if (!this_1._activeTriggerIntersections.contains(pair_1)) + this_1._activeTriggerIntersections.push(pair_1); + } + }; + var this_1 = this; + for (var j = 0; j < neighbors.length; j++) { + _loop_5(j); + } + } + ListPool.free(colliders); + this.checkForExitedColliders(); }; - var this_2 = this; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - _loop_6(i); - } - for (var i = 0; i < this._previousTriggerIntersections.length; i++) { - this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); - } - this._previousTriggerIntersections.length = 0; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - if ( - !this._previousTriggerIntersections.contains( - this._activeTriggerIntersections[i] - ) - ) { - this._previousTriggerIntersections.push( - this._activeTriggerIntersections[i] - ); - } - } - this._activeTriggerIntersections.length = 0; - }; - ColliderTriggerHelper.prototype.notifyTriggerListeners = function ( - collisionPair, - isEntering - ) { - collisionPair.first.entity.getComponents( - "ITriggerListener", - this._tempTriggerList - ); - for (var i = 0; i < this._tempTriggerList.length; i++) { - if (isEntering) { - this._tempTriggerList[i].onTriggerEnter( - collisionPair.second, - collisionPair.first - ); - } else { - this._tempTriggerList[i].onTriggerExit( - collisionPair.second, - collisionPair.first - ); - } - this._tempTriggerList.length = 0; - if (collisionPair.second.entity) { - collisionPair.second.entity.getComponents( - "ITriggerListener", - this._tempTriggerList - ); - for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { - if (isEntering) { - this._tempTriggerList[i_2].onTriggerEnter( - collisionPair.first, - collisionPair.second - ); - } else { - this._tempTriggerList[i_2].onTriggerExit( - collisionPair.first, - collisionPair.second - ); - } - } - this._tempTriggerList.length = 0; - } - } - }; - return ColliderTriggerHelper; -})(); + ColliderTriggerHelper.prototype.checkForExitedColliders = function () { + var _this = this; + var _loop_6 = function (i) { + var index = this_2._previousTriggerIntersections.findIndex(function (value) { + if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second) + return true; + return false; + }); + if (index != -1) + this_2._previousTriggerIntersections.removeAt(index); + }; + var this_2 = this; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + _loop_6(i); + } + for (var i = 0; i < this._previousTriggerIntersections.length; i++) { + this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); + } + this._previousTriggerIntersections.length = 0; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) { + this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); + } + } + this._activeTriggerIntersections.length = 0; + }; + ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) { + collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + if (isEntering) { + this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); + } + else { + this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); + } + this._tempTriggerList.length = 0; + if (collisionPair.second.entity) { + collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { + if (isEntering) { + this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second); + } + else { + this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second); + } + } + this._tempTriggerList.length = 0; + } + } + }; + return ColliderTriggerHelper; +}()); var PointSectors; (function (PointSectors) { - PointSectors[(PointSectors["center"] = 0)] = "center"; - PointSectors[(PointSectors["top"] = 1)] = "top"; - PointSectors[(PointSectors["bottom"] = 2)] = "bottom"; - PointSectors[(PointSectors["topLeft"] = 9)] = "topLeft"; - PointSectors[(PointSectors["topRight"] = 5)] = "topRight"; - PointSectors[(PointSectors["left"] = 8)] = "left"; - PointSectors[(PointSectors["right"] = 4)] = "right"; - PointSectors[(PointSectors["bottomLeft"] = 10)] = "bottomLeft"; - PointSectors[(PointSectors["bottomRight"] = 6)] = "bottomRight"; + PointSectors[PointSectors["center"] = 0] = "center"; + PointSectors[PointSectors["top"] = 1] = "top"; + PointSectors[PointSectors["bottom"] = 2] = "bottom"; + PointSectors[PointSectors["topLeft"] = 9] = "topLeft"; + PointSectors[PointSectors["topRight"] = 5] = "topRight"; + PointSectors[PointSectors["left"] = 8] = "left"; + PointSectors[PointSectors["right"] = 4] = "right"; + PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft"; + PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight"; })(PointSectors || (PointSectors = {})); var Collisions = (function () { - function Collisions() {} - Collisions.isLineToLine = function (a1, a2, b1, b2) { - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) return false; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) return false; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) return false; - return true; - }; - Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { - var intersection = new Vector2(0, 0); - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) return intersection; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) return intersection; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) return intersection; - intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); - return intersection; - }; - Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); - }; - Collisions.isCircleToCircle = function ( - circleCenter1, - circleRadius1, - circleCenter2, - circleRadius2 - ) { - return ( - Vector2.distanceSquared(circleCenter1, circleCenter2) < - (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2) - ); - }; - Collisions.isCircleToLine = function ( - circleCenter, - radius, - lineFrom, - lineTo - ) { - return ( - Vector2.distanceSquared( - circleCenter, - this.closestPointOnLine(lineFrom, lineTo, circleCenter) - ) < - radius * radius - ); - }; - Collisions.isCircleToPoint = function (circleCenter, radius, point) { - return Vector2.distanceSquared(circleCenter, point) < radius * radius; - }; - Collisions.isRectToCircle = function (rect, cPosition, cRadius) { - var ew = rect.width * 0.5; - var eh = rect.height * 0.5; - var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); - var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); - return vx * vx + vy * vy < cRadius * cRadius; - }; - Collisions.isRectToLine = function (rect, lineFrom, lineTo) { - var fromSector = this.getSector( - rect.x, - rect.y, - rect.width, - rect.height, - lineFrom - ); - var toSector = this.getSector( - rect.x, - rect.y, - rect.width, - rect.height, - lineTo - ); - if (fromSector == PointSectors.center || toSector == PointSectors.center) { - return true; - } else if ((fromSector & toSector) != 0) { - return false; - } else { - var both = fromSector | toSector; - var edgeFrom = void 0; - var edgeTo = void 0; - if ((both & PointSectors.top) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - if ((both & PointSectors.bottom) != 0) { - edgeFrom = new Vector2(rect.x, rect.y + rect.height); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - if ((both & PointSectors.left) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - if ((both & PointSectors.right) != 0) { - edgeFrom = new Vector2(rect.x + rect.width, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) return true; - } - } - return false; - }; - Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { - return ( - point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH - ); - }; - Collisions.getSector = function (rX, rY, rW, rH, point) { - var sector = PointSectors.center; - if (point.x < rX) sector |= PointSectors.left; - else if (point.x >= rX + rW) sector |= PointSectors.right; - if (point.y < rY) sector |= PointSectors.top; - else if (point.y >= rY + rH) sector |= PointSectors.bottom; - return sector; - }; - return Collisions; -})(); -var Physics = (function () { - function Physics() {} - Physics.reset = function () { - this._spatialHash = new SpatialHash(this.spatialHashCellSize); - }; - Physics.clear = function () { - this._spatialHash.clear(); - }; - Physics.overlapCircleAll = function (center, randius, results, layerMask) { - if (layerMask === void 0) { - layerMask = -1; - } - return this._spatialHash.overlapCircle(center, randius, results, layerMask); - }; - Physics.boxcastBroadphase = function (rect, layerMask) { - if (layerMask === void 0) { - layerMask = this.allLayers; - } - return this._spatialHash.aabbBroadphase(rect, null, layerMask); - }; - Physics.boxcastBroadphaseExcludingSelf = function ( - collider, - rect, - layerMask - ) { - if (layerMask === void 0) { - layerMask = this.allLayers; - } - return this._spatialHash.aabbBroadphase(rect, collider, layerMask); - }; - Physics.addCollider = function (collider) { - Physics._spatialHash.register(collider); - }; - Physics.removeCollider = function (collider) { - Physics._spatialHash.remove(collider); - }; - Physics.updateCollider = function (collider) { - this._spatialHash.remove(collider); - this._spatialHash.register(collider); - }; - Physics.spatialHashCellSize = 100; - Physics.allLayers = -1; - return Physics; -})(); -var Shape = (function () { - function Shape() {} - return Shape; -})(); -var Polygon = (function (_super) { - __extends(Polygon, _super); - function Polygon(points, isBox) { - var _this = _super.call(this) || this; - _this.isUnrotated = true; - _this._areEdgeNormalsDirty = true; - _this.setPoints(points); - _this.isBox = isBox; - return _this; - } - Object.defineProperty(Polygon.prototype, "edgeNormals", { - get: function () { - if (this._areEdgeNormalsDirty) this.buildEdgeNormals(); - return this._edgeNormals; - }, - enumerable: true, - configurable: true, - }); - Polygon.prototype.buildEdgeNormals = function () { - var totalEdges = this.isBox ? 2 : this.points.length; - if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) - this._edgeNormals = new Array(totalEdges); - var p2; - for (var i = 0; i < totalEdges; i++) { - var p1 = this.points[i]; - if (i + 1 >= this.points.length) p2 = this.points[0]; - else p2 = this.points[i + 1]; - var perp = Vector2Ext.perpendicular(p1, p2); - perp = Vector2.normalize(perp); - this._edgeNormals[i] = perp; - } - }; - Polygon.prototype.setPoints = function (points) { - this.points = points; - this.recalculateCenterAndEdgeNormals(); - this._originalPoints = []; - for (var i = 0; i < this.points.length; i++) { - this._originalPoints.push(this.points[i]); - } - }; - Polygon.prototype.collidesWithShape = function (other) { - var result = new CollisionResult(); - if (other instanceof Polygon) { - return ShapeCollisions.polygonToPolygon(this, other); - } - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); - return result; - } - return null; - } - throw new Error("overlaps of Polygon to " + other + " are not supported"); - }; - Polygon.prototype.recalculateCenterAndEdgeNormals = function () { - this._polygonCenter = Polygon.findPolygonCenter(this.points); - this._areEdgeNormalsDirty = true; - }; - Polygon.prototype.overlaps = function (other) { - var result; - if (other instanceof Polygon) - return ShapeCollisions.polygonToPolygon(this, other); - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); + function Collisions() { + } + Collisions.isLineToLine = function (a1, a2, b1, b2) { + var b = Vector2.subtract(a2, a1); + var d = Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return false; + var c = Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return false; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return false; return true; - } - return false; - } - throw new Error("overlaps of Pologon to " + other + " are not supported"); - }; - Polygon.findPolygonCenter = function (points) { - var x = 0, - y = 0; - for (var i = 0; i < points.length; i++) { - x += points[i].x; - y += points[i].y; - } - return new Vector2(x / points.length, y / points.length); - }; - Polygon.getClosestPointOnPolygonToPoint = function (points, point) { - var distanceSquared = Number.MAX_VALUE; - var edgeNormal = new Vector2(0, 0); - var closestPoint = new Vector2(0, 0); - var tempDistanceSquared; - for (var i = 0; i < points.length; i++) { - var j = i + 1; - if (j == points.length) j = 0; - var closest = ShapeCollisions.closestPointOnLine( - points[i], - points[j], - point - ); - tempDistanceSquared = Vector2.distanceSquared(point, closest); - if (tempDistanceSquared < distanceSquared) { - distanceSquared = tempDistanceSquared; - closestPoint = closest; - var line = Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; - } - } - edgeNormal = Vector2.normalize(edgeNormal); - return { - closestPoint: closestPoint, - distanceSquared: distanceSquared, - edgeNormal: edgeNormal, - }; - }; - Polygon.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToPoly(point, this); - }; - Polygon.prototype.containsPoint = function (point) { - point = Vector2.subtract(point, this.position); - var isInside = false; - for ( - var i = 0, j = this.points.length - 1; - i < this.points.length; - j = i++ - ) { - if ( - this.points[i].y > point.y != this.points[j].y > point.y && - point.x < - ((this.points[j].x - this.points[i].x) * - (point.y - this.points[i].y)) / - (this.points[j].y - this.points[i].y) + - this.points[i].x - ) { - isInside = !isInside; - } - } - return isInside; - }; - Polygon.buildSymmertricalPolygon = function (vertCount, radius) { - var verts = new Array(vertCount); - for (var i = 0; i < vertCount; i++) { - var a = 2 * Math.PI * (i / vertCount); - verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); + }; + Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { + var intersection = new Vector2(0, 0); + var b = Vector2.subtract(a2, a1); + var d = Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return intersection; + var c = Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return intersection; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return intersection; + intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); + return intersection; + }; + Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = Vector2.subtract(lineB, lineA); + var w = Vector2.subtract(closestTo, lineA); + var t = Vector2.dot(w, v) / Vector2.dot(v, v); + t = MathHelper.clamp(t, 0, 1); + return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); + }; + Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) { + return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); + }; + Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) { + return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; + }; + Collisions.isCircleToPoint = function (circleCenter, radius, point) { + return Vector2.distanceSquared(circleCenter, point) < radius * radius; + }; + Collisions.isRectToCircle = function (rect, cPosition, cRadius) { + var ew = rect.width * 0.5; + var eh = rect.height * 0.5; + var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); + var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); + return vx * vx + vy * vy < cRadius * cRadius; + }; + Collisions.isRectToLine = function (rect, lineFrom, lineTo) { + var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); + var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); + if (fromSector == PointSectors.center || toSector == PointSectors.center) { + return true; + } + else if ((fromSector & toSector) != 0) { + return false; + } + else { + var both = fromSector | toSector; + var edgeFrom = void 0; + var edgeTo = void 0; + if ((both & PointSectors.top) != 0) { + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x + rect.width, rect.y); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.bottom) != 0) { + edgeFrom = new Vector2(rect.x, rect.y + rect.height); + edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.left) != 0) { + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.right) != 0) { + edgeFrom = new Vector2(rect.x + rect.width, rect.y); + edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + } + return false; + }; + Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { + return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; + }; + Collisions.getSector = function (rX, rY, rW, rH, point) { + var sector = PointSectors.center; + if (point.x < rX) + sector |= PointSectors.left; + else if (point.x >= rX + rW) + sector |= PointSectors.right; + if (point.y < rY) + sector |= PointSectors.top; + else if (point.y >= rY + rH) + sector |= PointSectors.bottom; + return sector; + }; + return Collisions; +}()); +var Physics = (function () { + function Physics() { } - return verts; - }; - Polygon.prototype.recalculateBounds = function (collider) { - this.center = collider.localOffset; - if (collider.shouldColliderScaleAndRotationWithTransform) { - var hasUnitScale = true; - var tempMat = void 0; - var combinedMatrix = Matrix2D.createTranslation( - -this._polygonCenter.x, - -this._polygonCenter.y - ); - if (collider.entity.scale != Vector2.one) { - tempMat = Matrix2D.createScale( - collider.entity.scale.x, - collider.entity.scale.y - ); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - hasUnitScale = false; - var scaledOffset = Vector2.multiply( - collider.localOffset, - collider.entity.scale - ); - this.center = scaledOffset; - } - if (collider.entity.rotation != 0) { - tempMat = Matrix2D.createRotation(collider.entity.rotation); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - var offsetAngle = - Math.atan2(collider.localOffset.y, collider.localOffset.x) * - MathHelper.Rad2Deg; - var offsetLength = hasUnitScale - ? collider._localOffsetLength - : Vector2.multiply( - collider.localOffset, - collider.entity.scale - ).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - offsetLength, - MathHelper.toDegrees(collider.entity.rotation) + offsetAngle - ); - } - tempMat = Matrix2D.createTranslation( - this._polygonCenter.x, - this._polygonCenter.y - ); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.rotation == 0; - if (collider._isRotationDirty) this._areEdgeNormalsDirty = true; + Physics.reset = function () { + this._spatialHash = new SpatialHash(this.spatialHashCellSize); + }; + Physics.clear = function () { + this._spatialHash.clear(); + }; + Physics.overlapCircleAll = function (center, randius, results, layerMask) { + if (layerMask === void 0) { layerMask = -1; } + return this._spatialHash.overlapCircle(center, randius, results, layerMask); + }; + Physics.boxcastBroadphase = function (rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + return this._spatialHash.aabbBroadphase(rect, null, layerMask); + }; + Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + return this._spatialHash.aabbBroadphase(rect, collider, layerMask); + }; + Physics.addCollider = function (collider) { + Physics._spatialHash.register(collider); + }; + Physics.removeCollider = function (collider) { + Physics._spatialHash.remove(collider); + }; + Physics.updateCollider = function (collider) { + this._spatialHash.remove(collider); + this._spatialHash.register(collider); + }; + Physics.spatialHashCellSize = 100; + Physics.allLayers = -1; + return Physics; +}()); +var Shape = (function () { + function Shape() { } - this.position = Vector2.add(collider.entity.position, this.center); - this.bounds = Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = Vector2.add(this.bounds.location, this.position); - }; - return Polygon; -})(Shape); + return Shape; +}()); +var Polygon = (function (_super) { + __extends(Polygon, _super); + function Polygon(points, isBox) { + var _this = _super.call(this) || this; + _this.isUnrotated = true; + _this._areEdgeNormalsDirty = true; + _this.setPoints(points); + _this.isBox = isBox; + return _this; + } + Object.defineProperty(Polygon.prototype, "edgeNormals", { + get: function () { + if (this._areEdgeNormalsDirty) + this.buildEdgeNormals(); + return this._edgeNormals; + }, + enumerable: true, + configurable: true + }); + Polygon.prototype.buildEdgeNormals = function () { + var totalEdges = this.isBox ? 2 : this.points.length; + if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) + this._edgeNormals = new Array(totalEdges); + var p2; + for (var i = 0; i < totalEdges; i++) { + var p1 = this.points[i]; + if (i + 1 >= this.points.length) + p2 = this.points[0]; + else + p2 = this.points[i + 1]; + var perp = Vector2Ext.perpendicular(p1, p2); + perp = Vector2.normalize(perp); + this._edgeNormals[i] = perp; + } + }; + Polygon.prototype.setPoints = function (points) { + this.points = points; + this.recalculateCenterAndEdgeNormals(); + this._originalPoints = []; + for (var i = 0; i < this.points.length; i++) { + this._originalPoints.push(this.points[i]); + } + }; + Polygon.prototype.collidesWithShape = function (other) { + var result = new CollisionResult(); + if (other instanceof Polygon) { + return ShapeCollisions.polygonToPolygon(this, other); + } + if (other instanceof Circle) { + result = ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return result; + } + return null; + } + throw new Error("overlaps of Polygon to " + other + " are not supported"); + }; + Polygon.prototype.recalculateCenterAndEdgeNormals = function () { + this._polygonCenter = Polygon.findPolygonCenter(this.points); + this._areEdgeNormalsDirty = true; + }; + Polygon.prototype.overlaps = function (other) { + var result; + if (other instanceof Polygon) + return ShapeCollisions.polygonToPolygon(this, other); + if (other instanceof Circle) { + result = ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return true; + } + return false; + } + throw new Error("overlaps of Pologon to " + other + " are not supported"); + }; + Polygon.findPolygonCenter = function (points) { + var x = 0, y = 0; + for (var i = 0; i < points.length; i++) { + x += points[i].x; + y += points[i].y; + } + return new Vector2(x / points.length, y / points.length); + }; + Polygon.getClosestPointOnPolygonToPoint = function (points, point) { + var distanceSquared = Number.MAX_VALUE; + var edgeNormal = new Vector2(0, 0); + var closestPoint = new Vector2(0, 0); + var tempDistanceSquared; + for (var i = 0; i < points.length; i++) { + var j = i + 1; + if (j == points.length) + j = 0; + var closest = ShapeCollisions.closestPointOnLine(points[i], points[j], point); + tempDistanceSquared = Vector2.distanceSquared(point, closest); + if (tempDistanceSquared < distanceSquared) { + distanceSquared = tempDistanceSquared; + closestPoint = closest; + var line = Vector2.subtract(points[j], points[i]); + edgeNormal.x = -line.y; + edgeNormal.y = line.x; + } + } + edgeNormal = Vector2.normalize(edgeNormal); + return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + }; + Polygon.prototype.pointCollidesWithShape = function (point) { + return ShapeCollisions.pointToPoly(point, this); + }; + Polygon.prototype.containsPoint = function (point) { + point = Vector2.subtract(point, this.position); + var isInside = false; + for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { + if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && + (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + + this.points[i].x)) { + isInside = !isInside; + } + } + return isInside; + }; + Polygon.buildSymmertricalPolygon = function (vertCount, radius) { + var verts = new Array(vertCount); + for (var i = 0; i < vertCount; i++) { + var a = 2 * Math.PI * (i / vertCount); + verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); + } + return verts; + }; + Polygon.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotationWithTransform) { + var hasUnitScale = true; + var tempMat = void 0; + var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); + if (collider.entity.scale != Vector2.one) { + tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); + combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); + hasUnitScale = false; + var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); + this.center = scaledOffset; + } + if (collider.entity.rotation != 0) { + tempMat = Matrix2D.createRotation(collider.entity.rotation); + combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); + } + tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); + combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); + Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); + this.isUnrotated = collider.entity.rotation == 0; + if (collider._isRotationDirty) + this._areEdgeNormalsDirty = true; + } + this.position = Vector2.add(collider.entity.position, this.center); + this.bounds = Rectangle.rectEncompassingPoints(this.points); + this.bounds.location = Vector2.add(this.bounds.location, this.position); + }; + return Polygon; +}(Shape)); var Box = (function (_super) { - __extends(Box, _super); - function Box(width, height) { - var _this = _super.call(this, Box.buildBox(width, height), true) || this; - _this.width = width; - _this.height = height; - return _this; - } - Box.buildBox = function (width, height) { - var halfWidth = width / 2; - var halfHeight = height / 2; - var verts = new Array(4); - verts[0] = new Vector2(-halfWidth, -halfHeight); - verts[1] = new Vector2(halfWidth, -halfHeight); - verts[2] = new Vector2(halfWidth, halfHeight); - verts[3] = new Vector2(-halfWidth, halfHeight); - return verts; - }; - Box.prototype.updateBox = function (width, height) { - this.width = width; - this.height = height; - var halfWidth = width / 2; - var halfHeight = height / 2; - this.points[0] = new Vector2(-halfWidth, -halfHeight); - this.points[1] = new Vector2(halfWidth, -halfHeight); - this.points[2] = new Vector2(halfWidth, halfHeight); - this.points[3] = new Vector2(-halfWidth, halfHeight); - for (var i = 0; i < this.points.length; i++) - this._originalPoints[i] = this.points[i]; - }; - Box.prototype.containsPoint = function (point) { - if (this.isUnrotated) return this.bounds.contains(point); - return _super.prototype.containsPoint.call(this, point); - }; - return Box; -})(Polygon); + __extends(Box, _super); + function Box(width, height) { + var _this = _super.call(this, Box.buildBox(width, height), true) || this; + _this.width = width; + _this.height = height; + return _this; + } + Box.buildBox = function (width, height) { + var halfWidth = width / 2; + var halfHeight = height / 2; + var verts = new Array(4); + verts[0] = new Vector2(-halfWidth, -halfHeight); + verts[1] = new Vector2(halfWidth, -halfHeight); + verts[2] = new Vector2(halfWidth, halfHeight); + verts[3] = new Vector2(-halfWidth, halfHeight); + return verts; + }; + Box.prototype.updateBox = function (width, height) { + this.width = width; + this.height = height; + var halfWidth = width / 2; + var halfHeight = height / 2; + this.points[0] = new Vector2(-halfWidth, -halfHeight); + this.points[1] = new Vector2(halfWidth, -halfHeight); + this.points[2] = new Vector2(halfWidth, halfHeight); + this.points[3] = new Vector2(-halfWidth, halfHeight); + for (var i = 0; i < this.points.length; i++) + this._originalPoints[i] = this.points[i]; + }; + Box.prototype.containsPoint = function (point) { + if (this.isUnrotated) + return this.bounds.contains(point); + return _super.prototype.containsPoint.call(this, point); + }; + return Box; +}(Polygon)); var Circle = (function (_super) { - __extends(Circle, _super); - function Circle(radius) { - var _this = _super.call(this) || this; - _this.radius = radius; - _this._originalRadius = radius; - return _this; - } - Circle.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToCircle(point, this); - }; - Circle.prototype.collidesWithShape = function (other) { - if (other instanceof Box && other.isUnrotated) { - return ShapeCollisions.circleToBox(this, other); - } - if (other instanceof Circle) { - return ShapeCollisions.circleToCircle(this, other); - } - if (other instanceof Polygon) { - return ShapeCollisions.circleToPolygon(this, other); - } - throw new Error("Collisions of Circle to " + other + " are not supported"); - }; - Circle.prototype.recalculateBounds = function (collider) { - this.center = collider.localOffset; - if (collider.shouldColliderScaleAndRotationWithTransform) { - var scale = collider.entity.scale; - var hasUnitScale = scale.x == 1 && scale.y == 1; - var maxScale = Math.max(scale.x, scale.y); - this.radius = this._originalRadius * maxScale; - if (collider.entity.rotation != 0) { - var offsetAngle = - Math.atan2(collider.localOffset.y, collider.localOffset.x) * - MathHelper.Rad2Deg; - var offsetLength = hasUnitScale - ? collider._localOffsetLength - : Vector2.multiply( - collider.localOffset, - collider.entity.scale - ).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - offsetLength, - MathHelper.toDegrees(collider.entity.rotation) + offsetAngle - ); - } - } - this.position = Vector2.add(collider.entity.position, this.center); - this.bounds = new Rectangle( - this.position.x - this.radius, - this.position.y - this.radius, - this.radius * 2, - this.radius * 2 - ); - }; - Circle.prototype.overlaps = function (other) { - if (other instanceof Box && other.isUnrotated) - return Collisions.isRectToCircle( - other.bounds, - this.position, - this.radius - ); - if (other instanceof Circle) - return Collisions.isCircleToCircle( - this.position, - this.radius, - other.position, - other.radius - ); - if (other instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, other); - throw new Error("overlaps of circle to " + other + " are not supported"); - }; - return Circle; -})(Shape); + __extends(Circle, _super); + function Circle(radius) { + var _this = _super.call(this) || this; + _this.radius = radius; + _this._originalRadius = radius; + return _this; + } + Circle.prototype.pointCollidesWithShape = function (point) { + return ShapeCollisions.pointToCircle(point, this); + }; + Circle.prototype.collidesWithShape = function (other) { + if (other instanceof Box && other.isUnrotated) { + return ShapeCollisions.circleToBox(this, other); + } + if (other instanceof Circle) { + return ShapeCollisions.circleToCircle(this, other); + } + if (other instanceof Polygon) { + return ShapeCollisions.circleToPolygon(this, other); + } + throw new Error("Collisions of Circle to " + other + " are not supported"); + }; + Circle.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotationWithTransform) { + var scale = collider.entity.scale; + var hasUnitScale = scale.x == 1 && scale.y == 1; + var maxScale = Math.max(scale.x, scale.y); + this.radius = this._originalRadius * maxScale; + if (collider.entity.rotation != 0) { + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; + var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); + } + } + this.position = Vector2.add(collider.entity.position, this.center); + this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); + }; + Circle.prototype.overlaps = function (other) { + if (other instanceof Box && other.isUnrotated) + return Collisions.isRectToCircle(other.bounds, this.position, this.radius); + if (other instanceof Circle) + return Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); + if (other instanceof Polygon) + return ShapeCollisions.circleToPolygon(this, other); + throw new Error("overlaps of circle to " + other + " are not supported"); + }; + return Circle; +}(Shape)); var CollisionResult = (function () { - function CollisionResult() {} - CollisionResult.prototype.invertResult = function () { - this.minimumTranslationVector = Vector2.negate( - this.minimumTranslationVector - ); - this.normal = Vector2.negate(this.normal); - }; - return CollisionResult; -})(); -var ShapeCollisions = (function () { - function ShapeCollisions() {} - ShapeCollisions.polygonToPolygon = function (first, second) { - var result = new CollisionResult(); - var isIntersecting = true; - var firstEdges = first.edgeNormals; - var secondEdges = second.edgeNormals; - var minIntervalDistance = Number.POSITIVE_INFINITY; - var translationAxis = new Vector2(); - var polygonOffset = Vector2.subtract(first.position, second.position); - var axis; - for ( - var edgeIndex = 0; - edgeIndex < firstEdges.length + secondEdges.length; - edgeIndex++ - ) { - if (edgeIndex < firstEdges.length) { - axis = firstEdges[edgeIndex]; - } else { - axis = secondEdges[edgeIndex - firstEdges.length]; - } - var minA = 0; - var minB = 0; - var maxA = 0; - var maxB = 0; - var intervalDist = 0; - var ta = this.getInterval(axis, first, minA, maxA); - minA = ta.min; - minB = ta.max; - var tb = this.getInterval(axis, second, minB, maxB); - minB = tb.min; - maxB = tb.max; - var relativeIntervalOffset = Vector2.dot(polygonOffset, axis); - minA += relativeIntervalOffset; - maxA += relativeIntervalOffset; - intervalDist = this.intervalDistance(minA, maxA, minB, maxB); - if (intervalDist > 0) isIntersecting = false; - if (!isIntersecting) return null; - intervalDist = Math.abs(intervalDist); - if (intervalDist < minIntervalDistance) { - minIntervalDistance = intervalDist; - translationAxis = axis; - if (Vector2.dot(translationAxis, polygonOffset) < 0) - translationAxis = new Vector2(-translationAxis); - } - } - result.normal = translationAxis; - result.minimumTranslationVector = Vector2.multiply( - new Vector2(-translationAxis), - new Vector2(minIntervalDistance) - ); - return result; - }; - ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { - if (minA < minB) return minB - maxA; - return minA - minB; - }; - ShapeCollisions.getInterval = function (axis, polygon, min, max) { - var dot = Vector2.dot(polygon.points[0], axis); - min = max = dot; - for (var i = 1; i < polygon.points.length; i++) { - dot = Vector2.dot(polygon.points[i], axis); - if (dot < min) { - min = dot; - } else if (dot > max) { - max = dot; - } - } - return { min: min, max: max }; - }; - ShapeCollisions.circleToPolygon = function (circle, polygon) { - var result = new CollisionResult(); - var poly2Circle = Vector2.subtract(circle.position, polygon.position); - var gpp = Polygon.getClosestPointOnPolygonToPoint( - polygon.points, - poly2Circle - ); - var closestPoint = gpp.closestPoint; - var distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - var circleCenterInsidePoly = polygon.containsPoint(circle.position); - if ( - distanceSquared > circle.radius * circle.radius && - !circleCenterInsidePoly - ) - return null; - var mtv; - if (circleCenterInsidePoly) { - mtv = Vector2.multiply( - result.normal, - new Vector2(Math.sqrt(distanceSquared) - circle.radius) - ); - } else { - if (distanceSquared == 0) { - mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); - } else { - var distance = Math.sqrt(distanceSquared); - mtv = Vector2.multiply( - new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), - new Vector2((circle.radius - distanceSquared) / distance) - ); - } - } - result.minimumTranslationVector = mtv; - result.point = Vector2.add(closestPoint, polygon.position); - return result; - }; - ShapeCollisions.circleToBox = function (circle, box) { - var result = new CollisionResult(); - var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint( - circle.position - ).res; - if (box.containsPoint(circle.position)) { - result.point = closestPointOnBounds; - var safePlace = Vector2.add( - closestPointOnBounds, - Vector2.subtract(result.normal, new Vector2(circle.radius)) - ); - result.minimumTranslationVector = Vector2.subtract( - circle.position, - safePlace - ); - return result; - } - var sqrDistance = Vector2.distanceSquared( - closestPointOnBounds, - circle.position - ); - if (sqrDistance == 0) { - result.minimumTranslationVector = Vector2.multiply( - result.normal, - new Vector2(circle.radius) - ); - } else if (sqrDistance <= circle.radius * circle.radius) { - result.normal = Vector2.subtract(circle.position, closestPointOnBounds); - var depth = result.normal.length() - circle.radius; - result.normal = Vector2Ext.normalize(result.normal); - result.minimumTranslationVector = Vector2.multiply( - new Vector2(depth), - result.normal - ); - return result; - } - return null; - }; - ShapeCollisions.pointToCircle = function (point, circle) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared(point, circle.position); - var sumOfRadii = 1 + circle.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize( - Vector2.subtract(point, circle.position) - ); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply( - new Vector2(-depth, -depth), - result.normal - ); - result.point = Vector2.add( - circle.position, - Vector2.multiply( - result.normal, - new Vector2(circle.radius, circle.radius) - ) - ); - return result; + function CollisionResult() { } - return null; - }; - ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); - }; - ShapeCollisions.pointToPoly = function (point, poly) { - var result = new CollisionResult(); - if (poly.containsPoint(point)) { - var distanceSquared = void 0; - var gpp = Polygon.getClosestPointOnPolygonToPoint( - poly.points, - Vector2.subtract(point, poly.position) - ); - var closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - result.minimumTranslationVector = Vector2.multiply( - result.normal, - new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared)) - ); - result.point = Vector2.add(closestPoint, poly.position); - return result; - } - return null; - }; - ShapeCollisions.circleToCircle = function (first, second) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared( - first.position, - second.position - ); - var sumOfRadii = first.radius + second.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize( - Vector2.subtract(first.position, second.position) - ); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply( - new Vector2(-depth), - result.normal - ); - result.point = Vector2.add( - second.position, - Vector2.multiply(result.normal, new Vector2(second.radius)) - ); - return result; - } - return null; - }; - return ShapeCollisions; -})(); + CollisionResult.prototype.invertResult = function () { + this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector); + this.normal = Vector2.negate(this.normal); + }; + return CollisionResult; +}()); +var ShapeCollisions = (function () { + function ShapeCollisions() { + } + ShapeCollisions.polygonToPolygon = function (first, second) { + var result = new CollisionResult(); + var isIntersecting = true; + var firstEdges = first.edgeNormals; + var secondEdges = second.edgeNormals; + var minIntervalDistance = Number.POSITIVE_INFINITY; + var translationAxis = new Vector2(); + var polygonOffset = Vector2.subtract(first.position, second.position); + var axis; + for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { + if (edgeIndex < firstEdges.length) { + axis = firstEdges[edgeIndex]; + } + else { + axis = secondEdges[edgeIndex - firstEdges.length]; + } + var minA = 0; + var minB = 0; + var maxA = 0; + var maxB = 0; + var intervalDist = 0; + var ta = this.getInterval(axis, first, minA, maxA); + minA = ta.min; + minB = ta.max; + var tb = this.getInterval(axis, second, minB, maxB); + minB = tb.min; + maxB = tb.max; + var relativeIntervalOffset = Vector2.dot(polygonOffset, axis); + minA += relativeIntervalOffset; + maxA += relativeIntervalOffset; + intervalDist = this.intervalDistance(minA, maxA, minB, maxB); + if (intervalDist > 0) + isIntersecting = false; + if (!isIntersecting) + return null; + intervalDist = Math.abs(intervalDist); + if (intervalDist < minIntervalDistance) { + minIntervalDistance = intervalDist; + translationAxis = axis; + if (Vector2.dot(translationAxis, polygonOffset) < 0) + translationAxis = new Vector2(-translationAxis); + } + } + result.normal = translationAxis; + result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis), new Vector2(minIntervalDistance)); + return result; + }; + ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { + if (minA < minB) + return minB - maxA; + return minA - minB; + }; + ShapeCollisions.getInterval = function (axis, polygon, min, max) { + var dot = Vector2.dot(polygon.points[0], axis); + min = max = dot; + for (var i = 1; i < polygon.points.length; i++) { + dot = Vector2.dot(polygon.points[i], axis); + if (dot < min) { + min = dot; + } + else if (dot > max) { + max = dot; + } + } + return { min: min, max: max }; + }; + ShapeCollisions.circleToPolygon = function (circle, polygon) { + var result = new CollisionResult(); + var poly2Circle = Vector2.subtract(circle.position, polygon.position); + var gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); + var closestPoint = gpp.closestPoint; + var distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + var circleCenterInsidePoly = polygon.containsPoint(circle.position); + if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) + return null; + var mtv; + if (circleCenterInsidePoly) { + mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared) - circle.radius)); + } + else { + if (distanceSquared == 0) { + mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); + } + else { + var distance = Math.sqrt(distanceSquared); + mtv = Vector2.multiply(new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), new Vector2((circle.radius - distanceSquared) / distance)); + } + } + result.minimumTranslationVector = mtv; + result.point = Vector2.add(closestPoint, polygon.position); + return result; + }; + ShapeCollisions.circleToBox = function (circle, box) { + var result = new CollisionResult(); + var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; + if (box.containsPoint(circle.position)) { + result.point = closestPointOnBounds; + var safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); + result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); + return result; + } + var sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); + if (sqrDistance == 0) { + result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius)); + } + else if (sqrDistance <= circle.radius * circle.radius) { + result.normal = Vector2.subtract(circle.position, closestPointOnBounds); + var depth = result.normal.length() - circle.radius; + result.normal = Vector2Ext.normalize(result.normal); + result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); + return result; + } + return null; + }; + ShapeCollisions.pointToCircle = function (point, circle) { + var result = new CollisionResult(); + var distanceSquared = Vector2.distanceSquared(point, circle.position); + var sumOfRadii = 1 + circle.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = Vector2.normalize(Vector2.subtract(point, circle.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal); + result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius))); + return result; + } + return null; + }; + ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = Vector2.subtract(lineB, lineA); + var w = Vector2.subtract(closestTo, lineA); + var t = Vector2.dot(w, v) / Vector2.dot(v, v); + t = MathHelper.clamp(t, 0, 1); + return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); + }; + ShapeCollisions.pointToPoly = function (point, poly) { + var result = new CollisionResult(); + if (poly.containsPoint(point)) { + var distanceSquared = void 0; + var gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position)); + var closestPoint = gpp.closestPoint; + distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); + result.point = Vector2.add(closestPoint, poly.position); + return result; + } + return null; + }; + ShapeCollisions.circleToCircle = function (first, second) { + var result = new CollisionResult(); + var distanceSquared = Vector2.distanceSquared(first.position, second.position); + var sumOfRadii = first.radius + second.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal); + result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius))); + return result; + } + return null; + }; + return ShapeCollisions; +}()); var SpatialHash = (function () { - function SpatialHash(cellSize) { - if (cellSize === void 0) { - cellSize = 100; - } - this.gridBounds = new Rectangle(); - this._tempHashSet = []; - this._cellDict = new NumberDictionary(); - this._cellSize = cellSize; - this._inverseCellSize = 1 / this._cellSize; - this._raycastParser = new RaycastResultParser(); - } - SpatialHash.prototype.remove = function (collider) { - var bounds = collider.registeredPhysicsBounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) - console.error( - "removing Collider [" + - collider + - "] from a cell that it is not present in" - ); - else cell.remove(collider); - } - } - }; - SpatialHash.prototype.register = function (collider) { - var bounds = collider.bounds; - collider.registeredPhysicsBounds = bounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) { - this.gridBounds = RectangleExt.union(this.gridBounds, p1); - } - if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) { - this.gridBounds = RectangleExt.union(this.gridBounds, p2); - } - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var c = this.cellAtPosition(x, y, true); - c.push(collider); - } - } - }; - SpatialHash.prototype.clear = function () { - this._cellDict.clear(); - }; - SpatialHash.prototype.overlapCircle = function ( - circleCenter, - radius, - results, - layerMask - ) { - var bounds = new Rectangle( - circleCenter.x - radius, - circleCenter.y - radius, - radius * 2, - radius * 2 - ); - this._overlapTestCircle.radius = radius; - this._overlapTestCircle.position = circleCenter; - var resultCounter = 0; - var potentials = this.aabbBroadphase(bounds, null, layerMask); - for (var i = 0; i < potentials.length; i++) { - var collider = potentials[i]; - if (collider instanceof BoxCollider) { - results[resultCounter] = collider; - resultCounter++; - } else { - throw new Error( - "overlapCircle against this collider type is not implemented!" - ); - } - if (resultCounter == results.length) return resultCounter; - } - return resultCounter; - }; - SpatialHash.prototype.aabbBroadphase = function ( - bounds, - excludeCollider, - layerMask - ) { - this._tempHashSet.length = 0; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) continue; - for (var i = 0; i < cell.length; i++) { - var collider = cell[i]; - if ( - collider == excludeCollider || - !Flags.isFlagSet(layerMask, collider.physicsLayer) - ) - continue; - if (bounds.intersects(collider.bounds)) { - if (this._tempHashSet.indexOf(collider) == -1) - this._tempHashSet.push(collider); - } - } - } - } - return this._tempHashSet; - }; - SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { - if (createCellIfEmpty === void 0) { - createCellIfEmpty = false; - } - var cell = this._cellDict.tryGetValue(x, y); - if (!cell) { - if (createCellIfEmpty) { - cell = []; - this._cellDict.add(x, y, cell); - } - } - return cell; - }; - SpatialHash.prototype.cellCoords = function (x, y) { - return new Point( - Math.floor(x * this._inverseCellSize), - Math.floor(y * this._inverseCellSize) - ); - }; - return SpatialHash; -})(); + function SpatialHash(cellSize) { + if (cellSize === void 0) { cellSize = 100; } + this.gridBounds = new Rectangle(); + this._tempHashSet = []; + this._cellDict = new NumberDictionary(); + this._cellSize = cellSize; + this._inverseCellSize = 1 / this._cellSize; + this._raycastParser = new RaycastResultParser(); + } + SpatialHash.prototype.remove = function (collider) { + var bounds = collider.registeredPhysicsBounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) + console.error("removing Collider [" + collider + "] from a cell that it is not present in"); + else + cell.remove(collider); + } + } + }; + SpatialHash.prototype.register = function (collider) { + var bounds = collider.bounds; + collider.registeredPhysicsBounds = bounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) { + this.gridBounds = RectangleExt.union(this.gridBounds, p1); + } + if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) { + this.gridBounds = RectangleExt.union(this.gridBounds, p2); + } + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var c = this.cellAtPosition(x, y, true); + c.push(collider); + } + } + }; + SpatialHash.prototype.clear = function () { + this._cellDict.clear(); + }; + SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { + var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); + this._overlapTestCircle.radius = radius; + this._overlapTestCircle.position = circleCenter; + var resultCounter = 0; + var potentials = this.aabbBroadphase(bounds, null, layerMask); + for (var i = 0; i < potentials.length; i++) { + var collider = potentials[i]; + if (collider instanceof BoxCollider) { + results[resultCounter] = collider; + resultCounter++; + } + else { + throw new Error("overlapCircle against this collider type is not implemented!"); + } + if (resultCounter == results.length) + return resultCounter; + } + return resultCounter; + }; + SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) { + this._tempHashSet.length = 0; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) + continue; + for (var i = 0; i < cell.length; i++) { + var collider = cell[i]; + if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer)) + continue; + if (bounds.intersects(collider.bounds)) { + if (this._tempHashSet.indexOf(collider) == -1) + this._tempHashSet.push(collider); + } + } + } + } + return this._tempHashSet; + }; + SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { + if (createCellIfEmpty === void 0) { createCellIfEmpty = false; } + var cell = this._cellDict.tryGetValue(x, y); + if (!cell) { + if (createCellIfEmpty) { + cell = []; + this._cellDict.add(x, y, cell); + } + } + return cell; + }; + SpatialHash.prototype.cellCoords = function (x, y) { + return new Point(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); + }; + return SpatialHash; +}()); var RaycastResultParser = (function () { - function RaycastResultParser() {} - return RaycastResultParser; -})(); + function RaycastResultParser() { + } + return RaycastResultParser; +}()); var NumberDictionary = (function () { - function NumberDictionary() { - this._store = new Map(); - } - NumberDictionary.prototype.getKey = function (x, y) { - return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); - }; - NumberDictionary.prototype.intToUint = function (i) { - if (i >= 0) return i; - else return 4294967296 + i; - }; - NumberDictionary.prototype.add = function (x, y, list) { - this._store.set(this.getKey(x, y), list); - }; - NumberDictionary.prototype.remove = function (obj) { - this._store.forEach(function (list) { - if (list.contains(obj)) list.remove(obj); - }); - }; - NumberDictionary.prototype.tryGetValue = function (x, y) { - return this._store.get(this.getKey(x, y)); - }; - NumberDictionary.prototype.clear = function () { - this._store.clear(); - }; - return NumberDictionary; -})(); -var ContentManager = (function () { - function ContentManager() { - this.loadedAssets = new Map(); - } - ContentManager.prototype.loadRes = function (name, local) { - var _this = this; - if (local === void 0) { - local = true; + function NumberDictionary() { + this._store = new Map(); } - return new Promise(function (resolve, reject) { - var res = _this.loadedAssets.get(name); - if (res) { - resolve(res); - return; - } - if (local) { - RES.getResAsync(name) - .then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }) - .catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } else { - RES.getResByUrl(name) - .then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }) - .catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } - }); - }; - ContentManager.prototype.dispose = function () { - this.loadedAssets.forEach(function (value) { - var assetsToRemove = value; - assetsToRemove.dispose(); - }); - this.loadedAssets.clear(); - }; - return ContentManager; -})(); + NumberDictionary.prototype.getKey = function (x, y) { + return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); + }; + NumberDictionary.prototype.intToUint = function (i) { + if (i >= 0) + return i; + else + return 4294967296 + i; + }; + NumberDictionary.prototype.add = function (x, y, list) { + this._store.set(this.getKey(x, y), list); + }; + NumberDictionary.prototype.remove = function (obj) { + this._store.forEach(function (list) { + if (list.contains(obj)) + list.remove(obj); + }); + }; + NumberDictionary.prototype.tryGetValue = function (x, y) { + return this._store.get(this.getKey(x, y)); + }; + NumberDictionary.prototype.clear = function () { + this._store.clear(); + }; + return NumberDictionary; +}()); +var ContentManager = (function () { + function ContentManager() { + this.loadedAssets = new Map(); + } + ContentManager.prototype.loadRes = function (name, local) { + var _this = this; + if (local === void 0) { local = true; } + return new Promise(function (resolve, reject) { + var res = _this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } + if (local) { + RES.getResAsync(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + else { + RES.getResByUrl(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }); + }; + ContentManager.prototype.dispose = function () { + this.loadedAssets.forEach(function (value) { + var assetsToRemove = value; + assetsToRemove.dispose(); + }); + this.loadedAssets.clear(); + }; + return ContentManager; +}()); var Emitter = (function () { - function Emitter() { - this._messageTable = new Map(); - } - Emitter.prototype.addObserver = function (eventType, handler) { - var list = this._messageTable.get(eventType); - if (!list) { - list = []; - this._messageTable.set(eventType, list); - } - if (list.contains(handler)) console.warn("您试图添加相同的观察者两次"); - list.push(handler); - }; - Emitter.prototype.removeObserver = function (eventType, handler) { - this._messageTable.get(eventType).remove(handler); - }; - Emitter.prototype.emit = function (eventType, data) { - var list = this._messageTable.get(eventType); - if (list) { - for (var i = list.length - 1; i >= 0; i--) list[i](data); - } - }; - return Emitter; -})(); + function Emitter() { + this._messageTable = new Map(); + } + Emitter.prototype.addObserver = function (eventType, handler) { + var list = this._messageTable.get(eventType); + if (!list) { + list = []; + this._messageTable.set(eventType, list); + } + if (list.contains(handler)) + console.warn("您试图添加相同的观察者两次"); + list.push(handler); + }; + Emitter.prototype.removeObserver = function (eventType, handler) { + this._messageTable.get(eventType).remove(handler); + }; + Emitter.prototype.emit = function (eventType, data) { + var list = this._messageTable.get(eventType); + if (list) { + for (var i = list.length - 1; i >= 0; i--) + list[i](data); + } + }; + return Emitter; +}()); var GlobalManager = (function () { - function GlobalManager() {} - Object.defineProperty(GlobalManager.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true, - }); - GlobalManager.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); - } else { - this.onDisabled(); - } - } - }; - GlobalManager.prototype.onEnabled = function () {}; - GlobalManager.prototype.onDisabled = function () {}; - GlobalManager.prototype.update = function () {}; - GlobalManager.registerGlobalManager = function (manager) { - this.globalManagers.push(manager); - manager.enabled = true; - }; - GlobalManager.unregisterGlobalManager = function (manager) { - this.globalManagers.remove(manager); - manager.enabled = false; - }; - GlobalManager.getGlobalManager = function (type) { - for (var i = 0; i < this.globalManagers.length; i++) { - if (this.globalManagers[i] instanceof type) return this.globalManagers[i]; + function GlobalManager() { } - return null; - }; - GlobalManager.globalManagers = []; - return GlobalManager; -})(); + Object.defineProperty(GlobalManager.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + GlobalManager.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } + } + }; + GlobalManager.prototype.onEnabled = function () { }; + GlobalManager.prototype.onDisabled = function () { }; + GlobalManager.prototype.update = function () { }; + GlobalManager.registerGlobalManager = function (manager) { + this.globalManagers.push(manager); + manager.enabled = true; + }; + GlobalManager.unregisterGlobalManager = function (manager) { + this.globalManagers.remove(manager); + manager.enabled = false; + }; + GlobalManager.getGlobalManager = function (type) { + for (var i = 0; i < this.globalManagers.length; i++) { + if (this.globalManagers[i] instanceof type) + return this.globalManagers[i]; + } + return null; + }; + GlobalManager.globalManagers = []; + return GlobalManager; +}()); var TouchState = (function () { - function TouchState() { - this.x = 0; - this.y = 0; - this.touchPoint = -1; - this.touchDown = false; - } - Object.defineProperty(TouchState.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - enumerable: true, - configurable: true, - }); - TouchState.prototype.reset = function () { - this.x = 0; - this.y = 0; - this.touchDown = false; - this.touchPoint = -1; - }; - return TouchState; -})(); + function TouchState() { + this.x = 0; + this.y = 0; + this.touchPoint = -1; + this.touchDown = false; + } + Object.defineProperty(TouchState.prototype, "position", { + get: function () { + return new Vector2(this.x, this.y); + }, + enumerable: true, + configurable: true + }); + TouchState.prototype.reset = function () { + this.x = 0; + this.y = 0; + this.touchDown = false; + this.touchPoint = -1; + }; + return TouchState; +}()); var Input = (function () { - function Input() {} - Object.defineProperty(Input, "touchPosition", { - get: function () { - if (!this._gameTouchs[0]) return Vector2.zero; - return this._gameTouchs[0].position; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "maxSupportedTouch", { - get: function () { - return this._stage.maxTouches; - }, - set: function (value) { - this._stage.maxTouches = value; - this.initTouchCache(); - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "resolutionScale", { - get: function () { - return this._resolutionScale; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "totalTouchCount", { - get: function () { - return this._totalTouchCount; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "gameTouchs", { - get: function () { - return this._gameTouchs; - }, - enumerable: true, - configurable: true, - }); - Object.defineProperty(Input, "touchPositionDelta", { - get: function () { - var delta = Vector2.subtract( - this.touchPosition, - this._previousTouchState.position - ); - if (delta.length() > 0) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - return delta; - }, - enumerable: true, - configurable: true, - }); - Input.initialize = function (stage) { - if (this._init) return; - this._init = true; - this._stage = stage; - this._stage.addEventListener( - egret.TouchEvent.TOUCH_BEGIN, - this.touchBegin, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_MOVE, - this.touchMove, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_END, - this.touchEnd, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_CANCEL, - this.touchEnd, - this - ); - this._stage.addEventListener( - egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, - this.touchEnd, - this - ); - this.initTouchCache(); - }; - Input.initTouchCache = function () { - this._totalTouchCount = 0; - this._touchIndex = 0; - this._gameTouchs.length = 0; - for (var i = 0; i < this.maxSupportedTouch; i++) { - this._gameTouchs.push(new TouchState()); + function Input() { } - }; - Input.touchBegin = function (evt) { - if (this._touchIndex < this.maxSupportedTouch) { - this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; - this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; - this._gameTouchs[this._touchIndex].x = evt.stageX; - this._gameTouchs[this._touchIndex].y = evt.stageY; - if (this._touchIndex == 0) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - this._touchIndex++; - this._totalTouchCount++; - } - }; - Input.touchMove = function (evt) { - if (evt.touchPointID == this._gameTouchs[0].touchPoint) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - var touchIndex = this._gameTouchs.findIndex(function (touch) { - return touch.touchPoint == evt.touchPointID; + Object.defineProperty(Input, "touchPosition", { + get: function () { + if (!this._gameTouchs[0]) + return Vector2.zero; + return this._gameTouchs[0].position; + }, + enumerable: true, + configurable: true }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.x = evt.stageX; - touchData.y = evt.stageY; - } - }; - Input.touchEnd = function (evt) { - var touchIndex = this._gameTouchs.findIndex(function (touch) { - return touch.touchPoint == evt.touchPointID; + Object.defineProperty(Input, "maxSupportedTouch", { + get: function () { + return this._stage.maxTouches; + }, + set: function (value) { + this._stage.maxTouches = value; + this.initTouchCache(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "resolutionScale", { + get: function () { + return this._resolutionScale; + }, + enumerable: true, + configurable: true }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.reset(); - if (touchIndex == 0) this._previousTouchState.reset(); - this._totalTouchCount--; - if (this.totalTouchCount == 0) { + Object.defineProperty(Input, "totalTouchCount", { + get: function () { + return this._totalTouchCount; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "gameTouchs", { + get: function () { + return this._gameTouchs; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "touchPositionDelta", { + get: function () { + var delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position); + if (delta.length() > 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + return delta; + }, + enumerable: true, + configurable: true + }); + Input.initialize = function (stage) { + if (this._init) + return; + this._init = true; + this._stage = stage; + this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); + this.initTouchCache(); + }; + Input.initTouchCache = function () { + this._totalTouchCount = 0; this._touchIndex = 0; - } - } - }; - Input.setpreviousTouchState = function (touchState) { - this._previousTouchState = new TouchState(); - this._previousTouchState.x = touchState.position.x; - this._previousTouchState.y = touchState.position.y; - this._previousTouchState.touchPoint = touchState.touchPoint; - this._previousTouchState.touchDown = touchState.touchDown; - }; - Input.scaledPosition = function (position) { - var scaledPos = new Vector2( - position.x - this._resolutionOffset.x, - position.y - this._resolutionOffset.y - ); - return Vector2.multiply(scaledPos, this.resolutionScale); - }; - Input._init = false; - Input._previousTouchState = new TouchState(); - Input._gameTouchs = []; - Input._resolutionOffset = new Vector2(); - Input._resolutionScale = Vector2.one; - Input._touchIndex = 0; - Input._totalTouchCount = 0; - return Input; -})(); + this._gameTouchs.length = 0; + for (var i = 0; i < this.maxSupportedTouch; i++) { + this._gameTouchs.push(new TouchState()); + } + }; + Input.touchBegin = function (evt) { + if (this._touchIndex < this.maxSupportedTouch) { + this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; + this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; + this._gameTouchs[this._touchIndex].x = evt.stageX; + this._gameTouchs[this._touchIndex].y = evt.stageY; + if (this._touchIndex == 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + this._touchIndex++; + this._totalTouchCount++; + } + }; + Input.touchMove = function (evt) { + if (evt.touchPointID == this._gameTouchs[0].touchPoint) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.x = evt.stageX; + touchData.y = evt.stageY; + } + }; + Input.touchEnd = function (evt) { + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.reset(); + if (touchIndex == 0) + this._previousTouchState.reset(); + this._totalTouchCount--; + if (this.totalTouchCount == 0) { + this._touchIndex = 0; + } + } + }; + Input.setpreviousTouchState = function (touchState) { + this._previousTouchState = new TouchState(); + this._previousTouchState.x = touchState.position.x; + this._previousTouchState.y = touchState.position.y; + this._previousTouchState.touchPoint = touchState.touchPoint; + this._previousTouchState.touchDown = touchState.touchDown; + }; + Input.scaledPosition = function (position) { + var scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); + return Vector2.multiply(scaledPos, this.resolutionScale); + }; + Input._init = false; + Input._previousTouchState = new TouchState(); + Input._gameTouchs = []; + Input._resolutionOffset = new Vector2(); + Input._resolutionScale = Vector2.one; + Input._touchIndex = 0; + Input._totalTouchCount = 0; + return Input; +}()); var ListPool = (function () { - function ListPool() {} - ListPool.warmCache = function (cacheCount) { - cacheCount -= this._objectQueue.length; - if (cacheCount > 0) { - for (var i = 0; i < cacheCount; i++) { - this._objectQueue.unshift([]); - } + function ListPool() { } - }; - ListPool.trimCache = function (cacheCount) { - while (cacheCount > this._objectQueue.length) this._objectQueue.shift(); - }; - ListPool.clearCache = function () { - this._objectQueue.length = 0; - }; - ListPool.obtain = function () { - if (this._objectQueue.length > 0) return this._objectQueue.shift(); - return []; - }; - ListPool.free = function (obj) { - this._objectQueue.unshift(obj); - obj.length = 0; - }; - ListPool._objectQueue = []; - return ListPool; -})(); + ListPool.warmCache = function (cacheCount) { + cacheCount -= this._objectQueue.length; + if (cacheCount > 0) { + for (var i = 0; i < cacheCount; i++) { + this._objectQueue.unshift([]); + } + } + }; + ListPool.trimCache = function (cacheCount) { + while (cacheCount > this._objectQueue.length) + this._objectQueue.shift(); + }; + ListPool.clearCache = function () { + this._objectQueue.length = 0; + }; + ListPool.obtain = function () { + if (this._objectQueue.length > 0) + return this._objectQueue.shift(); + return []; + }; + ListPool.free = function (obj) { + this._objectQueue.unshift(obj); + obj.length = 0; + }; + ListPool._objectQueue = []; + return ListPool; +}()); var Pair = (function () { - function Pair(first, second) { - this.first = first; - this.second = second; - } - Pair.prototype.clear = function () { - this.first = this.second = null; - }; - Pair.prototype.equals = function (other) { - return this.first == other.first && this.second == other.second; - }; - return Pair; -})(); + function Pair(first, second) { + this.first = first; + this.second = second; + } + Pair.prototype.clear = function () { + this.first = this.second = null; + }; + Pair.prototype.equals = function (other) { + return this.first == other.first && this.second == other.second; + }; + return Pair; +}()); var RectangleExt = (function () { - function RectangleExt() {} - RectangleExt.union = function (first, point) { - var rect = new Rectangle(point.x, point.y, 0, 0); - return this.unionR(first, rect); - }; - RectangleExt.unionR = function (value1, value2) { - var result = new Rectangle(); - result.x = Math.min(value1.x, value2.x); - result.y = Math.min(value1.y, value2.y); - result.width = Math.max(value1.right, value2.right) - result.x; - result.height = Math.max(value1.bottom, value2.bottom) - result.y; - return result; - }; - return RectangleExt; -})(); -var Triangulator = (function () { - function Triangulator() { - this.triangleIndices = []; - this._triPrev = new Array(12); - this._triNext = new Array(12); - } - Triangulator.prototype.triangulate = function (points, arePointsCCW) { - if (arePointsCCW === void 0) { - arePointsCCW = true; + function RectangleExt() { } - var count = points.length; - this.initialize(count); - var iterations = 0; - var index = 0; - while (count > 3 && iterations < 500) { - iterations++; - var isEar = true; - var a = points[this._triPrev[index]]; - var b = points[index]; - var c = points[this._triNext[index]]; - if (Vector2Ext.isTriangleCCW(a, b, c)) { - var k = this._triNext[this._triNext[index]]; - do { - if (Triangulator.testPointTriangle(points[k], a, b, c)) { - isEar = false; - break; - } - k = this._triNext[k]; - } while (k != this._triPrev[index]); - } else { - isEar = false; - } - if (isEar) { + RectangleExt.union = function (first, point) { + var rect = new Rectangle(point.x, point.y, 0, 0); + return this.unionR(first, rect); + }; + RectangleExt.unionR = function (value1, value2) { + var result = new Rectangle(); + result.x = Math.min(value1.x, value2.x); + result.y = Math.min(value1.y, value2.y); + result.width = Math.max(value1.right, value2.right) - result.x; + result.height = Math.max(value1.bottom, value2.bottom) - result.y; + return result; + }; + return RectangleExt; +}()); +var Triangulator = (function () { + function Triangulator() { + this.triangleIndices = []; + this._triPrev = new Array(12); + this._triNext = new Array(12); + } + Triangulator.prototype.triangulate = function (points, arePointsCCW) { + if (arePointsCCW === void 0) { arePointsCCW = true; } + var count = points.length; + this.initialize(count); + var iterations = 0; + var index = 0; + while (count > 3 && iterations < 500) { + iterations++; + var isEar = true; + var a = points[this._triPrev[index]]; + var b = points[index]; + var c = points[this._triNext[index]]; + if (Vector2Ext.isTriangleCCW(a, b, c)) { + var k = this._triNext[this._triNext[index]]; + do { + if (Triangulator.testPointTriangle(points[k], a, b, c)) { + isEar = false; + break; + } + k = this._triNext[k]; + } while (k != this._triPrev[index]); + } + else { + isEar = false; + } + if (isEar) { + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); + this._triNext[this._triPrev[index]] = this._triNext[index]; + this._triPrev[this._triNext[index]] = this._triPrev[index]; + count--; + index = this._triPrev[index]; + } + else { + index = this._triNext[index]; + } + } this.triangleIndices.push(this._triPrev[index]); this.triangleIndices.push(index); this.triangleIndices.push(this._triNext[index]); - this._triNext[this._triPrev[index]] = this._triNext[index]; - this._triPrev[this._triNext[index]] = this._triPrev[index]; - count--; - index = this._triPrev[index]; - } else { - index = this._triNext[index]; - } - } - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); - if (!arePointsCCW) this.triangleIndices.reverse(); - }; - Triangulator.prototype.initialize = function (count) { - this.triangleIndices.length = 0; - if (this._triNext.length < count) { - this._triNext.reverse(); - this._triNext = new Array(Math.max(this._triNext.length * 2, count)); - } - if (this._triPrev.length < count) { - this._triPrev.reverse(); - this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); - } - for (var i = 0; i < count; i++) { - this._triPrev[i] = i - 1; - this._triNext[i] = i + 1; - } - this._triPrev[0] = count - 1; - this._triNext[count - 1] = 0; - }; - Triangulator.testPointTriangle = function (point, a, b, c) { - if ( - Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0 - ) - return false; - if ( - Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0 - ) - return false; - if ( - Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0 - ) - return false; - return true; - }; - return Triangulator; -})(); + if (!arePointsCCW) + this.triangleIndices.reverse(); + }; + Triangulator.prototype.initialize = function (count) { + this.triangleIndices.length = 0; + if (this._triNext.length < count) { + this._triNext.reverse(); + this._triNext = new Array(Math.max(this._triNext.length * 2, count)); + } + if (this._triPrev.length < count) { + this._triPrev.reverse(); + this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); + } + for (var i = 0; i < count; i++) { + this._triPrev[i] = i - 1; + this._triNext[i] = i + 1; + } + this._triPrev[0] = count - 1; + this._triNext[count - 1] = 0; + }; + Triangulator.testPointTriangle = function (point, a, b, c) { + if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0) + return false; + if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0) + return false; + if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0) + return false; + return true; + }; + return Triangulator; +}()); var Vector2Ext = (function () { - function Vector2Ext() {} - Vector2Ext.isTriangleCCW = function (a, center, c) { - return ( - this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0 - ); - }; - Vector2Ext.cross = function (u, v) { - return u.y * v.x - u.x * v.y; - }; - Vector2Ext.perpendicular = function (first, second) { - return new Vector2(-1 * (second.y - first.y), second.x - first.x); - }; - Vector2Ext.normalize = function (vec) { - var magnitude = Math.sqrt(vec.x * vec.x + vec.y * vec.y); - if (magnitude > MathHelper.Epsilon) { - vec = Vector2.divide(vec, new Vector2(magnitude)); - } else { - vec.x = vec.y = 0; - } - return vec; - }; - Vector2Ext.transformA = function ( - sourceArray, - sourceIndex, - matrix, - destinationArray, - destinationIndex, - length - ) { - for (var i = 0; i < length; i++) { - var position = sourceArray[sourceIndex + i]; - var destination = destinationArray[destinationIndex + i]; - destination.x = - position.x * matrix.m11 + position.y * matrix.m21 + matrix.m31; - destination.y = - position.x * matrix.m12 + position.y * matrix.m22 + matrix.m32; - destinationArray[destinationIndex + i] = destination; + function Vector2Ext() { } - }; - Vector2Ext.transformR = function (position, matrix) { - var x = position.x * matrix.m11 + position.y * matrix.m21 + matrix.m31; - var y = position.x * matrix.m12 + position.y * matrix.m22 + matrix.m32; - return new Vector2(x, y); - }; - Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { - this.transformA( - sourceArray, - 0, - matrix, - destinationArray, - 0, - sourceArray.length - ); - }; - Vector2Ext.round = function (vec) { - return new Vector2(Math.round(vec.x), Math.round(vec.y)); - }; - return Vector2Ext; -})(); + Vector2Ext.isTriangleCCW = function (a, center, c) { + return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; + }; + Vector2Ext.cross = function (u, v) { + return u.y * v.x - u.x * v.y; + }; + Vector2Ext.perpendicular = function (first, second) { + return new Vector2(-1 * (second.y - first.y), second.x - first.x); + }; + Vector2Ext.normalize = function (vec) { + var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); + if (magnitude > MathHelper.Epsilon) { + vec = Vector2.divide(vec, new Vector2(magnitude)); + } + else { + vec.x = vec.y = 0; + } + return vec; + }; + Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) { + for (var i = 0; i < length; i++) { + var position = sourceArray[sourceIndex + i]; + var destination = destinationArray[destinationIndex + i]; + destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + destinationArray[destinationIndex + i] = destination; + } + }; + Vector2Ext.transformR = function (position, matrix) { + var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + return new Vector2(x, y); + }; + Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { + this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); + }; + Vector2Ext.round = function (vec) { + return new Vector2(Math.round(vec.x), Math.round(vec.y)); + }; + return Vector2Ext; +}()); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 48790482..37478306 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1,5250 +1 @@ -(window.framework = {}), - (window.__extends = - (this && this.__extends) || - (function () { - var t = - Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && - function (t, e) { - t.__proto__ = e; - }) || - function (t, e) { - for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]); - }; - return function (e, n) { - function i() { - this.constructor = e; - } - t(e, n), - (e.prototype = - null === n - ? Object.create(n) - : ((i.prototype = n.prototype), new i())); - }; - })()); -var __awaiter = - (this && this.__awaiter) || - function (t, e, n, i) { - return new (n || (n = Promise))(function (o, r) { - function s(t) { - try { - h(i.next(t)); - } catch (t) { - r(t); - } - } - function a(t) { - try { - h(i.throw(t)); - } catch (t) { - r(t); - } - } - function h(t) { - t.done - ? o(t.value) - : new n(function (e) { - e(t.value); - }).then(s, a); - } - h((i = i.apply(t, e || [])).next()); - }); - }, - __generator = - (this && this.__generator) || - function (t, e) { - var n, - i, - o, - r, - s = { - label: 0, - sent: function () { - if (1 & o[0]) throw o[1]; - return o[1]; - }, - trys: [], - ops: [], - }; - return ( - (r = { next: a(0), throw: a(1), return: a(2) }), - "function" == typeof Symbol && - (r[Symbol.iterator] = function () { - return this; - }), - r - ); - function a(r) { - return function (a) { - return (function (r) { - if (n) throw new TypeError("Generator is already executing."); - for (; s; ) - try { - if ( - ((n = 1), - i && - (o = - 2 & r[0] - ? i.return - : r[0] - ? i.throw || ((o = i.return) && o.call(i), 0) - : i.next) && - !(o = o.call(i, r[1])).done) - ) - return o; - switch (((i = 0), o && (r = [2 & r[0], o.value]), r[0])) { - case 0: - case 1: - o = r; - break; - case 4: - return s.label++, { value: r[1], done: !1 }; - case 5: - s.label++, (i = r[1]), (r = [0]); - continue; - case 7: - (r = s.ops.pop()), s.trys.pop(); - continue; - default: - if ( - !(o = (o = s.trys).length > 0 && o[o.length - 1]) && - (6 === r[0] || 2 === r[0]) - ) { - s = 0; - continue; - } - if (3 === r[0] && (!o || (r[1] > o[0] && r[1] < o[3]))) { - s.label = r[1]; - break; - } - if (6 === r[0] && s.label < o[1]) { - (s.label = o[1]), (o = r); - break; - } - if (o && s.label < o[2]) { - (s.label = o[2]), s.ops.push(r); - break; - } - o[2] && s.ops.pop(), s.trys.pop(); - continue; - } - r = e.call(t, s); - } catch (t) { - (r = [6, t]), (i = 0); - } finally { - n = o = 0; - } - if (5 & r[0]) throw r[1]; - return { value: r[0] ? r[1] : void 0, done: !0 }; - })([r, a]); - }; - } - }; -(Array.prototype.findIndex = function (t) { - return (function (t, e) { - for (var n = 0, i = t.length; n < i; n++) - if (e.call(arguments[2], t[n], n, t)) return n; - return -1; - })(this, t); -}), - (Array.prototype.any = function (t) { - return (function (t, e) { - return t.findIndex(e) > -1; - })(this, t); - }), - (Array.prototype.firstOrDefault = function (t) { - return (function (t, e) { - var n = t.findIndex(e); - return -1 == n ? null : t[n]; - })(this, t); - }), - (Array.prototype.find = function (t) { - return (function (t, e) { - return t.firstOrDefault(e); - })(this, t); - }), - (Array.prototype.where = function (t) { - return (function (t, e) { - if ("function" == typeof t.reduce) - return t.reduce(function (n, i, o) { - return e.call(arguments[2], i, o, t) && n.push(i), n; - }, []); - for (var n = [], i = 0, o = t.length; i < o; i++) { - var r = t[i]; - e.call(arguments[2], r, i, t) && n.push(r); - } - return n; - })(this, t); - }), - (Array.prototype.count = function (t) { - return (function (t, e) { - return t.where(e).length; - })(this, t); - }), - (Array.prototype.findAll = function (t) { - return (function (t, e) { - return t.where(e); - })(this, t); - }), - (Array.prototype.contains = function (t) { - return (function (t, e) { - for (var n = 0, i = t.length; n < i; n++) if (t[n] == e) return !0; - return !1; - })(this, t); - }), - (Array.prototype.removeAll = function (t) { - !(function (t, e) { - var n; - do { - (n = t.findIndex(e)) >= 0 && t.splice(n, 1); - } while (n >= 0); - })(this, t); - }), - (Array.prototype.remove = function (t) { - return (function (t, e) { - var n = t.findIndex(function (t) { - return t === e; - }); - return n >= 0 && (t.splice(n, 1), !0); - })(this, t); - }), - (Array.prototype.removeAt = function (t) { - return (function (t, e) { - t.splice(e, 1); - })(this, t); - }), - (Array.prototype.removeRange = function (t, e) { - return (function (t, e, n) { - t.splice(e, n); - })(this, t, e); - }), - (Array.prototype.select = function (t) { - return (function (t, e) { - if ("function" == typeof t.reduce) - return t.reduce(function (n, i, o) { - return n.push(e.call(arguments[2], i, o, t)), n; - }, []); - for (var n = [], i = 0, o = t.length; i < o; i++) - n.push(e.call(arguments[2], t[i], i, t)); - return n; - })(this, t); - }), - (Array.prototype.orderBy = function (t, e) { - return (function (t, e, n) { - return ( - t.sort(function (t, i) { - var o = e(t), - r = e(i); - return n ? n(o, r) : o > r ? 1 : -1; - }), - t - ); - })(this, t, e); - }), - (Array.prototype.orderByDescending = function (t, e) { - return (function (t, e, n) { - return ( - t.sort(function (t, i) { - var o = e(t), - r = e(i); - return n ? -n(o, r) : o < r ? 1 : -1; - }), - t - ); - })(this, t, e); - }), - (Array.prototype.groupBy = function (t) { - return (function (t, e) { - if ("function" == typeof t.reduce) { - var n = []; - return t.reduce(function (i, o, r) { - var s = JSON.stringify(e.call(arguments[1], o, r, t)), - a = n.findIndex(function (t) { - return t === s; - }); - return ( - a < 0 && (a = n.push(s) - 1), i[a] || (i[a] = []), i[a].push(o), i - ); - }, []); - } - for ( - var i = [], - o = [], - r = function (n, r) { - var a = JSON.stringify(e.call(s[1], t[n], n, t)), - h = o.findIndex(function (t) { - return t === a; - }); - h < 0 && (h = o.push(a) - 1), i[h] || (i[h] = []), i[h].push(t[n]); - }, - s = arguments, - a = 0, - h = t.length; - a < h; - a++ - ) - r(a); - return i; - })(this, t); - }), - (Array.prototype.sum = function (t) { - return (function (t, e) { - for (var n, i = 0, o = t.length; i < o; i++) - 0 == i - ? (n = e ? e.call(arguments[2], t[i], i, t) : t[i]) - : (n += e ? e.call(arguments[2], t[i], i, t) : t[i]); - return n; - })(this, t); - }); -var DirtyType, - ComponentTransform, - PriorityQueueNode = (function () { - return function () { - (this.priority = 0), (this.insertionIndex = 0), (this.queueIndex = 0); - }; - })(), - AStarPathfinder = (function () { - function t() {} - return ( - (t.search = function (t, e, n) { - var i = this, - o = !1, - r = new Map(); - r.set(e, e); - var s = new Map(), - a = new PriorityQueue(1e3); - a.enqueue(new AStarNode(e), 0), s.set(e, 0); - for ( - var h = function () { - var e = a.dequeue(); - if (JSON.stringify(e.data) == JSON.stringify(n)) - return (o = !0), "break"; - t.getNeighbors(e.data).forEach(function (o) { - var h = s.get(e.data) + t.cost(e.data, o); - if (!i.hasKey(s, o) || h < s.get(o)) { - s.set(o, h); - var c = h + t.heuristic(o, n); - a.enqueue(new AStarNode(o), c), r.set(o, e.data); - } - }); - }; - a.count > 0; - - ) { - if ("break" === h()) break; - } - return o ? this.recontructPath(r, e, n) : null; - }), - (t.hasKey = function (t, e) { - for (var n, i = t.keys(); !(n = i.next()).done; ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return !0; - return !1; - }), - (t.getKey = function (t, e) { - for ( - var n, i, o = t.keys(), r = t.values(); - (n = o.next()), (i = r.next()), !n.done; - - ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return i.value; - return null; - }), - (t.recontructPath = function (t, e, n) { - var i = [], - o = n; - for (i.push(n); o != e; ) (o = this.getKey(t, o)), i.push(o); - return i.reverse(), i; - }), - t - ); - })(), - AStarNode = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.data = e), n; - } - return __extends(e, t), e; - })(PriorityQueueNode), - AstarGridGraph = (function () { - function t(t, e) { - (this.dirs = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]), - (this.walls = []), - (this.weightedNodes = []), - (this.defaultWeight = 1), - (this.weightedNodeWeight = 5), - (this._neighbors = new Array(4)), - (this._width = t), - (this._height = e); - } - return ( - (t.prototype.isNodeInBounds = function (t) { - return 0 <= t.x && t.x < this._width && 0 <= t.y && t.y < this._height; - }), - (t.prototype.isNodePassable = function (t) { - return !this.walls.firstOrDefault(function (e) { - return JSON.stringify(e) == JSON.stringify(t); - }); - }), - (t.prototype.search = function (t, e) { - return AStarPathfinder.search(this, t, e); - }), - (t.prototype.getNeighbors = function (t) { - var e = this; - return ( - (this._neighbors.length = 0), - this.dirs.forEach(function (n) { - var i = new Point(t.x + n.x, t.y + n.y); - e.isNodeInBounds(i) && e.isNodePassable(i) && e._neighbors.push(i); - }), - this._neighbors - ); - }), - (t.prototype.cost = function (t, e) { - return this.weightedNodes.find(function (t) { - return JSON.stringify(t) == JSON.stringify(e); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }), - (t.prototype.heuristic = function (t, e) { - return Math.abs(t.x - e.x) + Math.abs(t.y - e.y); - }), - t - ); - })(), - PriorityQueue = (function () { - function t(t) { - (this._numNodes = 0), - (this._nodes = new Array(t + 1)), - (this._numNodesEverEnqueued = 0); - } - return ( - (t.prototype.clear = function () { - this._nodes.splice(1, this._numNodes), (this._numNodes = 0); - }), - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._numNodes; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.contains = function (t) { - return this._nodes[t.queueIndex] == t; - }), - (t.prototype.enqueue = function (t, e) { - (t.priority = e), - this._numNodes++, - (this._nodes[this._numNodes] = t), - (t.queueIndex = this._numNodes), - (t.insertionIndex = this._numNodesEverEnqueued++), - this.cascadeUp(this._nodes[this._numNodes]); - }), - (t.prototype.dequeue = function () { - var t = this._nodes[1]; - return this.remove(t), t; - }), - (t.prototype.remove = function (t) { - if (t.queueIndex == this._numNodes) - return (this._nodes[this._numNodes] = null), void this._numNodes--; - var e = this._nodes[this._numNodes]; - this.swap(t, e), - delete this._nodes[this._numNodes], - this._numNodes--, - this.onNodeUpdated(e); - }), - (t.prototype.isValidQueue = function () { - for (var t = 1; t < this._nodes.length; t++) - if (this._nodes[t]) { - var e = 2 * t; - if ( - e < this._nodes.length && - this._nodes[e] && - this.hasHigherPriority(this._nodes[e], this._nodes[t]) - ) - return !1; - var n = e + 1; - if ( - n < this._nodes.length && - this._nodes[n] && - this.hasHigherPriority(this._nodes[n], this._nodes[t]) - ) - return !1; - } - return !0; - }), - (t.prototype.onNodeUpdated = function (t) { - var e = Math.floor(t.queueIndex / 2), - n = this._nodes[e]; - e > 0 && this.hasHigherPriority(t, n) - ? this.cascadeUp(t) - : this.cascadeDown(t); - }), - (t.prototype.cascadeDown = function (t) { - for (var e, n = t.queueIndex; ; ) { - e = t; - var i = 2 * n; - if (i > this._numNodes) { - (t.queueIndex = n), (this._nodes[n] = t); - break; - } - var o = this._nodes[i]; - this.hasHigherPriority(o, e) && (e = o); - var r = i + 1; - if (r <= this._numNodes) { - var s = this._nodes[r]; - this.hasHigherPriority(s, e) && (e = s); - } - if (e == t) { - (t.queueIndex = n), (this._nodes[n] = t); - break; - } - this._nodes[n] = e; - var a = e.queueIndex; - (e.queueIndex = n), (n = a); - } - }), - (t.prototype.cascadeUp = function (t) { - for (var e = Math.floor(t.queueIndex / 2); e >= 1; ) { - var n = this._nodes[e]; - if (this.hasHigherPriority(n, t)) break; - this.swap(t, n), (e = Math.floor(t.queueIndex / 2)); - } - }), - (t.prototype.swap = function (t, e) { - (this._nodes[t.queueIndex] = e), (this._nodes[e.queueIndex] = t); - var n = t.queueIndex; - (t.queueIndex = e.queueIndex), (e.queueIndex = n); - }), - (t.prototype.hasHigherPriority = function (t, e) { - return ( - t.priority < e.priority || - (t.priority == e.priority && t.insertionIndex < e.insertionIndex) - ); - }), - t - ); - })(), - BreadthFirstPathfinder = (function () { - function t() {} - return ( - (t.search = function (t, e, n) { - var i = this, - o = !1, - r = []; - r.unshift(e); - var s = new Map(); - s.set(e, e); - for ( - var a = function () { - var e = r.shift(); - if (JSON.stringify(e) == JSON.stringify(n)) - return (o = !0), "break"; - t.getNeighbors(e).forEach(function (t) { - i.hasKey(s, t) || (r.unshift(t), s.set(t, e)); - }); - }; - r.length > 0; - - ) { - if ("break" === a()) break; - } - return o ? AStarPathfinder.recontructPath(s, e, n) : null; - }), - (t.hasKey = function (t, e) { - for (var n, i = t.keys(); !(n = i.next()).done; ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return !0; - return !1; - }), - t - ); - })(), - UnweightedGraph = (function () { - function t() { - this.edges = new Map(); - } - return ( - (t.prototype.addEdgesForNode = function (t, e) { - return this.edges.set(t, e), this; - }), - (t.prototype.getNeighbors = function (t) { - return this.edges.get(t); - }), - t - ); - })(), - Point = (function () { - return function (t, e) { - (this.x = t || 0), (this.y = e || this.x); - }; - })(), - UnweightedGridGraph = (function () { - function t(e, n, i) { - void 0 === i && (i = !1), - (this.walls = []), - (this._neighbors = new Array(4)), - (this._width = e), - (this._hegiht = n), - (this._dirs = i ? t.COMPASS_DIRS : t.CARDINAL_DIRS); - } - return ( - (t.prototype.isNodeInBounds = function (t) { - return 0 <= t.x && t.x < this._width && 0 <= t.y && t.y < this._hegiht; - }), - (t.prototype.isNodePassable = function (t) { - return !this.walls.firstOrDefault(function (e) { - return JSON.stringify(e) == JSON.stringify(t); - }); - }), - (t.prototype.getNeighbors = function (t) { - var e = this; - return ( - (this._neighbors.length = 0), - this._dirs.forEach(function (n) { - var i = new Point(t.x + n.x, t.y + n.y); - e.isNodeInBounds(i) && e.isNodePassable(i) && e._neighbors.push(i); - }), - this._neighbors - ); - }), - (t.prototype.search = function (t, e) { - return BreadthFirstPathfinder.search(this, t, e); - }), - (t.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, -1), - ]), - (t.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]), - t - ); - })(), - WeightedGridGraph = (function () { - function t(e, n, i) { - void 0 === i && (i = !1), - (this.walls = []), - (this.weightedNodes = []), - (this.defaultWeight = 1), - (this.weightedNodeWeight = 5), - (this._neighbors = new Array(4)), - (this._width = e), - (this._height = n), - (this._dirs = i ? t.COMPASS_DIRS : t.CARDINAL_DIRS); - } - return ( - (t.prototype.isNodeInBounds = function (t) { - return 0 <= t.x && t.x < this._width && 0 <= t.y && t.y < this._height; - }), - (t.prototype.isNodePassable = function (t) { - return !this.walls.firstOrDefault(function (e) { - return JSON.stringify(e) == JSON.stringify(t); - }); - }), - (t.prototype.search = function (t, e) { - return WeightedPathfinder.search(this, t, e); - }), - (t.prototype.getNeighbors = function (t) { - var e = this; - return ( - (this._neighbors.length = 0), - this._dirs.forEach(function (n) { - var i = new Point(t.x + n.x, t.y + n.y); - e.isNodeInBounds(i) && e.isNodePassable(i) && e._neighbors.push(i); - }), - this._neighbors - ); - }), - (t.prototype.cost = function (t, e) { - return this.weightedNodes.find(function (t) { - return JSON.stringify(t) == JSON.stringify(e); - }) - ? this.weightedNodeWeight - : this.defaultWeight; - }), - (t.CARDINAL_DIRS = [ - new Point(1, 0), - new Point(0, -1), - new Point(-1, 0), - new Point(0, 1), - ]), - (t.COMPASS_DIRS = [ - new Point(1, 0), - new Point(1, -1), - new Point(0, -1), - new Point(-1, -1), - new Point(-1, 0), - new Point(-1, 1), - new Point(0, 1), - new Point(1, 1), - ]), - t - ); - })(), - WeightedNode = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.data = e), n; - } - return __extends(e, t), e; - })(PriorityQueueNode), - WeightedPathfinder = (function () { - function t() {} - return ( - (t.search = function (t, e, n) { - var i = this, - o = !1, - r = new Map(); - r.set(e, e); - var s = new Map(), - a = new PriorityQueue(1e3); - a.enqueue(new WeightedNode(e), 0), s.set(e, 0); - for ( - var h = function () { - var e = a.dequeue(); - if (JSON.stringify(e.data) == JSON.stringify(n)) - return (o = !0), "break"; - t.getNeighbors(e.data).forEach(function (n) { - var o = s.get(e.data) + t.cost(e.data, n); - if (!i.hasKey(s, n) || o < s.get(n)) { - s.set(n, o); - var h = o; - a.enqueue(new WeightedNode(n), h), r.set(n, e.data); - } - }); - }; - a.count > 0; - - ) { - if ("break" === h()) break; - } - return o ? this.recontructPath(r, e, n) : null; - }), - (t.hasKey = function (t, e) { - for (var n, i = t.keys(); !(n = i.next()).done; ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return !0; - return !1; - }), - (t.getKey = function (t, e) { - for ( - var n, i, o = t.keys(), r = t.values(); - (n = o.next()), (i = r.next()), !n.done; - - ) - if (JSON.stringify(n.value) == JSON.stringify(e)) return i.value; - return null; - }), - (t.recontructPath = function (t, e, n) { - var i = [], - o = n; - for (i.push(n); o != e; ) (o = this.getKey(t, o)), i.push(o); - return i.reverse(), i; - }), - t - ); - })(), - DebugDefaults = (function () { - function t() {} - return (t.verletParticle = 14431326), (t.verletConstraintEdge = 4406838), t; - })(), - Component = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return (e._enabled = !0), (e.updateInterval = 1), e; - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "enabled", { - get: function () { - return this.entity - ? this.entity.enabled && this._enabled - : this._enabled; - }, - set: function (t) { - this.setEnabled(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setEnabled = function (t) { - return ( - this._enabled != t && - ((this._enabled = t), - this._enabled ? this.onEnabled() : this.onDisabled()), - this - ); - }), - (e.prototype.initialize = function () {}), - (e.prototype.onAddedToEntity = function () {}), - (e.prototype.onRemovedFromEntity = function () {}), - (e.prototype.onEnabled = function () {}), - (e.prototype.onDisabled = function () {}), - (e.prototype.onEntityTransformChanged = function (t) {}), - (e.prototype.update = function () {}), - (e.prototype.debugRender = function () {}), - (e.prototype.registerComponent = function () { - this.entity.componentBits.set( - ComponentTypeManager.getIndexFor(this), - !1 - ), - this.entity.scene.entityProcessors.onComponentAdded(this.entity); - }), - (e.prototype.deregisterComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)), - this.entity.scene.entityProcessors.onComponentRemoved(this.entity); - }), - e - ); - })(egret.DisplayObjectContainer), - Entity = (function (t) { - function e(n) { - var i = t.call(this) || this; - return ( - (i._position = Vector2.zero), - (i._updateOrder = 0), - (i._enabled = !0), - (i._tag = 0), - (i.name = n), - (i.components = new ComponentList(i)), - (i.id = e._idGenerator++), - (i.componentBits = new BitSet()), - i - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "position", { - get: function () { - return this._position; - }, - set: function (t) { - this._position = t; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "scale", { - get: function () { - return new Vector2(this.scaleX, this.scaleY); - }, - set: function (t) { - (this.scaleX = t.x), (this.scaleY = t.y); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (t) { - this.setEnabled(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setEnabled = function (t) { - return this._enabled != t && (this._enabled = t), this; - }), - Object.defineProperty(e.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (t) { - this.setTag(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "stage", { - get: function () { - return this.scene ? this.scene.stage : null; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (t) { - this.setUpdateOrder(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.roundPosition = function () { - this.position = Vector2Ext.round(this.position); - }), - (e.prototype.setUpdateOrder = function (t) { - if (this._updateOrder != t) - return (this._updateOrder = t), this.scene, this; - }), - (e.prototype.setTag = function (t) { - return ( - this._tag != t && - (this.scene && this.scene.entities.removeFromTagList(this), - (this._tag = t), - this.scene && this.scene.entities.addToTagList(this)), - this - ); - }), - (e.prototype.attachToScene = function (t) { - (this.scene = t), - t.entities.add(this), - this.components.registerAllComponents(); - for (var e = 0; e < this.numChildren; e++) - this.getChildAt(e).entity.attachToScene(t); - }), - (e.prototype.detachFromScene = function () { - this.scene.entities.remove(this), - this.components.deregisterAllComponents(); - for (var t = 0; t < this.numChildren; t++) - this.getChildAt(t).entity.detachFromScene(); - }), - (e.prototype.addComponent = function (t) { - return ( - (t.entity = this), - this.components.add(t), - this.addChild(t), - t.initialize(), - t - ); - }), - (e.prototype.hasComponent = function (t) { - return null != this.components.getComponent(t, !1); - }), - (e.prototype.getOrCreateComponent = function (t) { - var e = this.components.getComponent(t, !0); - return e || (e = this.addComponent(t)), e; - }), - (e.prototype.getComponent = function (t) { - return this.components.getComponent(t, !1); - }), - (e.prototype.getComponents = function (t, e) { - return this.components.getComponents(t, e); - }), - (e.prototype.removeComponentForType = function (t) { - var e = this.getComponent(t); - return !!e && (this.removeComponent(e), !0); - }), - (e.prototype.removeComponent = function (t) { - this.components.remove(t); - }), - (e.prototype.removeAllComponents = function () { - for (var t = 0; t < this.components.count; t++) - this.removeComponent(this.components.buffer[t]); - }), - (e.prototype.update = function () { - this.components.update(); - }), - (e.prototype.onAddedToScene = function () {}), - (e.prototype.onRemovedFromScene = function () { - this._isDestoryed && this.components.removeAllComponents(); - }), - (e.prototype.onTransformChanged = function (t) { - this.components.onEntityTransformChanged(t); - }), - (e.prototype.destroy = function () { - (this._isDestoryed = !0), - this.scene.entities.remove(this), - this.removeChildren(); - for (var t = this.numChildren - 1; t >= 0; t--) { - this.getChildAt(t).entity.destroy(); - } - }), - e - ); - })(egret.DisplayObjectContainer), - Scene = (function (t) { - function e() { - var e = t.call(this) || this; - return ( - (e.enablePostProcessing = !0), - (e._renderers = []), - (e._postProcessors = []), - (e.entityProcessors = new EntityProcessorList()), - (e.renderableComponents = new RenderableComponentList()), - (e.entities = new EntityList(e)), - (e.content = new ContentManager()), - (e.width = SceneManager.stage.stageWidth), - (e.height = SceneManager.stage.stageHeight), - e.addEventListener(egret.Event.ACTIVATE, e.onActive, e), - e.addEventListener(egret.Event.DEACTIVATE, e.onDeactive, e), - e - ); - } - return ( - __extends(e, t), - (e.prototype.createEntity = function (t) { - var e = new Entity(t); - return (e.position = new Vector2(0, 0)), this.addEntity(e); - }), - (e.prototype.addEntity = function (t) { - this.entities.add(t), (t.scene = this), this.addChild(t); - for (var e = 0; e < t.numChildren; e++) - this.addEntity(t.getChildAt(e).entity); - return t; - }), - (e.prototype.destroyAllEntities = function () { - for (var t = 0; t < this.entities.count; t++) - this.entities.buffer[t].destroy(); - }), - (e.prototype.findEntity = function (t) { - return this.entities.findEntity(t); - }), - (e.prototype.addEntityProcessor = function (t) { - return (t.scene = this), this.entityProcessors.add(t), t; - }), - (e.prototype.removeEntityProcessor = function (t) { - this.entityProcessors.remove(t); - }), - (e.prototype.getEntityProcessor = function () { - return this.entityProcessors.getProcessor(); - }), - (e.prototype.addRenderer = function (t) { - return ( - this._renderers.push(t), - this._renderers.sort(), - t.onAddedToScene(this), - t - ); - }), - (e.prototype.getRenderer = function (t) { - for (var e = 0; e < this._renderers.length; e++) - if (this._renderers[e] instanceof t) return this._renderers[e]; - return null; - }), - (e.prototype.removeRenderer = function (t) { - this._renderers.remove(t), t.unload(); - }), - (e.prototype.begin = function () { - SceneManager.sceneTransition - ? SceneManager.stage.addChildAt( - this, - SceneManager.stage.numChildren - 1 - ) - : SceneManager.stage.addChild(this), - 0 == this._renderers.length && - (this.addRenderer(new DefaultRenderer()), - console.warn( - "场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染" - )), - (this.camera = this.createEntity("camera").getOrCreateComponent( - new Camera() - )), - Physics.reset(), - this.entityProcessors && this.entityProcessors.begin(), - this.camera.onSceneSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ), - (this._didSceneBegin = !0), - this.onStart(); - }), - (e.prototype.end = function () { - (this._didSceneBegin = !1), - this.removeEventListener( - egret.Event.DEACTIVATE, - this.onDeactive, - this - ), - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - for (var t = 0; t < this._renderers.length; t++) - this._renderers[t].unload(); - for (t = 0; t < this._postProcessors.length; t++) - this._postProcessors[t].unload(); - this.entities.removeAllEntities(), - this.removeChildren(), - Physics.clear(), - (this.camera = null), - this.content.dispose(), - this.entityProcessors && this.entityProcessors.end(), - this.unload(); - }), - (e.prototype.onStart = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (t) { - return [2]; - }); - }); - }), - (e.prototype.onActive = function () {}), - (e.prototype.onDeactive = function () {}), - (e.prototype.unload = function () {}), - (e.prototype.update = function () { - this.entities.updateLists(), - this.entityProcessors && this.entityProcessors.update(), - this.entities.update(), - this.entityProcessors && this.entityProcessors.lateUpdate(), - this.renderableComponents.updateList(); - }), - (e.prototype.postRender = function () { - var t = 0; - if (this.enablePostProcessing) - for (var e = 0; e < this._postProcessors.length; e++) - if (this._postProcessors[e].enable) { - MathHelper.isEven(t); - t++, this._postProcessors[e].process(); - } - }), - (e.prototype.render = function () { - for (var t = 0; t < this._renderers.length; t++) - this._renderers[t].render(this); - }), - (e.prototype.addPostProcessor = function (t) { - return ( - this._postProcessors.push(t), - this._postProcessors.sort(), - t.onAddedToScene(this), - this._didSceneBegin && - t.onSceneBackBufferSizeChanged( - this.stage.stageWidth, - this.stage.stageHeight - ), - t - ); - }), - e - ); - })(egret.DisplayObjectContainer), - SceneManager = (function () { - function t(e) { - e.addEventListener(egret.Event.ENTER_FRAME, t.update, this), - (t.stage = e), - t.initialize(e); - } - return ( - Object.defineProperty(t, "scene", { - get: function () { - return this._scene; - }, - set: function (t) { - if (!t) throw new Error("场景不能为空"); - null == this._scene - ? ((this._scene = t), this._scene.begin()) - : (this._nextScene = t); - }, - enumerable: !0, - configurable: !0, - }), - (t.initialize = function (t) { - Input.initialize(t); - }), - (t.update = function () { - if ((Time.update(egret.getTimer()), t._scene)) { - for (var e = GlobalManager.globalManagers.length - 1; e >= 0; e--) - GlobalManager.globalManagers[e].enabled && - GlobalManager.globalManagers[e].update(); - if ( - ((t.sceneTransition && - (!t.sceneTransition || - (t.sceneTransition.loadsNewScene && - !t.sceneTransition.isNewSceneLoaded))) || - t._scene.update(), - t._nextScene) - ) { - t._scene.end(); - for (e = 0; e < t._scene.entities.buffer.length; e++) { - t._scene.entities.buffer[e].destroy(); - } - (t._scene = t._nextScene), (t._nextScene = null), t._scene.begin(); - } - } - t.render(); - }), - (t.render = function () { - this.sceneTransition - ? (this.sceneTransition.preRender(), - this._scene && !this.sceneTransition.hasPreviousSceneRender - ? (this._scene.render(), - this._scene.postRender(), - this.sceneTransition.onBeginTransition()) - : this.sceneTransition && - (this._scene && - this.sceneTransition.isNewSceneLoaded && - (this._scene.render(), this._scene.postRender()), - this.sceneTransition.render())) - : this._scene && (this._scene.render(), this._scene.postRender()); - }), - (t.startSceneTransition = function (t) { - if (!this.sceneTransition) return (this.sceneTransition = t), t; - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - }), - t - ); - })(); -!(function (t) { - (t[(t.clean = 0)] = "clean"), - (t[(t.positionDirty = 1)] = "positionDirty"), - (t[(t.scaleDirty = 2)] = "scaleDirty"), - (t[(t.rotationDirty = 3)] = "rotationDirty"); -})(DirtyType || (DirtyType = {})), - (function (t) { - (t[(t.position = 0)] = "position"), - (t[(t.scale = 1)] = "scale"), - (t[(t.rotation = 2)] = "rotation"); - })(ComponentTransform || (ComponentTransform = {})); -var CameraStyle, - Transform = (function () { - function t(t) { - (this._localRotation = 0), - (this._worldTransform = Matrix2D.identity), - (this._worldToLocalTransform = Matrix2D.identity), - (this._worldInverseTransform = Matrix2D.identity), - (this._rotation = 0), - (this.entity = t), - (this._scale = this._localScale = Vector2.one), - (this._children = []); - } - return ( - Object.defineProperty(t.prototype, "childCount", { - get: function () { - return this._children.length; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.getChild = function (t) { - return this._children[t]; - }), - Object.defineProperty(t.prototype, "worldInverseTransform", { - get: function () { - return ( - this.updateTransform(), - this._worldInverseDirty && - ((this._worldInverseTransform = Matrix2D.invert( - this._worldTransform, - this._worldInverseTransform - )), - (this._worldInverseDirty = !1)), - this._worldInverseTransform - ); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localToWorldTransform", { - get: function () { - return this.updateTransform(), this._worldTransform; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "worldToLocalTransform", { - get: function () { - return ( - this._worldToLocalDirty && - (this.parent - ? (this.parent.updateTransform(), - (this._worldToLocalTransform = Matrix2D.invert( - this.parent._worldTransform, - this._worldToLocalTransform - ))) - : (this._worldInverseTransform = new Matrix2D()), - (this._worldToLocalDirty = !1)), - this._worldToLocalTransform - ); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "parent", { - get: function () { - return this._parent; - }, - set: function (t) { - this.setParent(t); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.setParent = function (t) { - return this._parent == t - ? this - : (this._parent && this._parent._children.remove(this), - t && t._children.push(this), - (this._parent = t), - this); - }), - Object.defineProperty(t.prototype, "rotation", { - get: function () { - return this.updateTransform(), this._rotation; - }, - set: function (t) { - this.setRotation(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localRotation", { - get: function () { - return this.updateTransform(), this._localRotation; - }, - set: function (t) { - this.setLocalRotation(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "position", { - get: function () { - return ( - this.updateTransform(), - this._positionDirty && - (this.parent - ? (this.parent.updateTransform(), - (this._position = Vector2Ext.transformR( - this._localPosition, - this.parent._worldTransform - ))) - : (this._position = this._localPosition), - (this._positionDirty = !1)), - this._position - ); - }, - set: function (t) { - this.setPosition(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localPosition", { - get: function () { - return this.updateTransform(), this._localPosition; - }, - set: function (t) { - this.setLocalPosition(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "scale", { - get: function () { - return this.updateTransform(), this._scale; - }, - set: function (t) { - this.setScale(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localScale", { - get: function () { - return this.updateTransform(), this._localScale; - }, - set: function (t) { - this.setLocalScale(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._rotation); - }, - set: function (t) { - this.setRotation(MathHelper.toRadians(t)); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "localRotationDegrees", { - get: function () { - return MathHelper.toDegrees(this._localRotation); - }, - set: function (t) { - this.localRotation = MathHelper.toRadians(t); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.setLocalScale = function (t) { - return ( - (this._localScale = t), - (this._localDirty = this._positionDirty = this._localScaleDirty = !0), - this.setDirty(DirtyType.scaleDirty), - this - ); - }), - (t.prototype.setScale = function (t) { - return ( - (this._scale = t), - this.parent - ? (this.localScale = Vector2.divide(t, this.parent._scale)) - : (this.localScale = t), - this - ); - }), - (t.prototype.setLocalRotationDegrees = function (t) { - return this.setLocalRotation(MathHelper.toRadians(t)); - }), - (t.prototype.setLocalRotation = function (t) { - return ( - (this._localRotation = t), - (this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = !0), - this.setDirty(DirtyType.rotationDirty), - this - ); - }), - (t.prototype.setRotation = function (t) { - return ( - (this._rotation = t), - this.parent - ? (this.localRotation = this.parent.rotation + t) - : (this.localRotation = t), - this - ); - }), - (t.prototype.setRotationDegrees = function (t) { - return this.setRotation(MathHelper.toRadians(t)); - }), - (t.prototype.setLocalPosition = function (t) { - return t == this._localPosition - ? this - : ((this._localPosition = t), - (this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = !0), - this.setDirty(DirtyType.positionDirty), - this); - }), - (t.prototype.setPosition = function (t) { - return t == this._position - ? this - : ((this._position = t), - this.parent - ? (this.localPosition = Vector2.transform( - this._position, - this._worldToLocalTransform - )) - : (this.localPosition = t), - (this._positionDirty = !1), - this); - }), - (t.prototype.setDirty = function (t) { - if (0 == (this._hierachyDirty & t)) { - switch (((this._hierachyDirty |= t), t)) { - case DirtyType.positionDirty: - this.entity.onTransformChanged(ComponentTransform.position); - break; - case DirtyType.rotationDirty: - this.entity.onTransformChanged(ComponentTransform.rotation); - break; - case DirtyType.scaleDirty: - this.entity.onTransformChanged(ComponentTransform.scale); - } - null == this._children && (this._children = []); - for (var e = 0; e < this._children.length; e++) - this._children[e].setDirty(t); - } - }), - (t.prototype.roundPosition = function () { - this.position = this._position.round(); - }), - (t.prototype.updateTransform = function () { - this._hierachyDirty != DirtyType.clean && - (this.parent && this.parent.updateTransform(), - this._localDirty && - (this._localPositionDirty && - ((this._translationMatrix = Matrix2D.createTranslation( - this._localPosition.x, - this._localPosition.y - )), - (this._localPositionDirty = !1)), - this._localRotationDirty && - ((this._rotationMatrix = Matrix2D.createRotation( - this._localRotation - )), - (this._localRotationDirty = !1)), - this._localScaleDirty && - ((this._scaleMatrix = Matrix2D.createScale( - this._localScale.x, - this._localScale.y - )), - (this._localScaleDirty = !1)), - (this._localTransform = Matrix2D.multiply( - this._scaleMatrix, - this._rotationMatrix - )), - (this._localTransform = Matrix2D.multiply( - this._localTransform, - this._translationMatrix - )), - this.parent || - ((this._worldTransform = this._localTransform), - (this._rotation = this._localRotation), - (this._scale = this._localScale), - (this._worldInverseDirty = !0)), - (this._localDirty = !1)), - this.parent && - ((this._worldTransform = Matrix2D.multiply( - this._localTransform, - this.parent._worldTransform - )), - (this._rotation = this._localRotation + this.parent._rotation), - (this._scale = Vector2.multiply( - this.parent._scale, - this._localScale - )), - (this._worldInverseDirty = !0)), - (this._worldToLocalDirty = !0), - (this._positionDirty = !0), - (this._hierachyDirty = DirtyType.clean)); - }), - t - ); - })(), - Camera = (function (t) { - function e() { - var e = t.call(this) || this; - return ( - (e._origin = Vector2.zero), - (e._minimumZoom = 0.3), - (e._maximumZoom = 3), - (e.followLerp = 0.1), - (e.deadzone = new Rectangle()), - (e.focusOffset = new Vector2()), - (e.mapLockEnabled = !1), - (e.mapSize = new Vector2()), - (e._worldSpaceDeadZone = new Rectangle()), - (e._desiredPositionDelta = new Vector2()), - (e.cameraStyle = CameraStyle.lockOn), - (e.width = SceneManager.stage.stageWidth), - (e.height = SceneManager.stage.stageHeight), - e.setZoom(0), - e - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "zoom", { - get: function () { - return 0 == this._zoom - ? 1 - : this._zoom < 1 - ? MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0) - : MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); - }, - set: function (t) { - this.setZoom(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "minimumZoom", { - get: function () { - return this._minimumZoom; - }, - set: function (t) { - this.setMinimumZoom(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "maximumZoom", { - get: function () { - return this._maximumZoom; - }, - set: function (t) { - this.setMaximumZoom(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (t) { - this._origin != t && (this._origin = t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "position", { - get: function () { - return this.entity.position; - }, - set: function (t) { - this.entity.position = t; - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.onSceneSizeChanged = function (t, e) { - var n = this._origin; - (this.origin = new Vector2(t / 2, e / 2)), - (this.entity.position = Vector2.add( - this.entity.position, - Vector2.subtract(this._origin, n) - )); - }), - (e.prototype.setMinimumZoom = function (t) { - return ( - this._zoom < t && (this._zoom = this.minimumZoom), - (this._minimumZoom = t), - this - ); - }), - (e.prototype.setMaximumZoom = function (t) { - return ( - this._zoom > t && (this._zoom = t), (this._maximumZoom = t), this - ); - }), - (e.prototype.setZoom = function (t) { - var e = MathHelper.clamp(t, -1, 1); - return ( - (this._zoom = - 0 == e - ? 1 - : e < 0 - ? MathHelper.map(e, -1, 0, this._minimumZoom, 1) - : MathHelper.map(e, 0, 1, 1, this._maximumZoom)), - (SceneManager.scene.scaleX = this._zoom), - (SceneManager.scene.scaleY = this._zoom), - this - ); - }), - (e.prototype.setRotation = function (t) { - return (SceneManager.scene.rotation = t), this; - }), - (e.prototype.setPosition = function (t) { - return (this.entity.position = t), this; - }), - (e.prototype.follow = function (t, e) { - void 0 === e && (e = CameraStyle.cameraWindow), - (this.targetEntity = t), - (this.cameraStyle = e); - var n = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ); - switch (this.cameraStyle) { - case CameraStyle.cameraWindow: - var i = n.width / 6, - o = n.height / 3; - this.deadzone = new Rectangle( - (n.width - i) / 2, - (n.height - o) / 2, - i, - o - ); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle(n.width / 2, n.height / 2, 10, 10); - } - }), - (e.prototype.update = function () { - var t = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - e = Vector2.multiply( - new Vector2(t.width, t.height), - new Vector2(0.5) - ); - (this._worldSpaceDeadZone.x = - this.position.x - e.x + this.deadzone.x + this.focusOffset.x), - (this._worldSpaceDeadZone.y = - this.position.y - e.y + this.deadzone.y + this.focusOffset.y), - (this._worldSpaceDeadZone.width = this.deadzone.width), - (this._worldSpaceDeadZone.height = this.deadzone.height), - this.targetEntity && this.updateFollow(), - (this.position = Vector2.lerp( - this.position, - Vector2.add(this.position, this._desiredPositionDelta), - this.followLerp - )), - this.entity.roundPosition(), - this.mapLockEnabled && - ((this.position = this.clampToMapSize(this.position)), - this.entity.roundPosition()); - }), - (e.prototype.clampToMapSize = function (t) { - var e = new Rectangle( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - n = Vector2.multiply( - new Vector2(e.width, e.height), - new Vector2(0.5) - ), - i = new Vector2(this.mapSize.x - n.x, this.mapSize.y - n.y); - return Vector2.clamp(t, n, i); - }), - (e.prototype.updateFollow = function () { - if ( - ((this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0), - this.cameraStyle == CameraStyle.lockOn) - ) { - var t = this.targetEntity.position.x, - e = this.targetEntity.position.y; - this._worldSpaceDeadZone.x > t - ? (this._desiredPositionDelta.x = t - this._worldSpaceDeadZone.x) - : this._worldSpaceDeadZone.x < t && - (this._desiredPositionDelta.x = t - this._worldSpaceDeadZone.x), - this._worldSpaceDeadZone.y < e - ? (this._desiredPositionDelta.y = e - this._worldSpaceDeadZone.y) - : this._worldSpaceDeadZone.y > e && - (this._desiredPositionDelta.y = e - this._worldSpaceDeadZone.y); - } else { - if ( - !this._targetCollider && - ((this._targetCollider = this.targetEntity.getComponent(Collider)), - !this._targetCollider) - ) - return; - var n = this.targetEntity.getComponent(Collider).bounds; - this._worldSpaceDeadZone.containsRect(n) || - (this._worldSpaceDeadZone.left > n.left - ? (this._desiredPositionDelta.x = - n.left - this._worldSpaceDeadZone.left) - : this._worldSpaceDeadZone.right < n.right && - (this._desiredPositionDelta.x = - n.right - this._worldSpaceDeadZone.right), - this._worldSpaceDeadZone.bottom < n.bottom - ? (this._desiredPositionDelta.y = - n.bottom - this._worldSpaceDeadZone.bottom) - : this._worldSpaceDeadZone.top > n.top && - (this._desiredPositionDelta.y = - n.top - this._worldSpaceDeadZone.top)); - } - }), - e - ); - })(Component); -!(function (t) { - (t[(t.lockOn = 0)] = "lockOn"), (t[(t.cameraWindow = 1)] = "cameraWindow"); -})(CameraStyle || (CameraStyle = {})); -var PointSectors, - ComponentPool = (function () { - function t(t) { - (this._type = t), (this._cache = []); - } - return ( - (t.prototype.obtain = function () { - try { - return this._cache.length > 0 - ? this._cache.shift() - : new this._type(); - } catch (t) { - throw new Error(this._type + t); - } - }), - (t.prototype.free = function (t) { - t.reset(), this._cache.push(t); - }), - t - ); - })(), - Mesh = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.initialize = function () {}), - (e.prototype.setVertPosition = function (t) { - (!this._verts || this._verts.length != t.length) && - (this._verts = new Array(t.length)); - for (var e = 0; e < this._verts.length; e++) - this._verts[e] = new VertexPosition(t[e]); - return this; - }), - (e.prototype.setTriangles = function (t) { - return ( - (this._primitiveCount = t.length / 3), (this._triangles = t), this - ); - }), - (e.prototype.recalculateBounds = function () { - this._topLeftVertPosition = new Vector2( - Number.MAX_VALUE, - Number.MAX_VALUE - ); - for ( - var t = new Vector2(Number.MIN_VALUE, Number.MIN_VALUE), e = 0; - e < this._verts.length; - e++ - ) - (this._topLeftVertPosition.x = Math.min( - this._topLeftVertPosition.x, - this._verts[e].position.x - )), - (this._topLeftVertPosition.y = Math.min( - this._topLeftVertPosition.y, - this._verts[e].position.y - )), - (t.x = Math.max(t.x, this._verts[e].position.x)), - (t.y = Math.max(t.y, this._verts[e].position.y)); - return ( - (this._width = t.x - this._topLeftVertPosition.x), - (this._height = t.y - this._topLeftVertPosition.y), - this - ); - }), - (e.prototype.render = function () {}), - e - ); - })(Component), - VertexPosition = (function () { - return function (t) { - this.position = t; - }; - })(), - PolygonMesh = (function (t) { - function e(e, n) { - void 0 === n && (n = !0); - var i = t.call(this) || this, - o = new Triangulator(); - return ( - o.triangulate(e, n), - i.setVertPosition(e), - i.setTriangles(o.triangleIndices), - i.recalculateBounds(), - i - ); - } - return __extends(e, t), e; - })(Mesh), - PooledComponent = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return __extends(e, t), e; - })(Component), - RenderableComponent = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return ( - (e._areBoundsDirty = !0), - (e._bounds = new Rectangle()), - (e._localOffset = Vector2.zero), - (e.color = 0), - e - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "width", { - get: function () { - return this.getWidth(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "height", { - get: function () { - return this.getHeight(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "isVisible", { - get: function () { - return this._isVisible; - }, - set: function (t) { - (this._isVisible = t), - this._isVisible ? this.onBecameVisible() : this.onBecameInvisible(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "bounds", { - get: function () { - return new Rectangle( - this.getBounds().x, - this.getBounds().y, - this.getBounds().width, - this.getBounds().height - ); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.getWidth = function () { - return this.bounds.width; - }), - (e.prototype.getHeight = function () { - return this.bounds.height; - }), - (e.prototype.onBecameVisible = function () {}), - (e.prototype.onBecameInvisible = function () {}), - (e.prototype.isVisibleFromCamera = function (t) { - return ( - (this.isVisible = t.getBounds().intersects(this.getBounds())), - this.isVisible - ); - }), - (e.prototype.onEntityTransformChanged = function (t) { - this._areBoundsDirty = !0; - }), - e - ); - })(PooledComponent), - ScreenSpaceCamera = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return __extends(e, t), (e.prototype.updateMatrixes = function () {}), e; - })(Camera), - Sprite = (function () { - return function (t, e, n) { - void 0 === e && - (e = new Rectangle(0, 0, t.textureWidth, t.textureHeight)), - void 0 === n && (n = e.getHalfSize()), - (this.uvs = new Rectangle()), - (this.texture2D = t), - (this.sourceRect = e), - (this.center = new Vector2(0.5 * e.width, 0.5 * e.height)), - (this.origin = n); - var i = 1 / t.textureWidth, - o = 1 / t.textureHeight; - (this.uvs.x = e.x * i), - (this.uvs.y = e.y * o), - (this.uvs.width = e.width * i), - (this.uvs.height = e.height * o); - }; - })(), - SpriteRenderer = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (t) { - this.setOrigin(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setOrigin = function (t) { - return this._origin != t && (this._origin = t), this; - }), - (e.prototype.setSprite = function (t) { - return ( - this.removeChildren(), - (this._sprite = t), - this._sprite && (this._origin = this._sprite.origin), - (this._bitmap = new egret.Bitmap(t.texture2D)), - this.addChild(this._bitmap), - this - ); - }), - (e.prototype.setColor = function (t) { - var e = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - (e[0] = Math.floor(t / 256 / 256) / 255), - (e[6] = Math.floor((t / 256) % 256) / 255), - (e[12] = (t % 256) / 255); - var n = new egret.ColorMatrixFilter(e); - return (this.filters = [n]), this; - }), - (e.prototype.isVisibleFromCamera = function (t) { - return ( - (this.isVisible = new Rectangle( - 0, - 0, - this.stage.stageWidth, - this.stage.stageHeight - ).intersects(this.bounds)), - (this.visible = this.isVisible), - this.isVisible - ); - }), - (e.prototype.render = function (t) { - (this.x = - this.entity.position.x - this.origin.x - t.position.x + t.origin.x), - (this.y = - this.entity.position.y - this.origin.y - t.position.y + t.origin.y); - }), - (e.prototype.onRemovedFromEntity = function () { - this.parent && this.parent.removeChild(this); - }), - (e.prototype.reset = function () {}), - e - ); - })(RenderableComponent), - Mover = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onAddedToEntity = function () { - this._triggerHelper = new ColliderTriggerHelper(this.entity); - }), - (e.prototype.calculateMovement = function (t) { - var e = new CollisionResult(); - if (!this.entity.getComponent(Collider) || !this._triggerHelper) - return null; - for ( - var n = this.entity.getComponents(Collider), i = 0; - i < n.length; - i++ - ) { - var o = n[i]; - if (!o.isTrigger) { - var r = o.bounds; - (r.x += t.x), (r.y += t.y); - for ( - var s = Physics.boxcastBroadphaseExcludingSelf( - o, - r, - o.collidesWithLayers - ), - a = 0; - a < s.length; - a++ - ) { - var h = s[a]; - if (!h.isTrigger) { - var c = o.collidesWith(h, t); - c && - ((t = Vector2.subtract(t, c.minimumTranslationVector)), - c.collider && (e = c)); - } - } - } - } - return ListPool.free(n), e; - }), - (e.prototype.applyMovement = function (t) { - (this.entity.position = Vector2.add(this.entity.position, t)), - this._triggerHelper && this._triggerHelper.update(); - }), - (e.prototype.move = function (t) { - var e = this.calculateMovement(t); - return this.applyMovement(t), e; - }), - e - ); - })(Component), - Collider = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return ( - (e.physicsLayer = 1), - (e.shouldColliderScaleAndRotationWithTransform = !0), - (e.collidesWithLayers = Physics.allLayers), - (e._isPositionDirty = !0), - (e._isRotationDirty = !0), - (e._localOffset = new Vector2(0, 0)), - e - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "bounds", { - get: function () { - return ( - (this._isPositionDirty || this._isRotationDirty) && - (this.shape.recalculateBounds(this), - (this._isPositionDirty = this._isRotationDirty = !1)), - this.shape.bounds - ); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "localOffset", { - get: function () { - return this._localOffset; - }, - set: function (t) { - this.setLocalOffset(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setLocalOffset = function (t) { - this._localOffset != t && - (this.unregisterColliderWithPhysicsSystem(), - (this._localOffset = t), - (this._localOffsetLength = this._localOffset.length()), - (this._isPositionDirty = !0), - this.registerColliderWithPhysicsSystem()); - }), - (e.prototype.registerColliderWithPhysicsSystem = function () { - this._isParentEntityAddedToScene && - !this._isColliderRegistered && - (Physics.addCollider(this), (this._isColliderRegistered = !0)); - }), - (e.prototype.unregisterColliderWithPhysicsSystem = function () { - this._isParentEntityAddedToScene && - this._isColliderRegistered && - Physics.removeCollider(this), - (this._isColliderRegistered = !1); - }), - (e.prototype.overlaps = function (t) { - return this.shape.overlaps(t.shape); - }), - (e.prototype.collidesWith = function (t, e) { - var n = this.shape.position; - this.shape.position = Vector2.add(this.shape.position, e); - var i = this.shape.collidesWithShape(t.shape); - return i && (i.collider = t), (this.shape.position = n), i; - }), - (e.prototype.onAddedToEntity = function () { - if (this._colliderRequiresAutoSizing) { - this instanceof BoxCollider || - console.error( - "Only box and circle colliders can be created automatically" - ); - var t = this.entity.getComponent(RenderableComponent); - if (t) { - var e = t.bounds, - n = e.width / this.entity.scale.x, - i = e.height / this.entity.scale.y; - if (this instanceof BoxCollider) { - (this.width = n), - (this.height = i), - (this.localOffset = Vector2.subtract( - e.center, - this.entity.position - )); - } - } - } - (this._isParentEntityAddedToScene = !0), - this.registerColliderWithPhysicsSystem(); - }), - (e.prototype.onRemovedFromEntity = function () { - this.unregisterColliderWithPhysicsSystem(), - (this._isParentEntityAddedToScene = !1); - }), - (e.prototype.onEntityTransformChanged = function (t) { - switch (t) { - case ComponentTransform.position: - case ComponentTransform.scale: - this._isPositionDirty = !0; - break; - case ComponentTransform.rotation: - this._isRotationDirty = !0; - } - this._isColliderRegistered && Physics.updateCollider(this); - }), - (e.prototype.onEnabled = function () { - this.registerColliderWithPhysicsSystem(), - (this._isPositionDirty = this._isRotationDirty = !0); - }), - (e.prototype.onDisabled = function () { - this.unregisterColliderWithPhysicsSystem(); - }), - e - ); - })(Component), - BoxCollider = (function (t) { - function e() { - var e = t.call(this) || this; - return (e.shape = new Box(1, 1)), (e._colliderRequiresAutoSizing = !0), e; - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "width", { - get: function () { - return this.shape.width; - }, - set: function (t) { - this.setWidth(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setWidth = function (t) { - this._colliderRequiresAutoSizing = !1; - var e = this.shape; - return ( - t != e.width && - (e.updateBox(t, e.height), - (this._isPositionDirty = !0), - this.entity && - this._isParentEntityAddedToScene && - Physics.updateCollider(this)), - this - ); - }), - Object.defineProperty(e.prototype, "height", { - get: function () { - return this.shape.height; - }, - set: function (t) { - this.setHeight(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.setHeight = function (t) { - this._colliderRequiresAutoSizing = !1; - var e = this.shape; - t != e.height && - (e.updateBox(e.width, t), - (this._isPositionDirty = !0), - this.entity && - this._isParentEntityAddedToScene && - Physics.updateCollider(this)); - }), - (e.prototype.setSize = function (t, e) { - this._colliderRequiresAutoSizing = !1; - var n = this.shape; - return ( - (t == n.width && e == n.height) || - (n.updateBox(t, e), - (this._isPositionDirty = !0), - this.entity && - this._isParentEntityAddedToScene && - Physics.updateCollider(this)), - this - ); - }), - e - ); - })(Collider), - EntitySystem = (function () { - function t(t) { - (this._entities = []), (this._matcher = t || Matcher.empty()); - } - return ( - Object.defineProperty(t.prototype, "matcher", { - get: function () { - return this._matcher; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "scene", { - get: function () { - return this._scene; - }, - set: function (t) { - (this._scene = t), (this._entities = []); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.initialize = function () {}), - (t.prototype.onChanged = function (t) { - var e = this._entities.contains(t), - n = this._matcher.IsIntersted(t); - n && !e ? this.add(t) : !n && e && this.remove(t); - }), - (t.prototype.add = function (t) { - this._entities.push(t), this.onAdded(t); - }), - (t.prototype.onAdded = function (t) {}), - (t.prototype.remove = function (t) { - this._entities.remove(t), this.onRemoved(t); - }), - (t.prototype.onRemoved = function (t) {}), - (t.prototype.update = function () { - this.begin(), this.process(this._entities); - }), - (t.prototype.lateUpdate = function () { - this.lateProcess(this._entities), this.end(); - }), - (t.prototype.begin = function () {}), - (t.prototype.process = function (t) {}), - (t.prototype.lateProcess = function (t) {}), - (t.prototype.end = function () {}), - t - ); - })(), - EntityProcessingSystem = (function (t) { - function e(e) { - return t.call(this, e) || this; - } - return ( - __extends(e, t), - (e.prototype.lateProcessEntity = function (t) {}), - (e.prototype.process = function (t) { - var e = this; - t.forEach(function (t) { - return e.processEntity(t); - }); - }), - (e.prototype.lateProcess = function (t) { - var e = this; - t.forEach(function (t) { - return e.lateProcessEntity(t); - }); - }), - e - ); - })(EntitySystem), - PassiveSystem = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onChanged = function (t) {}), - (e.prototype.process = function (t) { - this.begin(), this.end(); - }), - e - ); - })(EntitySystem), - ProcessingSystem = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onChanged = function (t) {}), - (e.prototype.process = function (t) { - this.begin(), this.processSystem(), this.end(); - }), - e - ); - })(EntitySystem), - BitSet = (function () { - function t(e) { - void 0 === e && (e = 64); - var n = e >> 6; - 0 != (e & t.LONG_MASK) && n++, (this._bits = new Array(n)); - } - return ( - (t.prototype.and = function (t) { - for ( - var e, n = Math.min(this._bits.length, t._bits.length), i = 0; - i < n; - ++i - ) - this._bits[i] &= t._bits[i]; - for (; e < this._bits.length; ) this._bits[e++] = 0; - }), - (t.prototype.andNot = function (t) { - for (var e = Math.min(this._bits.length, t._bits.length); --e >= 0; ) - this._bits[e] &= ~t._bits[e]; - }), - (t.prototype.cardinality = function () { - for (var t = 0, e = this._bits.length - 1; e >= 0; e--) { - var n = this._bits[e]; - if (0 != n) - if (-1 != n) { - var i = - ((n = - (((n = - ((n >> 1) & 0x5555555555555400) + - (0x5555555555555400 & n)) >> - 2) & - 0x3333333333333400) + - (0x3333333333333400 & n)) >> - 32) + - n; - t += - (((i = - (((i = ((i >> 4) & 252645135) + (252645135 & i)) >> 8) & - 16711935) + - (16711935 & i)) >> - 16) & - 65535) + - (65535 & i); - } else t += 64; - } - return t; - }), - (t.prototype.clear = function (t) { - if (null != t) { - var e = t >> 6; - this.ensure(e), (this._bits[e] &= ~(1 << t)); - } else for (var n = 0; n < this._bits.length; n++) this._bits[n] = 0; - }), - (t.prototype.ensure = function (t) { - if (t >= this._bits.length) { - var e = new Number[t + 1](); - (e = this._bits.copyWithin(0, 0, this._bits.length)), - (this._bits = e); - } - }), - (t.prototype.get = function (t) { - var e = t >> 6; - return !(e >= this._bits.length) && 0 != (this._bits[e] & (1 << t)); - }), - (t.prototype.intersects = function (t) { - for (var e = Math.min(this._bits.length, t._bits.length); --e >= 0; ) - if (0 != (this._bits[e] & t._bits[e])) return !0; - return !1; - }), - (t.prototype.isEmpty = function () { - for (var t = this._bits.length - 1; t >= 0; t--) - if (this._bits[t]) return !1; - return !0; - }), - (t.prototype.nextSetBit = function (t) { - for (var e = t >> 6, n = 1 << t; e < this._bits.length; ) { - var i = this._bits[e]; - do { - if (0 != (i & n)) return t; - (n <<= 1), t++; - } while (0 != n); - (n = 1), e++; - } - return -1; - }), - (t.prototype.set = function (t, e) { - if ((void 0 === e && (e = !0), e)) { - var n = t >> 6; - this.ensure(n), (this._bits[n] |= 1 << t); - } else this.clear(t); - }), - (t.LONG_MASK = 63), - t - ); - })(), - ComponentList = (function () { - function t(t) { - (this._components = []), - (this._componentsToAdd = []), - (this._componentsToRemove = []), - (this._tempBufferList = []), - (this._entity = t); - } - return ( - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.add = function (t) { - this._componentsToAdd.push(t); - }), - (t.prototype.remove = function (t) { - this._componentsToAdd.contains(t) - ? this._componentsToAdd.remove(t) - : this._componentsToRemove.push(t); - }), - (t.prototype.removeAllComponents = function () { - for (var t = 0; t < this._components.length; t++) - this.handleRemove(this._components[t]); - (this._components.length = 0), - (this._componentsToAdd.length = 0), - (this._componentsToRemove.length = 0); - }), - (t.prototype.deregisterAllComponents = function () { - for (var t = 0; t < this._components.length; t++) { - var e = this._components[t]; - e instanceof RenderableComponent && - this._entity.scene.renderableComponents.remove(e), - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(e), - !1 - ), - this._entity.scene.entityProcessors.onComponentRemoved( - this._entity - ); - } - }), - (t.prototype.registerAllComponents = function () { - for (var t = 0; t < this._components.length; t++) { - var e = this._components[t]; - e instanceof RenderableComponent && - this._entity.scene.renderableComponents.add(e), - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(e)), - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - } - }), - (t.prototype.updateLists = function () { - if (this._componentsToRemove.length > 0) { - for (var t = 0; t < this._componentsToRemove.length; t++) - this.handleRemove(this._componentsToRemove[t]), - this._components.remove(this._componentsToRemove[t]); - this._componentsToRemove.length = 0; - } - if (this._componentsToAdd.length > 0) { - t = 0; - for (var e = this._componentsToAdd.length; t < e; t++) { - (n = this._componentsToAdd[t]) instanceof RenderableComponent && - this._entity.scene.renderableComponents.add(n), - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(n) - ), - this._entity.scene.entityProcessors.onComponentAdded( - this._entity - ), - this._components.push(n), - this._tempBufferList.push(n); - } - this._componentsToAdd.length = 0; - for (t = 0; t < this._tempBufferList.length; t++) { - var n; - (n = this._tempBufferList[t]).onAddedToEntity(), - n.enabled && n.onEnabled(); - } - this._tempBufferList.length = 0; - } - }), - (t.prototype.handleRemove = function (t) { - t instanceof RenderableComponent && - this._entity.scene.renderableComponents.remove(t), - this._entity.componentBits.set( - ComponentTypeManager.getIndexFor(t), - !1 - ), - this._entity.scene.entityProcessors.onComponentRemoved(this._entity), - t.onRemovedFromEntity(), - (t.entity = null); - }), - (t.prototype.getComponent = function (t, e) { - for (var n = 0; n < this._components.length; n++) { - if ((i = this._components[n]) instanceof t) return i; - } - if (!e) - for (n = 0; n < this._componentsToAdd.length; n++) { - var i; - if ((i = this._componentsToAdd[n]) instanceof t) return i; - } - return null; - }), - (t.prototype.getComponents = function (t, e) { - e || (e = []); - for (var n = 0; n < this._components.length; n++) { - var i = this._components[n]; - "string" == typeof t - ? egret.is(i, t) && e.push(i) - : i instanceof t && e.push(i); - } - for (n = 0; n < this._componentsToAdd.length; n++) { - i = this._componentsToAdd[n]; - "string" == typeof t - ? egret.is(i, t) && e.push(i) - : i instanceof t && e.push(i); - } - return e; - }), - (t.prototype.update = function () { - this.updateLists(); - for (var t = 0; t < this._components.length; t++) { - var e = this._components[t]; - !e.enabled || - (1 != e.updateInterval && - Time.frameCount % e.updateInterval != 0) || - e.update(); - } - }), - (t.prototype.onEntityTransformChanged = function (t) { - for (var e = 0; e < this._components.length; e++) - this._components[e].enabled && - this._components[e].onEntityTransformChanged(t); - for (e = 0; e < this._componentsToAdd.length; e++) - this._componentsToAdd[e].enabled && - this._componentsToAdd[e].onEntityTransformChanged(t); - }), - t - ); - })(), - ComponentTypeManager = (function () { - function t() {} - return ( - (t.add = function (t) { - this._componentTypesMask.has(t) || - (this._componentTypesMask[t] = this._componentTypesMask.size); - }), - (t.getIndexFor = function (t) { - var e = -1; - return ( - this._componentTypesMask.has(t) || - (this.add(t), (e = this._componentTypesMask.get(t))), - e - ); - }), - (t._componentTypesMask = new Map()), - t - ); - })(), - EntityList = (function () { - function t(t) { - (this._entitiesToRemove = []), - (this._entitiesToAdded = []), - (this._tempEntityList = []), - (this._entities = []), - (this._entityDict = new Map()), - (this._unsortedTags = []), - (this.scene = t); - } - return ( - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._entities.length; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "buffer", { - get: function () { - return this._entities; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.add = function (t) { - -1 == this._entitiesToAdded.indexOf(t) && this._entitiesToAdded.push(t); - }), - (t.prototype.remove = function (t) { - this._entitiesToAdded.contains(t) - ? this._entitiesToAdded.remove(t) - : this._entitiesToRemove.contains(t) || - this._entitiesToRemove.push(t); - }), - (t.prototype.findEntity = function (t) { - for (var e = 0; e < this._entities.length; e++) - if (this._entities[e].name == t) return this._entities[e]; - return this._entitiesToAdded.firstOrDefault(function (e) { - return e.name == t; - }); - }), - (t.prototype.getTagList = function (t) { - var e = this._entityDict.get(t); - return ( - e || ((e = []), this._entityDict.set(t, e)), this._entityDict.get(t) - ); - }), - (t.prototype.addToTagList = function (t) { - var e = this.getTagList(t.tag); - e.contains(t) || (e.push(t), this._unsortedTags.push(t.tag)); - }), - (t.prototype.removeFromTagList = function (t) { - var e = this._entityDict.get(t.tag); - e && e.remove(t); - }), - (t.prototype.update = function () { - for (var t = 0; t < this._entities.length; t++) { - var e = this._entities[t]; - e.enabled && e.update(); - } - }), - (t.prototype.removeAllEntities = function () { - (this._entitiesToAdded.length = 0), this.updateLists(); - for (var t = 0; t < this._entities.length; t++) - (this._entities[t]._isDestoryed = !0), - this._entities[t].onRemovedFromScene(), - (this._entities[t].scene = null); - (this._entities.length = 0), this._entityDict.clear(); - }), - (t.prototype.updateLists = function () { - var t = this; - if (this._entitiesToRemove.length > 0) { - var e = this._entitiesToRemove; - (this._entitiesToRemove = this._tempEntityList), - (this._tempEntityList = e), - this._tempEntityList.forEach(function (e) { - t._entities.remove(e), - (e.scene = null), - t.scene.entityProcessors.onEntityRemoved(e); - }), - (this._tempEntityList.length = 0); - } - if (this._entitiesToAdded.length > 0) { - e = this._entitiesToAdded; - (this._entitiesToAdded = this._tempEntityList), - (this._tempEntityList = e), - this._tempEntityList.forEach(function (e) { - t._entities.contains(e) || - (t._entities.push(e), - (e.scene = t.scene), - t.scene.entityProcessors.onEntityAdded(e)); - }), - this._tempEntityList.forEach(function (t) { - return t.onAddedToScene(); - }), - (this._tempEntityList.length = 0); - } - this._unsortedTags.length > 0 && - (this._unsortedTags.forEach(function (e) { - t._entityDict.get(e).sort(); - }), - (this._unsortedTags.length = 0)); - }), - t - ); - })(), - EntityProcessorList = (function () { - function t() { - this._processors = []; - } - return ( - (t.prototype.add = function (t) { - this._processors.push(t); - }), - (t.prototype.remove = function (t) { - this._processors.remove(t); - }), - (t.prototype.onComponentAdded = function (t) { - this.notifyEntityChanged(t); - }), - (t.prototype.onComponentRemoved = function (t) { - this.notifyEntityChanged(t); - }), - (t.prototype.onEntityAdded = function (t) { - this.notifyEntityChanged(t); - }), - (t.prototype.onEntityRemoved = function (t) { - this.removeFromProcessors(t); - }), - (t.prototype.notifyEntityChanged = function (t) { - for (var e = 0; e < this._processors.length; e++) - this._processors[e].onChanged(t); - }), - (t.prototype.removeFromProcessors = function (t) { - for (var e = 0; e < this._processors.length; e++) - this._processors[e].remove(t); - }), - (t.prototype.begin = function () {}), - (t.prototype.update = function () { - for (var t = 0; t < this._processors.length; t++) - this._processors[t].update(); - }), - (t.prototype.lateUpdate = function () { - for (var t = 0; t < this._processors.length; t++) - this._processors[t].lateUpdate(); - }), - (t.prototype.end = function () {}), - (t.prototype.getProcessor = function () { - for (var t = 0; t < this._processors.length; t++) { - var e = this._processors[t]; - if (e instanceof EntitySystem) return e; - } - return null; - }), - t - ); - })(), - Matcher = (function () { - function t() { - (this.allSet = new BitSet()), - (this.exclusionSet = new BitSet()), - (this.oneSet = new BitSet()); - } - return ( - (t.empty = function () { - return new t(); - }), - (t.prototype.getAllSet = function () { - return this.allSet; - }), - (t.prototype.getExclusionSet = function () { - return this.exclusionSet; - }), - (t.prototype.getOneSet = function () { - return this.oneSet; - }), - (t.prototype.IsIntersted = function (t) { - if (!this.allSet.isEmpty()) - for ( - var e = this.allSet.nextSetBit(0); - e >= 0; - e = this.allSet.nextSetBit(e + 1) - ) - if (!t.componentBits.get(e)) return !1; - return ( - !( - !this.exclusionSet.isEmpty() && - this.exclusionSet.intersects(t.componentBits) - ) && - !(!this.oneSet.isEmpty() && !this.oneSet.intersects(t.componentBits)) - ); - }), - (t.prototype.all = function () { - for (var t = this, e = [], n = 0; n < arguments.length; n++) - e[n] = arguments[n]; - return ( - e.forEach(function (e) { - t.allSet.set(ComponentTypeManager.getIndexFor(e)); - }), - this - ); - }), - (t.prototype.exclude = function () { - for (var t = this, e = [], n = 0; n < arguments.length; n++) - e[n] = arguments[n]; - return ( - e.forEach(function (e) { - t.exclusionSet.set(ComponentTypeManager.getIndexFor(e)); - }), - this - ); - }), - (t.prototype.one = function () { - for (var t = this, e = [], n = 0; n < arguments.length; n++) - e[n] = arguments[n]; - return ( - e.forEach(function (e) { - t.oneSet.set(ComponentTypeManager.getIndexFor(e)); - }), - this - ); - }), - t - ); - })(), - RenderableComponentList = (function () { - function t() { - this._components = []; - } - return ( - Object.defineProperty(t.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.add = function (t) { - this._components.push(t); - }), - (t.prototype.remove = function (t) { - this._components.remove(t); - }), - (t.prototype.updateList = function () {}), - t - ); - })(), - Time = (function () { - function t() {} - return ( - (t.update = function (t) { - var e = (t - this._lastTime) / 1e3; - (this.deltaTime = e * this.timeScale), - (this.unscaledDeltaTime = e), - this.frameCount++, - (this._lastTime = t); - }), - (t.deltaTime = 0), - (t.timeScale = 1), - (t.frameCount = 0), - (t._lastTime = 0), - t - ); - })(), - GraphicsCapabilities = (function () { - function t() {} - return ( - (t.prototype.initialize = function (t) { - this.platformInitialize(t); - }), - (t.prototype.platformInitialize = function (t) { - var e = new egret.sys.RenderBuffer().context.getInstance(); - (this.supportsNonPowerOfTwo = !1), - (this.supportsTextureFilterAnisotropic = - null != e.getExtension("EXT_texture_filter_anisotropic")), - (this.supportsDepth24 = !0), - (this.supportsPackedDepthStencil = !0), - (this.supportsDepthNonLinear = !1), - (this.supportsTextureMaxLevel = !0), - (this.supportsS3tc = - null != e.getExtension("WEBGL_compressed_texture_s3tc") || - null != e.getExtension("WEBGL_compressed_texture_s3tc_srgb")), - (this.supportsDxt1 = this.supportsS3tc), - (this.supportsPvrtc = !1), - (this.supportsAtitc = - null != e.getExtension("WEBGL_compressed_texture_astc")), - (this.supportsFramebufferObjectARB = !1); - }), - t - ); - })(), - GraphicsDevice = (function () { - return function () { - (this.graphicsCapabilities = new GraphicsCapabilities()), - this.graphicsCapabilities.initialize(this); - }; - })(), - Viewport = (function () { - function t(t, e, n, i) { - (this._x = t), - (this._y = e), - (this._width = n), - (this._height = i), - (this._minDepth = 0), - (this._maxDepth = 1); - } - return ( - Object.defineProperty(t.prototype, "aspectRatio", { - get: function () { - return 0 != this._height && 0 != this._width - ? this._width / this._height - : 0; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "bounds", { - get: function () { - return new Rectangle(this._x, this._y, this._width, this._height); - }, - set: function (t) { - (this._x = t.x), - (this._y = t.y), - (this._width = t.width), - (this._height = t.height); - }, - enumerable: !0, - configurable: !0, - }), - t - ); - })(), - GraphicsResource = (function () { - return function () {}; - })(), - GaussianBlurEffect = (function (t) { - function e() { - return ( - t.call(this, PostProcessor.default_vert, e.blur_frag, { - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight, - }) || this - ); - } - return ( - __extends(e, t), - (e.blur_frag = - "precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}"), - e - ); - })(egret.CustomFilter), - PolygonLightEffect = (function (t) { - function e() { - return t.call(this, e.vertSrc, e.fragmentSrc) || this; - } - return ( - __extends(e, t), - (e.vertSrc = - "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}"), - (e.fragmentSrc = - "precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}"), - e - ); - })(egret.CustomFilter), - PostProcessor = (function () { - function t(t) { - void 0 === t && (t = null), (this.enable = !0), (this.effect = t); - } - return ( - (t.prototype.onAddedToScene = function (t) { - (this.scene = t), - (this.shape = new egret.Shape()), - this.shape.graphics.beginFill(16777215, 1), - this.shape.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - this.shape.graphics.endFill(), - t.addChild(this.shape); - }), - (t.prototype.process = function () { - this.drawFullscreenQuad(); - }), - (t.prototype.onSceneBackBufferSizeChanged = function (t, e) {}), - (t.prototype.drawFullscreenQuad = function () { - this.scene.filters = [this.effect]; - }), - (t.prototype.unload = function () { - this.effect && (this.effect = null), - this.scene.removeChild(this.shape), - (this.scene = null); - }), - (t.default_vert = - "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}"), - t - ); - })(), - BloomSettings = (function () { - function t(t, e, n, i, o, r) { - (this.threshold = t), - (this.blurAmount = e), - (this.intensity = n), - (this.baseIntensity = i), - (this.saturation = o), - (this.baseStaturation = r); - } - return ( - (t.presetSettings = [ - new t(0.1, 0.6, 2, 1, 1, 0), - new t(0, 3, 1, 1, 1, 1), - new t(0.5, 8, 2, 1, 0, 1), - new t(0.25, 8, 1.3, 1, 1, 0), - new t(0, 2, 1, 0.1, 1, 1), - new t(0.5, 2, 1, 1, 1, 1), - ]), - t - ); - })(), - GaussianBlurPostProcessor = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.onAddedToScene = function (e) { - t.prototype.onAddedToScene.call(this, e), - (this.effect = new GaussianBlurEffect()); - }), - e - ); - })(PostProcessor), - Renderer = (function () { - function t() {} - return ( - (t.prototype.onAddedToScene = function (t) {}), - (t.prototype.beginRender = function (t) {}), - (t.prototype.unload = function () {}), - (t.prototype.renderAfterStateCheck = function (t, e) { - t.render(e); - }), - t - ); - })(), - DefaultRenderer = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.render = function (t) { - var e = this.camera ? this.camera : t.camera; - this.beginRender(e); - for (var n = 0; n < t.renderableComponents.count; n++) { - var i = t.renderableComponents.buffer[n]; - i.enabled && - i.isVisibleFromCamera(e) && - this.renderAfterStateCheck(i, e); - } - }), - e - ); - })(Renderer), - ScreenSpaceRenderer = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return __extends(e, t), (e.prototype.render = function (t) {}), e; - })(Renderer), - PolyLight = (function (t) { - function e(e, n, i) { - var o = t.call(this) || this; - return ( - (o._indices = []), - (o.radius = e), - (o.power = i), - (o.color = n), - o.computeTriangleIndices(), - o - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "radius", { - get: function () { - return this._radius; - }, - set: function (t) { - this.setRadius(t); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.computeTriangleIndices = function (t) { - void 0 === t && (t = 20), (this._indices.length = 0); - for (var e = 0; e < t; e += 2) - this._indices.push(0), - this._indices.push(e + 2), - this._indices.push(e + 1); - }), - (e.prototype.setRadius = function (t) { - t != this._radius && ((this._radius = t), (this._areBoundsDirty = !0)); - }), - (e.prototype.render = function (t) {}), - (e.prototype.reset = function () {}), - e - ); - })(RenderableComponent), - SceneTransition = (function () { - function t(t) { - (this.sceneLoadAction = t), (this.loadsNewScene = null != t); - } - return ( - Object.defineProperty(t.prototype, "hasPreviousSceneRender", { - get: function () { - return ( - !!this._hasPreviousSceneRender || - ((this._hasPreviousSceneRender = !0), !1) - ); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.preRender = function () {}), - (t.prototype.render = function () {}), - (t.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (t) { - switch (t.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - return t.sent(), this.transitionComplete(), [2]; - } - }); - }); - }), - (t.prototype.transitionComplete = function () { - (SceneManager.sceneTransition = null), - this.onTransitionCompleted && this.onTransitionCompleted(); - }), - (t.prototype.loadNextScene = function () { - return __awaiter(this, void 0, void 0, function () { - var t; - return __generator(this, function (e) { - switch (e.label) { - case 0: - return ( - this.onScreenObscured && this.onScreenObscured(), - this.loadsNewScene || (this.isNewSceneLoaded = !0), - (t = SceneManager), - [4, this.sceneLoadAction()] - ); - case 1: - return (t.scene = e.sent()), (this.isNewSceneLoaded = !0), [2]; - } - }); - }); - }), - (t.prototype.tickEffectProgressProperty = function (t, e, n, i) { - return ( - void 0 === i && (i = !1), - new Promise(function (o) { - var r = i ? 1 : 0, - s = i ? 0 : 1; - egret.Tween.get(t.uniforms) - .set({ _progress: r }) - .to({ _progress: s }, 1e3 * e, n) - .call(function () { - o(); - }); - }) - ); - }), - t - ); - })(), - FadeTransition = (function (t) { - function e(e) { - var n = t.call(this, e) || this; - return ( - (n.fadeToColor = 0), - (n.fadeOutDuration = 0.4), - (n.fadeEaseType = egret.Ease.quadInOut), - (n.delayBeforeFadeInDuration = 0.1), - (n._alpha = 0), - (n._mask = new egret.Shape()), - n - ); - } - return ( - __extends(e, t), - (e.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - var t = this; - return __generator(this, function (e) { - return ( - this._mask.graphics.beginFill(this.fadeToColor, 1), - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - this._mask.graphics.endFill(), - SceneManager.stage.addChild(this._mask), - egret.Tween.get(this) - .to( - { _alpha: 1 }, - 1e3 * this.fadeOutDuration, - this.fadeEaseType - ) - .call(function () { - return __awaiter(t, void 0, void 0, function () { - return __generator(this, function (t) { - switch (t.label) { - case 0: - return [4, this.loadNextScene()]; - case 1: - return t.sent(), [2]; - } - }); - }); - }) - .wait(this.delayBeforeFadeInDuration) - .call(function () { - egret.Tween.get(t) - .to({ _alpha: 0 }, 1e3 * t.fadeOutDuration, t.fadeEaseType) - .call(function () { - t.transitionComplete(), - SceneManager.stage.removeChild(t._mask); - }); - }), - [2] - ); - }); - }); - }), - (e.prototype.render = function () { - this._mask.graphics.clear(), - this._mask.graphics.beginFill(this.fadeToColor, this._alpha), - this._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - this._mask.graphics.endFill(); - }), - e - ); - })(SceneTransition), - WindTransition = (function (t) { - function e(e) { - var n = t.call(this, e) || this; - (n.duration = 1), (n.easeType = egret.Ease.quadOut); - return ( - (n._windEffect = new egret.CustomFilter( - "attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}", - "precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float _progress;\nuniform float _size;\nuniform float _windSegments;\nvoid main(void) {\nvec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\nfloat x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\nfloat r = x - floor(x);\nfloat m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\nvec4 fg = texture2D(uSampler, vTextureCoord);\ngl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n}", - { _progress: 0, _size: 0.3, _windSegments: 100 } - )), - (n._mask = new egret.Shape()), - n._mask.graphics.beginFill(16777215, 1), - n._mask.graphics.drawRect( - 0, - 0, - SceneManager.stage.stageWidth, - SceneManager.stage.stageHeight - ), - n._mask.graphics.endFill(), - (n._mask.filters = [n._windEffect]), - SceneManager.stage.addChild(n._mask), - n - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "windSegments", { - set: function (t) { - this._windEffect.uniforms._windSegments = t; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(e.prototype, "size", { - set: function (t) { - this._windEffect.uniforms._size = t; - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (t) { - switch (t.label) { - case 0: - return ( - this.loadNextScene(), - [ - 4, - this.tickEffectProgressProperty( - this._windEffect, - this.duration, - this.easeType - ), - ] - ); - case 1: - return ( - t.sent(), - this.transitionComplete(), - SceneManager.stage.removeChild(this._mask), - [2] - ); - } - }); - }); - }), - e - ); - })(SceneTransition), - BaseView = (function (t) { - function e() { - return (null !== t && t.apply(this, arguments)) || this; - } - return ( - __extends(e, t), - (e.prototype.init = function () {}), - (e.prototype.show = function (t) {}), - (e.prototype.refreshData = function (t) { - this._data = t; - }), - (e.prototype.refreshView = function () {}), - (e.prototype.close = function () {}), - (e.prototype.destroy = function () { - for ( - this.parent && this.parent.removeChild(this); - this.numChildren > 0; - - ) - this.removeChildAt(0); - }), - e - ); - })(egret.DisplayObjectContainer), - BaseFuiView = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.name = e), n; - } - return __extends(e, t), e; - })(BaseView), - BaseSingle = (function () { - function t() {} - return ( - (t.getInstance = function () { - return ( - null == this._instance && (this._instance = new this()), - this._instance - ); - }), - (t.prototype.clearFuiObj = function (t) { - return ( - !!t && - (egret.Tween.removeTweens(t.displayObject), - t.displayObject && - t.displayObject.parent && - t.displayObject.parent.removeChild(t.displayObject), - t.dispose(), - (t = null), - !0) - ); - }), - t - ); - })(), - ViewManager = (function (t) { - function e() { - var e = (null !== t && t.apply(this, arguments)) || this; - return (e._openDic = []), e; - } - return ( - __extends(e, t), - (e.prototype.refreshView = function (t, e) { - var n = this.getView(t); - n && (n.refreshData(e), n.refreshView()); - }), - (e.prototype.openView = function (t, e, n) { - var i = this.getView(t); - if ((i || (i = new t()), this.existView(t))) - return i.refreshData(e), void i.refreshView(); - this._openDic.push(i); - }), - (e.prototype.getView = function (t) { - return this._openDic.firstOrDefault(function (e) { - return e instanceof t; - }); - }), - (e.prototype.existView = function (t) { - return ( - -1 != - this._openDic.findIndex(function (e) { - return e instanceof t; - }) - ); - }), - e - ); - })(BaseSingle), - Flags = (function () { - function t() {} - return ( - (t.isFlagSet = function (t, e) { - return 0 != (t & e); - }), - (t.isUnshiftedFlagSet = function (t, e) { - return 0 != (t & (e = 1 << e)); - }), - (t.setFlagExclusive = function (t, e) { - return 1 << e; - }), - (t.setFlag = function (t, e) { - return t | (1 << e); - }), - (t.unsetFlag = function (t, e) { - return t & ~(e = 1 << e); - }), - (t.invertFlags = function (t) { - return ~t; - }), - t - ); - })(), - MathHelper = (function () { - function t() {} - return ( - (t.toDegrees = function (t) { - return 57.29577951308232 * t; - }), - (t.toRadians = function (t) { - return 0.017453292519943295 * t; - }), - (t.map = function (t, e, n, i, o) { - return i + ((t - e) * (o - i)) / (n - e); - }), - (t.lerp = function (t, e, n) { - return t + (e - t) * n; - }), - (t.clamp = function (t, e, n) { - return t < e ? e : t > n ? n : t; - }), - (t.pointOnCirlce = function (e, n, i) { - var o = t.toRadians(i); - return new Vector2(Math.cos(o) * o + e.x, Math.sin(o) * o + e.y); - }), - (t.isEven = function (t) { - return t % 2 == 0; - }), - (t.Epsilon = 1e-5), - (t.Rad2Deg = 57.29578), - (t.Deg2Rad = 0.0174532924), - t - ); - })(), - Matrix2D = (function () { - function t(t, e, n, i, o, r) { - (this.m11 = 0), - (this.m12 = 0), - (this.m21 = 0), - (this.m22 = 0), - (this.m31 = 0), - (this.m32 = 0), - (this.m11 = t || 1), - (this.m12 = e || 0), - (this.m21 = n || 0), - (this.m22 = i || 1), - (this.m31 = o || 0), - (this.m32 = r || 0); - } - return ( - Object.defineProperty(t, "identity", { - get: function () { - return t._identity; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "translation", { - get: function () { - return new Vector2(this.m31, this.m32); - }, - set: function (t) { - (this.m31 = t.x), (this.m32 = t.y); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "rotation", { - get: function () { - return Math.atan2(this.m21, this.m11); - }, - set: function (t) { - var e = Math.cos(t), - n = Math.sin(t); - (this.m11 = e), (this.m12 = n), (this.m21 = -n), (this.m22 = e); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this.rotation); - }, - set: function (t) { - this.rotation = MathHelper.toRadians(t); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "scale", { - get: function () { - return new Vector2(this.m11, this.m22); - }, - set: function (t) { - (this.m11 = t.x), (this.m12 = t.y); - }, - enumerable: !0, - configurable: !0, - }), - (t.add = function (t, e) { - return ( - (t.m11 += e.m11), - (t.m12 += e.m12), - (t.m21 += e.m21), - (t.m22 += e.m22), - (t.m31 += e.m31), - (t.m32 += e.m32), - t - ); - }), - (t.divide = function (t, e) { - return ( - (t.m11 /= e.m11), - (t.m12 /= e.m12), - (t.m21 /= e.m21), - (t.m22 /= e.m22), - (t.m31 /= e.m31), - (t.m32 /= e.m32), - t - ); - }), - (t.multiply = function (e, n) { - var i = new t(), - o = e.m11 * n.m11 + e.m12 * n.m21, - r = e.m11 * n.m12 + e.m12 * n.m22, - s = e.m21 * n.m11 + e.m22 * n.m21, - a = e.m21 * n.m12 + e.m22 * n.m22, - h = e.m31 * n.m11 + e.m32 * n.m21 + n.m31, - c = e.m31 * n.m12 + e.m32 * n.m22 + n.m32; - return ( - (i.m11 = o), - (i.m12 = r), - (i.m21 = s), - (i.m22 = a), - (i.m31 = h), - (i.m32 = c), - i - ); - }), - (t.multiplyTranslation = function (e, n, i) { - var o = t.createTranslation(n, i); - return t.multiply(e, o); - }), - (t.prototype.determinant = function () { - return this.m11 * this.m22 - this.m12 * this.m21; - }), - (t.invert = function (e, n) { - void 0 === n && (n = new t()); - var i = 1 / e.determinant(); - return ( - (n.m11 = e.m22 * i), - (n.m12 = -e.m12 * i), - (n.m21 = -e.m21 * i), - (n.m22 = e.m11 * i), - (n.m31 = (e.m32 * e.m21 - e.m31 * e.m22) * i), - (n.m32 = -(e.m32 * e.m11 - e.m31 * e.m12) * i), - n - ); - }), - (t.createTranslation = function (e, n, i) { - return ( - ((i = i || new t()).m11 = 1), - (i.m12 = 0), - (i.m21 = 0), - (i.m22 = 1), - (i.m31 = e), - (i.m32 = n), - i - ); - }), - (t.createRotation = function (e, n) { - n = new t(); - var i = Math.cos(e), - o = Math.sin(e); - return (n.m11 = i), (n.m12 = o), (n.m21 = -o), (n.m22 = i), n; - }), - (t.createScale = function (e, n, i) { - return ( - void 0 === i && (i = new t()), - (i.m11 = e), - (i.m12 = 0), - (i.m21 = 0), - (i.m22 = n), - (i.m31 = 0), - (i.m32 = 0), - i - ); - }), - (t.prototype.toEgretMatrix = function () { - return new egret.Matrix( - this.m11, - this.m12, - this.m21, - this.m22, - this.m31, - this.m32 - ); - }), - (t._identity = new t(1, 0, 0, 1, 0, 0)), - t - ); - })(), - Rectangle = (function () { - function t(t, e, n, i) { - (this.x = t || 0), - (this.y = e || 0), - (this.width = n || 0), - (this.height = i || 0); - } - return ( - Object.defineProperty(t.prototype, "left", { - get: function () { - return this.x; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "right", { - get: function () { - return this.x + this.width; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "top", { - get: function () { - return this.y; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "bottom", { - get: function () { - return this.y + this.height; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "center", { - get: function () { - return new Vector2(this.x + this.width / 2, this.y + this.height / 2); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "location", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (t) { - (this.x = t.x), (this.y = t.y); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t.prototype, "size", { - get: function () { - return new Vector2(this.width, this.height); - }, - set: function (t) { - (this.width = t.x), (this.height = t.y); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.intersects = function (t) { - return ( - t.left < this.right && - this.left < t.right && - t.top < this.bottom && - this.top < t.bottom - ); - }), - (t.prototype.contains = function (t) { - return ( - this.x <= t.x && - t.x < this.x + this.width && - this.y <= t.y && - t.y < this.y + this.height - ); - }), - (t.prototype.containsRect = function (t) { - return ( - this.x <= t.x && - t.x < this.x + this.width && - this.y <= t.y && - t.y < this.y + this.height - ); - }), - (t.prototype.getHalfSize = function () { - return new Vector2(0.5 * this.width, 0.5 * this.height); - }), - (t.fromMinMax = function (e, n, i, o) { - return new t(e, n, i - e, o - n); - }), - (t.prototype.getClosestPointOnRectangleBorderToPoint = function (t) { - var e = new Vector2(0, 0), - n = new Vector2(0, 0); - if ( - ((n.x = MathHelper.clamp(t.x, this.left, this.right)), - (n.y = MathHelper.clamp(t.y, this.top, this.bottom)), - this.contains(n)) - ) { - var i = n.x - this.left, - o = this.right - n.x, - r = n.y - this.top, - s = this.bottom - n.y, - a = Math.min(i, o, r, s); - a == r - ? ((n.y = this.top), (e.y = -1)) - : a == s - ? ((n.y = this.bottom), (e.y = 1)) - : a == i - ? ((n.x = this.left), (e.x = -1)) - : ((n.x = this.right), (e.x = 1)); - } else - n.x == this.left && (e.x = -1), - n.x == this.right && (e.x = 1), - n.y == this.top && (e.y = -1), - n.y == this.bottom && (e.y = 1); - return { res: n, edgeNormal: e }; - }), - (t.prototype.calculateBounds = function (t, e, n, i, o, r, s) { - if (0 == o) - (this.x = t.x + e.x - n.x * i.x), - (this.y = t.y + e.y - n.y * i.y), - (this.width = r * i.x), - (this.height = s * i.y); - else { - var a = t.x + e.x, - h = t.y + e.y; - (this._transformMat = Matrix2D.createTranslation(-a - n.x, -h - n.y)), - (this._tempMat = Matrix2D.createScale(i.x, i.y)), - (this._transformMat = Matrix2D.multiply( - this._transformMat, - this._tempMat - )), - (this._tempMat = Matrix2D.createRotation(o)), - (this._transformMat = Matrix2D.multiply( - this._transformMat, - this._tempMat - )), - (this._tempMat = Matrix2D.createTranslation(a, h)), - (this._transformMat = Matrix2D.multiply( - this._transformMat, - this._tempMat - )); - var c = new Vector2(a, h), - u = new Vector2(a + r, h), - l = new Vector2(a, h + s), - p = new Vector2(a + r, h + s); - (c = Vector2Ext.transformR(c, this._transformMat)), - (u = Vector2Ext.transformR(u, this._transformMat)), - (l = Vector2Ext.transformR(l, this._transformMat)), - (p = Vector2Ext.transformR(p, this._transformMat)); - var f = Math.min(c.x, p.x, u.x, l.x), - d = Math.max(c.x, p.x, u.x, l.x), - y = Math.min(c.y, p.y, u.y, l.y), - g = Math.max(c.y, p.y, u.y, l.y); - (this.location = new Vector2(f, y)), - (this.width = d - f), - (this.height = g - y); - } - }), - (t.rectEncompassingPoints = function (t) { - for ( - var e = Number.POSITIVE_INFINITY, - n = Number.POSITIVE_INFINITY, - i = Number.NEGATIVE_INFINITY, - o = Number.NEGATIVE_INFINITY, - r = 0; - r < t.length; - r++ - ) { - var s = t[r]; - s.x < e && (e = s.x), - s.x > i && (i = s.x), - s.y < n && (n = s.y), - s.y > o && (o = s.y); - } - return this.fromMinMax(e, n, i, o); - }), - t - ); - })(), - Vector2 = (function () { - function t(t, e) { - (this.x = 0), (this.y = 0), (this.x = t || 0), (this.y = e || this.x); - } - return ( - Object.defineProperty(t, "zero", { - get: function () { - return t.zeroVector2; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "one", { - get: function () { - return t.unitVector2; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "unitX", { - get: function () { - return t.unitXVector; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "unitY", { - get: function () { - return t.unitYVector; - }, - enumerable: !0, - configurable: !0, - }), - (t.add = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x + n.x), (i.y = e.y + n.y), i; - }), - (t.divide = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x / n.x), (i.y = e.y / n.y), i; - }), - (t.multiply = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x * n.x), (i.y = e.y * n.y), i; - }), - (t.subtract = function (e, n) { - var i = new t(0, 0); - return (i.x = e.x - n.x), (i.y = e.y - n.y), i; - }), - (t.prototype.normalize = function () { - var t = 1 / Math.sqrt(this.x * this.x + this.y * this.y); - (this.x *= t), (this.y *= t); - }), - (t.prototype.length = function () { - return Math.sqrt(this.x * this.x + this.y * this.y); - }), - (t.prototype.round = function () { - return new t(Math.round(this.x), Math.round(this.y)); - }), - (t.normalize = function (t) { - var e = 1 / Math.sqrt(t.x * t.x + t.y * t.y); - return (t.x *= e), (t.y *= e), t; - }), - (t.dot = function (t, e) { - return t.x * e.x + t.y * e.y; - }), - (t.distanceSquared = function (t, e) { - var n = t.x - e.x, - i = t.y - e.y; - return n * n + i * i; - }), - (t.clamp = function (e, n, i) { - return new t( - MathHelper.clamp(e.x, n.x, i.x), - MathHelper.clamp(e.y, n.y, i.y) - ); - }), - (t.lerp = function (e, n, i) { - return new t( - MathHelper.lerp(e.x, n.x, i), - MathHelper.lerp(e.y, n.y, i) - ); - }), - (t.transform = function (e, n) { - return new t(e.x * n.m11 + e.y * n.m21, e.x * n.m12 + e.y * n.m22); - }), - (t.distance = function (t, e) { - var n = t.x - e.x, - i = t.y - e.y; - return Math.sqrt(n * n + i * i); - }), - (t.negate = function (e) { - var n = new t(); - return (n.x = -e.x), (n.y = -e.y), n; - }), - (t.unitYVector = new t(0, 1)), - (t.unitXVector = new t(1, 0)), - (t.unitVector2 = new t(1, 1)), - (t.zeroVector2 = new t(0, 0)), - t - ); - })(), - Vector3 = (function () { - return function (t, e, n) { - (this.x = t), (this.y = e), (this.z = n); - }; - })(), - ColliderTriggerHelper = (function () { - function t(t) { - (this._activeTriggerIntersections = []), - (this._previousTriggerIntersections = []), - (this._tempTriggerList = []), - (this._entity = t); - } - return ( - (t.prototype.update = function () { - for ( - var t = this._entity.getComponents(Collider), e = 0; - e < t.length; - e++ - ) - for ( - var n = t[e], - i = Physics.boxcastBroadphase(n.bounds, n.collidesWithLayers), - o = function (t) { - var e = i[t]; - if (!n.isTrigger && !e.isTrigger) return "continue"; - if (n.overlaps(e)) { - var o = new Pair(n, e); - -1 == - r._activeTriggerIntersections.findIndex(function (t) { - return t.first == o.first && t.second == o.second; - }) && - -1 == - r._previousTriggerIntersections.findIndex(function (t) { - return t.first == o.first && t.second == o.second; - }) && - r.notifyTriggerListeners(o, !0), - r._activeTriggerIntersections.contains(o) || - r._activeTriggerIntersections.push(o); - } - }, - r = this, - s = 0; - s < i.length; - s++ - ) - o(s); - ListPool.free(t), this.checkForExitedColliders(); - }), - (t.prototype.checkForExitedColliders = function () { - for ( - var t = this, - e = function (e) { - var i = n._previousTriggerIntersections.findIndex(function (n) { - return ( - n.first == t._activeTriggerIntersections[e].first && - n.second == t._activeTriggerIntersections[e].second - ); - }); - -1 != i && n._previousTriggerIntersections.removeAt(i); - }, - n = this, - i = 0; - i < this._activeTriggerIntersections.length; - i++ - ) - e(i); - for (i = 0; i < this._previousTriggerIntersections.length; i++) - this.notifyTriggerListeners( - this._previousTriggerIntersections[i], - !1 - ); - this._previousTriggerIntersections.length = 0; - for (i = 0; i < this._activeTriggerIntersections.length; i++) - this._previousTriggerIntersections.contains( - this._activeTriggerIntersections[i] - ) || - this._previousTriggerIntersections.push( - this._activeTriggerIntersections[i] - ); - this._activeTriggerIntersections.length = 0; - }), - (t.prototype.notifyTriggerListeners = function (t, e) { - t.first.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var n = 0; n < this._tempTriggerList.length; n++) - if ( - (e - ? this._tempTriggerList[n].onTriggerEnter(t.second, t.first) - : this._tempTriggerList[n].onTriggerExit(t.second, t.first), - (this._tempTriggerList.length = 0), - t.second.entity) - ) { - t.second.entity.getComponents( - "ITriggerListener", - this._tempTriggerList - ); - for (var i = 0; i < this._tempTriggerList.length; i++) - e - ? this._tempTriggerList[i].onTriggerEnter(t.first, t.second) - : this._tempTriggerList[i].onTriggerExit(t.first, t.second); - this._tempTriggerList.length = 0; - } - }), - t - ); - })(); -!(function (t) { - (t[(t.center = 0)] = "center"), - (t[(t.top = 1)] = "top"), - (t[(t.bottom = 2)] = "bottom"), - (t[(t.topLeft = 9)] = "topLeft"), - (t[(t.topRight = 5)] = "topRight"), - (t[(t.left = 8)] = "left"), - (t[(t.right = 4)] = "right"), - (t[(t.bottomLeft = 10)] = "bottomLeft"), - (t[(t.bottomRight = 6)] = "bottomRight"); -})(PointSectors || (PointSectors = {})); -var Collisions = (function () { - function t() {} - return ( - (t.isLineToLine = function (t, e, n, i) { - var o = Vector2.subtract(e, t), - r = Vector2.subtract(i, n), - s = o.x * r.y - o.y * r.x; - if (0 == s) return !1; - var a = Vector2.subtract(n, t), - h = (a.x * r.y - a.y * r.x) / s; - if (h < 0 || h > 1) return !1; - var c = (a.x * o.y - a.y * o.x) / s; - return !(c < 0 || c > 1); - }), - (t.lineToLineIntersection = function (t, e, n, i) { - var o = new Vector2(0, 0), - r = Vector2.subtract(e, t), - s = Vector2.subtract(i, n), - a = r.x * s.y - r.y * s.x; - if (0 == a) return o; - var h = Vector2.subtract(n, t), - c = (h.x * s.y - h.y * s.x) / a; - if (c < 0 || c > 1) return o; - var u = (h.x * r.y - h.y * r.x) / a; - return u < 0 || u > 1 - ? o - : (o = Vector2.add(t, new Vector2(c * r.x, c * r.y))); - }), - (t.closestPointOnLine = function (t, e, n) { - var i = Vector2.subtract(e, t), - o = Vector2.subtract(n, t), - r = Vector2.dot(o, i) / Vector2.dot(i, i); - return ( - (r = MathHelper.clamp(r, 0, 1)), - Vector2.add(t, new Vector2(i.x * r, i.y * r)) - ); - }), - (t.isCircleToCircle = function (t, e, n, i) { - return Vector2.distanceSquared(t, n) < (e + i) * (e + i); - }), - (t.isCircleToLine = function (t, e, n, i) { - return ( - Vector2.distanceSquared(t, this.closestPointOnLine(n, i, t)) < e * e - ); - }), - (t.isCircleToPoint = function (t, e, n) { - return Vector2.distanceSquared(t, n) < e * e; - }), - (t.isRectToCircle = function (t, e, n) { - var i = 0.5 * t.width, - o = 0.5 * t.height, - r = Math.max(0, Math.max(e.x - t.x) - i), - s = Math.max(0, Math.max(e.y - t.y) - o); - return r * r + s * s < n * n; - }), - (t.isRectToLine = function (t, e, n) { - var i = this.getSector(t.x, t.y, t.width, t.height, e), - o = this.getSector(t.x, t.y, t.width, t.height, n); - if (i == PointSectors.center || o == PointSectors.center) return !0; - if (0 != (i & o)) return !1; - var r = i | o, - s = void 0, - a = void 0; - return ( - !( - 0 == (r & PointSectors.top) || - ((s = new Vector2(t.x, t.y)), - (a = new Vector2(t.x + t.width, t.y)), - !this.isLineToLine(s, a, e, n)) - ) || - !( - 0 == (r & PointSectors.bottom) || - ((s = new Vector2(t.x, t.y + t.height)), - (a = new Vector2(t.x + t.width, t.y + t.height)), - !this.isLineToLine(s, a, e, n)) - ) || - !( - 0 == (r & PointSectors.left) || - ((s = new Vector2(t.x, t.y)), - (a = new Vector2(t.x, t.y + t.height)), - !this.isLineToLine(s, a, e, n)) - ) || - !( - 0 == (r & PointSectors.right) || - ((s = new Vector2(t.x + t.width, t.y)), - (a = new Vector2(t.x + t.width, t.y + t.height)), - !this.isLineToLine(s, a, e, n)) - ) - ); - }), - (t.isRectToPoint = function (t, e, n, i, o) { - return o.x >= t && o.y >= e && o.x < t + n && o.y < e + i; - }), - (t.getSector = function (t, e, n, i, o) { - var r = PointSectors.center; - return ( - o.x < t - ? (r |= PointSectors.left) - : o.x >= t + n && (r |= PointSectors.right), - o.y < e - ? (r |= PointSectors.top) - : o.y >= e + i && (r |= PointSectors.bottom), - r - ); - }), - t - ); - })(), - Physics = (function () { - function t() {} - return ( - (t.reset = function () { - this._spatialHash = new SpatialHash(this.spatialHashCellSize); - }), - (t.clear = function () { - this._spatialHash.clear(); - }), - (t.overlapCircleAll = function (t, e, n, i) { - return ( - void 0 === i && (i = -1), this._spatialHash.overlapCircle(t, e, n, i) - ); - }), - (t.boxcastBroadphase = function (t, e) { - return ( - void 0 === e && (e = this.allLayers), - this._spatialHash.aabbBroadphase(t, null, e) - ); - }), - (t.boxcastBroadphaseExcludingSelf = function (t, e, n) { - return ( - void 0 === n && (n = this.allLayers), - this._spatialHash.aabbBroadphase(e, t, n) - ); - }), - (t.addCollider = function (e) { - t._spatialHash.register(e); - }), - (t.removeCollider = function (e) { - t._spatialHash.remove(e); - }), - (t.updateCollider = function (t) { - this._spatialHash.remove(t), this._spatialHash.register(t); - }), - (t.spatialHashCellSize = 100), - (t.allLayers = -1), - t - ); - })(), - Shape = (function () { - return function () {}; - })(), - Polygon = (function (t) { - function e(e, n) { - var i = t.call(this) || this; - return ( - (i.isUnrotated = !0), - (i._areEdgeNormalsDirty = !0), - i.setPoints(e), - (i.isBox = n), - i - ); - } - return ( - __extends(e, t), - Object.defineProperty(e.prototype, "edgeNormals", { - get: function () { - return ( - this._areEdgeNormalsDirty && this.buildEdgeNormals(), - this._edgeNormals - ); - }, - enumerable: !0, - configurable: !0, - }), - (e.prototype.buildEdgeNormals = function () { - var t, - e = this.isBox ? 2 : this.points.length; - (null != this._edgeNormals && this._edgeNormals.length == e) || - (this._edgeNormals = new Array(e)); - for (var n = 0; n < e; n++) { - var i = this.points[n]; - t = n + 1 >= this.points.length ? this.points[0] : this.points[n + 1]; - var o = Vector2Ext.perpendicular(i, t); - (o = Vector2.normalize(o)), (this._edgeNormals[n] = o); - } - }), - (e.prototype.setPoints = function (t) { - (this.points = t), - this.recalculateCenterAndEdgeNormals(), - (this._originalPoints = []); - for (var e = 0; e < this.points.length; e++) - this._originalPoints.push(this.points[e]); - }), - (e.prototype.collidesWithShape = function (t) { - var n = new CollisionResult(); - if (t instanceof e) return ShapeCollisions.polygonToPolygon(this, t); - if (t instanceof Circle) - return (n = ShapeCollisions.circleToPolygon(t, this)) - ? (n.invertResult(), n) - : null; - throw new Error("overlaps of Polygon to " + t + " are not supported"); - }), - (e.prototype.recalculateCenterAndEdgeNormals = function () { - (this._polygonCenter = e.findPolygonCenter(this.points)), - (this._areEdgeNormalsDirty = !0); - }), - (e.prototype.overlaps = function (t) { - var n; - if (t instanceof e) return ShapeCollisions.polygonToPolygon(this, t); - if (t instanceof Circle) - return ( - !!(n = ShapeCollisions.circleToPolygon(t, this)) && - (n.invertResult(), !0) - ); - throw new Error("overlaps of Pologon to " + t + " are not supported"); - }), - (e.findPolygonCenter = function (t) { - for (var e = 0, n = 0, i = 0; i < t.length; i++) - (e += t[i].x), (n += t[i].y); - return new Vector2(e / t.length, n / t.length); - }), - (e.getClosestPointOnPolygonToPoint = function (t, e) { - for ( - var n, - i = Number.MAX_VALUE, - o = new Vector2(0, 0), - r = new Vector2(0, 0), - s = 0; - s < t.length; - s++ - ) { - var a = s + 1; - a == t.length && (a = 0); - var h = ShapeCollisions.closestPointOnLine(t[s], t[a], e); - if ((n = Vector2.distanceSquared(e, h)) < i) { - (i = n), (r = h); - var c = Vector2.subtract(t[a], t[s]); - (o.x = -c.y), (o.y = c.x); - } - } - return { - closestPoint: r, - distanceSquared: i, - edgeNormal: (o = Vector2.normalize(o)), - }; - }), - (e.prototype.pointCollidesWithShape = function (t) { - return ShapeCollisions.pointToPoly(t, this); - }), - (e.prototype.containsPoint = function (t) { - t = Vector2.subtract(t, this.position); - for ( - var e = !1, n = 0, i = this.points.length - 1; - n < this.points.length; - i = n++ - ) - this.points[n].y > t.y != this.points[i].y > t.y && - t.x < - ((this.points[i].x - this.points[n].x) * - (t.y - this.points[n].y)) / - (this.points[i].y - this.points[n].y) + - this.points[n].x && - (e = !e); - return e; - }), - (e.buildSymmertricalPolygon = function (t, e) { - for (var n = new Array(t), i = 0; i < t; i++) { - var o = 2 * Math.PI * (i / t); - n[i] = new Vector2(Math.cos(o), Math.sin(o) * e); - } - return n; - }), - (e.prototype.recalculateBounds = function (t) { - if ( - ((this.center = t.localOffset), - t.shouldColliderScaleAndRotationWithTransform) - ) { - var e = !0, - n = void 0, - i = Matrix2D.createTranslation( - -this._polygonCenter.x, - -this._polygonCenter.y - ); - if (t.entity.scale != Vector2.one) { - (n = Matrix2D.createScale(t.entity.scale.x, t.entity.scale.y)), - (i = Matrix2D.multiply(i, n)), - (e = !1); - var o = Vector2.multiply(t.localOffset, t.entity.scale); - this.center = o; - } - if (0 != t.entity.rotation) { - (n = Matrix2D.createRotation(t.entity.rotation)), - (i = Matrix2D.multiply(i, n)); - var r = - Math.atan2(t.localOffset.y, t.localOffset.x) * - MathHelper.Rad2Deg, - s = e - ? t._localOffsetLength - : Vector2.multiply(t.localOffset, t.entity.scale).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - s, - MathHelper.toDegrees(t.entity.rotation) + r - ); - } - (n = Matrix2D.createTranslation( - this._polygonCenter.x, - this._polygonCenter.y - )), - (i = Matrix2D.multiply(i, n)), - Vector2Ext.transform(this._originalPoints, i, this.points), - (this.isUnrotated = 0 == t.entity.rotation), - t._isRotationDirty && (this._areEdgeNormalsDirty = !0); - } - (this.position = Vector2.add(t.entity.position, this.center)), - (this.bounds = Rectangle.rectEncompassingPoints(this.points)), - (this.bounds.location = Vector2.add( - this.bounds.location, - this.position - )); - }), - e - ); - })(Shape), - Box = (function (t) { - function e(n, i) { - var o = t.call(this, e.buildBox(n, i), !0) || this; - return (o.width = n), (o.height = i), o; - } - return ( - __extends(e, t), - (e.buildBox = function (t, e) { - var n = t / 2, - i = e / 2, - o = new Array(4); - return ( - (o[0] = new Vector2(-n, -i)), - (o[1] = new Vector2(n, -i)), - (o[2] = new Vector2(n, i)), - (o[3] = new Vector2(-n, i)), - o - ); - }), - (e.prototype.updateBox = function (t, e) { - (this.width = t), (this.height = e); - var n = t / 2, - i = e / 2; - (this.points[0] = new Vector2(-n, -i)), - (this.points[1] = new Vector2(n, -i)), - (this.points[2] = new Vector2(n, i)), - (this.points[3] = new Vector2(-n, i)); - for (var o = 0; o < this.points.length; o++) - this._originalPoints[o] = this.points[o]; - }), - (e.prototype.containsPoint = function (e) { - return this.isUnrotated - ? this.bounds.contains(e) - : t.prototype.containsPoint.call(this, e); - }), - e - ); - })(Polygon), - Circle = (function (t) { - function e(e) { - var n = t.call(this) || this; - return (n.radius = e), (n._originalRadius = e), n; - } - return ( - __extends(e, t), - (e.prototype.pointCollidesWithShape = function (t) { - return ShapeCollisions.pointToCircle(t, this); - }), - (e.prototype.collidesWithShape = function (t) { - if (t instanceof Box && t.isUnrotated) - return ShapeCollisions.circleToBox(this, t); - if (t instanceof e) return ShapeCollisions.circleToCircle(this, t); - if (t instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, t); - throw new Error("Collisions of Circle to " + t + " are not supported"); - }), - (e.prototype.recalculateBounds = function (t) { - if ( - ((this.center = t.localOffset), - t.shouldColliderScaleAndRotationWithTransform) - ) { - var e = t.entity.scale, - n = 1 == e.x && 1 == e.y, - i = Math.max(e.x, e.y); - if ( - ((this.radius = this._originalRadius * i), 0 != t.entity.rotation) - ) { - var o = - Math.atan2(t.localOffset.y, t.localOffset.x) * - MathHelper.Rad2Deg, - r = n - ? t._localOffsetLength - : Vector2.multiply(t.localOffset, t.entity.scale).length(); - this.center = MathHelper.pointOnCirlce( - Vector2.zero, - r, - MathHelper.toDegrees(t.entity.rotation) + o - ); - } - } - (this.position = Vector2.add(t.entity.position, this.center)), - (this.bounds = new Rectangle( - this.position.x - this.radius, - this.position.y - this.radius, - 2 * this.radius, - 2 * this.radius - )); - }), - (e.prototype.overlaps = function (t) { - if (t instanceof Box && t.isUnrotated) - return Collisions.isRectToCircle( - t.bounds, - this.position, - this.radius - ); - if (t instanceof e) - return Collisions.isCircleToCircle( - this.position, - this.radius, - t.position, - t.radius - ); - if (t instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, t); - throw new Error("overlaps of circle to " + t + " are not supported"); - }), - e - ); - })(Shape), - CollisionResult = (function () { - function t() {} - return ( - (t.prototype.invertResult = function () { - (this.minimumTranslationVector = Vector2.negate( - this.minimumTranslationVector - )), - (this.normal = Vector2.negate(this.normal)); - }), - t - ); - })(), - ShapeCollisions = (function () { - function t() {} - return ( - (t.polygonToPolygon = function (t, e) { - for ( - var n, - i = new CollisionResult(), - o = !0, - r = t.edgeNormals, - s = e.edgeNormals, - a = Number.POSITIVE_INFINITY, - h = new Vector2(), - c = Vector2.subtract(t.position, e.position), - u = 0; - u < r.length + s.length; - u++ - ) { - n = u < r.length ? r[u] : s[u - r.length]; - var l = 0, - p = 0, - f = 0, - d = 0, - y = 0, - g = this.getInterval(n, t, l, f); - (l = g.min), (p = g.max); - var m = this.getInterval(n, e, p, d); - (p = m.min), (d = m.max); - var _ = Vector2.dot(c, n); - if ( - ((l += _), - (f += _), - (y = this.intervalDistance(l, f, p, d)) > 0 && (o = !1), - !o) - ) - return null; - (y = Math.abs(y)) < a && - ((a = y), (h = n), Vector2.dot(h, c) < 0 && (h = new Vector2(-h))); - } - return ( - (i.normal = h), - (i.minimumTranslationVector = Vector2.multiply( - new Vector2(-h), - new Vector2(a) - )), - i - ); - }), - (t.intervalDistance = function (t, e, n, i) { - return t < n ? n - e : t - n; - }), - (t.getInterval = function (t, e, n, i) { - var o = Vector2.dot(e.points[0], t); - n = i = o; - for (var r = 1; r < e.points.length; r++) - (o = Vector2.dot(e.points[r], t)) < n ? (n = o) : o > i && (i = o); - return { min: n, max: i }; - }), - (t.circleToPolygon = function (t, e) { - var n = new CollisionResult(), - i = Vector2.subtract(t.position, e.position), - o = Polygon.getClosestPointOnPolygonToPoint(e.points, i), - r = o.closestPoint, - s = o.distanceSquared; - n.normal = o.edgeNormal; - var a, - h = e.containsPoint(t.position); - if (s > t.radius * t.radius && !h) return null; - if (h) - a = Vector2.multiply(n.normal, new Vector2(Math.sqrt(s) - t.radius)); - else if (0 == s) a = Vector2.multiply(n.normal, new Vector2(t.radius)); - else { - var c = Math.sqrt(s); - a = Vector2.multiply( - new Vector2(-Vector2.subtract(i, r)), - new Vector2((t.radius - s) / c) - ); - } - return ( - (n.minimumTranslationVector = a), - (n.point = Vector2.add(r, e.position)), - n - ); - }), - (t.circleToBox = function (t, e) { - var n = new CollisionResult(), - i = e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res; - if (e.containsPoint(t.position)) { - n.point = i; - var o = Vector2.add( - i, - Vector2.subtract(n.normal, new Vector2(t.radius)) - ); - return ( - (n.minimumTranslationVector = Vector2.subtract(t.position, o)), n - ); - } - var r = Vector2.distanceSquared(i, t.position); - if (0 == r) - n.minimumTranslationVector = Vector2.multiply( - n.normal, - new Vector2(t.radius) - ); - else if (r <= t.radius * t.radius) { - n.normal = Vector2.subtract(t.position, i); - var s = n.normal.length() - t.radius; - return ( - (n.normal = Vector2Ext.normalize(n.normal)), - (n.minimumTranslationVector = Vector2.multiply( - new Vector2(s), - n.normal - )), - n - ); - } - return null; - }), - (t.pointToCircle = function (t, e) { - var n = new CollisionResult(), - i = Vector2.distanceSquared(t, e.position), - o = 1 + e.radius; - if (i < o * o) { - n.normal = Vector2.normalize(Vector2.subtract(t, e.position)); - var r = o - Math.sqrt(i); - return ( - (n.minimumTranslationVector = Vector2.multiply( - new Vector2(-r, -r), - n.normal - )), - (n.point = Vector2.add( - e.position, - Vector2.multiply(n.normal, new Vector2(e.radius, e.radius)) - )), - n - ); - } - return null; - }), - (t.closestPointOnLine = function (t, e, n) { - var i = Vector2.subtract(e, t), - o = Vector2.subtract(n, t), - r = Vector2.dot(o, i) / Vector2.dot(i, i); - return ( - (r = MathHelper.clamp(r, 0, 1)), - Vector2.add(t, Vector2.multiply(i, new Vector2(r, r))) - ); - }), - (t.pointToPoly = function (t, e) { - var n = new CollisionResult(); - if (e.containsPoint(t)) { - var i, - o = Polygon.getClosestPointOnPolygonToPoint( - e.points, - Vector2.subtract(t, e.position) - ), - r = o.closestPoint; - return ( - (i = o.distanceSquared), - (n.normal = o.edgeNormal), - (n.minimumTranslationVector = Vector2.multiply( - n.normal, - new Vector2(Math.sqrt(i), Math.sqrt(i)) - )), - (n.point = Vector2.add(r, e.position)), - n - ); - } - return null; - }), - (t.circleToCircle = function (t, e) { - var n = new CollisionResult(), - i = Vector2.distanceSquared(t.position, e.position), - o = t.radius + e.radius; - if (i < o * o) { - n.normal = Vector2.normalize( - Vector2.subtract(t.position, e.position) - ); - var r = o - Math.sqrt(i); - return ( - (n.minimumTranslationVector = Vector2.multiply( - new Vector2(-r), - n.normal - )), - (n.point = Vector2.add( - e.position, - Vector2.multiply(n.normal, new Vector2(e.radius)) - )), - n - ); - } - return null; - }), - t - ); - })(), - SpatialHash = (function () { - function t(t) { - void 0 === t && (t = 100), - (this.gridBounds = new Rectangle()), - (this._tempHashSet = []), - (this._cellDict = new NumberDictionary()), - (this._cellSize = t), - (this._inverseCellSize = 1 / this._cellSize), - (this._raycastParser = new RaycastResultParser()); - } - return ( - (t.prototype.remove = function (t) { - for ( - var e = t.registeredPhysicsBounds, - n = this.cellCoords(e.x, e.y), - i = this.cellCoords(e.right, e.bottom), - o = n.x; - o <= i.x; - o++ - ) - for (var r = n.y; r <= i.y; r++) { - var s = this.cellAtPosition(o, r); - s - ? s.remove(t) - : console.error( - "removing Collider [" + - t + - "] from a cell that it is not present in" - ); - } - }), - (t.prototype.register = function (t) { - var e = t.bounds; - t.registeredPhysicsBounds = e; - var n = this.cellCoords(e.x, e.y), - i = this.cellCoords(e.right, e.bottom); - this.gridBounds.contains(new Vector2(n.x, n.y)) || - (this.gridBounds = RectangleExt.union(this.gridBounds, n)), - this.gridBounds.contains(new Vector2(i.x, i.y)) || - (this.gridBounds = RectangleExt.union(this.gridBounds, i)); - for (var o = n.x; o <= i.x; o++) - for (var r = n.y; r <= i.y; r++) { - this.cellAtPosition(o, r, !0).push(t); - } - }), - (t.prototype.clear = function () { - this._cellDict.clear(); - }), - (t.prototype.overlapCircle = function (t, e, n, i) { - var o = new Rectangle(t.x - e, t.y - e, 2 * e, 2 * e); - (this._overlapTestCircle.radius = e), - (this._overlapTestCircle.position = t); - for ( - var r = 0, s = this.aabbBroadphase(o, null, i), a = 0; - a < s.length; - a++ - ) { - var h = s[a]; - if (!(h instanceof BoxCollider)) - throw new Error( - "overlapCircle against this collider type is not implemented!" - ); - if (((n[r] = h), ++r == n.length)) return r; - } - return r; - }), - (t.prototype.aabbBroadphase = function (t, e, n) { - this._tempHashSet.length = 0; - for ( - var i = this.cellCoords(t.x, t.y), - o = this.cellCoords(t.right, t.bottom), - r = i.x; - r <= o.x; - r++ - ) - for (var s = i.y; s <= o.y; s++) { - var a = this.cellAtPosition(r, s); - if (a) - for (var h = 0; h < a.length; h++) { - var c = a[h]; - c != e && - Flags.isFlagSet(n, c.physicsLayer) && - t.intersects(c.bounds) && - -1 == this._tempHashSet.indexOf(c) && - this._tempHashSet.push(c); - } - } - return this._tempHashSet; - }), - (t.prototype.cellAtPosition = function (t, e, n) { - void 0 === n && (n = !1); - var i = this._cellDict.tryGetValue(t, e); - return i || (n && ((i = []), this._cellDict.add(t, e, i))), i; - }), - (t.prototype.cellCoords = function (t, e) { - return new Point( - Math.floor(t * this._inverseCellSize), - Math.floor(e * this._inverseCellSize) - ); - }), - t - ); - })(), - RaycastResultParser = (function () { - return function () {}; - })(), - NumberDictionary = (function () { - function t() { - this._store = new Map(); - } - return ( - (t.prototype.getKey = function (t, e) { - return Long.fromNumber(t) - .shiftLeft(32) - .or(this.intToUint(e)) - .toString(); - }), - (t.prototype.intToUint = function (t) { - return t >= 0 ? t : 4294967296 + t; - }), - (t.prototype.add = function (t, e, n) { - this._store.set(this.getKey(t, e), n); - }), - (t.prototype.remove = function (t) { - this._store.forEach(function (e) { - e.contains(t) && e.remove(t); - }); - }), - (t.prototype.tryGetValue = function (t, e) { - return this._store.get(this.getKey(t, e)); - }), - (t.prototype.clear = function () { - this._store.clear(); - }), - t - ); - })(), - ContentManager = (function () { - function t() { - this.loadedAssets = new Map(); - } - return ( - (t.prototype.loadRes = function (t, e) { - var n = this; - return ( - void 0 === e && (e = !0), - new Promise(function (i, o) { - var r = n.loadedAssets.get(t); - r - ? i(r) - : e - ? RES.getResAsync(t) - .then(function (e) { - n.loadedAssets.set(t, e), i(e); - }) - .catch(function (e) { - console.error("资源加载错误:", t, e), o(e); - }) - : RES.getResByUrl(t) - .then(function (e) { - n.loadedAssets.set(t, e), i(e); - }) - .catch(function (e) { - console.error("资源加载错误:", t, e), o(e); - }); - }) - ); - }), - (t.prototype.dispose = function () { - this.loadedAssets.forEach(function (t) { - t.dispose(); - }), - this.loadedAssets.clear(); - }), - t - ); - })(), - Emitter = (function () { - function t() { - this._messageTable = new Map(); - } - return ( - (t.prototype.addObserver = function (t, e) { - var n = this._messageTable.get(t); - n || ((n = []), this._messageTable.set(t, n)), - n.contains(e) && console.warn("您试图添加相同的观察者两次"), - n.push(e); - }), - (t.prototype.removeObserver = function (t, e) { - this._messageTable.get(t).remove(e); - }), - (t.prototype.emit = function (t, e) { - var n = this._messageTable.get(t); - if (n) for (var i = n.length - 1; i >= 0; i--) n[i](e); - }), - t - ); - })(), - GlobalManager = (function () { - function t() {} - return ( - Object.defineProperty(t.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (t) { - this.setEnabled(t); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.setEnabled = function (t) { - this._enabled != t && - ((this._enabled = t), - this._enabled ? this.onEnabled() : this.onDisabled()); - }), - (t.prototype.onEnabled = function () {}), - (t.prototype.onDisabled = function () {}), - (t.prototype.update = function () {}), - (t.registerGlobalManager = function (t) { - this.globalManagers.push(t), (t.enabled = !0); - }), - (t.unregisterGlobalManager = function (t) { - this.globalManagers.remove(t), (t.enabled = !1); - }), - (t.getGlobalManager = function (t) { - for (var e = 0; e < this.globalManagers.length; e++) - if (this.globalManagers[e] instanceof t) - return this.globalManagers[e]; - return null; - }), - (t.globalManagers = []), - t - ); - })(), - TouchState = (function () { - function t() { - (this.x = 0), (this.y = 0), (this.touchPoint = -1), (this.touchDown = !1); - } - return ( - Object.defineProperty(t.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - enumerable: !0, - configurable: !0, - }), - (t.prototype.reset = function () { - (this.x = 0), - (this.y = 0), - (this.touchDown = !1), - (this.touchPoint = -1); - }), - t - ); - })(), - Input = (function () { - function t() {} - return ( - Object.defineProperty(t, "touchPosition", { - get: function () { - return this._gameTouchs[0] - ? this._gameTouchs[0].position - : Vector2.zero; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "maxSupportedTouch", { - get: function () { - return this._stage.maxTouches; - }, - set: function (t) { - (this._stage.maxTouches = t), this.initTouchCache(); - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "resolutionScale", { - get: function () { - return this._resolutionScale; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "totalTouchCount", { - get: function () { - return this._totalTouchCount; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "gameTouchs", { - get: function () { - return this._gameTouchs; - }, - enumerable: !0, - configurable: !0, - }), - Object.defineProperty(t, "touchPositionDelta", { - get: function () { - var t = Vector2.subtract( - this.touchPosition, - this._previousTouchState.position - ); - return ( - t.length() > 0 && this.setpreviousTouchState(this._gameTouchs[0]), t - ); - }, - enumerable: !0, - configurable: !0, - }), - (t.initialize = function (t) { - this._init || - ((this._init = !0), - (this._stage = t), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_BEGIN, - this.touchBegin, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_MOVE, - this.touchMove, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_END, - this.touchEnd, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_CANCEL, - this.touchEnd, - this - ), - this._stage.addEventListener( - egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, - this.touchEnd, - this - ), - this.initTouchCache()); - }), - (t.initTouchCache = function () { - (this._totalTouchCount = 0), - (this._touchIndex = 0), - (this._gameTouchs.length = 0); - for (var t = 0; t < this.maxSupportedTouch; t++) - this._gameTouchs.push(new TouchState()); - }), - (t.touchBegin = function (t) { - this._touchIndex < this.maxSupportedTouch && - ((this._gameTouchs[this._touchIndex].touchPoint = t.touchPointID), - (this._gameTouchs[this._touchIndex].touchDown = t.touchDown), - (this._gameTouchs[this._touchIndex].x = t.stageX), - (this._gameTouchs[this._touchIndex].y = t.stageY), - 0 == this._touchIndex && - this.setpreviousTouchState(this._gameTouchs[0]), - this._touchIndex++, - this._totalTouchCount++); - }), - (t.touchMove = function (t) { - t.touchPointID == this._gameTouchs[0].touchPoint && - this.setpreviousTouchState(this._gameTouchs[0]); - var e = this._gameTouchs.findIndex(function (e) { - return e.touchPoint == t.touchPointID; - }); - if (-1 != e) { - var n = this._gameTouchs[e]; - (n.x = t.stageX), (n.y = t.stageY); - } - }), - (t.touchEnd = function (t) { - var e = this._gameTouchs.findIndex(function (e) { - return e.touchPoint == t.touchPointID; - }); - -1 != e && - (this._gameTouchs[e].reset(), - 0 == e && this._previousTouchState.reset(), - this._totalTouchCount--, - 0 == this.totalTouchCount && (this._touchIndex = 0)); - }), - (t.setpreviousTouchState = function (t) { - (this._previousTouchState = new TouchState()), - (this._previousTouchState.x = t.position.x), - (this._previousTouchState.y = t.position.y), - (this._previousTouchState.touchPoint = t.touchPoint), - (this._previousTouchState.touchDown = t.touchDown); - }), - (t.scaledPosition = function (t) { - var e = new Vector2( - t.x - this._resolutionOffset.x, - t.y - this._resolutionOffset.y - ); - return Vector2.multiply(e, this.resolutionScale); - }), - (t._init = !1), - (t._previousTouchState = new TouchState()), - (t._gameTouchs = []), - (t._resolutionOffset = new Vector2()), - (t._resolutionScale = Vector2.one), - (t._touchIndex = 0), - (t._totalTouchCount = 0), - t - ); - })(), - ListPool = (function () { - function t() {} - return ( - (t.warmCache = function (t) { - if ((t -= this._objectQueue.length) > 0) - for (var e = 0; e < t; e++) this._objectQueue.unshift([]); - }), - (t.trimCache = function (t) { - for (; t > this._objectQueue.length; ) this._objectQueue.shift(); - }), - (t.clearCache = function () { - this._objectQueue.length = 0; - }), - (t.obtain = function () { - return this._objectQueue.length > 0 ? this._objectQueue.shift() : []; - }), - (t.free = function (t) { - this._objectQueue.unshift(t), (t.length = 0); - }), - (t._objectQueue = []), - t - ); - })(), - Pair = (function () { - function t(t, e) { - (this.first = t), (this.second = e); - } - return ( - (t.prototype.clear = function () { - this.first = this.second = null; - }), - (t.prototype.equals = function (t) { - return this.first == t.first && this.second == t.second; - }), - t - ); - })(), - RectangleExt = (function () { - function t() {} - return ( - (t.union = function (t, e) { - var n = new Rectangle(e.x, e.y, 0, 0); - return this.unionR(t, n); - }), - (t.unionR = function (t, e) { - var n = new Rectangle(); - return ( - (n.x = Math.min(t.x, e.x)), - (n.y = Math.min(t.y, e.y)), - (n.width = Math.max(t.right, e.right) - n.x), - (n.height = Math.max(t.bottom, e.bottom) - n.y), - n - ); - }), - t - ); - })(), - Triangulator = (function () { - function t() { - (this.triangleIndices = []), - (this._triPrev = new Array(12)), - (this._triNext = new Array(12)); - } - return ( - (t.prototype.triangulate = function (e, n) { - void 0 === n && (n = !0); - var i = e.length; - this.initialize(i); - for (var o = 0, r = 0; i > 3 && o < 500; ) { - o++; - var s = !0, - a = e[this._triPrev[r]], - h = e[r], - c = e[this._triNext[r]]; - if (Vector2Ext.isTriangleCCW(a, h, c)) { - var u = this._triNext[this._triNext[r]]; - do { - if (t.testPointTriangle(e[u], a, h, c)) { - s = !1; - break; - } - u = this._triNext[u]; - } while (u != this._triPrev[r]); - } else s = !1; - s - ? (this.triangleIndices.push(this._triPrev[r]), - this.triangleIndices.push(r), - this.triangleIndices.push(this._triNext[r]), - (this._triNext[this._triPrev[r]] = this._triNext[r]), - (this._triPrev[this._triNext[r]] = this._triPrev[r]), - i--, - (r = this._triPrev[r])) - : (r = this._triNext[r]); - } - this.triangleIndices.push(this._triPrev[r]), - this.triangleIndices.push(r), - this.triangleIndices.push(this._triNext[r]), - n || this.triangleIndices.reverse(); - }), - (t.prototype.initialize = function (t) { - (this.triangleIndices.length = 0), - this._triNext.length < t && - (this._triNext.reverse(), - (this._triNext = new Array(Math.max(2 * this._triNext.length, t)))), - this._triPrev.length < t && - (this._triPrev.reverse(), - (this._triPrev = new Array(Math.max(2 * this._triPrev.length, t)))); - for (var e = 0; e < t; e++) - (this._triPrev[e] = e - 1), (this._triNext[e] = e + 1); - (this._triPrev[0] = t - 1), (this._triNext[t - 1] = 0); - }), - (t.testPointTriangle = function (t, e, n, i) { - return ( - !( - Vector2Ext.cross(Vector2.subtract(t, e), Vector2.subtract(n, e)) < 0 - ) && - !( - Vector2Ext.cross(Vector2.subtract(t, n), Vector2.subtract(i, n)) < 0 - ) && - !( - Vector2Ext.cross(Vector2.subtract(t, i), Vector2.subtract(e, i)) < 0 - ) - ); - }), - t - ); - })(), - Vector2Ext = (function () { - function t() {} - return ( - (t.isTriangleCCW = function (t, e, n) { - return this.cross(Vector2.subtract(e, t), Vector2.subtract(n, e)) < 0; - }), - (t.cross = function (t, e) { - return t.y * e.x - t.x * e.y; - }), - (t.perpendicular = function (t, e) { - return new Vector2(-1 * (e.y - t.y), e.x - t.x); - }), - (t.normalize = function (t) { - var e = Math.sqrt(t.x * t.x + t.y * t.y); - return ( - e > MathHelper.Epsilon - ? (t = Vector2.divide(t, new Vector2(e))) - : (t.x = t.y = 0), - t - ); - }), - (t.transformA = function (t, e, n, i, o, r) { - for (var s = 0; s < r; s++) { - var a = t[e + s], - h = i[o + s]; - (h.x = a.x * n.m11 + a.y * n.m21 + n.m31), - (h.y = a.x * n.m12 + a.y * n.m22 + n.m32), - (i[o + s] = h); - } - }), - (t.transformR = function (t, e) { - var n = t.x * e.m11 + t.y * e.m21 + e.m31, - i = t.x * e.m12 + t.y * e.m22 + e.m32; - return new Vector2(n, i); - }), - (t.transform = function (t, e, n) { - this.transformA(t, 0, e, n, 0, t.length); - }), - (t.round = function (t) { - return new Vector2(Math.round(t.x), Math.round(t.y)); - }), - t - ); - })(); +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{h(i.next(t))}catch(t){r(t)}}function a(t){try{h(i.throw(t))}catch(t){r(t)}}function h(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,a)}h((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(n){var i=t.call(this)||this;return i._position=Vector2.zero,i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.scaleX=t.x,this.scaleY=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer),Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,o=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*o,this.uvs.width=e.width*i,this.uvs.height=e.height*o}}(),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),e.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t),this},e.prototype.setSprite=function(t){return this.removeChildren(),this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this._bitmap=new egret.Bitmap(t.texture2D),this.addChild(this._bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=this.entity.position.x-this.origin.x-t.position.x+t.origin.x,this.y=this.entity.position.y-this.origin.y-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n0;)this.removeChildAt(0)},e}(egret.DisplayObjectContainer),BaseFuiView=function(t){function e(e){var n=t.call(this)||this;return n.name=e,n}return __extends(e,t),e}(BaseView),BaseSingle=function(){function t(){}return t.getInstance=function(){return null==this._instance&&(this._instance=new this),this._instance},t.prototype.clearFuiObj=function(t){return!!t&&(egret.Tween.removeTweens(t.displayObject),t.displayObject&&t.displayObject.parent&&t.displayObject.parent.removeChild(t.displayObject),t.dispose(),t=null,!0)},t}(),ViewManager=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._openDic=[],e}return __extends(e,t),e.prototype.refreshView=function(t,e){var n=this.getView(t);n&&(n.refreshData(e),n.refreshView())},e.prototype.openView=function(t,e,n){var i=this.getView(t);if(i||(i=new t),this.existView(t))return i.refreshData(e),void i.refreshView();this._openDic.push(i)},e.prototype.getView=function(t){return this._openDic.firstOrDefault(function(e){return e instanceof t})},e.prototype.existView=function(t){return-1!=this._openDic.findIndex(function(e){return e instanceof t})},e}(BaseSingle),Flags=function(){function t(){}return t.isFlagSet=function(t,e){return 0!=(t&e)},t.isUnshiftedFlagSet=function(t,e){return 0!=(t&(e=1<n?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=h,i.m32=c,i},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return(i=i||new t).m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,n,i){this.x=t||0,this.y=e||0,this.width=n||0,this.height=i||0}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(g=Math.abs(g))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/c))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s +class Mesh extends RenderableComponent { + private _mesh: egret.Mesh; - for (let i = 0; i < this._verts.length; i ++){ - this._verts[i] = new VertexPosition(positions[i]); - } + constructor(){ + super(); - return this; + this._mesh = new egret.Mesh(); } - public setTriangles(triangles: number[]){ - this._primitiveCount = triangles.length / 3; - this._triangles = triangles; + public setTexture(texture: egret.Texture): Mesh{ + this._mesh.texture = texture; + return this; } - public recalculateBounds(){ - this._topLeftVertPosition = new Vector2(Number.MAX_VALUE, Number.MAX_VALUE); - let max = new Vector2(Number.MIN_VALUE, Number.MIN_VALUE); - - for (let i = 0; i < this._verts.length; i ++){ - this._topLeftVertPosition.x = Math.min(this._topLeftVertPosition.x, this._verts[i].position.x); - this._topLeftVertPosition.y = Math.min(this._topLeftVertPosition.y, this._verts[i].position.y); - max.x = Math.max(max.x, this._verts[i].position.x); - max.y = Math.max(max.y, this._verts[i].position.y); - } - - this._width = max.x - this._topLeftVertPosition.x; - this._height = max.y - this._topLeftVertPosition.y; + public onAddedToEntity(){ + this.addChild(this._mesh); + } - return this; + public onRemovedFromEntity(){ + this.removeChild(this._mesh); } - public render(){ + public render(camera: Camera){ + this.x = this.entity.position.x - camera.position.x + camera.origin.x; + this.y = this.entity.position.y - camera.position.y + camera.origin.y; } -} -class VertexPosition{ - public position: Vector2; - - constructor(position: Vector2){ - this.position = position; + public reset() { } } \ No newline at end of file diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index 9ce3464c..a5766250 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -104,23 +104,6 @@ abstract class Collider extends Component{ this._isParentEntityAddedToScene = false; } - public onEntityTransformChanged(comp: ComponentTransform){ - switch (comp){ - case ComponentTransform.position: - this._isPositionDirty = true; - break; - case ComponentTransform.scale: - this._isPositionDirty = true; - break; - case ComponentTransform.rotation: - this._isRotationDirty = true; - break; - } - - if (this._isColliderRegistered) - Physics.updateCollider(this); - } - public onEnabled(){ this.registerColliderWithPhysicsSystem(); this._isPositionDirty = this._isRotationDirty = true; diff --git a/source/src/ECS/Components/PolygonMesh.ts b/source/src/ECS/Components/PolygonMesh.ts deleted file mode 100644 index 7f75118c..00000000 --- a/source/src/ECS/Components/PolygonMesh.ts +++ /dev/null @@ -1,12 +0,0 @@ -class PolygonMesh extends Mesh { - constructor(points: Vector2[], arePointsCCW: boolean = true){ - super(); - - let triangulator = new Triangulator(); - triangulator.triangulate(points, arePointsCCW); - - this.setVertPosition(points); - this.setTriangles(triangulator.triangleIndices); - this.recalculateBounds(); - } -} \ No newline at end of file diff --git a/source/src/ECS/Components/RenderableComponent.ts b/source/src/ECS/Components/RenderableComponent.ts index 6bc5e11d..9a1940a3 100644 --- a/source/src/ECS/Components/RenderableComponent.ts +++ b/source/src/ECS/Components/RenderableComponent.ts @@ -1,3 +1,4 @@ +/// /** * 所有可渲染组件的基类 */ @@ -52,8 +53,4 @@ abstract class RenderableComponent extends PooledComponent implements IRenderabl this.isVisible = camera.getBounds().intersects(this.getBounds()); return this.isVisible; } - - public onEntityTransformChanged(comp: ComponentTransform){ - this._areBoundsDirty = true; - } } \ No newline at end of file diff --git a/source/src/ECS/Components/ScreenSpaceCamera.ts b/source/src/ECS/Components/ScreenSpaceCamera.ts deleted file mode 100644 index e6ac9cbd..00000000 --- a/source/src/ECS/Components/ScreenSpaceCamera.ts +++ /dev/null @@ -1,5 +0,0 @@ -class ScreenSpaceCamera extends Camera { - protected updateMatrixes(){ - - } -} \ No newline at end of file diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 91d7fa60..eb5ae729 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -193,10 +193,6 @@ class Entity extends egret.DisplayObjectContainer { this.components.removeAllComponents(); } - public onTransformChanged(comp: ComponentTransform){ - this.components.onEntityTransformChanged(comp); - } - public destroy(){ this._isDestoryed = true; this.scene.entities.remove(this); diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts deleted file mode 100644 index 6402b688..00000000 --- a/source/src/ECS/Transform.ts +++ /dev/null @@ -1,345 +0,0 @@ -enum DirtyType{ - clean, - positionDirty, - scaleDirty, - rotationDirty, -} - -enum ComponentTransform{ - position, - scale, - rotation -} - -class Transform { - /** 相关联的实体 */ - public readonly entity: Entity; - private _children: Transform[]; - private _parent: Transform; - - private _localPosition: Vector2; - private _localRotation: number = 0; - private _localScale: Vector2; - - private _translationMatrix: Matrix2D; - private _rotationMatrix: Matrix2D; - private _scaleMatrix: Matrix2D; - - private _worldTransform = Matrix2D.identity; - private _worldToLocalTransform = Matrix2D.identity; - private _worldInverseTransform = Matrix2D.identity; - - private _rotation: number = 0; - private _position: Vector2; - private _scale: Vector2; - - private _localTransform; - private _hierachyDirty: DirtyType; - private _localDirty: boolean; - private _localPositionDirty: boolean; - private _localScaleDirty: boolean; - private _localRotationDirty: boolean; - private _positionDirty: boolean; - private _worldToLocalDirty: boolean; - private _worldInverseDirty: boolean; - - public get childCount(){ - return this._children.length; - } - - constructor(entity: Entity){ - this.entity = entity; - this._scale = this._localScale = Vector2.one; - this._children = []; - } - - public getChild(index: number){ - return this._children[index]; - } - - public get worldInverseTransform(){ - this.updateTransform(); - if (this._worldInverseDirty){ - this._worldInverseTransform = Matrix2D.invert(this._worldTransform, this._worldInverseTransform); - this._worldInverseDirty = false; - } - - return this._worldInverseTransform; - } - - public get localToWorldTransform(){ - this.updateTransform(); - return this._worldTransform; - } - - public get worldToLocalTransform(){ - if (this._worldToLocalDirty){ - if (!this.parent){ - this._worldInverseTransform = new Matrix2D(); - } else{ - this.parent.updateTransform(); - this._worldToLocalTransform = Matrix2D.invert(this.parent._worldTransform, this._worldToLocalTransform); - } - - this._worldToLocalDirty = false; - } - - return this._worldToLocalTransform; - } - - public get parent(){ - return this._parent; - } - - public set parent(value: Transform){ - this.setParent(value); - } - - public setParent(parent: Transform){ - if (this._parent == parent) - return this; - - if (this._parent) - this._parent._children.remove(this); - - if (parent) - parent._children.push(this); - - this._parent = parent; - - return this; - } - - public get rotation() { - this.updateTransform(); - return this._rotation; - } - - public set rotation(value: number){ - this.setRotation(value); - } - - public get localRotation(){ - this.updateTransform(); - return this._localRotation; - } - - public set localRotation(value: number){ - this.setLocalRotation(value); - } - - public get position(){ - this.updateTransform(); - if (this._positionDirty){ - if (!this.parent){ - this._position = this._localPosition; - }else{ - this.parent.updateTransform(); - this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform); - } - - this._positionDirty = false; - } - - - return this._position; - } - - public set position(value: Vector2){ - this.setPosition(value); - } - - public get localPosition(){ - this.updateTransform(); - return this._localPosition; - } - - public set localPosition(value: Vector2){ - this.setLocalPosition(value); - } - - public get scale(){ - this.updateTransform(); - return this._scale; - } - - public set scale(value: Vector2){ - this.setScale(value); - } - - public get localScale(){ - this.updateTransform(); - return this._localScale; - } - - public set localScale(value: Vector2){ - this.setLocalScale(value); - } - - public get rotationDegrees(){ - return MathHelper.toDegrees(this._rotation); - } - - public set rotationDegrees(value: number){ - this.setRotation(MathHelper.toRadians(value)); - } - - public get localRotationDegrees(){ - return MathHelper.toDegrees(this._localRotation); - } - - public set localRotationDegrees(value: number){ - this.localRotation = MathHelper.toRadians(value); - } - - public setLocalScale(scale: Vector2){ - this._localScale = scale; - this._localDirty = this._positionDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.scaleDirty); - - return this; - } - - public setScale(scale: Vector2){ - this._scale = scale; - if (this.parent){ - this.localScale = Vector2.divide(scale, this.parent._scale); - }else{ - this.localScale = scale; - } - - return this; - } - - public setLocalRotationDegrees(degrees: number){ - return this.setLocalRotation(MathHelper.toRadians(degrees)); - } - - public setLocalRotation(radians: number){ - this._localRotation = radians; - this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.rotationDirty); - - return this; - } - - public setRotation(radians: number){ - this._rotation = radians; - if (this.parent){ - this.localRotation = this.parent.rotation + radians; - } else { - this.localRotation = radians; - } - - return this; - } - - public setRotationDegrees(degrees: number){ - return this.setRotation(MathHelper.toRadians(degrees)); - } - - public setLocalPosition(localPosition: Vector2){ - if (localPosition == this._localPosition) - return this; - - this._localPosition = localPosition; - this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; - this.setDirty(DirtyType.positionDirty); - - return this; - } - - public setPosition(position: Vector2){ - if (position == this._position) - return this; - - this._position = position; - if (this.parent){ - this.localPosition = Vector2.transform(this._position, this._worldToLocalTransform); - }else{ - this.localPosition = position; - } - - this._positionDirty = false; - - return this; - } - - public setDirty(dirtyFlagType: DirtyType){ - if ((this._hierachyDirty & dirtyFlagType) == 0){ - this._hierachyDirty |= dirtyFlagType; - - switch (dirtyFlagType){ - case DirtyType.positionDirty: - this.entity.onTransformChanged(ComponentTransform.position); - break; - case DirtyType.rotationDirty: - this.entity.onTransformChanged(ComponentTransform.rotation); - break; - case DirtyType.scaleDirty: - this.entity.onTransformChanged(ComponentTransform.scale); - break; - } - - if (this._children == null) - this._children = []; - - for (let i = 0; i < this._children.length; i ++){ - this._children[i].setDirty(dirtyFlagType); - } - } - } - - public roundPosition(){ - this.position = this._position.round(); - } - - public updateTransform(){ - if (this._hierachyDirty != DirtyType.clean){ - if (this.parent) - this.parent.updateTransform(); - - if (this._localDirty){ - if (this._localPositionDirty){ - this._translationMatrix = Matrix2D.createTranslation(this._localPosition.x, this._localPosition.y); - this._localPositionDirty = false; - } - - if (this._localRotationDirty){ - this._rotationMatrix = Matrix2D.createRotation(this._localRotation); - this._localRotationDirty = false; - } - - if (this._localScaleDirty){ - this._scaleMatrix = Matrix2D.createScale(this._localScale.x, this._localScale.y); - this._localScaleDirty = false; - } - - this._localTransform = Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix); - this._localTransform = Matrix2D.multiply(this._localTransform, this._translationMatrix); - - if (!this.parent){ - this._worldTransform = this._localTransform; - this._rotation = this._localRotation; - this._scale = this._localScale; - this._worldInverseDirty = true; - } - - this._localDirty = false; - } - - if (this.parent){ - this._worldTransform = Matrix2D.multiply(this._localTransform, this.parent._worldTransform); - - this._rotation = this._localRotation + this.parent._rotation; - this._scale = Vector2.multiply( this.parent._scale, this._localScale); - this._worldInverseDirty = true; - } - - this._worldToLocalDirty = true; - this._positionDirty = true; - this._hierachyDirty = DirtyType.clean; - } - - } -} \ No newline at end of file diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index 0a83171f..07849ed6 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -171,16 +171,4 @@ class ComponentList { component.update(); } } - - public onEntityTransformChanged(comp){ - for (let i = 0; i < this._components.length; i++){ - if (this._components[i].enabled) - this._components[i].onEntityTransformChanged(comp); - } - - for (let i = 0; i < this._componentsToAdd.length; i ++){ - if (this._componentsToAdd[i].enabled) - this._componentsToAdd[i].onEntityTransformChanged(comp); - } - } } \ No newline at end of file diff --git a/source/src/Graphics/Batcher/GraphicsResource.ts b/source/src/Graphics/Batcher/GraphicsResource.ts deleted file mode 100644 index b57b6ba6..00000000 --- a/source/src/Graphics/Batcher/GraphicsResource.ts +++ /dev/null @@ -1,3 +0,0 @@ -abstract class GraphicsResource { - -} \ No newline at end of file diff --git a/source/src/Graphics/PostProcessing/PostProcessors/BloomSettings.ts b/source/src/Graphics/PostProcessing/PostProcessors/BloomSettings.ts deleted file mode 100644 index e8cba8aa..00000000 --- a/source/src/Graphics/PostProcessing/PostProcessors/BloomSettings.ts +++ /dev/null @@ -1,27 +0,0 @@ -class BloomSettings { - public readonly threshold; - public readonly blurAmount; - public readonly intensity; - public readonly baseIntensity; - public readonly saturation; - public readonly baseStaturation; - - constructor(bloomThreshold: number, blurAmount: number, bloomIntensity: number,baseIntensity: number, - bloomSaturation: number, baseSaturation: number){ - this.threshold = bloomThreshold; - this.blurAmount = blurAmount; - this.intensity = bloomIntensity; - this.baseIntensity = baseIntensity; - this.saturation = bloomSaturation; - this.baseStaturation = baseSaturation; - } - - public static presetSettings: BloomSettings[] = [ - new BloomSettings(0.1, 0.6, 2, 1, 1, 0), - new BloomSettings(0, 3, 1, 1, 1, 1), - new BloomSettings(0.5, 8, 2, 1, 0, 1), - new BloomSettings(0.25, 8, 1.3, 1, 1, 0), - new BloomSettings(0, 2, 1, 0.1, 1, 1), - new BloomSettings(0.5, 2, 1, 1, 1, 1) - ]; -} \ No newline at end of file