1 line
78 KiB
JavaScript
1 line
78 KiB
JavaScript
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 i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var i=0,n=t.length;i<n;i++)if(e.call(arguments[2],t[i],i,t))return i;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 i=t.findIndex(e);return-1==i?null:t[i]}(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(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n<o;n++){var r=t[n];e.call(arguments[2],r,n,t)&&i.push(r)}return i}(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 i=0,n=t.length;i<n;i++)if(t[i]==e)return!0;return!1}(this,t)},Array.prototype.removeAll=function(t){!function(t,e){var i;do{(i=t.findIndex(e))>=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,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,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;n<o;n++)i.push(e.call(arguments[2],t[n],n,t));return i}(this,t)},Array.prototype.orderBy=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?i(o,r):o>r?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(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 i=[];return t.reduce(function(n,o,r){var s=JSON.stringify(e.call(arguments[1],o,r,t)),a=i.findIndex(function(t){return t===s});return a<0&&(a=i.push(s)-1),n[a]||(n[a]=[]),n[a].push(o),n},[])}for(var n=[],o=[],r=function(i,r){var a=JSON.stringify(e.call(s[1],t[i],i,t)),h=o.findIndex(function(t){return t===a});h<0&&(h=o.push(a)-1),n[h]||(n[h]=[]),n[h].push(t[i])},s=arguments,a=0,h=t.length;a<h;a++)r(a);return n}(this,t)},Array.prototype.sum=function(t){return function(t,e){for(var i,n=0,o=t.length;n<o;n++)0==n?i=e?e.call(arguments[2],t[n],n,t):t[n]:i+=e?e.call(arguments[2],t[n],n,t):t[n];return i}(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,i){var n=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(i))return o=!0,"break";t.getNeighbors(e.data).forEach(function(o){var h=s.get(e.data)+t.cost(e.data,o);if(!n.hasKey(s,o)||h<s.get(o)){s.set(o,h);var c=h+t.heuristic(o,i);a.enqueue(new AStarNode(o),c),r.set(o,e.data)}})};a.count>0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}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(i){var n=new Point(t.x+i.x,t.y+i.y);e.isNodeInBounds(n)&&e.isNodePassable(n)&&e._neighbors.push(n)}),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 i=e+1;if(i<this._nodes.length&&this._nodes[i]&&this.hasHigherPriority(this._nodes[i],this._nodes[t]))return!1}return!0},t.prototype.onNodeUpdated=function(t){var e=Math.floor(t.queueIndex/2),i=this._nodes[e];e>0&&this.hasHigherPriority(t,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},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,i){var n=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(i))return o=!0,"break";t.getNeighbors(e).forEach(function(t){n.hasKey(s,t)||(r.unshift(t),s.set(t,e))})};r.length>0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.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,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?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(i){var n=new Point(t.x+i.x,t.y+i.y);e.isNodeInBounds(n)&&e.isNodePassable(n)&&e._neighbors.push(n)}),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,i,n){void 0===n&&(n=!1),this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=i,this._dirs=n?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(i){var n=new Point(t.x+i.x,t.y+i.y);e.isNodeInBounds(n)&&e.isNodePassable(n)&&e._neighbors.push(n)}),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 i=t.call(this)||this;return i.data=e,i}return __extends(e,t),e}(PriorityQueueNode),WeightedPathfinder=function(){function t(){}return t.search=function(t,e,i){var n=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(i))return o=!0,"break";t.getNeighbors(e.data).forEach(function(i){var o=s.get(e.data)+t.cost(e.data,i);if(!n.hasKey(s,i)||o<s.get(i)){s.set(i,o);var h=o;a.enqueue(new WeightedNode(i),h),r.set(i,e.data)}})};a.count>0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),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){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.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},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e<this.transform.childCount;e++)this.transform.getChild(e).entity.attachToScene(t)},t.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t<this.transform.childCount;t++)this.transform.getChild(t).entity.detachFromScene()},t.prototype.addComponent=function(t){return t.entity=this,this.components.add(t),t.initialize(),t},t.prototype.hasComponent=function(t){return null!=this.components.getComponent(t,!1)},t.prototype.getOrCreateComponent=function(t){var e=this.components.getComponent(t,!0);return e||(e=this.addComponent(t)),e},t.prototype.getComponent=function(t){return this.components.getComponent(t,!1)},t.prototype.getComponents=function(t,e){return this.components.getComponents(t,e)},t.prototype.removeComponentForType=function(t){var e=this.getComponent(t);return!!e&&(this.removeComponent(e),!0)},t.prototype.removeComponent=function(t){this.components.remove(t)},t.prototype.removeAllComponents=function(){for(var t=0;t<this.components.count;t++)this.removeComponent(this.components.buffer[t])},t.prototype.update=function(){this.components.update(),this.transform.updateTransform()},t.prototype.onAddedToScene=function(){},t.prototype.onRemovedFromScene=function(){this._isDestoryed&&this.components.remove},t.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},t.prototype.destory=function(){this._isDestoryed=!0,this.scene.entities.remove(this),this.transform.parent=null;for(var t=this.transform.childCount-1;t>=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var i=t.call(this)||this;return e.stage.addChild(i),i._projectionMatrix=new Matrix2D(0,0,0,0,0,0),i.entityProcessors=new EntityProcessorList,i.entities=new EntityList(i),i.addEventListener(egret.Event.ACTIVATE,i.onActive,i),i.addEventListener(egret.Event.DEACTIVATE,i.onDeactive,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i}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;e<t.transform.childCount;e++)this.addEntity(t.transform.getChild(e).entity);return t},e.prototype.destroyAllEntities=function(){for(var t=0;t<this.entities.count;t++)this.entities.buffer[t].destory()},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.setActive=function(){return SceneManager.setActiveScene(this),this},e.prototype.initialize=function(){this.camera=this.createEntity("camera").getOrCreateComponent(new Camera),Physics.reset(),this.entityProcessors&&this.entityProcessors.begin()},e.prototype.onActive=function(){},e.prototype.onDeactive=function(){},e.prototype.update=function(){Time.update(egret.getTimer()),this.entities.updateLists(),this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.entityProcessors&&this.entityProcessors.lateUpdate()},e.prototype.prepRenderState=function(){this._projectionMatrix.m11=2/this.stage.width,this._projectionMatrix.m22=-2/this.stage.height,this._transformMatrix=this.camera.transformMatrix,this._matrixTransformMatrix=Matrix2D.multiply(this._transformMatrix,this._projectionMatrix)},e.prototype.destory=function(){this.removeEventListener(egret.Event.DEACTIVATE,this.onDeactive,this),this.removeEventListener(egret.Event.ACTIVATE,this.onActive,this),this.camera.destory(),this.camera=null,this.entities.removeAllEntities()},e}(egret.DisplayObjectContainer),SceneManager=function(){function t(){}return t.createScene=function(t,e){return e.name=t,this._loadedScenes.set(t,e),e},t.setActiveScene=function(t){if(this._activeScene){if(this._activeScene==t)return;this._lastScene=this._activeScene,this._activeScene.destory()}return this._activeScene=t,this._activeScene.initialize(),t},t.getActiveScene=function(){return this._activeScene},t._loadedScenes=new Map,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 PointSectors,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=new Vector2(0,0),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=Matrix2D.identity,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.parent?(this.parent.updateTransform(),this._position=Vector2.transform(this._localPosition,this.parent._worldTransform)):this._position=this._localPosition,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)},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.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._transformMatrix=Matrix2D.identity,e._inverseTransformMatrix=Matrix2D.identity,e._minimumZoom=.3,e._maximumZoom=3,e._areMatrixesDirty=!0,e._areBoundsDirty=!0,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"bounds",{get:function(){if(this._areMatrixesDirty&&this.updateMatrixes(),this._areBoundsDirty){var t=this.entity.scene.stage,e=this.screenToWorldPoint(new Vector2(this._inset.left,this._inset.top)),i=this.screenToWorldPoint(new Vector2(t.stageWidth-this._inset.right,t.stageHeight-this._inset.bottom));if(0!=this.entity.transform.rotation){var n=this.screenToWorldPoint(new Vector2(t.stageWidth-this._inset.right,this._inset.top)),o=this.screenToWorldPoint(new Vector2(this._inset.left,t.stageHeight-this._inset.bottom)),r=MathHelper.minOf(e.x,i.x,n.x,o.x),s=MathHelper.maxOf(e.x,i.x,n.x,o.x),a=MathHelper.minOf(e.y,i.y,n.y,o.y),h=MathHelper.maxOf(e.y,i.y,n.y,o.y);this._bounds.location=new Vector2(r,a),this._bounds.width=s-r,this._bounds.height=h-a}else this._bounds.location=e,this._bounds.width=i.x-e.x,this._bounds.height=i.y-e.y;this._areBoundsDirty=!1}return this._bounds},enumerable:!0,configurable:!0}),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,this._areMatrixesDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"transformMatrix",{get:function(){return this._areBoundsDirty&&this.updateMatrixes(),this._transformMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"inverseTransformMatrix",{get:function(){return this._areBoundsDirty&&this.updateMatrixes(),this._inverseTransformMatrix},enumerable:!0,configurable:!0}),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),this._areMatrixesDirty=!0,this},e.prototype.initialize=function(){},e.prototype.update=function(){},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._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2.transform(t,this._transformMatrix)},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){}}(),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,i){void 0===i&&(i=!0);var n=t.call(this)||this,o=new Triangulator;return o.triangulate(e,i),n.setVertPosition(e),n.setTriangles(o.triangleIndices),n.recalculateBounds(),n}return __extends(e,t),e}(Mesh),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!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 this.getBounds()},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.getBounds=function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,new Vector2(0,0),this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},e}(Component),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),e.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=new Vector2(this._sprite.anchorOffsetX,this._sprite.anchorOffsetY)),this},e.prototype.initialize=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 i=this.entity.getComponents(Collider),n=0;n<i.length;n++){var o=i[n];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(i),e},e.prototype.applyMovement=function(t){this.entity.transform.position=Vector2.add(this.entity.transform.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._isColliderRegisterd&&(Physics.addCollider(this),this._isColliderRegisterd=!0)},e.prototype.unregisterColliderWithPhysicsSystem=function(){this._isParentEntityAddedToScene&&this._isColliderRegisterd&&Physics.removeCollider(this),this._isColliderRegisterd=!1},e.prototype.overlaps=function(t){return this.shape.overlaps(t.shape)},e.prototype.collidesWith=function(t,e){var i=this.shape.position;this.shape.position=Vector2.add(this.shape.position,e);var n=this.shape.collidesWithShape(t.shape);return n&&(n.collider=t),this.shape.position=i,n},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,i=e.width/this.entity.transform.scale.x,n=e.height/this.entity.transform.scale.y;if(this instanceof BoxCollider){this.width=i,this.height=n,this.localOffset=Vector2.subtract(e.center,this.entity.transform.position)}}}this._isParentEntityAddedToScene=!0,this.registerColliderWithPhysicsSystem()},e.prototype.onEntityTransformChanged=function(t){switch(t){case ComponentTransform.position:case ComponentTransform.scale:this._isPositionDirty=!0;break;case ComponentTransform.rotation:this._isRotationDirty=!0}this._isColliderRegisterd&&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 i=this.shape;return t==i.width&&e==i.height||(i.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),i=this._matcher.IsIntersted(t);i&&!e?this.add(t):!i&&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 i=e>>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n<i;++n)this._bits[n]&=t._bits[n];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 i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}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 i=0;i<this._bits.length;i++)this._bits[i]=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,i=1<<t;e<this._bits.length;){var n=this._bits[e];do{if(0!=(n&i))return t;i<<=1,t++}while(0!=i);i=1,e++}return-1},t.prototype.set=function(t,e){if(void 0===e&&(e=!0),e){var i=t>>6;this.ensure(i),this._bits[i]|=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];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];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++){var i=this._componentsToAdd[t];this._entity.componentBits.set(ComponentTypeManager.getIndexFor(i)),this._entity.scene.entityProcessors.onComponentAdded(this._entity),this._components.push(i),this._tempBufferList.push(i)}this._componentsToAdd.length=0;for(t=0;t<this._tempBufferList.length;t++){(i=this._tempBufferList[t]).onAddedToEntity(),i.enabled&&i.onEnabled()}this._tempBufferList.length=0}},t.prototype.handleRemove=function(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 i=0;i<this._components.length;i++){if((n=this._components[i])instanceof t)return n}if(!e)for(i=0;i<this._componentsToAdd.length;i++){var n;if((n=this._componentsToAdd[i])instanceof t)return n}return null},t.prototype.getComponents=function(t,e){e||(e=[]);for(var i=0;i<this._components.length;i++){var n=this._components[i];"string"==typeof t&&egret.is(n,t)?e.push(n):n instanceof t&&e.push(n)}for(i=0;i<this._componentsToAdd.length;i++){n=this._componentsToAdd[i];"string"==typeof t&&egret.is(n,t)?e.push(n):n instanceof t&&e.push(n)}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){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].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.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.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}(),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}(),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.017453292519943295*t},t.map=function(t,e,i,n,o){return n+(t-e)*(o-n)/(i-e)},t.lerp=function(t,e,i){return t+(e-t)*i},t.clamp=function(t,e,i){return t<e?e:t>i?i:t},t.minOf=function(t,e,i,n){return Math.min(t,Math.min(e,Math.min(i,n)))},t.maxOf=function(t,e,i,n){return Math.max(t,Math.max(e,Math.max(i,n)))},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,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=i,this.m22=n,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),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,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 i=t.m11*e.m11+t.m12*e.m21,n=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=i,t.m12=n,t.m21=o,t.m22=r,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=t.identity);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=t.identity;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=t.identity),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||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}),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.fromMinMax=function(e,i,n,o){return new t(e,i,n-e,o-i)},t.prototype.getClosestPointOnRectangleBorderToPoint=function(t){var e=new Vector2(0,0),i=new Vector2(0,0);if(i.x=MathHelper.clamp(t.x,this.left,this.right),i.y=MathHelper.clamp(t.y,this.top,this.bottom),this.contains(i)){var n=i.x-this.left,o=this.right-i.x,r=i.y-this.top,s=this.bottom-i.y,a=MathHelper.minOf(n,o,r,s);a==r?(i.y=this.top,e.y=-1):a==s?(i.y=this.bottom,e.y=1):a==n?(i.x=this.left,e.x=-1):(i.x=this.right,e.x=1)}else i.x==this.left&&(e.x=-1),i.x==this.right&&(e.x=1),i.y==this.top&&(e.y=-1),i.y==this.bottom&&(e.y=1);return{res:i,edgeNormal:e}},t.prototype.calculateBounds=function(t,e,i,n,o,r,s){if(0==o)this.x=t.x+e.x-i.x*n.x,this.y=t.y+e.y-i.y*n.y,this.width=r*n.x,this.height=s*n.y;else{var a=t.x+e.x,h=t.y+e.y;this._transformMat=Matrix2D.createTranslation(-a-i.x,-h-i.y),this._tempMat=Matrix2D.createScale(n.x,n.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=Vector2.transform(c,this._transformMat),u=Vector2.transform(u,this._transformMat),l=Vector2.transform(l,this._transformMat),p=Vector2.transform(p,this._transformMat);var f=MathHelper.minOf(c.x,p.x,u.x,l.x),y=MathHelper.maxOf(c.x,p.x,u.x,l.x),d=MathHelper.minOf(c.y,p.y,u.y,l.y),m=MathHelper.maxOf(c.y,p.y,u.y,l.y);this.location=new Vector2(f,d),this.width=y-f,this.height=m-d}},t.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,n=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>n&&(n=s.x),s.y<i&&(i=s.y),s.y>o&&(o=s.y)}return this.fromMinMax(e,i,n,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,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,e},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,e},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.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 i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},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}(),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 i=t[e],n=Physics.boxcastBroadphase(i.bounds,i.collidesWithLayers),o=0;o<n.length;o++){var r=n[o];if((i.isTrigger||r.isTrigger)&&i.overlaps(r)){var s=new Pair(i,r);!this._activeTriggerIntersections.contains(s)&&!this._previousTriggerIntersections.contains(s)&&this.notifyTriggerListeners(s,!0),this._activeTriggerIntersections.push(s)}}ListPool.free(t),this.checkForExitedColliders()},t.prototype.checkForExitedColliders=function(){var t=this,e=[];this._previousTriggerIntersections=this._previousTriggerIntersections.filter(function(i){for(var n=0;n<t._activeTriggerIntersections.length;n++)if(i==t._activeTriggerIntersections[n])return e.push(i),!0;return!1}),this._previousTriggerIntersections.forEach(function(e){return t.notifyTriggerListeners(e,!1)}),this._previousTriggerIntersections.length=0,e.forEach(function(e){return t._previousTriggerIntersections.push(e)}),this._activeTriggerIntersections.length=0},t.prototype.notifyTriggerListeners=function(t,e){t.first.entity.getComponents("ITriggerListener",this._tempTriggerList);for(var i=0;i<this._tempTriggerList.length;i++)if(e?this._tempTriggerList[i].onTriggerEnter(t.second,t.first):this._tempTriggerList[i].onTriggerExit(t.second,t.first),this._tempTriggerList.length=0,t.second.entity){t.second.entity.getComponents("ITriggerListener",this._tempTriggerList);for(var n=0;n<this._tempTriggerList.length;n++)e?this._tempTriggerList[n].onTriggerEnter(t.first,t.second):this._tempTriggerList[n].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,i,n){var o=Vector2.subtract(e,t),r=Vector2.subtract(n,i),s=o.x*r.y-o.y*r.x;if(0==s)return!1;var a=Vector2.subtract(i,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,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,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,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))<e*e},t.isCircleToPoint=function(t,e,i){return Vector2.distanceSquared(t,i)<e*e},t.isRectToCircle=function(t,e,i){var n=.5*t.width,o=.5*t.height,r=Math.max(0,Math.max(e.x-t.x)-n),s=Math.max(0,Math.max(e.y-t.y)-o);return r*r+s*s<i*i},t.isRectToLine=function(t,e,i){var n=this.getSector(t.x,t.y,t.width,t.height,e),o=this.getSector(t.x,t.y,t.width,t.height,i);if(n==PointSectors.center||o==PointSectors.center)return!0;if(0!=(n&o))return!1;var r=n|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,i)))||(!(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,i)))||(!(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,i)))||!(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,i)))))},t.isRectToPoint=function(t,e,i,n,o){return o.x>=t&&o.y>=e&&o.x<t+i&&o.y<e+n},t.getSector=function(t,e,i,n,o){var r=PointSectors.center;return o.x<t?r|=PointSectors.left:o.x>=t+i&&(r|=PointSectors.right),o.y<e?r|=PointSectors.top:o.y>=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},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(i,n){var o=t.call(this)||this;return o.isUnrotated=!0,o._areEdgeNormalsDirty=!0,o.setPoints(e.buildSymmertricalPolygon(i,n)),o}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 i=0;i<e;i++){var n=this.points[i];t=i+1>=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){var e=this;this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=new Array(this.points.length),this.points.forEach(function(t){return e._originalPoints.push(t)})},e.prototype.collidesWithShape=function(t){var i=new CollisionResult;if(t instanceof e)return i=ShapeCollisions.polygonToPolygon(this,t);if(t instanceof Circle)return(i=ShapeCollisions.circleToPolygon(t,this))?(i.invertResult(),i):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 i;if(t instanceof e)return ShapeCollisions.polygonToPolygon(this,t);if(t instanceof Circle)return!!(i=ShapeCollisions.circleToPolygon(t,this))&&(i.invertResult(),!0);throw new Error("overlaps of Pologon to "+t+" are not supported")},e.findPolygonCenter=function(t){for(var e=0,i=0,n=0;n<t.length;n++)e+=t[n].x,i+=t[n].y;return new Vector2(e/t.length,i/t.length)},e.getClosestPointOnPolygonToPoint=function(t,e){for(var i,n=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((i=Vector2.distanceSquared(e,h))<n){n=i,r=h;var c=Vector2.subtract(t[a],t[s]);o.x=-c.y,o.y=c.x}}return{closestPoint:r,distanceSquared:n,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,i=0,n=this.points.length-1;i<this.points.length;n=i++)this.points[i].y>t.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n<t;n++){var o=2*Math.PI*(n/t);i[n]=new Vector2(Math.cos(o),Math.sin(o)*e)}return i},e.prototype.recalculateBounds=function(t){if(this.center=t.localOffset,t.shouldColliderScaleAndRotationWithTransform){var e=!0,i=void 0,n=Matrix2D.createTranslation(-this._polygonCenter.x,-this._polygonCenter.y);if(t.entity.transform.scale!=Vector2.one){i=Matrix2D.createScale(t.entity.transform.scale.x,t.entity.transform.scale.y),n=Matrix2D.multiply(n,i),e=!1;var o=Vector2.multiply(t.localOffset,t.entity.transform.scale);this.center=o}if(0!=t.entity.transform.rotation){i=Matrix2D.createRotation(t.entity.transform.rotation),n=Matrix2D.multiply(n,i);var r=Math.atan2(t.localOffset.y,t.localOffset.x)*MathHelper.Rad2Deg,s=e?t._localOffsetLength:Vector2.multiply(t.localOffset,t.entity.transform.scale).length();this.center=MathHelper.pointOnCirlce(Vector2.zero,s,t.entity.transform.rotationDegrees+r)}i=Matrix2D.createTranslation(this._polygonCenter.x,this._polygonCenter.y),n=Matrix2D.multiply(n,i),Vector2Ext.transform(this._originalPoints,n,this.points),this.isUnrotated=0==t.entity.transform.rotation,t._isRotationDirty&&(this._areEdgeNormalsDirty=!0)}this.position=Vector2.add(t.entity.transform.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(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.updateBox=function(t,e){this.width=t,this.height=e;var i=t/2,n=e/2;this.points[0]=new Vector2(-i,-n),this.points[1]=new Vector2(i,-n),this.points[2]=new Vector2(i,n),this.points[3]=new Vector2(-i,n);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 i=t.call(this)||this;return i.radius=e,i._originalRadius=e,i}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.transform.scale,i=1==e.x&&1==e.y,n=Math.max(e.x,e.y);if(this.radius=this._originalRadius*n,0!=t.entity.transform.rotation){var o=Math.atan2(t.localOffset.y,t.localOffset.x)*MathHelper.Rad2Deg,r=i?t._localOffsetLength:Vector2.multiply(t.localOffset,t.entity.transform.scale).length();this.center=MathHelper.pointOnCirlce(Vector2.zero,r,t.entity.transform.rotationDegrees+o)}}this.position=Vector2.add(t.entity.transform.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 i,n=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++){i=u<r.length?r[u]:s[u-r.length];var l=0,p=0,f=0,y=0,d=0,m=this.getInterval(i,t,l,f);l=m.min,p=m.max;var g=this.getInterval(i,e,p,y);p=g.min,y=g.max;var _=Vector2.dot(c,i);if(l+=_,f+=_,(d=this.intervalDistance(l,f,p,y))>0&&(o=!1),!o)return null;(d=Math.abs(d))<a&&(a=d,h=i,Vector2.dot(h,c)<0&&(h=new Vector2(-h)))}return n.normal=h,n.minimumTranslationVector=Vector2.multiply(new Vector2(-h),new Vector2(a)),n},t.intervalDistance=function(t,e,i,n){return t<i?i-e:t-i},t.getInterval=function(t,e,i,n){var o=Vector2.dot(e.points[0],t);i=n=o;for(var r=1;r<e.points.length;r++)(o=Vector2.dot(e.points[r],t))<i?i=o:o>n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/c))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n<o*o){i.normal=Vector2.normalize(Vector2.subtract(t,e.position));var r=o-Math.sqrt(n);return i.minimumTranslationVector=Vector2.multiply(new Vector2(-r,-r),i.normal),i.point=Vector2.add(e.position,Vector2.multiply(i.normal,new Vector2(e.radius,e.radius))),i}return null},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,Vector2.multiply(n,new Vector2(r,r)))},t.pointToPoly=function(t,e){var i=new CollisionResult;if(e.containsPoint(t)){var n,o=Polygon.getClosestPointOnPolygonToPoint(e.points,Vector2.subtract(t,e.position)),r=o.closestPoint;return n=o.distanceSquared,i.normal=o.edgeNormal,i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(Math.sqrt(n),Math.sqrt(n))),i.point=Vector2.add(r,e.position),i}return null},t.circleToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t.position,e.position),o=t.radius+e.radius;if(n<o*o){i.normal=Vector2.normalize(Vector2.subtract(t.position,e.position));var r=o-Math.sqrt(n);return i.minimumTranslationVector=Vector2.multiply(new Vector2(-r),i.normal),i.point=Vector2.add(e.position,Vector2.multiply(i.normal,new Vector2(e.radius))),i}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,i=this.cellCoords(e.x,e.y),n=this.cellCoords(e.right,e.bottom),o=i.x;o<=n.x;o++)for(var r=i.y;r<=n.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 i=this.cellCoords(e.x,e.y),n=this.cellCoords(e.right,e.bottom);this.gridBounds.contains(new Vector2(i.x,i.y))||(this.gridBounds=RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(new Vector2(n.x,n.y))||(this.gridBounds=RectangleExt.union(this.gridBounds,n));for(var o=i.x;o<=n.x;o++)for(var r=i.y;r<=n.y;r++){this.cellAtPosition(o,r,!0).push(t)}},t.prototype.overlapCircle=function(t,e,i,n){var o=new Rectangle(t.x-e,t.y-e,2*e,2*e);this._overlapTestCircle.radius=e,this._overlapTestCircle.position=t;return this.aabbBroadphase(o,null,n).forEach(function(t){if(0==i.length)return 0}),0},t.prototype.aabbBroadphase=function(t,e,i){this._tempHashSet.length=0;for(var n=this.cellCoords(t.x,t.y),o=this.cellCoords(t.right,t.bottom),r=n.x;r<=o.x;r++)for(var s=n.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(i,c.physicsLayer)&&(t.intersects(c.bounds)&&this._tempHashSet.push(c))}}return this._tempHashSet},t.prototype.cellAtPosition=function(t,e,i){void 0===i&&(i=!1);var n=this._cellDict.tryGetValue(t,e);return n||i&&(n=[],this._cellDict.add(t,e,n)),n},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 t<<32|e},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},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.getAllObjects=function(){var t=[];return this._store.forEach(function(e){return t.concat(e)}),t},t.prototype.clear=function(){this._store.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](e)},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 i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>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],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||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,i,n){return!(Vector2Ext.cross(Vector2.subtract(t,e),Vector2.subtract(i,e))<0)&&(!(Vector2Ext.cross(Vector2.subtract(t,i),Vector2.subtract(n,i))<0)&&!(Vector2Ext.cross(Vector2.subtract(t,n),Vector2.subtract(e,n))<0))},t}(),Vector2Ext=function(){function t(){}return t.isTriangleCCW=function(t,e,i){return this.cross(Vector2.subtract(e,t),Vector2.subtract(i,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,i,n,o,r){for(var s=0;s<r;s++){var a=t[e+s],h=n[o+1];h.x=a.x*i.m11+a.y*i.m21+i.m31,h.y=a.x*i.m12+a.y*i.m22+i.m32,n[o+s]=h}},t.transform=function(t,e,i){this.transformA(t,0,e,i,0,t.length)},t}(),WebGLUtils=function(){function t(){}return t.getWebGL=function(){if(egret.WebGLUtils.checkCanUseWebGL())return document.querySelector("canvas").getContext("webgl");throw new Error("cannot get webgl")},t.drawUserIndexPrimitives=function(t,e,i,n,o,r,s){var a=this.getWebGL();a.bindBuffer(a.ARRAY_BUFFER,0),this.checkGLError(),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,0),this.checkGLError(),a.drawElements(t,this.getElementCountArray(t,s),a.UNSIGNED_SHORT,2*r),this.checkGLError()},t.getElementCountArray=function(t,e){var i=this.getWebGL();switch(t){case i.LINES:return 2*e;case i.LINE_STRIP:return e+1;case i.TRIANGLES:return 3*e;case i.TRIANGLE_STRIP:return e+2}throw new Error("not support")},t.checkGLError=function(){var t=this.getWebGL(),e=t.getError();if(e!=t.NO_ERROR)throw new Error("GL.GetError() returned"+e)},t}(); |