1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),Array.prototype.findIndex=function(t){return function(t,n){for(var e=0,r=t.length;e<r;e++)if(n.call(arguments[2],t[e],e,t))return e;return-1}(this,t)},Array.prototype.any=function(t){return function(t,n){return t.findIndex(n)>-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,n){var e=t.findIndex(n);return-1==e?null:t[e]}(this,t)},Array.prototype.find=function(t){return function(t,n){return t.firstOrDefault(n)}(this,t)},Array.prototype.where=function(t){return function(t,n){if("function"==typeof t.reduce)return t.reduce(function(e,r,i){return n.call(arguments[2],r,i,t)&&e.push(r),e},[]);for(var e=[],r=0,i=t.length;r<i;r++){var o=t[r];n.call(arguments[2],o,r,t)&&e.push(o)}return e}(this,t)},Array.prototype.count=function(t){return function(t,n){return t.where(n).length}(this,t)},Array.prototype.findAll=function(t){return function(t,n){return t.where(n)}(this,t)},Array.prototype.contains=function(t){return function(t,n){for(var e=0,r=t.length;e<r;e++)if(JSON.stringify(t[e])==JSON.stringify(n))return!0;return!1}(this,t)},Array.prototype.removeAll=function(t){!function(t,n){var e;do{(e=t.findIndex(n))>=0&&t.splice(e,1)}while(e>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,n){var e=t.findIndex(function(t){return t===n});return e>=0&&(t.splice(e,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,n){t.splice(n,1)}(this,t)},Array.prototype.removeRange=function(t,n){return function(t,n,e){t.splice(n,e)}(this,t,n)},Array.prototype.select=function(t){return function(t,n){if("function"==typeof t.reduce)return t.reduce(function(e,r,i){return e.push(n.call(arguments[2],r,i,t)),e},[]);for(var e=[],r=0,i=t.length;r<i;r++)e.push(n.call(arguments[2],t[r],r,t));return e}(this,t)},Array.prototype.orderBy=function(t,n){return function(t,n,e){return t.sort(function(t,r){var i=n(t),o=n(r);return e?e(i,o):i>o?1:-1}),t}(this,t,n)},Array.prototype.orderByDescending=function(t,n){return function(t,n,e){return t.sort(function(t,r){var i=n(t),o=n(r);return e?-e(i,o):i<o?1:-1}),t}(this,t,n)},Array.prototype.groupBy=function(t){return function(t,n){if("function"==typeof t.reduce){var e=[];return t.reduce(function(r,i,o){var s=JSON.stringify(n.call(arguments[1],i,o,t)),a=e.findIndex(function(t){return t===s});return a<0&&(a=e.push(s)-1),r[a]||(r[a]=[]),r[a].push(i),r},[])}for(var r=[],i=[],o=function(e,o){var a=JSON.stringify(n.call(s[1],t[e],e,t)),c=i.findIndex(function(t){return t===a});c<0&&(c=i.push(a)-1),r[c]||(r[c]=[]),r[c].push(t[e])},s=arguments,a=0,c=t.length;a<c;a++)o(a);return r}(this,t)},Array.prototype.sum=function(t){return function(t,n){for(var e,r=0,i=t.length;r<i;r++)0==r?e=n?n.call(arguments[2],t[r],r,t):t[r]:e+=n?n.call(arguments[2],t[r],r,t):t[r];return e}(this,t)};var Component=function(){function t(){}return t.prototype.update=function(){},t.prototype.bind=function(t){return this.displayRender=t,this},t}(),Entity=function(){function t(t){this._updateOrder=0,this.name=t,this.transform=new Transform(this),this.components=[]}return 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.push(this);for(var n=0;n<this.transform.childCount;n++)this.transform.getChild(n).entity.attachToScene(t)},t.prototype.addComponent=function(t){return t.entity=this,this.components.push(t),t.initialize(),t},t.prototype.update=function(){this.components.forEach(function(t){return t.update()})},t.prototype.destory=function(){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 n(n){var e=t.call(this)||this;return e.entities=[],n.stage.addChild(e),e.camera=e.createEntity("camera").addComponent(new Camera),e._projectionMatrix=new Matrix2D(0,0,0,0,0,0),e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e.addEventListener(egret.Event.ENTER_FRAME,e.update,e),e}return __extends(n,t),n.prototype.createEntity=function(t){var n=new Entity(t);return n.transform.position=new Vector2(0,0),this.addEntity(n)},n.prototype.addEntity=function(t){return this.entities.push(t),t.scene=this,t},n.prototype.setActive=function(){return SceneManager.setActiveScene(this),this},n.prototype.initialize=function(){},n.prototype.onActive=function(){},n.prototype.onDeactive=function(){},n.prototype.update=function(){this.entities.forEach(function(t){return t.update()})},n.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)},n.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.forEach(function(t){return t.destory()}),this.entities.length=0},n}(egret.DisplayObjectContainer),SceneManager=function(){function t(){}return t.createScene=function(t,n){return n.name=t,this._loadedScenes.set(t,n),n},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}(),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,"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,"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}),t.prototype.setLocalPosition=function(t){return t==this._localPosition?this:(this._localPosition=t,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 n=0;n<this.entity.components.length;n++){var e=this.entity.components[n];e.displayRender&&(e.displayRender.x=this.entity.scene.camera.transformMatrix.m31+this.position.x,e.displayRender.y=this.entity.scene.camera.transformMatrix.m32+this.position.y)}return this},t.prototype.updateTransform=function(){this._translationMatrix=Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y),this._rotationMatrix=Matrix2D.createRotation(this._localRotation),this._scaleMatrix=Matrix2D.createScale(this._localScale.x,this._localScale.y),this._localTransform=Matrix2D.multiply(this._scaleMatrix,this._rotationMatrix),this._localTransform=Matrix2D.multiply(this._localTransform,this._translationMatrix),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._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale)},t}(),Camera=function(t){function n(){var n=t.call(this)||this;return n._transformMatrix=Matrix2D.identity,n._inverseTransformMatrix=Matrix2D.identity,n}return __extends(n,t),Object.defineProperty(n.prototype,"transformMatrix",{get:function(){return this.updateMatrixes(),this._transformMatrix},enumerable:!0,configurable:!0}),n.prototype.initialize=function(){},n.prototype.update=function(){var t=this;SceneManager.getActiveScene().entities.forEach(function(n){return n.components.forEach(function(n){n.displayRender&&(-1==t.entity.scene.$children.indexOf(n.displayRender)&&t.entity.scene.stage.addChild(n.displayRender))})})},n.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},n.prototype.updateMatrixes=function(){this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y)},n.prototype.destory=function(){},n}(Component),MathHelper=function(){function t(){}return t.toDegrees=function(t){return 57.29577951308232*t},t.toRadians=function(t){return.017453292519943295*t},t}(),Matrix2D=function(){function t(t,n,e,r,i,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t,this.m12=n,this.m21=e,this.m22=r,this.m31=i,this.m32=o}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 n=Math.cos(t),e=Math.sin(t);this.m11=n,this.m12=e,this.m21=-e,this.m22=n},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,n){return t.m11+=n.m11,t.m12+=n.m12,t.m21+=n.m21,t.m22+=n.m22,t.m31+=n.m31,t.m32+=n.m32,t},t.divide=function(t,n){return t.m11/=n.m11,t.m12/=n.m12,t.m21/=n.m21,t.m22/=n.m22,t.m31/=n.m31,t.m32/=n.m32,t},t.multiply=function(t,n){var e=t.m11*n.m11+t.m12*n.m21,r=t.m11*n.m12+t.m12*n.m22,i=t.m21*n.m11+t.m22*n.m21,o=t.m21*n.m12+t.m22*n.m22,s=t.m31*n.m11+t.m32*n.m21+n.m31,a=t.m31*n.m12+t.m32*n.m22+n.m32;return t.m11=e,t.m12=r,t.m21=i,t.m22=o,t.m31=s,t.m32=a,t},t.multiplyTranslation=function(n,e,r){var i=t.createTranslation(e,r);return t.multiply(n,i)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(t,n){var e=1/t.determinant();return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},t.createTranslation=function(n,e,r){return void 0===r&&(r=t.identity),r.m11=1,r.m12=0,r.m21=0,r.m22=1,r.m31=n,r.m32=e,r},t.createRotation=function(n,e){e=t.identity;var r=Math.cos(n),i=Math.sin(n);return e.m11=r,e.m12=i,e.m21=-i,e.m22=r,e},t.createScale=function(n,e,r){return void 0===r&&(r=t.identity),r.m11=n,r.m12=0,r.m21=0,r.m22=e,r.m31=0,r.m32=0,r},t._identity=new t(1,0,0,1,0,0),t}(),Vector2=function(){function t(t,n){this.x=0,this.y=0,this.x=t,this.y=n}return Object.defineProperty(t,"One",{get:function(){return this.unitVector2},enumerable:!0,configurable:!0}),t.add=function(t,n){return t.x+=n.x,t.y+=n.y,t},t.divide=function(t,n){return t.x/=n.x,t.y/=n.y,t},t.multiply=function(t,n){return t.x*=n.x,t.y*=n.y,t},t.subtract=function(t,n){return t.x-=n.x,t.y-=n.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(n,e){return new t(n.x*e.m11+n.y*e.m21,n.x*e.m12+n.y*e.m22)},t.unitVector2=new t(1,1),t}(); |