Files
esengine/demo/libs/framework/framework.min.js
2020-06-09 19:45:09 +08:00

1 line
38 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 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<o;n++)if(e.call(arguments[2],t[n],n,t))return n;return-1}(this,t)},Array.prototype.any=function(t){return function(t,e){return t.findIndex(e)>-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,o,i){return e.call(arguments[2],o,i,t)&&n.push(o),n},[]);for(var n=[],o=0,i=t.length;o<i;o++){var r=t[o];e.call(arguments[2],r,o,t)&&n.push(r)}return n}(this,t)},Array.prototype.count=function(t){return function(t,e){return t.where(e).length}(this,t)},Array.prototype.findAll=function(t){return function(t,e){return t.where(e)}(this,t)},Array.prototype.contains=function(t){return function(t,e){for(var n=0,o=t.length;n<o;n++)if(t[n]==e)return!0;return!1}(this,t)},Array.prototype.removeAll=function(t){!function(t,e){var n;do{(n=t.findIndex(e))>=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,o,i){return n.push(e.call(arguments[2],o,i,t)),n},[]);for(var n=[],o=0,i=t.length;o<i;o++)n.push(e.call(arguments[2],t[o],o,t));return n}(this,t)},Array.prototype.orderBy=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):i>r?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):i<r?1:-1}),t}(this,t,e)},Array.prototype.groupBy=function(t){return function(t,e){if("function"==typeof t.reduce){var n=[];return t.reduce(function(o,i,r){var s=JSON.stringify(e.call(arguments[1],i,r,t)),a=n.findIndex(function(t){return t===s});return a<0&&(a=n.push(s)-1),o[a]||(o[a]=[]),o[a].push(i),o},[])}for(var o=[],i=[],r=function(n,r){var a=JSON.stringify(e.call(s[1],t[n],n,t)),h=i.findIndex(function(t){return t===a});h<0&&(h=i.push(a)-1),o[h]||(o[h]=[]),o[h].push(t[n])},s=arguments,a=0,h=t.length;a<h;a++)r(a);return o}(this,t)},Array.prototype.sum=function(t){return function(t,e){for(var n,o=0,i=t.length;o<i;o++)0==o?n=e?e.call(arguments[2],t[o],o,t):t[o]:n+=e?e.call(arguments[2],t[o],o,t):t[o];return n}(this,t)};var DirtyType,ComponentTransform,PriorityQueueNode=function(){return function(){this.priority=0,this.insertionIndex=0,this.queueIndex=0}}(),AStarPathfinder=function(){function t(){}return t.search=function(t,e,n){var o=this,i=!1,r=new Map;r.set(e,e);var s=new Map,a=new PriorityQueue(1e3);a.enqueue(new AStarNode(e),0),s.set(e,0);for(var h=function(){var e=a.dequeue();if(JSON.stringify(e.data)==JSON.stringify(n))return i=!0,"break";t.getNeighbors(e.data).forEach(function(i){var h=s.get(e.data)+t.cost(e.data,i);if(!o.hasKey(s,i)||h<s.get(i)){s.set(i,h);var c=h+t.heuristic(i,n);a.enqueue(new AStarNode(i),c),r.set(i,e.data)}})};a.count>0;){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.x<this._width&&0<=t.y&&t.y<this._height},t.prototype.isNodePassable=function(t){return!this.walls.contains(t)},t.prototype.search=function(t,e){return AStarPathfinder.search(this,t,e)},t.prototype.getNeighbors=function(t){var e=this;return this._neighbors.length=0,this.dirs.forEach(function(n){var o=new Point(t.x+n.x,t.y+n.y);e.isNodeInBounds(o)&&e.isNodePassable(o)&&e._neighbors.push(o)}),this._neighbors},t.prototype.cost=function(t,e){return this.weightedNodes.find(function(t){return JSON.stringify(t)==JSON.stringify(e)})?this.weightedNodeWeight:this.defaultWeight},t.prototype.heuristic=function(t,e){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)},t}(),PriorityQueue=function(){function t(t){this._numNodes=0,this._nodes=new Array(t+1),this._numNodesEverEnqueued=0}return t.prototype.clear=function(){this._nodes.splice(1,this._numNodes),this._numNodes=0},Object.defineProperty(t.prototype,"count",{get:function(){return this._numNodes},enumerable:!0,configurable:!0}),t.prototype.contains=function(t){return this._nodes[t.queueIndex]==t},t.prototype.enqueue=function(t,e){t.priority=e,this._numNodes++,this._nodes[this._numNodes]=t,t.queueIndex=this._numNodes,t.insertionIndex=this._numNodesEverEnqueued++,this.cascadeUp(this._nodes[this._numNodes])},t.prototype.dequeue=function(){var t=this._nodes[1];return this.remove(t),t},t.prototype.remove=function(t){if(t.queueIndex==this._numNodes)return this._nodes[this._numNodes]=null,void this._numNodes--;var e=this._nodes[this._numNodes];this.swap(t,e),delete this._nodes[this._numNodes],this._numNodes--,this.onNodeUpdated(e)},t.prototype.isValidQueue=function(){for(var t=1;t<this._nodes.length;t++)if(this._nodes[t]){var e=2*t;if(e<this._nodes.length&&this._nodes[e]&&this.hasHigherPriority(this._nodes[e],this._nodes[t]))return!1;var n=e+1;if(n<this._nodes.length&&this._nodes[n]&&this.hasHigherPriority(this._nodes[n],this._nodes[t]))return!1}return!0},t.prototype.onNodeUpdated=function(t){var e=Math.floor(t.queueIndex/2),n=this._nodes[e];e>0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var 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<e.priority||t.priority==e.priority&&t.insertionIndex<e.insertionIndex},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.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.bind=function(t){return this.displayRender=t,this},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(t){this._updateOrder=0,this._enabled=!0,this.name=t,this.transform=new Transform(this),this.components=new ComponentList(this),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,"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.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.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 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;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").addComponent(new Camera),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 Transform=function(){function t(t){this._localRotation=0,this._worldTransform=Matrix2D.identity,this._worldToLocalTransform=Matrix2D.identity,this._worldInverseTransform=Matrix2D.identity,this._rotation=0,this.entity=t,this._scale=this._localScale=Vector2.One,this._children=[]}return Object.defineProperty(t.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),t.prototype.getChild=function(t){return this._children[t]},Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.updateTransform(),this._worldInverseDirty&&(this._worldInverseTransform=Matrix2D.invert(this._worldTransform,this._worldInverseTransform),this._worldInverseDirty=!1),this._worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.updateTransform(),this._worldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this._worldToLocalDirty&&(this.parent?(this.parent.updateTransform(),this._worldToLocalTransform=Matrix2D.invert(this.parent._worldTransform,this._worldToLocalTransform)):this._worldInverseTransform=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){this._scale=t,this.parent?this.localScale=Vector2.divide(t,this.parent._scale):this.localScale=t;for(var e=0;e<this.entity.components.buffer.length;e++){var n=this.entity.components.buffer[e];n.displayRender&&(n.displayRender.scaleX=this.scale.x,n.displayRender.scaleY=this.scale.y)}return 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){this._rotation=t,this.parent?this.localRotation=this.parent.rotation+t:this.localRotation=t;for(var e=0;e<this.entity.components.buffer.length;e++){var n=this.entity.components.buffer[e];n.displayRender&&(n.displayRender.rotation=this.rotation)}return 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){if(t==this._position)return this;this._position=t,this.parent?this.localPosition=Vector2.transform(this._position,this._worldToLocalTransform):this.localPosition=t;for(var e=0;e<this.entity.components.buffer.length;e++){var n=this.entity.components.buffer[e];n.displayRender&&(n.displayRender.x=this.entity.scene.camera.transformMatrix.m31+this.position.x,n.displayRender.y=this.entity.scene.camera.transformMatrix.m32+this.position.y)}return 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.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t,this._areMatrixesDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"transformMatrix",{get:function(){return this.updateMatrixes(),this._transformMatrix},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(){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<n;++o)this._bits[o]&=t._bits[o];for(;e<this._bits.length;)this._bits[e++]=0},t.prototype.andNot=function(t){for(var e=Math.min(this._bits.length,t._bits.length);--e>=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var 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<<t)}else for(var n=0;n<this._bits.length;n++)this._bits[n]=0},t.prototype.ensure=function(t){if(t>=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<<t)},t.prototype.intersects=function(t){for(var e=Math.min(this._bits.length,t._bits.length);--e>=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<<t;e<this._bits.length;){var o=this._bits[e];do{if(0!=(o&n))return t;n<<=1,t++}while(0!=n);n=1,e++}return-1},t.prototype.set=function(t,e){if(void 0===e&&(e=!0),e){var n=t>>6;this.ensure(n),this._bits[n]|=1<<t}else this.clear(t)},t.LONG_MASK=63,t}(),ComponentList=function(){function t(t){this._components=[],this._componentsToAdd=[],this._componentsToRemove=[],this._tempBufferList=[],this._entity=t}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._componentsToAdd.push(t)},t.prototype.remove=function(t){this._componentsToAdd.contains(t)?this._componentsToAdd.remove(t):this._componentsToRemove.push(t)},t.prototype.removeAllComponents=function(){for(var t=0;t<this._components.length;t++)this.handleRemove(this._components[t]);this._components.length=0,this._componentsToAdd.length=0,this._componentsToRemove.length=0},t.prototype.deregisterAllComponents=function(){for(var t=0;t<this._components.length;t++){var e=this._components[t];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 n=this._componentsToAdd[t];this._entity.componentBits.set(ComponentTypeManager.getIndexFor(n)),this._entity.scene.entityProcessors.onComponentAdded(this._entity),this._components.push(n),this._tempBufferList.push(n)}this._componentsToAdd.length=0;for(t=0;t<this._tempBufferList.length;t++){(n=this._tempBufferList[t]).onAddedToEntity(),n.enabled&&n.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 n=0;n<this._components.length;n++){if((o=this._components[n])instanceof t)return o}if(!e)for(n=0;n<this._componentsToAdd.length;n++){var o;if((o=this._componentsToAdd[n])instanceof t)return o}return null},t.prototype.update=function(){this.updateLists()},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.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.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},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}},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._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 t<e?e:t>n?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}();