diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index c20ebc01..0a0d79c6 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -92,13 +92,16 @@ declare abstract class Component { deregisterComponent(): void; } declare class Entity { + private static _idGenerator; name: string; + readonly id: number; scene: Scene; readonly transform: Transform; readonly components: ComponentList; private _updateOrder; private _enabled; private _isDestoryed; + private _tag; componentBits: BitSet; parent: Transform; position: Vector2; @@ -115,9 +118,11 @@ declare class Entity { readonly isDestoryed: boolean; enabled: boolean; setEnabled(isEnabled: boolean): this; + tag: number; constructor(name: string); updateOrder: number; setUpdateOrder(updateOrder: number): this; + setTag(tag: number): Entity; attachToScene(newScene: Scene): void; detachFromScene(): void; addComponent(component: T): T; @@ -323,12 +328,17 @@ declare class EntityList { private _entitiesToAdded; private _tempEntityList; private _entities; + private _entityDict; + private _unsortedTags; constructor(scene: Scene); readonly count: number; readonly buffer: Entity[]; add(entity: Entity): void; remove(entity: Entity): void; findEntity(name: string): Entity; + getTagList(tag: number): Entity[]; + addToTagList(entity: Entity): void; + removeFromTagList(entity: Entity): void; update(): void; removeAllEntities(): void; updateLists(): void; @@ -398,16 +408,50 @@ declare class Point { y: number; constructor(x: number, y: number); } +declare class Rectangle { + x: number; + y: number; + width: number; + height: number; + constructor(x: number, y: number, width: number, height: number); +} declare class Vector2 { x: number; y: number; - private static readonly unitVector2; + private static readonly zeroVector; + private static readonly unitVector; static readonly One: Vector2; + static readonly Zero: Vector2; constructor(x: number, y: number); static add(value1: Vector2, value2: Vector2): Vector2; static divide(value1: Vector2, value2: Vector2): Vector2; static multiply(value1: Vector2, value2: Vector2): Vector2; static subtract(value1: Vector2, value2: Vector2): Vector2; normalize(): void; + static dot(value1: Vector2, value2: Vector2): number; + static distanceSquared(value1: Vector2, value2: Vector2): number; static transform(position: Vector2, matrix: Matrix2D): Vector2; } +declare enum PointSectors { + center = 0, + top = 1, + bottom = 2, + topLeft = 9, + topRight = 5, + left = 8, + right = 4, + bottomLeft = 10, + bottomRight = 6 +} +declare class Collisions { + static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean; + static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2; + static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; + static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean; + static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean; + static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean; + static isRectToCircle(rect: Rectangle, cPosition: Vector2, cRadius: number): boolean; + static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean; + static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean; + static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors; +} diff --git a/source/bin/framework.js b/source/bin/framework.js index d4a31b55..1b3c63a2 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -558,9 +558,11 @@ var Entity = (function () { function Entity(name) { this._updateOrder = 0; this._enabled = true; + this._tag = 0; this.name = name; this.transform = new Transform(this); this.components = new ComponentList(this); + this.id = Entity._idGenerator++; this.componentBits = new BitSet(); } Object.defineProperty(Entity.prototype, "parent", { @@ -697,6 +699,16 @@ var Entity = (function () { } 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, "updateOrder", { get: function () { return this._updateOrder; @@ -715,6 +727,18 @@ var Entity = (function () { 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); @@ -1675,6 +1699,8 @@ var EntityList = (function () { this._entitiesToAdded = []; this._tempEntityList = []; this._entities = []; + this._entityDict = new Map(); + this._unsortedTags = []; this.scene = scene; } Object.defineProperty(EntityList.prototype, "count", { @@ -1709,6 +1735,27 @@ var EntityList = (function () { } 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]; @@ -1723,6 +1770,7 @@ var EntityList = (function () { this._entities[i].scene = null; } this._entities.length = 0; + this._entityDict.clear(); }; EntityList.prototype.updateLists = function () { var _this = this; @@ -1749,6 +1797,12 @@ var EntityList = (function () { 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; }()); @@ -2026,6 +2080,15 @@ var Point = (function () { } return Point; }()); +var Rectangle = (function () { + function Rectangle(x, y, width, height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + return Rectangle; +}()); var Vector2 = (function () { function Vector2(x, y) { this.x = 0; @@ -2035,7 +2098,14 @@ var Vector2 = (function () { } Object.defineProperty(Vector2, "One", { get: function () { - return this.unitVector2; + return this.unitVector; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "Zero", { + get: function () { + return this.zeroVector; }, enumerable: true, configurable: true @@ -2065,9 +2135,169 @@ var Vector2 = (function () { this.x *= val; this.y *= val; }; + 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.transform = function (position, matrix) { return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); }; - Vector2.unitVector2 = new Vector2(1, 1); + Vector2.zeroVector = new Vector2(0, 0); + Vector2.unitVector = new Vector2(1, 1); return Vector2; }()); +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 = {})); +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 = Vector2.Zero; + 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) { + if (this.isRectToPoint(rect.x, rect.y, rect.width, rect.height, cPosition)) + return true; + var edgeFrom; + var edgeTo; + var sector = this.getSector(rect.x, rect.y, rect.width, rect.height, cPosition); + if ((sector & PointSectors.top) != 0) { + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x + rect.width, rect.y); + if (this.isCircleToLine(cPosition, cRadius, edgeFrom, edgeTo)) + return true; + } + if ((sector & 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.isCircleToLine(cPosition, cRadius, edgeFrom, edgeTo)) + return true; + } + if ((sector & PointSectors.left) != 0) { + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x, rect.y + rect.height); + if (this.isCircleToLine(cPosition, cRadius, edgeFrom, edgeTo)) + return true; + } + if ((sector & 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.isCircleToLine(cPosition, cRadius, edgeFrom, edgeTo)) + return true; + } + return false; + }; + 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; +}()); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index f83322e0..2ef71137 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +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 o(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var n=0,o=t.length;n-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,o,i){return e.call(arguments[2],o,i,t)&&n.push(o),n},[]);for(var n=[],o=0,i=t.length;o=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,o,i){return n.push(e.call(arguments[2],o,i,t)),n},[]);for(var n=[],o=0,i=t.length;or?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,o){var i=e(t),r=e(o);return n?-n(i,r):i0;){if("break"===h())break}return i?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,o=t.keys();!(n=o.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,o,i=t.keys(),r=t.values();n=i.next(),o=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return o.value;return null},t.recontructPath=function(t,e,n){var o=[],i=n;for(o.push(n);i!=e;)i=this.getKey(t,i),o.push(i);return o.reverse(),o},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 o=2*n;if(o>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var i=this._nodes[o];this.hasHigherPriority(i,e)&&(e=i);var r=o+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=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.entities=new EntityList(n),n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n.addEventListener(egret.Event.ENTER_FRAME,n.update,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var 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),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){var t=this;SceneManager.getActiveScene().entities.buffer.forEach(function(e){return e.components.buffer.forEach(function(e){e.displayRender&&(-1==t.entity.scene.$children.indexOf(e.displayRender)&&t.entity.scene.stage.addChild(e.displayRender))})})},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areMatrixesDirty=!1)},e.prototype.destory=function(){},e}(Component),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),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),o=0;o=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 o=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((o=((o=(o>>4&252645135)+(252645135&o))>>8&16711935)+(16711935&o))>>16&65535)+(65535&o)}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.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e)}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.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}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._lastTime=t},t.timeScale=1,t._lastTime=0,t}(),MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,n,o,i){return o+(t-e)*(i-o)/(n-e)},t.clamp=function(t,e,n){return tn?n:t},t}(),Matrix2D=function(){function t(t,e,n,o,i,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=e,this.m21=n,this.m22=o,this.m31=i,this.m32=r}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(t,e){var n=t.m11*e.m11+t.m12*e.m21,o=t.m11*e.m12+t.m12*e.m22,i=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=n,t.m12=o,t.m21=i,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,n,o){var i=t.createTranslation(n,o);return t.multiply(e,i)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=t.identity);var o=1/e.determinant();return n.m11=e.m22*o,n.m12=-e.m12*o,n.m21=-e.m21*o,n.m22=e.m11*o,n.m31=(e.m32*e.m21-e.m31*e.m22)*o,n.m32=-(e.m32*e.m11-e.m31*e.m12)*o,n},t.createTranslation=function(e,n,o){return void 0===o&&(o=t.identity),o.m11=1,o.m12=0,o.m21=0,o.m22=1,o.m31=e,o.m32=n,o},t.createRotation=function(e,n){n=t.identity;var o=Math.cos(e),i=Math.sin(e);return n.m11=o,n.m12=i,n.m21=-i,n.m22=o,n},t.createScale=function(e,n,o){return void 0===o&&(o=t.identity),o.m11=e,o.m12=0,o.m21=0,o.m22=n,o.m31=0,o.m32=0,o},t._identity=new t(1,0,0,1,0,0),t}(),Point=function(){return function(t,e){this.x=t,this.y=e}}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t,this.y=e}return Object.defineProperty(t,"One",{get:function(){return this.unitVector2},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.x+=e.x,t.y+=e.y,t},t.divide=function(t,e){return t.x/=e.x,t.y/=e.y,t},t.multiply=function(t,e){return t.x*=e.x,t.y*=e.y,t},t.subtract=function(t,e){return t.x-=e.x,t.y-=e.y,t},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},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.unitVector2=new t(1,1),t}(); \ No newline at end of file +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)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var n=0,i=t.length;n-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"===c())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.priority=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.entities=new EntityList(n),n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n.addEventListener(egret.Event.ENTER_FRAME,n.update,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var 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),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){var t=this;SceneManager.getActiveScene().entities.buffer.forEach(function(e){return e.components.buffer.forEach(function(e){e.displayRender&&(-1==t.entity.scene.$children.indexOf(e.displayRender)&&t.entity.scene.stage.addChild(e.displayRender))})})},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areMatrixesDirty=!1)},e.prototype.destory=function(){},e}(Component),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),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=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.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}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._lastTime=t},t.timeScale=1,t._lastTime=0,t}(),MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t.map=function(t,e,n,i,o){return i+(t-e)*(o-i)/(n-e)},t.clamp=function(t,e,n){return tn?n:t},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,this.m12=e,this.m21=n,this.m22=i,this.m31=o,this.m32=r}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(t,e){var n=t.m11*e.m11+t.m12*e.m21,i=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,r=t.m21*e.m12+t.m22*e.m22,s=t.m31*e.m11+t.m32*e.m21+e.m31,a=t.m31*e.m12+t.m32*e.m22+e.m32;return t.m11=n,t.m12=i,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},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=t.identity);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 void 0===i&&(i=t.identity),i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=t.identity;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=t.identity),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t._identity=new t(1,0,0,1,0,0),t}(),Point=function(){return function(t,e){this.x=t,this.y=e}}(),Rectangle=function(){return function(t,e,n,i){this.x=t,this.y=e,this.width=n,this.height=i}}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t,this.y=e}return Object.defineProperty(t,"One",{get:function(){return this.unitVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"Zero",{get:function(){return this.zeroVector},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.x+=e.x,t.y+=e.y,t},t.divide=function(t,e){return t.x/=e.x,t.y/=e.y,t},t.multiply=function(t,e){return t.x*=e.x,t.y*=e.y,t},t.subtract=function(t,e){return t.x-=e.x,t.y-=e.y,t},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=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.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.zeroVector=new t(0,0),t.unitVector=new t(1,1),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),c=(a.x*r.y-a.y*r.x)/s;if(c<0||c>1)return!1;var h=(a.x*o.y-a.y*o.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var o=Vector2.Zero,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 c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return o;var u=(c.x*r.y-c.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(h*r.x,h*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}(); \ No newline at end of file