From 6b8569b0b5b5dae90651c8a97484270e40bfcbe7 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Mon, 20 Jul 2020 16:38:49 +0800 Subject: [PATCH 01/15] =?UTF-8?q?collider=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/bin/framework.d.ts | 16 +-- source/bin/framework.js | 124 +++++++----------- source/bin/framework.min.js | 2 +- .../Components/Physics/Colliders/Collider.ts | 10 +- source/src/Math/Rectangle.ts | 12 ++ source/src/Physics/Collision.ts | 2 +- source/src/Physics/Shapes/Box.ts | 24 ++-- source/src/Physics/Shapes/Circle.ts | 28 +--- source/src/Physics/Shapes/Polygon.ts | 50 +------ source/src/Physics/Shapes/Shape.ts | 5 +- source/src/Physics/Verlet/SpatialHash.ts | 17 +-- source/src/Utils/RectangleExt.ts | 14 +- source/tsconfig.json | 2 +- 13 files changed, 110 insertions(+), 196 deletions(-) diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 2ecb9ae1..c4a9c71c 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -894,6 +894,7 @@ declare class Rectangle extends egret.Rectangle { edgeNormal: Vector2; }; getClosestPointOnBoundsToOrigin(): Vector2; + setEgretRect(rect: egret.Rectangle): Rectangle; static rectEncompassingPoints(points: Vector2[]): Rectangle; } declare class Vector3 { @@ -930,7 +931,7 @@ declare class Collisions { static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean; static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean; static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean; - static isRectToCircle(rect: Rectangle, cPosition: Vector2, cRadius: number): boolean; + static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean; static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean; static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean; static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors; @@ -955,22 +956,21 @@ declare class Physics { static updateCollider(collider: Collider): void; static debugDraw(secondsToDisplay: any): void; } -declare abstract class Shape { - bounds: Rectangle; +declare abstract class Shape extends egret.DisplayObject { + abstract bounds: Rectangle; position: Vector2; abstract center: Vector2; - abstract recalculateBounds(collider: Collider): any; abstract pointCollidesWithShape(point: Vector2): CollisionResult; abstract overlaps(other: Shape): any; abstract collidesWithShape(other: Shape): CollisionResult; } declare class Polygon extends Shape { points: Vector2[]; - isUnrotated: boolean; private _polygonCenter; private _areEdgeNormalsDirty; protected _originalPoints: Vector2[]; center: Vector2; + readonly bounds: Rectangle; _edgeNormals: Vector2[]; readonly edgeNormals: Vector2[]; isBox: boolean; @@ -990,11 +990,8 @@ declare class Polygon extends Shape { pointCollidesWithShape(point: Vector2): CollisionResult; containsPoint(point: Vector2): boolean; static buildSymmertricalPolygon(vertCount: number, radius: number): any[]; - recalculateBounds(collider: Collider): void; } declare class Box extends Polygon { - width: number; - height: number; constructor(width: number, height: number); private static buildBox; overlaps(other: Shape): any; @@ -1006,10 +1003,10 @@ declare class Circle extends Shape { radius: number; _originalRadius: number; center: Vector2; + readonly bounds: Rectangle; constructor(radius: number); pointCollidesWithShape(point: Vector2): CollisionResult; collidesWithShape(other: Shape): CollisionResult; - recalculateBounds(collider: Collider): void; overlaps(other: Shape): any; } declare class CollisionResult { @@ -1062,7 +1059,6 @@ declare class RaycastResultParser { declare class NumberDictionary { private _store; private getKey; - private intToUint; add(x: number, y: number, list: Collider[]): void; remove(obj: Collider): void; tryGetValue(x: number, y: number): Collider[]; diff --git a/source/bin/framework.js b/source/bin/framework.js index f5fb929a..40a8a0d3 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -2197,8 +2197,9 @@ var Collider = (function (_super) { } Object.defineProperty(Collider.prototype, "bounds", { get: function () { - this.shape.recalculateBounds(this); - return this.shape.bounds; + var shapeBounds = this.shape.bounds; + var colliderBuonds = new Rectangle(this.x + this.localOffset.x, this.y + this.localOffset.y, shapeBounds.width, shapeBounds.height); + return colliderBuonds; }, enumerable: true, configurable: true @@ -2261,9 +2262,8 @@ var Collider = (function (_super) { this.localOffset = bounds.location; } else { - var boxCollider = this; - boxCollider.width = width; - boxCollider.height = height; + this.width = width; + this.height = height; this.localOffset = bounds.location; } } @@ -4402,6 +4402,13 @@ var Rectangle = (function (_super) { } return boundsPoint; }; + Rectangle.prototype.setEgretRect = function (rect) { + this.x = rect.x; + this.y = rect.y; + this.width = rect.width; + this.height = rect.height; + return this; + }; Rectangle.rectEncompassingPoints = function (points) { var minX = Number.POSITIVE_INFINITY; var minY = Number.POSITIVE_INFINITY; @@ -4687,24 +4694,32 @@ var Physics = (function () { Physics.allLayers = -1; return Physics; }()); -var Shape = (function () { +var Shape = (function (_super) { + __extends(Shape, _super); function Shape() { - this.bounds = new Rectangle(); - this.position = Vector2.zero; + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.position = Vector2.zero; + return _this; } return Shape; -}()); +}(egret.DisplayObject)); var Polygon = (function (_super) { __extends(Polygon, _super); function Polygon(points, isBox) { var _this = _super.call(this) || this; - _this.isUnrotated = true; _this._areEdgeNormalsDirty = true; _this.center = new Vector2(); _this.setPoints(points); _this.isBox = isBox; return _this; } + Object.defineProperty(Polygon.prototype, "bounds", { + get: function () { + return new Rectangle(0, 0, this.width, this.height); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Polygon.prototype, "edgeNormals", { get: function () { if (this._areEdgeNormalsDirty) @@ -4829,36 +4844,6 @@ var Polygon = (function (_super) { } return verts; }; - Polygon.prototype.recalculateBounds = function (collider) { - var localOffset = collider.localOffset; - if (collider.shouldColliderScaleAndRotateWithTransform) { - var hasUnitScale = true; - var tempMat = void 0; - var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); - if (collider.entity.scale != Vector2.one) { - tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - hasUnitScale = false; - var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); - localOffset = scaledOffset; - } - if (collider.entity.rotation != 0) { - tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); - localOffset = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); - } - tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.rotation == 0; - } - this.position = Vector2.add(collider.entity.position, localOffset); - this.bounds = Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = Vector2.add(this.bounds.location, this.position); - this.center = localOffset; - }; return Polygon; }(Shape)); var Box = (function (_super) { @@ -4880,16 +4865,14 @@ var Box = (function (_super) { return verts; }; Box.prototype.overlaps = function (other) { - if (this.isUnrotated) { - if (other instanceof Box && other.isUnrotated) - return this.bounds.intersects(other.bounds); - if (other instanceof Circle) - return Collisions.isRectToCircle(this.bounds, other.position, other.radius); - } + if (other instanceof Box) + return this.bounds.intersects(other.bounds); + if (other instanceof Circle) + return Collisions.isRectToCircle(this.bounds, other.position, other.radius); return _super.prototype.overlaps.call(this, other); }; Box.prototype.collidesWithShape = function (other) { - if (this.isUnrotated && other instanceof Box && other.isUnrotated) { + if (other instanceof Box) { return ShapeCollisions.boxToBox(this, other); } return _super.prototype.collidesWithShape.call(this, other); @@ -4907,9 +4890,7 @@ var Box = (function (_super) { this._originalPoints[i] = this.points[i]; }; Box.prototype.containsPoint = function (point) { - if (this.isUnrotated) - return this.bounds.contains(point.x, point.y); - return _super.prototype.containsPoint.call(this, point); + return this.bounds.contains(point.x, point.y); }; return Box; }(Polygon)); @@ -4922,11 +4903,18 @@ var Circle = (function (_super) { _this._originalRadius = radius; return _this; } + Object.defineProperty(Circle.prototype, "bounds", { + get: function () { + return new Rectangle().setEgretRect(this.getBounds()); + }, + enumerable: true, + configurable: true + }); Circle.prototype.pointCollidesWithShape = function (point) { return ShapeCollisions.pointToCircle(point, this); }; Circle.prototype.collidesWithShape = function (other) { - if (other instanceof Box && other.isUnrotated) { + if (other instanceof Box) { return ShapeCollisions.circleToBox(this, other); } if (other instanceof Circle) { @@ -4937,24 +4925,8 @@ var Circle = (function (_super) { } throw new Error("Collisions of Circle to " + other + " are not supported"); }; - Circle.prototype.recalculateBounds = function (collider) { - this.center = collider.localOffset; - if (collider.shouldColliderScaleAndRotateWithTransform) { - var scale = collider.entity.scale; - var hasUnitScale = scale.x == 1 && scale.y == 1; - var maxScale = Math.max(scale.x, scale.y); - this.radius = this._originalRadius * maxScale; - if (collider.entity.rotation != 0) { - var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); - } - } - this.position = Vector2.add(collider.entity.position, this.center); - this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); - }; Circle.prototype.overlaps = function (other) { - if (other instanceof Box && other.isUnrotated) + if (other instanceof Box) return Collisions.isRectToCircle(other.bounds, this.position, this.radius); if (other instanceof Circle) return Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); @@ -5306,13 +5278,7 @@ var NumberDictionary = (function () { this._store = new Map(); } NumberDictionary.prototype.getKey = function (x, y) { - return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); - }; - NumberDictionary.prototype.intToUint = function (i) { - if (i >= 0) - return i; - else - return 4294967296 + i; + return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); }; NumberDictionary.prototype.add = function (x, y, list) { this._store.set(this.getKey(x, y), list); @@ -6296,8 +6262,12 @@ var RectangleExt = (function () { } RectangleExt.union = function (first, point) { var rect = new Rectangle(point.x, point.y, 0, 0); - var rectResult = first.union(rect); - return new Rectangle(rectResult.x, rectResult.y, rectResult.width, rectResult.height); + var result = new Rectangle(); + result.x = Math.min(first.x, rect.x); + result.y = Math.min(first.y, rect.y); + result.width = Math.max(first.right, rect.right) - result.x; + result.height = Math.max(first.bottom, result.bottom) - result.y; + return result; }; return RectangleExt; }()); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 6519cad4..aade8e71 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){this.bounds=new Rectangle,this.position=Vector2.zero}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(this.intToUint(e)).toString()},t.prototype.intToUint=function(t){return t>=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);s||(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(!o)throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=0,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars);for(var t=0;t0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.position=Vector2.zero,e}return __extends(e,t),e}(egret.DisplayObject),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(0,0,this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(Long.fromNumber(e,!1)).toString()},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);s||(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(!o)throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=0,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars);for(var t=0;t class Polygon extends Shape { public points: Vector2[]; - public isUnrotated: boolean = true; private _polygonCenter: Vector2; private _areEdgeNormalsDirty = true; protected _originalPoints: Vector2[]; public center = new Vector2(); + public get bounds(){ + return new Rectangle(0, 0, this.width, this.height); + } + public _edgeNormals: Vector2[]; public get edgeNormals(){ if (this._areEdgeNormalsDirty) @@ -195,49 +198,4 @@ class Polygon extends Shape { return verts; } - - public recalculateBounds(collider: Collider) { - // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始 - // this.center = collider.localOffset; - let localOffset = collider.localOffset; - if (collider.shouldColliderScaleAndRotateWithTransform){ - let hasUnitScale = true; - let tempMat: Matrix2D; - let combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); - - if (collider.entity.scale != Vector2.one){ - tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - - hasUnitScale = false; - - // 缩放偏移量并将其设置为中心。如果我们有旋转,它会在下面重置 - let scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); - localOffset = scaledOffset; - } - - if (collider.entity.rotation != 0){ - tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - - // 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动我们的偏移使角度为0 - // 我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。 - let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); - localOffset = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); - } - - tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - - // 最后变换原始点 - Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.rotation == 0; - } - - this.position = Vector2.add(collider.entity.position, localOffset); - this.bounds = Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = Vector2.add(this.bounds.location, this.position); - this.center = localOffset; - } } \ No newline at end of file diff --git a/source/src/Physics/Shapes/Shape.ts b/source/src/Physics/Shapes/Shape.ts index 8a709699..2e249b9d 100644 --- a/source/src/Physics/Shapes/Shape.ts +++ b/source/src/Physics/Shapes/Shape.ts @@ -1,9 +1,8 @@ -abstract class Shape { - public bounds: Rectangle = new Rectangle(); +abstract class Shape extends egret.DisplayObject { + public abstract bounds: Rectangle; public position: Vector2 = Vector2.zero; public abstract center: Vector2; - public abstract recalculateBounds(collider: Collider); public abstract pointCollidesWithShape(point: Vector2): CollisionResult; public abstract overlaps(other: Shape); public abstract collidesWithShape(other: Shape): CollisionResult; diff --git a/source/src/Physics/Verlet/SpatialHash.ts b/source/src/Physics/Verlet/SpatialHash.ts index 60360f1e..11d63581 100644 --- a/source/src/Physics/Verlet/SpatialHash.ts +++ b/source/src/Physics/Verlet/SpatialHash.ts @@ -209,26 +209,15 @@ class RaycastResultParser { * 它的主要目的是将int、int x、y坐标散列到单个Uint32键中,使用O(1)查找。 */ class NumberDictionary { - private _store: Map = new Map(); + private _store: Map = new Map(); /** * 根据x和y值计算并返回散列键 * @param x * @param y */ - private getKey(x: number, y: number): number { - return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); - } - - /** - * - * @param i - */ - private intToUint(i) { - if (i >= 0) - return i; - else - return 4294967296 + i; + private getKey(x: number, y: number): string { + return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); } public add(x: number, y: number, list: Collider[]) { diff --git a/source/src/Utils/RectangleExt.ts b/source/src/Utils/RectangleExt.ts index d9e50969..4b83e05f 100644 --- a/source/src/Utils/RectangleExt.ts +++ b/source/src/Utils/RectangleExt.ts @@ -1,7 +1,17 @@ class RectangleExt { + /** + * 计算两个矩形的并集。结果将是一个包含其他两个的矩形。 + * @param first + * @param point + */ public static union(first: Rectangle, point: Vector2){ let rect = new Rectangle(point.x, point.y, 0, 0); - let rectResult = first.union(rect); - return new Rectangle(rectResult.x, rectResult.y, rectResult.width, rectResult.height); + // let rectResult = first.union(rect); + let result = new Rectangle(); + result.x = Math.min(first.x, rect.x); + result.y = Math.min(first.y, rect.y); + result.width = Math.max(first.right, rect.right) - result.x; + result.height = Math.max(first.bottom, result.bottom) - result.y; + return result; } } \ No newline at end of file diff --git a/source/tsconfig.json b/source/tsconfig.json index ef11be0d..ea8f743c 100644 --- a/source/tsconfig.json +++ b/source/tsconfig.json @@ -11,7 +11,7 @@ "es5", "dom", "es2015.promise", - "es6" + "es6", ] , }, "include": [ From 5b8f414a45ad62d33a4708facd535d46d14f8061 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Wed, 22 Jul 2020 20:07:14 +0800 Subject: [PATCH 02/15] =?UTF-8?q?=E6=95=B4=E7=90=86ecs=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 + .idea/egret-framework.iml | 12 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + demo/libs/framework/framework.d.ts | 30 +- demo/libs/framework/framework.js | 222 ++++---- demo/libs/framework/framework.min.js | 2 +- demo/libs/modules/egret/egret.web.min.js | 2 +- demo/src/game/MainScene.ts | 4 +- source/bin/framework.d.ts | 14 +- source/bin/framework.js | 108 ++-- source/bin/framework.min.js | 2 +- source/src/ECS/Component.ts | 221 +++++--- source/src/ECS/Components/Camera.ts | 434 +++++++------- .../Components/Physics/Colliders/Collider.ts | 48 +- .../Physics/Colliders/PolygonCollider.ts | 2 - source/src/ECS/Components/SpriteRenderer.ts | 26 +- source/src/ECS/Entity.ts | 530 +++++++++++------- source/src/ECS/Scene.ts | 521 +++++++++++------ source/src/ECS/SceneManager.ts | 13 + source/src/ECS/Transform.ts | 138 +++++ source/src/ECS/Utils/ComponentList.ts | 395 ++++++------- source/src/ECS/Utils/EntityList.ts | 303 ++++++---- .../Graphics/PostProcessing/PostProcessor.ts | 4 +- source/src/Physics/Shapes/Circle.ts | 3 + source/src/Physics/Shapes/Polygon.ts | 16 +- source/src/Physics/Shapes/Shape.ts | 20 +- source/src/Physics/Verlet/SpatialHash.ts | 5 +- source/src/Utils/Analysis/TimeRuler.ts | 47 +- source/src/Utils/ListPool.ts | 2 +- 31 files changed, 1908 insertions(+), 1239 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/egret-framework.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 source/src/ECS/Transform.ts diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..0e40fe8f --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/egret-framework.iml b/.idea/egret-framework.iml new file mode 100644 index 00000000..24643cc3 --- /dev/null +++ b/.idea/egret-framework.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..28a804d8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..bfd6610a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index 2ecb9ae1..9ab1a179 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -245,7 +245,7 @@ declare class Entity extends egret.DisplayObjectContainer { getOrCreateComponent(type: T): T; getComponent(type: any): T; getComponents(typeName: string | any, componentList?: any): any; - private onEntityTransformChanged; + onEntityTransformChanged(comp: TransformComponent): void; removeComponentForType(type: any): boolean; removeComponent(component: Component): void; removeAllComponents(): void; @@ -300,6 +300,7 @@ declare class SceneManager { static emitter: Emitter; static content: ContentManager; private static _instnace; + private static timerRuler; static readonly Instance: SceneManager; constructor(stage: egret.Stage); static scene: Scene; @@ -309,6 +310,8 @@ declare class SceneManager { static startSceneTransition(sceneTransition: T): T; static registerActiveSceneChanged(current: Scene, next: Scene): void; onSceneChanged(): void; + private static startDebugUpdate; + private static endDebugUpdate; } declare class Camera extends Component { private _zoom; @@ -488,14 +491,10 @@ declare abstract class Collider extends Component { registeredPhysicsBounds: Rectangle; shouldColliderScaleAndRotateWithTransform: boolean; collidesWithLayers: number; - _localOffsetLength: number; protected _isParentEntityAddedToScene: any; protected _colliderRequiresAutoSizing: any; - protected _localOffset: Vector2; protected _isColliderRegistered: any; readonly bounds: Rectangle; - localOffset: Vector2; - setLocalOffset(offset: Vector2): void; registerColliderWithPhysicsSystem(): void; unregisterColliderWithPhysicsSystem(): void; overlaps(other: Collider): any; @@ -894,6 +893,7 @@ declare class Rectangle extends egret.Rectangle { edgeNormal: Vector2; }; getClosestPointOnBoundsToOrigin(): Vector2; + setEgretRect(rect: egret.Rectangle): Rectangle; static rectEncompassingPoints(points: Vector2[]): Rectangle; } declare class Vector3 { @@ -930,7 +930,7 @@ declare class Collisions { static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean; static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean; static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean; - static isRectToCircle(rect: Rectangle, cPosition: Vector2, cRadius: number): boolean; + static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean; static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean; static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean; static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors; @@ -955,22 +955,22 @@ declare class Physics { static updateCollider(collider: Collider): void; static debugDraw(secondsToDisplay: any): void; } -declare abstract class Shape { - bounds: Rectangle; - position: Vector2; +declare abstract class Shape extends egret.DisplayObject { + abstract bounds: Rectangle; abstract center: Vector2; - abstract recalculateBounds(collider: Collider): any; + abstract position: Vector2; abstract pointCollidesWithShape(point: Vector2): CollisionResult; abstract overlaps(other: Shape): any; abstract collidesWithShape(other: Shape): CollisionResult; } declare class Polygon extends Shape { points: Vector2[]; - isUnrotated: boolean; private _polygonCenter; private _areEdgeNormalsDirty; protected _originalPoints: Vector2[]; center: Vector2; + readonly position: Vector2; + readonly bounds: Rectangle; _edgeNormals: Vector2[]; readonly edgeNormals: Vector2[]; isBox: boolean; @@ -990,11 +990,8 @@ declare class Polygon extends Shape { pointCollidesWithShape(point: Vector2): CollisionResult; containsPoint(point: Vector2): boolean; static buildSymmertricalPolygon(vertCount: number, radius: number): any[]; - recalculateBounds(collider: Collider): void; } declare class Box extends Polygon { - width: number; - height: number; constructor(width: number, height: number); private static buildBox; overlaps(other: Shape): any; @@ -1006,10 +1003,11 @@ declare class Circle extends Shape { radius: number; _originalRadius: number; center: Vector2; + readonly position: Vector2; + readonly bounds: Rectangle; constructor(radius: number); pointCollidesWithShape(point: Vector2): CollisionResult; collidesWithShape(other: Shape): CollisionResult; - recalculateBounds(collider: Collider): void; overlaps(other: Shape): any; } declare class CollisionResult { @@ -1062,7 +1060,6 @@ declare class RaycastResultParser { declare class NumberDictionary { private _store; private getKey; - private intToUint; add(x: number, y: number, list: Collider[]): void; remove(obj: Collider): void; tryGetValue(x: number, y: number): Collider[]; @@ -1413,6 +1410,7 @@ declare class MarkerCollection { markCount: number; markerNests: number[]; nestCount: number; + constructor(); } declare class Marker { markerId: number; diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index f5fb929a..c729622d 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -1403,6 +1403,7 @@ var SceneManager = (function () { SceneManager.content = new ContentManager(); SceneManager.stage = stage; SceneManager.initialize(stage); + SceneManager.timerRuler = new TimeRuler(); } Object.defineProperty(SceneManager, "Instance", { get: function () { @@ -1435,6 +1436,7 @@ var SceneManager = (function () { Input.initialize(stage); }; SceneManager.update = function () { + SceneManager.startDebugUpdate(); Time.update(egret.getTimer()); if (SceneManager._scene) { for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { @@ -1453,6 +1455,7 @@ var SceneManager = (function () { SceneManager._scene.begin(); } } + SceneManager.endDebugUpdate(); SceneManager.render(); }; SceneManager.render = function () { @@ -1493,6 +1496,13 @@ var SceneManager = (function () { SceneManager.emitter.emit(CoreEvents.SceneChanged); Time.sceneChanged(); }; + SceneManager.startDebugUpdate = function () { + TimeRuler.Instance.startFrame(); + TimeRuler.Instance.beginMark("update", 0x00FF00); + }; + SceneManager.endDebugUpdate = function () { + TimeRuler.Instance.endMark("update"); + }; return SceneManager; }()); var Camera = (function (_super) { @@ -1866,8 +1876,12 @@ var SpriteRenderer = (function (_super) { return this.isVisible; }; SpriteRenderer.prototype.render = function (camera) { - this.x = -camera.position.x + camera.origin.x; - this.y = -camera.position.y + camera.origin.y; + if (this.x != -camera.position.x + camera.origin.x || + this.y != -camera.position.y + camera.origin.y) { + this.x = -camera.position.x + camera.origin.x; + this.y = -camera.position.y + camera.origin.y; + this.entity.onEntityTransformChanged(TransformComponent.position); + } }; SpriteRenderer.prototype.onRemovedFromEntity = function () { if (this.parent) @@ -2192,35 +2206,17 @@ var Collider = (function (_super) { _this.registeredPhysicsBounds = new Rectangle(); _this.shouldColliderScaleAndRotateWithTransform = true; _this.collidesWithLayers = Physics.allLayers; - _this._localOffset = new Vector2(0, 0); return _this; } Object.defineProperty(Collider.prototype, "bounds", { get: function () { - this.shape.recalculateBounds(this); - return this.shape.bounds; + var shapeBounds = this.shape.bounds; + var colliderBuonds = new Rectangle(this.entity.x, this.entity.y, shapeBounds.width, shapeBounds.height); + return colliderBuonds; }, enumerable: true, configurable: true }); - Object.defineProperty(Collider.prototype, "localOffset", { - get: function () { - return this._localOffset; - }, - set: function (value) { - this.setLocalOffset(value); - }, - enumerable: true, - configurable: true - }); - Collider.prototype.setLocalOffset = function (offset) { - if (this._localOffset != offset) { - this.unregisterColliderWithPhysicsSystem(); - this._localOffset = offset; - this._localOffsetLength = this._localOffset.length(); - this.registerColliderWithPhysicsSystem(); - } - }; Collider.prototype.registerColliderWithPhysicsSystem = function () { if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { Physics.addCollider(this); @@ -2237,12 +2233,12 @@ var Collider = (function (_super) { return this.shape.overlaps(other.shape); }; Collider.prototype.collidesWith = function (collider, motion) { - var oldPosition = this.shape.position; - this.shape.position = Vector2.add(this.shape.position, motion); + var oldPosition = this.entity.position; + this.entity.position = Vector2.add(this.entity.position, motion); var result = this.shape.collidesWithShape(collider.shape); if (result) result.collider = collider; - this.shape.position = oldPosition; + this.entity.position = oldPosition; return result; }; Collider.prototype.onAddedToEntity = function () { @@ -2258,14 +2254,12 @@ var Collider = (function (_super) { if (this instanceof CircleCollider) { var circleCollider = this; circleCollider.radius = Math.max(width, height) * 0.5; - this.localOffset = bounds.location; } else { - var boxCollider = this; - boxCollider.width = width; - boxCollider.height = height; - this.localOffset = bounds.location; + this.width = width; + this.height = height; } + this.addChild(this.shape); } else { console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); @@ -2277,6 +2271,7 @@ var Collider = (function (_super) { Collider.prototype.onRemovedFromEntity = function () { this.unregisterColliderWithPhysicsSystem(); this._isParentEntityAddedToScene = false; + this.removeChild(this.shape); }; Collider.prototype.onEnabled = function () { this.registerColliderWithPhysicsSystem(); @@ -2291,8 +2286,8 @@ var Collider = (function (_super) { Collider.prototype.update = function () { var renderable = this.entity.getComponent(RenderableComponent); if (renderable) { - this.$setX(renderable.x + this.localOffset.x); - this.$setY(renderable.y + this.localOffset.y); + this.$setX(renderable.x); + this.$setY(renderable.y); } }; return Collider; @@ -2395,8 +2390,6 @@ var PolygonCollider = (function (_super) { var isPolygonClosed = points[0] == points[points.length - 1]; if (isPolygonClosed) points.splice(points.length - 1, 1); - var center = Polygon.findPolygonCenter(points); - _this.setLocalOffset(center); Polygon.recenterPolygonVerts(points); _this.shape = new Polygon(points); return _this; @@ -4402,6 +4395,13 @@ var Rectangle = (function (_super) { } return boundsPoint; }; + Rectangle.prototype.setEgretRect = function (rect) { + this.x = rect.x; + this.y = rect.y; + this.width = rect.width; + this.height = rect.height; + return this; + }; Rectangle.rectEncompassingPoints = function (points) { var minX = Number.POSITIVE_INFINITY; var minY = Number.POSITIVE_INFINITY; @@ -4687,24 +4687,37 @@ var Physics = (function () { Physics.allLayers = -1; return Physics; }()); -var Shape = (function () { +var Shape = (function (_super) { + __extends(Shape, _super); function Shape() { - this.bounds = new Rectangle(); - this.position = Vector2.zero; + return _super !== null && _super.apply(this, arguments) || this; } return Shape; -}()); +}(egret.DisplayObject)); var Polygon = (function (_super) { __extends(Polygon, _super); function Polygon(points, isBox) { var _this = _super.call(this) || this; - _this.isUnrotated = true; _this._areEdgeNormalsDirty = true; _this.center = new Vector2(); _this.setPoints(points); _this.isBox = isBox; return _this; } + Object.defineProperty(Polygon.prototype, "position", { + get: function () { + return new Vector2(this.parent.x, this.parent.y); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Polygon.prototype, "bounds", { + get: function () { + return new Rectangle(this.x, this.y, this.width, this.height); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Polygon.prototype, "edgeNormals", { get: function () { if (this._areEdgeNormalsDirty) @@ -4829,36 +4842,6 @@ var Polygon = (function (_super) { } return verts; }; - Polygon.prototype.recalculateBounds = function (collider) { - var localOffset = collider.localOffset; - if (collider.shouldColliderScaleAndRotateWithTransform) { - var hasUnitScale = true; - var tempMat = void 0; - var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y); - if (collider.entity.scale != Vector2.one) { - tempMat = Matrix2D.createScale(collider.entity.scale.x, collider.entity.scale.y); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - hasUnitScale = false; - var scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale); - localOffset = scaledOffset; - } - if (collider.entity.rotation != 0) { - tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); - localOffset = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); - } - tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y); - combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat); - Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); - this.isUnrotated = collider.entity.rotation == 0; - } - this.position = Vector2.add(collider.entity.position, localOffset); - this.bounds = Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = Vector2.add(this.bounds.location, this.position); - this.center = localOffset; - }; return Polygon; }(Shape)); var Box = (function (_super) { @@ -4880,16 +4863,14 @@ var Box = (function (_super) { return verts; }; Box.prototype.overlaps = function (other) { - if (this.isUnrotated) { - if (other instanceof Box && other.isUnrotated) - return this.bounds.intersects(other.bounds); - if (other instanceof Circle) - return Collisions.isRectToCircle(this.bounds, other.position, other.radius); - } + if (other instanceof Box) + return this.bounds.intersects(other.bounds); + if (other instanceof Circle) + return Collisions.isRectToCircle(this.bounds, other.position, other.radius); return _super.prototype.overlaps.call(this, other); }; Box.prototype.collidesWithShape = function (other) { - if (this.isUnrotated && other instanceof Box && other.isUnrotated) { + if (other instanceof Box) { return ShapeCollisions.boxToBox(this, other); } return _super.prototype.collidesWithShape.call(this, other); @@ -4907,9 +4888,7 @@ var Box = (function (_super) { this._originalPoints[i] = this.points[i]; }; Box.prototype.containsPoint = function (point) { - if (this.isUnrotated) - return this.bounds.contains(point.x, point.y); - return _super.prototype.containsPoint.call(this, point); + return this.bounds.contains(point.x, point.y); }; return Box; }(Polygon)); @@ -4922,11 +4901,25 @@ var Circle = (function (_super) { _this._originalRadius = radius; return _this; } + Object.defineProperty(Circle.prototype, "position", { + get: function () { + return new Vector2(this.parent.x, this.parent.y); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Circle.prototype, "bounds", { + get: function () { + return new Rectangle().setEgretRect(this.getBounds()); + }, + enumerable: true, + configurable: true + }); Circle.prototype.pointCollidesWithShape = function (point) { return ShapeCollisions.pointToCircle(point, this); }; Circle.prototype.collidesWithShape = function (other) { - if (other instanceof Box && other.isUnrotated) { + if (other instanceof Box) { return ShapeCollisions.circleToBox(this, other); } if (other instanceof Circle) { @@ -4937,24 +4930,8 @@ var Circle = (function (_super) { } throw new Error("Collisions of Circle to " + other + " are not supported"); }; - Circle.prototype.recalculateBounds = function (collider) { - this.center = collider.localOffset; - if (collider.shouldColliderScaleAndRotateWithTransform) { - var scale = collider.entity.scale; - var hasUnitScale = scale.x == 1 && scale.y == 1; - var maxScale = Math.max(scale.x, scale.y); - this.radius = this._originalRadius * maxScale; - if (collider.entity.rotation != 0) { - var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; - var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle); - } - } - this.position = Vector2.add(collider.entity.position, this.center); - this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); - }; Circle.prototype.overlaps = function (other) { - if (other instanceof Box && other.isUnrotated) + if (other instanceof Box) return Collisions.isRectToCircle(other.bounds, this.position, this.radius); if (other instanceof Circle) return Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); @@ -5203,7 +5180,8 @@ var SpatialHash = (function () { for (var x = p1.x; x <= p2.x; x++) { for (var y = p1.y; y <= p2.y; y++) { var c = this.cellAtPosition(x, y, true); - c.push(collider); + if (c.indexOf(collider) == -1) + c.push(collider); } } }; @@ -5213,7 +5191,6 @@ var SpatialHash = (function () { SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; - this._overlapTestCircle.position = circleCenter; var resultCounter = 0; var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); bounds = aabbBroadphaseResult.bounds; @@ -5306,13 +5283,7 @@ var NumberDictionary = (function () { this._store = new Map(); } NumberDictionary.prototype.getKey = function (x, y) { - return Long.fromNumber(x).shiftLeft(32).or(this.intToUint(y)).toString(); - }; - NumberDictionary.prototype.intToUint = function (i) { - if (i >= 0) - return i; - else - return 4294967296 + i; + return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); }; NumberDictionary.prototype.add = function (x, y, list) { this._store.set(this.getKey(x, y), list); @@ -6296,8 +6267,12 @@ var RectangleExt = (function () { } RectangleExt.union = function (first, point) { var rect = new Rectangle(point.x, point.y, 0, 0); - var rectResult = first.union(rect); - return new Rectangle(rectResult.x, rectResult.y, rectResult.width, rectResult.height); + var result = new Rectangle(); + result.x = Math.min(first.x, rect.x); + result.y = Math.min(first.y, rect.y); + result.width = Math.max(first.right, rect.right) - result.x; + result.height = Math.max(first.bottom, result.bottom) - result.y; + return result; }; return RectangleExt; }()); @@ -6648,6 +6623,8 @@ var TimeRuler = (function () { var lock = new LockUtils(this._frameKey); lock.lock().then(function () { _this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10); + if (isNaN(_this._updateCount)) + _this._updateCount = 0; var count = _this._updateCount; count += 1; egret.localStorage.setItem(_this._frameKey, count.toString()); @@ -6714,7 +6691,7 @@ var TimeRuler = (function () { throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); } var markerId = _this._markerNameToIdMap.get(markerName); - if (!markerId) { + if (isNaN(markerId)) { markerId = _this.markers.length; _this._markerNameToIdMap.set(markerName, markerId); } @@ -6737,7 +6714,7 @@ var TimeRuler = (function () { throw new Error("call beginMark method before calling endMark method"); } var markerId = _this._markerNameToIdMap.get(markerName); - if (!markerId) { + if (isNaN(markerId)) { throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method"); } var markerIdx = bar.markerNests[--bar.nestCount]; @@ -6810,7 +6787,7 @@ var TimeRuler = (function () { var startY = position.y - (height - TimeRuler.barHeight); var y = startY; }; - TimeRuler.maxBars = 0; + TimeRuler.maxBars = 8; TimeRuler.maxSamples = 256; TimeRuler.maxNestCall = 32; TimeRuler.barHeight = 8; @@ -6823,20 +6800,27 @@ var TimeRuler = (function () { var FrameLog = (function () { function FrameLog() { this.bars = new Array(TimeRuler.maxBars); - for (var i = 0; i < TimeRuler.maxBars; ++i) - this.bars[i] = new MarkerCollection(); + this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); } return FrameLog; }()); var MarkerCollection = (function () { function MarkerCollection() { this.markers = new Array(TimeRuler.maxSamples); + this.markCount = 0; this.markerNests = new Array(TimeRuler.maxNestCall); + this.nestCount = 0; + this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); + this.markerNests.fill(0, 0, TimeRuler.maxNestCall); } return MarkerCollection; }()); var Marker = (function () { function Marker() { + this.markerId = 0; + this.beginTime = 0; + this.endTime = 0; + this.color = 0x000000; } return Marker; }()); @@ -6844,11 +6828,21 @@ var MarkerInfo = (function () { function MarkerInfo(name) { this.logs = new Array(TimeRuler.maxBars); this.name = name; + this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); } return MarkerInfo; }()); var MarkerLog = (function () { function MarkerLog() { + this.snapMin = 0; + this.snapMax = 0; + this.snapAvg = 0; + this.min = 0; + this.max = 0; + this.avg = 0; + this.samples = 0; + this.color = 0x000000; + this.initialized = false; } return MarkerLog; }()); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 6519cad4..d6c96e6d 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){this.bounds=new Rectangle,this.position=Vector2.zero}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(this.intToUint(e)).toString()},t.prototype.intToUint=function(t){return t>=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);s||(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(!o)throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=0,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars);for(var t=0;t0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.endDebugUpdate(),t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t.startDebugUpdate=function(){TimeRuler.Instance.startFrame(),TimeRuler.Instance.beginMark("update",65280)},t.endDebugUpdate=function(){TimeRuler.Instance.endMark("update")},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x==-t.position.x+t.origin.x&&this.y==-t.position.y+t.origin.y||(this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y,this.entity.onEntityTransformChanged(TransformComponent.position))},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t, e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(egret.DisplayObject),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.parent.x,this.parent.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.x,this.y,this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(Long.fromNumber(e,!1)).toString()},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(isNaN(o))throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=8,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars),this.bars.fill(new MarkerCollection,0,TimeRuler.maxBars)}}(),MarkerCollection=function(){return function(){this.markers=new Array(TimeRuler.maxSamples),this.markCount=0,this.markerNests=new Array(TimeRuler.maxNestCall),this.nestCount=0,this.markers.fill(new Marker,0,TimeRuler.maxSamples),this.markerNests.fill(0,0,TimeRuler.maxNestCall)}}(),Marker=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}(),MarkerInfo=function(){return function(t){this.logs=new Array(TimeRuler.maxBars),this.name=t,this.logs.fill(new MarkerLog,0,TimeRuler.maxBars)}}(),MarkerLog=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}(); \ No newline at end of file diff --git a/demo/libs/modules/egret/egret.web.min.js b/demo/libs/modules/egret/egret.web.min.js index f6c20063..268b33be 100644 --- a/demo/libs/modules/egret/egret.web.min.js +++ b/demo/libs/modules/egret/egret.web.min.js @@ -1,5 +1,5 @@ var __reflect=this&&this.__reflect||function(e,t,r){e.__class__=t,r?r.push(t):r=[t],e.__types__=e.__types__?r.concat(e.__types__):r},__extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},egret;!function(e){var t;!function(t){var r=function(t){function r(r){var i=t.call(this)||this;return i.onUpdate=function(t){var r=new e.GeolocationEvent(e.Event.CHANGE),n=t.coords;r.altitude=n.altitude,r.heading=n.heading,r.accuracy=n.accuracy,r.latitude=n.latitude,r.longitude=n.longitude,r.speed=n.speed,r.altitudeAccuracy=n.altitudeAccuracy,i.dispatchEvent(r)},i.onError=function(t){var r=e.GeolocationEvent.UNAVAILABLE;t.code==t.PERMISSION_DENIED&&(r=e.GeolocationEvent.PERMISSION_DENIED);var n=new e.GeolocationEvent(e.IOErrorEvent.IO_ERROR);n.errorType=r,n.errorMessage=t.message,i.dispatchEvent(n)},i.geolocation=navigator.geolocation,i}return __extends(r,t),r.prototype.start=function(){var t=this.geolocation;t?this.watchId=t.watchPosition(this.onUpdate,this.onError):this.onError({code:2,message:e.sys.tr(3004),PERMISSION_DENIED:1,POSITION_UNAVAILABLE:2})},r.prototype.stop=function(){var e=this.geolocation;e.clearWatch(this.watchId)},r}(e.EventDispatcher);t.WebGeolocation=r,__reflect(r.prototype,"egret.web.WebGeolocation",["egret.Geolocation"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var r=null!==t&&t.apply(this,arguments)||this;return r.onChange=function(t){var i=new e.MotionEvent(e.Event.CHANGE),n={x:t.acceleration.x,y:t.acceleration.y,z:t.acceleration.z},a={x:t.accelerationIncludingGravity.x,y:t.accelerationIncludingGravity.y,z:t.accelerationIncludingGravity.z},o={alpha:t.rotationRate.alpha,beta:t.rotationRate.beta,gamma:t.rotationRate.gamma};i.acceleration=n,i.accelerationIncludingGravity=a,i.rotationRate=o,r.dispatchEvent(i)},r}return __extends(r,t),r.prototype.start=function(){window.addEventListener("devicemotion",this.onChange)},r.prototype.stop=function(){window.removeEventListener("devicemotion",this.onChange)},r}(e.EventDispatcher);t.WebMotion=r,__reflect(r.prototype,"egret.web.WebMotion",["egret.Motion"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(e){if(window.location){var t=location.search;if(""==t)return"";t=t.slice(1);for(var r=t.split("&"),i=r.length,n=0;i>n;n++){var a=r[n],o=a.split("=");if(o[0]==e)return o[1]}}return""}t.getOption=r,e.getOption=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(t){var i=r.call(this)||this;return i.$startTime=0,i.audio=null,i.isStopped=!1,i.canPlay=function(){i.audio.removeEventListener("canplay",i.canPlay);try{i.audio.currentTime=i.$startTime}catch(e){}finally{i.audio.play()}},i.onPlayEnd=function(){return 1==i.$loops?(i.stop(),void i.dispatchEventWith(e.Event.SOUND_COMPLETE)):(i.$loops>0&&i.$loops--,void i.$play())},i._volume=1,t.addEventListener("ended",i.onPlayEnd),i.audio=t,i}return __extends(i,r),i.prototype.$play=function(){if(this.isStopped)return void e.$error(1036);try{this.audio.volume=this._volume,this.audio.currentTime=this.$startTime}catch(t){return void this.audio.addEventListener("canplay",this.canPlay)}this.audio.play()},i.prototype.stop=function(){if(this.audio){this.isStopped||e.sys.$popSoundChannel(this),this.isStopped=!0;var r=this.audio;r.removeEventListener("ended",this.onPlayEnd),r.removeEventListener("canplay",this.canPlay),r.volume=0,this._volume=0,this.audio=null;var i=this.$url;window.setTimeout(function(){r.pause(),t.HtmlSound.$recycle(i,r)},200)}},Object.defineProperty(i.prototype,"volume",{get:function(){return this._volume},set:function(t){return this.isStopped?void e.$error(1036):(this._volume=t,void(this.audio&&(this.audio.volume=t)))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"position",{get:function(){return this.audio?this.audio.currentTime:0},enumerable:!0,configurable:!0}),i}(e.EventDispatcher);t.HtmlSoundChannel=r,__reflect(r.prototype,"egret.web.HtmlSoundChannel",["egret.SoundChannel","egret.IEventDispatcher"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(){function t(){}return t.decodeAudios=function(){if(!(t.decodeArr.length<=0||t.isDecoding)){t.isDecoding=!0;var r=t.decodeArr.shift();t.ctx.decodeAudioData(r.buffer,function(e){r.self.audioBuffer=e,r.success&&r.success(),t.isDecoding=!1,t.decodeAudios()},function(){e.log("sound decode error"),r.fail&&r.fail(),t.isDecoding=!1,t.decodeAudios()})}},t.decodeArr=[],t.isDecoding=!1,t}();t.WebAudioDecode=r,__reflect(r.prototype,"egret.web.WebAudioDecode");var i=function(i){function n(){var e=i.call(this)||this;return e.loaded=!1,e}return __extends(n,i),Object.defineProperty(n.prototype,"length",{get:function(){if(this.audioBuffer)return this.audioBuffer.duration;throw new Error("sound not loaded!")},enumerable:!0,configurable:!0}),n.prototype.load=function(t){function i(){a.loaded=!0,a.dispatchEventWith(e.Event.COMPLETE)}function n(){a.dispatchEventWith(e.IOErrorEvent.IO_ERROR)}var a=this;this.url=t;var o=new XMLHttpRequest;o.open("GET",t,!0),o.responseType="arraybuffer",o.addEventListener("load",function(){var t=o.status>=400;t?a.dispatchEventWith(e.IOErrorEvent.IO_ERROR):(r.decodeArr.push({buffer:o.response,success:i,fail:n,self:a,url:a.url}),r.decodeAudios())}),o.addEventListener("error",function(){a.dispatchEventWith(e.IOErrorEvent.IO_ERROR)}),o.send()},n.prototype.play=function(r,i){r=+r||0,i=+i||0;var n=new t.WebAudioSoundChannel;return n.$url=this.url,n.$loops=i,n.$audioBuffer=this.audioBuffer,n.$startTime=r,n.$play(),e.sys.$pushSoundChannel(n),n},n.prototype.close=function(){},n.MUSIC="music",n.EFFECT="effect",n}(e.EventDispatcher);t.WebAudioSound=i,__reflect(i.prototype,"egret.web.WebAudioSound",["egret.Sound"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(){var i=r.call(this)||this;return i.$startTime=0,i.bufferSource=null,i.context=t.WebAudioDecode.ctx,i.isStopped=!1,i._currentTime=0,i._volume=1,i.onPlayEnd=function(){return 1==i.$loops?(i.stop(),void i.dispatchEventWith(e.Event.SOUND_COMPLETE)):(i.$loops>0&&i.$loops--,void i.$play())},i._startTime=0,i.context.createGain?i.gain=i.context.createGain():i.gain=i.context.createGainNode(),i}return __extends(i,r),i.prototype.$play=function(){if(this.isStopped)return void e.$error(1036);this.bufferSource&&(this.bufferSource.onended=null,this.bufferSource=null);var t=this.context,r=this.gain,i=t.createBufferSource();this.bufferSource=i,i.buffer=this.$audioBuffer,i.connect(r),r.connect(t.destination),i.onended=this.onPlayEnd,this._startTime=Date.now(),this.gain.gain.value=this._volume,i.start(0,this.$startTime),this._currentTime=0},i.prototype.stop=function(){if(this.bufferSource){var t=this.bufferSource;t.stop?t.stop(0):t.noteOff(0),t.onended=null,t.disconnect(),this.bufferSource=null,this.$audioBuffer=null}this.isStopped||e.sys.$popSoundChannel(this),this.isStopped=!0},Object.defineProperty(i.prototype,"volume",{get:function(){return this._volume},set:function(t){return this.isStopped?void e.$error(1036):(this._volume=t,void(this.gain.gain.value=t))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"position",{get:function(){return this.bufferSource?(Date.now()-this._startTime)/1e3+this.$startTime:0},enumerable:!0,configurable:!0}),i}(e.EventDispatcher);t.WebAudioSoundChannel=r,__reflect(r.prototype,"egret.web.WebAudioSoundChannel",["egret.SoundChannel","egret.IEventDispatcher"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(r,i){void 0===i&&(i=!0);var n=t.call(this)||this;return n.loaded=!1,n.closed=!1,n.heightSet=0/0,n.widthSet=0/0,n.waiting=!1,n.userPause=!1,n.userPlay=!1,n.isPlayed=!1,n.screenChanged=function(t){var r=document.fullscreenEnabled||document.webkitIsFullScreen;r||(n.checkFullScreen(!1),e.Capabilities.isMobile||(n._fullscreen=r))},n._fullscreen=!0,n.onVideoLoaded=function(){n.video.removeEventListener("canplay",n.onVideoLoaded);var t=n.video;n.loaded=!0,n.posterData&&(n.posterData.width=n.getPlayWidth(),n.posterData.height=n.getPlayHeight()),t.width=t.videoWidth,t.height=t.videoHeight,window.setTimeout(function(){n.dispatchEventWith(e.Event.COMPLETE)},200)},n.$renderNode=new e.sys.BitmapNode,n.src=r,n.once(e.Event.ADDED_TO_STAGE,n.loadPoster,n),r&&n.load(),n}return __extends(r,t),r.prototype.createNativeDisplayObject=function(){this.$nativeDisplayObject=new egret_native.NativeDisplayObject(1)},r.prototype.load=function(t,r){var i=this;if(void 0===r&&(r=!0),t=t||this.src,this.src=t,!this.video||this.video.src!=t){var n;!this.video||e.Capabilities.isMobile?(n=document.createElement("video"),this.video=n,n.controls=null):n=this.video,n.src=t,n.setAttribute("autoplay","autoplay"),n.setAttribute("webkit-playsinline","true"),n.addEventListener("canplay",this.onVideoLoaded),n.addEventListener("error",function(){return i.onVideoError()}),n.addEventListener("ended",function(){return i.onVideoEnded()});var a=!1;n.addEventListener("canplay",function(){i.waiting=!1,a?i.userPause?i.pause():i.userPlay&&i.play():(a=!0,n.pause())}),n.addEventListener("waiting",function(){i.waiting=!0}),n.load(),this.videoPlay(),n.style.position="absolute",n.style.top="0px",n.style.zIndex="-88888",n.style.left="0px",n.height=1,n.width=1}},r.prototype.play=function(t,r){var i=this;if(void 0===r&&(r=!1),0==this.loaded)return this.load(this.src),void this.once(e.Event.COMPLETE,function(e){return i.play(t,r)},this);this.isPlayed=!0;var n=this.video;void 0!=t&&(n.currentTime=+t||0),n.loop=!!r,e.Capabilities.isMobile?n.style.zIndex="-88888":n.style.zIndex="9999",n.style.position="absolute",n.style.top="0px",n.style.left="0px",n.height=n.videoHeight,n.width=n.videoWidth,"Windows PC"!=e.Capabilities.os&&"Mac OS"!=e.Capabilities.os&&window.setTimeout(function(){n.width=0},1e3),this.checkFullScreen(this._fullscreen)},r.prototype.videoPlay=function(){return this.userPause=!1,this.waiting?void(this.userPlay=!0):(this.userPlay=!1,void this.video.play())},r.prototype.checkFullScreen=function(t){var r=this.video;if(t)null==r.parentElement&&(r.removeAttribute("webkit-playsinline"),document.body.appendChild(r)),e.stopTick(this.markDirty,this),this.goFullscreen();else if(null!=r.parentElement&&r.parentElement.removeChild(r),r.setAttribute("webkit-playsinline","true"),this.setFullScreenMonitor(!1),e.startTick(this.markDirty,this),e.Capabilities.isMobile)return this.video.currentTime=0,void this.onVideoEnded();this.videoPlay()},r.prototype.goFullscreen=function(){var t,r=this.video;return t=e.web.getPrefixStyleName("requestFullscreen",r),r[t]||(t=e.web.getPrefixStyleName("requestFullScreen",r),r[t])?(r.removeAttribute("webkit-playsinline"),r[t](),this.setFullScreenMonitor(!0),!0):!0},r.prototype.setFullScreenMonitor=function(e){var t=this.video;e?(t.addEventListener("mozfullscreenchange",this.screenChanged),t.addEventListener("webkitfullscreenchange",this.screenChanged),t.addEventListener("mozfullscreenerror",this.screenError),t.addEventListener("webkitfullscreenerror",this.screenError)):(t.removeEventListener("mozfullscreenchange",this.screenChanged),t.removeEventListener("webkitfullscreenchange",this.screenChanged),t.removeEventListener("mozfullscreenerror",this.screenError),t.removeEventListener("webkitfullscreenerror",this.screenError))},r.prototype.screenError=function(){e.$error(3014)},r.prototype.exitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.oCancelFullScreen?document.oCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()},r.prototype.onVideoEnded=function(){this.pause(),this.isPlayed=!1,this.dispatchEventWith(e.Event.ENDED)},r.prototype.onVideoError=function(){this.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},r.prototype.close=function(){var e=this;this.closed=!0,this.video.removeEventListener("canplay",this.onVideoLoaded),this.video.removeEventListener("error",function(){return e.onVideoError()}),this.video.removeEventListener("ended",function(){return e.onVideoEnded()}),this.pause(),0==this.loaded&&this.video&&(this.video.src=""),this.video&&this.video.parentElement&&(this.video.parentElement.removeChild(this.video),this.video=null),this.loaded=!1},r.prototype.pause=function(){return this.userPlay=!1,this.waiting?void(this.userPause=!0):(this.userPause=!1,this.video.pause(),void e.stopTick(this.markDirty,this))},Object.defineProperty(r.prototype,"volume",{get:function(){return this.video?this.video.volume:1},set:function(e){this.video&&(this.video.volume=e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"position",{get:function(){return this.video?this.video.currentTime:0},set:function(e){this.video&&(this.video.currentTime=e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"fullscreen",{get:function(){return this._fullscreen},set:function(t){e.Capabilities.isMobile||(this._fullscreen=!!t,this.video&&0==this.video.paused&&this.checkFullScreen(this._fullscreen))},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"bitmapData",{get:function(){return this.video&&this.loaded?(this._bitmapData||(this.video.width=this.video.videoWidth,this.video.height=this.video.videoHeight,this._bitmapData=new e.BitmapData(this.video),this._bitmapData.$deleteSource=!1),this._bitmapData):null},enumerable:!0,configurable:!0}),r.prototype.loadPoster=function(){var t=this,r=this.poster;if(r){var i=new e.ImageLoader;i.once(e.Event.COMPLETE,function(r){i.data;if(t.posterData=i.data,t.$renderDirty=!0,t.posterData.width=t.getPlayWidth(),t.posterData.height=t.getPlayHeight(),e.nativeRender){var n=new e.Texture;n._setBitmapData(t.posterData),t.$nativeDisplayObject.setTexture(n)}},this),i.load(r)}},r.prototype.$measureContentBounds=function(e){var t=this.bitmapData,r=this.posterData;t?e.setTo(0,0,this.getPlayWidth(),this.getPlayHeight()):r?e.setTo(0,0,this.getPlayWidth(),this.getPlayHeight()):e.setEmpty()},r.prototype.getPlayWidth=function(){return isNaN(this.widthSet)?this.bitmapData?this.bitmapData.width:this.posterData?this.posterData.width:0/0:this.widthSet},r.prototype.getPlayHeight=function(){return isNaN(this.heightSet)?this.bitmapData?this.bitmapData.height:this.posterData?this.posterData.height:0/0:this.heightSet},r.prototype.$updateRenderNode=function(){var t=this.$renderNode,r=this.bitmapData,i=this.posterData,n=this.getPlayWidth(),a=this.getPlayHeight();this.isPlayed&&!e.Capabilities.isMobile||!i?this.isPlayed&&r&&(t.image=r,t.imageWidth=r.width,t.imageHeight=r.height,e.WebGLUtils.deleteWebGLTexture(r.webGLTexture),r.webGLTexture=null,t.drawImage(0,0,r.width,r.height,0,0,n,a)):(t.image=i,t.imageWidth=n,t.imageHeight=a,t.drawImage(0,0,i.width,i.height,0,0,n,a))},r.prototype.markDirty=function(){return this.$renderDirty=!0,!0},r.prototype.$setHeight=function(e){if(this.heightSet=e,this.paused){var r=this;this.$renderDirty=!0,window.setTimeout(function(){r.$renderDirty=!1},200)}t.prototype.$setHeight.call(this,e)},r.prototype.$setWidth=function(e){if(this.widthSet=e,this.paused){var r=this;this.$renderDirty=!0,window.setTimeout(function(){r.$renderDirty=!1},200)}t.prototype.$setWidth.call(this,e)},Object.defineProperty(r.prototype,"paused",{get:function(){return this.video?this.video.paused:!0},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"length",{get:function(){if(this.video)return this.video.duration;throw new Error("Video not loaded!")},enumerable:!0,configurable:!0}),r}(e.DisplayObject);t.WebVideo=r,__reflect(r.prototype,"egret.web.WebVideo",["egret.Video","egret.DisplayObject"]),e.Video=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var e=t.call(this)||this;return e.timeout=0,e._url="",e._method="",e}return __extends(r,t),Object.defineProperty(r.prototype,"response",{get:function(){if(!this._xhr)return null;if(void 0!=this._xhr.response)return this._xhr.response;if("text"==this._responseType)return this._xhr.responseText;if("arraybuffer"==this._responseType&&/msie 9.0/i.test(navigator.userAgent)){var e=window;return e.convertResponseBodyToText(this._xhr.responseBody)}return"document"==this._responseType?this._xhr.responseXML:null},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"responseType",{get:function(){return this._responseType},set:function(e){this._responseType=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"withCredentials",{get:function(){return this._withCredentials},set:function(e){this._withCredentials=e},enumerable:!0,configurable:!0}),r.prototype.getXHR=function(){return window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP")},r.prototype.open=function(e,t){void 0===t&&(t="GET"),this._url=e,this._method=t,this._xhr&&(this._xhr.abort(),this._xhr=null);var r=this.getXHR();window.XMLHttpRequest?(r.addEventListener("load",this.onload.bind(this)),r.addEventListener("error",this.onerror.bind(this))):r.onreadystatechange=this.onReadyStateChange.bind(this),r.onprogress=this.updateProgress.bind(this),r.ontimeout=this.onTimeout.bind(this),r.open(this._method,this._url,!0),this._xhr=r},r.prototype.send=function(e){if(null!=this._responseType&&(this._xhr.responseType=this._responseType),null!=this._withCredentials&&(this._xhr.withCredentials=this._withCredentials),this.headerObj)for(var t in this.headerObj)this._xhr.setRequestHeader(t,this.headerObj[t]);this._xhr.timeout=this.timeout,this._xhr.send(e)},r.prototype.abort=function(){this._xhr&&this._xhr.abort()},r.prototype.getAllResponseHeaders=function(){if(!this._xhr)return null;var e=this._xhr.getAllResponseHeaders();return e?e:""},r.prototype.setRequestHeader=function(e,t){this.headerObj||(this.headerObj={}),this.headerObj[e]=t},r.prototype.getResponseHeader=function(e){if(!this._xhr)return null;var t=this._xhr.getResponseHeader(e);return t?t:""},r.prototype.onTimeout=function(){this.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},r.prototype.onReadyStateChange=function(){var t=this._xhr;if(4==t.readyState){var r=t.status>=400||0==t.status,i=(this._url,this);window.setTimeout(function(){r?i.dispatchEventWith(e.IOErrorEvent.IO_ERROR):i.dispatchEventWith(e.Event.COMPLETE)},0)}},r.prototype.updateProgress=function(t){t.lengthComputable&&e.ProgressEvent.dispatchProgressEvent(this,e.ProgressEvent.PROGRESS,t.loaded,t.total)},r.prototype.onload=function(){var t=this,r=this._xhr,i=(this._url,r.status>=400);window.setTimeout(function(){i?t.dispatchEventWith(e.IOErrorEvent.IO_ERROR):t.dispatchEventWith(e.Event.COMPLETE)},0)},r.prototype.onerror=function(){var t=(this._url,this);window.setTimeout(function(){t.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},0)},r}(e.EventDispatcher);t.WebHttpRequest=r,__reflect(r.prototype,"egret.web.WebHttpRequest",["egret.HttpRequest"]),e.HttpRequest=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=window.URL||window.webkitURL,i=function(i){function n(){var e=null!==i&&i.apply(this,arguments)||this;return e.data=null,e._crossOrigin=null,e._hasCrossOriginSet=!1,e.currentImage=null,e.request=null,e}return __extends(n,i),Object.defineProperty(n.prototype,"crossOrigin",{get:function(){return this._crossOrigin},set:function(e){this._hasCrossOriginSet=!0,this._crossOrigin=e},enumerable:!0,configurable:!0}),n.prototype.load=function(r){if(t.Html5Capatibility._canUseBlob&&0!=r.indexOf("wxLocalResource:")&&0!=r.indexOf("data:")&&0!=r.indexOf("http:")&&0!=r.indexOf("https:")){var i=this.request;i||(i=this.request=new e.web.WebHttpRequest,i.addEventListener(e.Event.COMPLETE,this.onBlobLoaded,this),i.addEventListener(e.IOErrorEvent.IO_ERROR,this.onBlobError,this),i.responseType="blob"),i.open(r),i.send()}else this.loadImage(r)},n.prototype.onBlobLoaded=function(e){var t=this.request.response;this.request=void 0,this.loadImage(r.createObjectURL(t))},n.prototype.onBlobError=function(e){this.dispatchIOError(this.currentURL),this.request=void 0},n.prototype.loadImage=function(e){var t=new Image;this.data=null,this.currentImage=t,this._hasCrossOriginSet?this._crossOrigin&&(t.crossOrigin=this._crossOrigin):n.crossOrigin&&(t.crossOrigin=n.crossOrigin),t.onload=this.onImageComplete.bind(this),t.onerror=this.onLoadError.bind(this),t.src=e},n.prototype.onImageComplete=function(t){var r=this.getImage(t);if(r){this.data=new e.BitmapData(r);var i=this;window.setTimeout(function(){i.dispatchEventWith(e.Event.COMPLETE)},0)}},n.prototype.onLoadError=function(e){var t=this.getImage(e);t&&this.dispatchIOError(t.src)},n.prototype.dispatchIOError=function(t){var r=this;window.setTimeout(function(){r.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},0)},n.prototype.getImage=function(t){var i=t.target,n=i.src;if(0==n.indexOf("blob:"))try{r.revokeObjectURL(i.src)}catch(a){e.$warn(1037)}return i.onerror=null,i.onload=null,this.currentImage!==i?null:(this.currentImage=null,i)},n.crossOrigin=null,n}(e.EventDispatcher);t.WebImageLoader=i,__reflect(i.prototype,"egret.web.WebImageLoader",["egret.ImageLoader"]),e.ImageLoader=i}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var e=t.call(this)||this;return e._isNeedShow=!1,e.inputElement=null,e.inputDiv=null,e._gscaleX=0,e._gscaleY=0,e.textValue="",e.colorValue=16777215,e._styleInfoes={},e}return __extends(r,t),r.prototype.$setTextField=function(e){return this.$textfield=e,!0},r.prototype.$addToStage=function(){this.htmlInput=e.web.$getTextAdapter(this.$textfield)},r.prototype._initElement=function(){var t=this.$textfield.localToGlobal(0,0),r=t.x,i=t.y,n=this.htmlInput.$scaleX,a=this.htmlInput.$scaleY;this.inputDiv.style.left=r*n+"px",this.inputDiv.style.top=i*a+"px",this.$textfield.multiline&&this.$textfield.height>this.$textfield.size?(this.inputDiv.style.top=i*a+"px",this.inputElement.style.top=-this.$textfield.lineSpacing/2*a+"px"):(this.inputDiv.style.top=i*a+"px",this.inputElement.style.top="0px");for(var o=this.$textfield,s=1,l=1,c=0;o.parent;)s*=o.scaleX,l*=o.scaleY,c+=o.rotation,o=o.parent;var h=e.web.getPrefixStyleName("transform");this.inputDiv.style[h]="rotate("+c+"deg)",this._gscaleX=n*s,this._gscaleY=a*l},r.prototype.$show=function(){this.htmlInput.isCurrentStageText(this)?this.inputElement.onblur=null:(this.inputElement=this.htmlInput.getInputElement(this),this.$textfield.multiline?this.inputElement.type="text":this.inputElement.type=this.$textfield.inputType,this.inputDiv=this.htmlInput._inputDIV),this.htmlInput._needShow=!0,this._isNeedShow=!0,this._initElement()},r.prototype.onBlurHandler=function(){this.htmlInput.clearInputElement(),window.scrollTo(0,0)},r.prototype.onFocusHandler=function(){var e=this;window.setTimeout(function(){e.inputElement&&e.inputElement.scrollIntoView()},200)},r.prototype.executeShow=function(){this.inputElement.value=this.$getText(),null==this.inputElement.onblur&&(this.inputElement.onblur=this.onBlurHandler.bind(this)),null==this.inputElement.onfocus&&(this.inputElement.onfocus=this.onFocusHandler.bind(this)),this.$resetStageText(),this.$textfield.maxChars>0?this.inputElement.setAttribute("maxlength",this.$textfield.maxChars):this.inputElement.removeAttribute("maxlength"),this.inputElement.selectionStart=this.inputElement.value.length,this.inputElement.selectionEnd=this.inputElement.value.length,this.inputElement.focus()},r.prototype.$hide=function(){this.htmlInput&&this.htmlInput.disconnectStageText(this)},r.prototype.$getText=function(){return this.textValue||(this.textValue=""),this.textValue},r.prototype.$setText=function(e){return this.textValue=e,this.resetText(),!0},r.prototype.resetText=function(){this.inputElement&&(this.inputElement.value=this.textValue)},r.prototype.$setColor=function(e){return this.colorValue=e,this.resetColor(),!0},r.prototype.resetColor=function(){this.inputElement&&this.setElementStyle("color",e.toColorString(this.colorValue))},r.prototype.$onBlur=function(){},r.prototype._onInput=function(){var t=this;window.setTimeout(function(){t.inputElement&&t.inputElement.selectionStart==t.inputElement.selectionEnd&&(t.textValue=t.inputElement.value,e.Event.dispatchEvent(t,"updateText",!1))},0)},r.prototype.setAreaHeight=function(){var t=this.$textfield;if(t.multiline){var r=e.TextFieldUtils.$getTextHeight(t);if(t.height<=t.size)this.setElementStyle("height",t.size*this._gscaleY+"px"),this.setElementStyle("padding","0px"),this.setElementStyle("lineHeight",t.size*this._gscaleY+"px");else if(t.height=0&&(a=o[s],void 0===n[a]);s--);try{Object.defineProperty(n,"imageSmoothingEnabled",{get:function(){return this[a]},set:function(e){this[a]=e}})}catch(l){n.imageSmoothingEnabled=n[a]}}return i}var i=function(){function t(t,i,n){this.surface=e.sys.createCanvasRenderBufferSurface(r,t,i,n),this.context=this.surface.getContext("2d"),this.context&&(this.context.$offsetX=0,this.context.$offsetY=0),this.resize(t,i) }return Object.defineProperty(t.prototype,"width",{get:function(){return this.surface.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this.surface.height},enumerable:!0,configurable:!0}),t.prototype.resize=function(t,r,i){e.sys.resizeCanvasRenderBuffer(this,t,r,i)},t.prototype.getPixels=function(e,t,r,i){return void 0===r&&(r=1),void 0===i&&(i=1),this.context.getImageData(e,t,r,i).data},t.prototype.toDataURL=function(e,t){return this.surface.toDataURL(e,t)},t.prototype.clear=function(){this.context.setTransform(1,0,0,1,0,0),this.context.clearRect(0,0,this.surface.width,this.surface.height)},t.prototype.destroy=function(){this.surface.width=this.surface.height=0},t}();t.CanvasRenderBuffer=i,__reflect(i.prototype,"egret.web.CanvasRenderBuffer",["egret.sys.RenderBuffer"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(r,i){var n=t.call(this)||this;return n.onTouchBegin=function(e){var t=n.getLocation(e);n.touch.onTouchBegin(t.x,t.y,e.identifier)},n.onMouseMove=function(e){0==e.buttons?n.onTouchEnd(e):n.onTouchMove(e)},n.onTouchMove=function(e){var t=n.getLocation(e);n.touch.onTouchMove(t.x,t.y,e.identifier)},n.onTouchEnd=function(e){var t=n.getLocation(e);n.touch.onTouchEnd(t.x,t.y,e.identifier)},n.scaleX=1,n.scaleY=1,n.rotation=0,n.canvas=i,n.touch=new e.sys.TouchHandler(r),n.addListeners(),n}return __extends(r,t),r.prototype.addListeners=function(){var t=this;window.navigator.msPointerEnabled?(this.canvas.addEventListener("MSPointerDown",function(e){e.identifier=e.pointerId,t.onTouchBegin(e),t.prevent(e)},!1),this.canvas.addEventListener("MSPointerMove",function(e){e.identifier=e.pointerId,t.onTouchMove(e),t.prevent(e)},!1),this.canvas.addEventListener("MSPointerUp",function(e){e.identifier=e.pointerId,t.onTouchEnd(e),t.prevent(e)},!1)):(e.Capabilities.isMobile||this.addMouseListener(),this.addTouchListener())},r.prototype.addMouseListener=function(){this.canvas.addEventListener("mousedown",this.onTouchBegin),this.canvas.addEventListener("mousemove",this.onMouseMove),this.canvas.addEventListener("mouseup",this.onTouchEnd)},r.prototype.addTouchListener=function(){var e=this;this.canvas.addEventListener("touchstart",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchBegin(t.changedTouches[i]);e.prevent(t)},!1),this.canvas.addEventListener("touchmove",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchMove(t.changedTouches[i]);e.prevent(t)},!1),this.canvas.addEventListener("touchend",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchEnd(t.changedTouches[i]);e.prevent(t)},!1),this.canvas.addEventListener("touchcancel",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchEnd(t.changedTouches[i]);e.prevent(t)},!1)},r.prototype.prevent=function(e){e.stopPropagation(),1==e.isScroll||this.canvas.userTyping||e.preventDefault()},r.prototype.getLocation=function(t){t.identifier=+t.identifier||0;var r=document.documentElement,i=this.canvas.getBoundingClientRect(),n=i.left+window.pageXOffset-r.clientLeft,a=i.top+window.pageYOffset-r.clientTop,o=t.pageX-n,s=o,l=t.pageY-a,c=l;return 90==this.rotation?(s=l,c=i.width-o):-90==this.rotation&&(s=i.height-l,c=o),s/=this.scaleX,c/=this.scaleY,e.$TempPoint.setTo(Math.round(s),Math.round(c))},r.prototype.updateScaleMode=function(e,t,r){this.scaleX=e,this.scaleY=t,this.rotation=r},r.prototype.$updateMaxTouches=function(){this.touch.$initMaxTouches()},r}(e.HashObject);t.WebTouchHandler=r,__reflect(r.prototype,"egret.web.WebTouchHandler")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){e.WebLifeCycleHandler=function(e){var t=function(){document[r]?e.pause():e.resume()};window.addEventListener("focus",e.resume,!1),window.addEventListener("blur",e.pause,!1);var r,i;"undefined"!=typeof document.hidden?(r="hidden",i="visibilitychange"):"undefined"!=typeof document.mozHidden?(r="mozHidden",i="mozvisibilitychange"):"undefined"!=typeof document.msHidden?(r="msHidden",i="msvisibilitychange"):"undefined"!=typeof document.webkitHidden?(r="webkitHidden",i="webkitvisibilitychange"):"undefined"!=typeof document.oHidden&&(r="oHidden",i="ovisibilitychange"),"onpageshow"in window&&"onpagehide"in window&&(window.addEventListener("pageshow",e.resume,!1),window.addEventListener("pagehide",e.pause,!1)),r&&i&&document.addEventListener(i,t,!1);var n=navigator.userAgent,a=/micromessenger/gi.test(n),o=/mqq/gi.test(n),s=/mobile.*qq/gi.test(n);if((s||a)&&(o=!1),o){var l=window.browser||{};l.execWebFn=l.execWebFn||{},l.execWebFn.postX5GamePlayerMessage=function(t){var r=t.type;"app_enter_background"==r?e.pause():"app_enter_foreground"==r&&e.resume()},window.browser=l}}}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(e,t){var r="";if(null!=t)r=i(e,t);else{if(null==o){var n=document.createElement("div").style;o=i("transform",n)}r=o}return""==r?e:r+e.charAt(0).toUpperCase()+e.substring(1,e.length)}function i(e,t){if(e in t)return"";e=e.charAt(0).toUpperCase()+e.substring(1,e.length);for(var r=["webkit","ms","Moz","O"],i=0;i=0||r.indexOf("ipad")>=0||r.indexOf("ipod")>=0;if(a)try{t.WebAudioDecode.ctx=new(window.AudioContext||window.webkitAudioContext||window.mozAudioContext)}catch(s){a=!1}var l,c=i._audioType;c==n.WEB_AUDIO&&a||c==n.HTML5_AUDIO?(l=!1,i.setAudioType(c)):!o&&r.indexOf("safari")>=0&&-1===r.indexOf("chrome")?(l=!1,i.setAudioType(n.WEB_AUDIO)):(l=!0,i.setAudioType(n.HTML5_AUDIO)),r.indexOf("android")>=0?l&&a&&i.setAudioType(n.WEB_AUDIO):o&&i.getIOSVersion()>=7&&(i._canUseBlob=!0,l&&a&&i.setAudioType(n.WEB_AUDIO));var h=window.URL||window.webkitURL;h||(i._canUseBlob=!1),r.indexOf("egretnative")>=0&&(i.setAudioType(n.HTML5_AUDIO),i._canUseBlob=!0),e.Sound=i._AudioClass},i.setAudioType=function(t){switch(i._audioType=t,t){case n.WEB_AUDIO:i._AudioClass=e.web.WebAudioSound;break;case n.HTML5_AUDIO:i._AudioClass=e.web.HtmlSound}},i.getIOSVersion=function(){var e=i.ua.toLowerCase().match(/cpu [^\d]*\d.*like mac os x/);if(!e||0==e.length)return 0;var t=e[0];return parseInt(t.match(/\d+(_\d)*/)[0])||0},i._canUseBlob=!1,i._audioType=0,i.ua="",i}(e.HashObject);t.Html5Capatibility=a,__reflect(a.prototype,"egret.web.Html5Capatibility");var o=null;t.getPrefixStyleName=r,t.getPrefix=i}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(e,t){return i(e,t)}function i(e,t){var r=document.createElement("canvas");return isNaN(e)||isNaN(t)||(r.width=e,r.height=t),r}function n(e,t,r,i){if(e){var n=e,a=n.surface;i?(a.widthr;r++){var i=e[r],n=i["egret-player"];n.updateScreenSize()}}function i(r){if(!s){s=!0,r||(r={});var i=navigator.userAgent.toLowerCase();if(i.indexOf("egretnative")>=0&&-1==i.indexOf("egretwebview")&&(e.Capabilities.runtimeType=e.RuntimeType.RUNTIME2),i.indexOf("egretnative")>=0&&e.nativeRender)egret_native.addModuleCallback(function(){if(t.Html5Capatibility.$init(),"webgl"==r.renderMode){var i=r.antialias;t.WebGLRenderContext.antialias=!!i}e.sys.CanvasRenderBuffer=t.CanvasRenderBuffer,n(r.renderMode),egret_native.nrSetRenderMode(2);var s;s=r.canvasScaleFactor?r.canvasScaleFactor:r.calculateCanvasScaleFactor?r.calculateCanvasScaleFactor(e.sys.canvasHitTestBuffer.context):window.devicePixelRatio,e.sys.DisplayList.$canvasScaleFactor=s;var c=e.ticker;a(c),r.screenAdapter?e.sys.screenAdapter=r.screenAdapter:e.sys.screenAdapter||(e.sys.screenAdapter=new e.sys.DefaultScreenAdapter);for(var h=document.querySelectorAll(".egret-player"),u=h.length,d=0;u>d;d++){var f=h[d],p=new t.WebPlayer(f,r);f["egret-player"]=p}window.addEventListener("resize",function(){isNaN(l)&&(l=window.setTimeout(o,300))})},null),egret_native.initNativeRender();else{t.Html5Capatibility._audioType=r.audioType,t.Html5Capatibility.$init();var c=r.renderMode;if("webgl"==c){var h=r.antialias;t.WebGLRenderContext.antialias=!!h}e.sys.CanvasRenderBuffer=t.CanvasRenderBuffer,i.indexOf("egretnative")>=0&&"webgl"!=c&&(e.$warn(1051),c="webgl"),n(c);var u=void 0;if(r.canvasScaleFactor)u=r.canvasScaleFactor;else if(r.calculateCanvasScaleFactor)u=r.calculateCanvasScaleFactor(e.sys.canvasHitTestBuffer.context);else{var d=e.sys.canvasHitTestBuffer.context,f=d.backingStorePixelRatio||d.webkitBackingStorePixelRatio||d.mozBackingStorePixelRatio||d.msBackingStorePixelRatio||d.oBackingStorePixelRatio||d.backingStorePixelRatio||1;u=(window.devicePixelRatio||1)/f}e.sys.DisplayList.$canvasScaleFactor=u;var p=e.ticker;a(p),r.screenAdapter?e.sys.screenAdapter=r.screenAdapter:e.sys.screenAdapter||(e.sys.screenAdapter=new e.sys.DefaultScreenAdapter);for(var v=document.querySelectorAll(".egret-player"),g=v.length,x=0;g>x;x++){var y=v[x],m=new t.WebPlayer(y,r);y["egret-player"]=m}window.addEventListener("resize",function(){isNaN(l)&&(l=window.setTimeout(o,300))})}}}function n(r){"webgl"==r&&e.WebGLUtils.checkCanUseWebGL()?(e.sys.RenderBuffer=t.WebGLRenderBuffer,e.sys.systemRenderer=new t.WebGLRenderer,e.sys.canvasRenderer=new e.CanvasRenderer,e.sys.customHitTestBuffer=new t.WebGLRenderBuffer(3,3),e.sys.canvasHitTestBuffer=new t.CanvasRenderBuffer(3,3),e.Capabilities.renderMode="webgl"):(e.sys.RenderBuffer=t.CanvasRenderBuffer,e.sys.systemRenderer=new e.CanvasRenderer,e.sys.canvasRenderer=e.sys.systemRenderer,e.sys.customHitTestBuffer=new t.CanvasRenderBuffer(3,3),e.sys.canvasHitTestBuffer=e.sys.customHitTestBuffer,e.Capabilities.renderMode="canvas")}function a(e){function t(){r(t),e.update()}var r=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;r||(r=function(e){return window.setTimeout(e,1e3/60)}),r(t)}function o(){l=0/0,e.updateAllScreens()}var s=!1;window.isNaN=function(e){return e=+e,e!==e},e.runEgret=i,e.updateAllScreens=r;var l=0/0}(t=e.web||(e.web={}))}(egret||(egret={}));var language,egret;!function(e){var t;!function(t){var r=function(){function t(){}return t.detect=function(){var r=e.Capabilities,i=navigator.userAgent.toLowerCase();r.isMobile=-1!=i.indexOf("mobile")||-1!=i.indexOf("android"),r.isMobile?i.indexOf("windows")<0&&(-1!=i.indexOf("iphone")||-1!=i.indexOf("ipad")||-1!=i.indexOf("ipod"))?r.os="iOS":-1!=i.indexOf("android")&&-1!=i.indexOf("linux")?r.os="Android":-1!=i.indexOf("windows")&&(r.os="Windows Phone"):-1!=i.indexOf("windows nt")?r.os="Windows PC":"MacIntel"==navigator.platform&&navigator.maxTouchPoints>1?(r.os="iOS",r.isMobile=!0):-1!=i.indexOf("mac os")&&(r.os="Mac OS");var n=(navigator.language||navigator.browserLanguage).toLowerCase(),a=n.split("-");a.length>1&&(a[1]=a[1].toUpperCase()),r.language=a.join("-"),t.injectUIntFixOnIE9()},t.injectUIntFixOnIE9=function(){if(/msie 9.0/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent)){var e="\r\n\r\n\r\n\r\n";document.write(e)}},t}();t.WebCapability=r,__reflect(r.prototype,"egret.web.WebCapability"),r.detect()}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(){function t(t,r,i,n,a){if(this.showPanle=!0,this.fpsHeight=0,this.WIDTH=101,this.HEIGHT=20,this.bgCanvasColor="#18304b",this.fpsFrontColor="#18fefe",this.WIDTH_COST=50,this.cost1Color="#18fefe",this.cost3Color="#ff0000",this.arrFps=[],this.arrCost=[],this.arrLog=[],r||i){"canvas"==e.Capabilities.renderMode?this.renderMode="Canvas":this.renderMode="WebGL",this.panelX=void 0===a.x?0:parseInt(a.x),this.panelY=void 0===a.y?0:parseInt(a.y),this.fontColor=void 0===a.textColor?"#ffffff":a.textColor.replace("0x","#"),this.fontSize=void 0===a.size?12:parseInt(a.size),e.Capabilities.isMobile&&(this.fontSize-=2);var o=document.createElement("div");o.style.position="absolute",o.style.background="rgba(0,0,0,"+a.bgAlpha+")",o.style.left=this.panelX+"px",o.style.top=this.panelY+"px",o.style.pointerEvents="none",o.id="egret-fps-panel",document.body.appendChild(o);var s=document.createElement("div");s.style.color=this.fontColor,s.style.fontSize=this.fontSize+"px",s.style.lineHeight=this.fontSize+"px",s.style.margin="4px 4px 4px 4px",this.container=s,o.appendChild(s),r&&this.addFps(),i&&this.addLog()}}return t.prototype.addFps=function(){var e=document.createElement("div");e.style.display="inline-block",this.containerFps=e,this.container.appendChild(e);var t=document.createElement("div");t.style.paddingBottom="2px",this.fps=t,this.containerFps.appendChild(t),t.innerHTML="0 FPS "+this.renderMode+"
min0 max0 avg0";var r=document.createElement("canvas");this.containerFps.appendChild(r),r.width=this.WIDTH,r.height=this.HEIGHT,this.canvasFps=r;var i=r.getContext("2d");this.contextFps=i,i.fillStyle=this.bgCanvasColor,i.fillRect(0,0,this.WIDTH,this.HEIGHT);var n=document.createElement("div");this.divDatas=n,this.containerFps.appendChild(n);var a=document.createElement("div");a.style["float"]="left",a.innerHTML="Draw
Cost",n.appendChild(a);var o=document.createElement("div");o.style.paddingLeft=a.offsetWidth+20+"px",n.appendChild(o);var s=document.createElement("div");this.divDraw=s,s.innerHTML="0
",o.appendChild(s);var l=document.createElement("div");this.divCost=l,l.innerHTML='0 0',o.appendChild(l),r=document.createElement("canvas"),this.canvasCost=r,this.containerFps.appendChild(r),r.width=this.WIDTH,r.height=this.HEIGHT,i=r.getContext("2d"),this.contextCost=i,i.fillStyle=this.bgCanvasColor,i.fillRect(0,0,this.WIDTH,this.HEIGHT),i.fillStyle="#000000",i.fillRect(this.WIDTH_COST,0,1,this.HEIGHT),this.fpsHeight=this.container.offsetHeight},t.prototype.addLog=function(){var e=document.createElement("div");e.style.maxWidth=document.body.clientWidth-8-this.panelX+"px",e.style.wordWrap="break-word",this.log=e,this.container.appendChild(e)},t.prototype.update=function(e,t){void 0===t&&(t=!1);var r,i,n;t?(r=this.arrFps[this.arrFps.length-1],i=this.arrCost[this.arrCost.length-1][0],n=this.arrCost[this.arrCost.length-1][1]):(r=e.fps,i=e.costTicker,n=e.costRender,this.lastNumDraw=e.draw,this.arrFps.push(r),this.arrCost.push([i,n]));var a=0,o=this.arrFps.length;o>101&&(o=101,this.arrFps.shift(),this.arrCost.shift());for(var s=this.arrFps[0],l=this.arrFps[0],c=0;o>c;c++){var h=this.arrFps[c];a+=h,s>h?s=h:h>l&&(l=h)}var u=this.WIDTH,d=this.HEIGHT,f=this.contextFps;f.drawImage(this.canvasFps,1,0,u-1,d,0,0,u-1,d),f.fillStyle=this.bgCanvasColor,f.fillRect(u-1,0,1,d);var p=Math.floor(r/60*20);1>p&&(p=1),f.fillStyle=this.fpsFrontColor,f.fillRect(u-1,20-p,1,p);var v=this.WIDTH_COST;f=this.contextCost,f.drawImage(this.canvasCost,1,0,v-1,d,0,0,v-1,d),f.drawImage(this.canvasCost,v+2,0,v-1,d,v+1,0,v-1,d);var g=Math.floor(i/2);1>g?g=1:g>20&&(g=20);var x=Math.floor(n/2);1>x?x=1:x>20&&(x=20),f.fillStyle=this.bgCanvasColor,f.fillRect(v-1,0,1,d),f.fillRect(2*v,0,1,d),f.fillRect(3*v+1,0,1,d),f.fillStyle=this.cost1Color,f.fillRect(v-1,20-g,1,g),f.fillStyle=this.cost3Color,f.fillRect(2*v,20-x,1,x);var y=Math.floor(a/o),m=r+" FPS "+this.renderMode;this.showPanle&&(m+="
min"+s+" max"+l+" avg"+y,this.divDraw.innerHTML=this.lastNumDraw+"
",this.divCost.innerHTML=''+i+' '+n+""),this.fps.innerHTML=m},t.prototype.updateInfo=function(e){this.arrLog.push(e),this.updateLogLayout()},t.prototype.updateWarn=function(e){this.arrLog.push("[Warning]"+e),this.updateLogLayout()},t.prototype.updateError=function(e){this.arrLog.push("[Error]"+e),this.updateLogLayout()},t.prototype.updateLogLayout=function(){for(this.log.innerHTML=this.arrLog.join("
");document.body.clientHeight")},t}();t.WebFps=r,__reflect(r.prototype,"egret.web.WebFps",["egret.FPSDisplay"]),e.FPSDisplay=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r;!function(r){function i(e){return window.localStorage.getItem(e)}function n(t,r){try{return window.localStorage.setItem(t,r),!0}catch(i){return e.$warn(1047,t,r),!1}}function a(e){window.localStorage.removeItem(e)}function o(){window.localStorage.clear()}t.getItem=i,t.setItem=n,t.removeItem=a,t.clear=o}(r=t.web||(t.web={}))}(t=e.localStorage||(e.localStorage={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(e,t){var i=r.call(this)||this;return i.init(e,t),i.initOrientation(),i}return __extends(i,r),i.prototype.init=function(r,i){console.log("Egret Engine Version:",e.Capabilities.engineVersion);var n=this.readOption(r,i),a=new e.Stage;a.$screen=this,a.$scaleMode=n.scaleMode,a.$orientation=n.orientation,a.$maxTouches=n.maxTouches,a.frameRate=n.frameRate,a.textureScaleFactor=n.textureScaleFactor;var o=new e.sys.RenderBuffer(void 0,void 0,!0),s=o.surface;this.attachCanvas(r,s);var l=new t.WebTouchHandler(a,s),c=new e.sys.Player(o,a,n.entryClassName);e.lifecycle.stage=a,e.lifecycle.addLifecycleListener(t.WebLifeCycleHandler);var h=new t.HTMLInput;(n.showFPS||n.showLog)&&(e.nativeRender||c.displayFPS(n.showFPS,n.showLog,n.logFilter,n.fpsStyles)),this.playerOption=n,this.container=r,this.canvas=s,this.stage=a,this.player=c,this.webTouchHandler=l,this.webInput=h,e.web.$cacheTextAdapter(h,a,r,s),this.updateScreenSize(),this.updateMaxTouches(),c.start()},i.prototype.initOrientation=function(){var t=this;window.addEventListener("orientationchange",function(){window.setTimeout(function(){e.StageOrientationEvent.dispatchStageOrientationEvent(t.stage,e.StageOrientationEvent.ORIENTATION_CHANGE)},350)})},i.prototype.readOption=function(t,r){var i={};i.entryClassName=t.getAttribute("data-entry-class"),i.scaleMode=t.getAttribute("data-scale-mode")||e.StageScaleMode.NO_SCALE,i.frameRate=+t.getAttribute("data-frame-rate")||30,i.contentWidth=+t.getAttribute("data-content-width")||480,i.contentHeight=+t.getAttribute("data-content-height")||800,i.orientation=t.getAttribute("data-orientation")||e.OrientationMode.AUTO,i.maxTouches=+t.getAttribute("data-multi-fingered")||2,i.textureScaleFactor=+t.getAttribute("texture-scale-factor")||1,i.showFPS="true"==t.getAttribute("data-show-fps");for(var n=t.getAttribute("data-show-fps-style")||"",a=n.split(","),o={},s=0;sa||l==e.OrientationMode.PORTRAIT&&a>o);var c=s?o:a,h=s?a:o;e.Capabilities.boundingClientWidth=c,e.Capabilities.boundingClientHeight=h;var u=e.sys.screenAdapter.calculateStageSize(this.stage.$scaleMode,c,h,r.contentWidth,r.contentHeight),d=u.stageWidth,f=u.stageHeight,p=u.displayWidth,v=u.displayHeight;t.style[e.web.getPrefixStyleName("transformOrigin")]="0% 0% 0px",t.width!=d&&(t.width=d),t.height!=f&&(t.height=f);var g=0;s?l==e.OrientationMode.LANDSCAPE?(g=90,t.style.top=n+(o-p)/2+"px",t.style.left=(a+v)/2+"px"):(g=-90,t.style.top=n+(o+p)/2+"px",t.style.left=(a-v)/2+"px"):(t.style.top=n+(o-v)/2+"px",t.style.left=(a-p)/2+"px");var x=p/d,y=v/f,m=x*e.sys.DisplayList.$canvasScaleFactor,b=y*e.sys.DisplayList.$canvasScaleFactor;"canvas"==e.Capabilities.renderMode&&(m=Math.ceil(m),b=Math.ceil(b));var w=e.Matrix.create();w.identity(),w.scale(x/m,y/b),w.rotate(g*Math.PI/180);var T="matrix("+w.a+","+w.b+","+w.c+","+w.d+","+w.tx+","+w.ty+")";e.Matrix.release(w),t.style[e.web.getPrefixStyleName("transform")]=T,e.sys.DisplayList.$setCanvasScale(m,b),this.webTouchHandler.updateScaleMode(x,y,g),this.webInput.$updateSize(),this.player.updateStageSize(d,f),e.nativeRender&&(t.width=d*m,t.height=f*b)}}},i.prototype.setContentSize=function(e,t){var r=this.playerOption;r.contentWidth=e,r.contentHeight=t,this.updateScreenSize()},i.prototype.updateMaxTouches=function(){this.webTouchHandler.$updateMaxTouches()},i}(e.HashObject);t.WebPlayer=r,__reflect(r.prototype,"egret.web.WebPlayer",["egret.sys.Screen"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(t,r){s||(s=e.sys.createCanvas(),l=s.getContext("2d"));var i=t.$getTextureWidth(),n=t.$getTextureHeight();null==r&&(r=e.$TempRectangle,r.x=0,r.y=0,r.width=i,r.height=n),r.x=Math.min(r.x,i-1),r.y=Math.min(r.y,n-1),r.width=Math.min(r.width,i-r.x),r.height=Math.min(r.height,n-r.y);var a=r.width,o=r.height,c=s;if(c.style.width=a+"px",c.style.height=o+"px",s.width=a,s.height=o,"webgl"==e.Capabilities.renderMode){var h=void 0;t.$renderBuffer?h=t:(h=new e.RenderTexture,h.drawToTexture(new e.Bitmap(t)));for(var u=h.$renderBuffer.getPixels(r.x,r.y,a,o),d=new ImageData(a,o),f=0;fn;n++){var a=t.childNodes[n];if(1==a.nodeType)return i(a,null)}return null}function i(e,t){if("parsererror"==e.localName)throw new Error(e.textContent);for(var r=new a(e.localName,t,e.prefix,e.namespaceURI,e.nodeName),n=e.attributes,s=r.attributes,l=n.length,c=0;l>c;c++){var h=n[c],u=h.name;0!=u.indexOf("xmlns:")&&(s[u]=h.value,r["$"+u]=h.value)}var d=e.childNodes;l=d.length;for(var f=r.children,c=0;l>c;c++){var p=d[c],v=p.nodeType,g=null;if(1==v)g=i(p,r);else if(3==v){var x=p.textContent.trim();x&&(g=new o(x,r))}g&&f.push(g)}return r}var n=function(){function e(e,t){this.nodeType=e,this.parent=t}return e}();t.XMLNode=n,__reflect(n.prototype,"egret.web.XMLNode");var a=function(e){function t(t,r,i,n,a){var o=e.call(this,1,r)||this;return o.attributes={},o.children=[],o.localName=t,o.prefix=i,o.namespace=n,o.name=a,o}return __extends(t,e),t}(n);t.XML=a,__reflect(a.prototype,"egret.web.XML");var o=function(e){function t(t,r){var i=e.call(this,3,r)||this;return i.text=t,i}return __extends(t,e),t}(n);t.XMLText=o,__reflect(o.prototype,"egret.web.XMLText");var s=new DOMParser;e.XML={parse:r}}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var r=null!==t&&t.apply(this,arguments)||this;return r.onChange=function(t){var i=new e.OrientationEvent(e.Event.CHANGE);i.beta=t.beta,i.gamma=t.gamma,i.alpha=t.alpha,r.dispatchEvent(i)},r}return __extends(r,t),r.prototype.start=function(){window.addEventListener("deviceorientation",this.onChange)},r.prototype.stop=function(){window.removeEventListener("deviceorientation",this.onChange)},r}(e.EventDispatcher);t.WebDeviceOrientation=r,__reflect(r.prototype,"egret.web.WebDeviceOrientation",["egret.DeviceOrientation"])}(t=e.web||(e.web={}))}(egret||(egret={})),egret.DeviceOrientation=egret.web.WebDeviceOrientation;var egret;!function(e){var t;!function(t){var r=function(){function e(){}return e.call=function(e,t){},e.addCallback=function(e,t){},e}();t.WebExternalInterface=r,__reflect(r.prototype,"egret.web.WebExternalInterface",["egret.ExternalInterface"]);var i=navigator.userAgent.toLowerCase();i.indexOf("egretnative")<0&&(e.ExternalInterface=r)}(t=e.web||(e.web={}))}(egret||(egret={})),function(e){var t;!function(t){function r(t){var r=JSON.parse(t),n=r.functionName,a=i[n];if(a){var o=r.value;a.call(null,o)}else e.$warn(1050,n)}var i={},n=function(){function e(){}return e.call=function(e,t){var r={};r.functionName=e,r.value=t,egret_native.sendInfoToPlugin(JSON.stringify(r))},e.addCallback=function(e,t){i[e]=t},e}();t.NativeExternalInterface=n,__reflect(n.prototype,"egret.web.NativeExternalInterface",["egret.ExternalInterface"]);var a=navigator.userAgent.toLowerCase();a.indexOf("egretnative")>=0&&(e.ExternalInterface=n,egret_native.receivedPluginInfo=r)}(t=e.web||(e.web={}))}(egret||(egret={})),function(e){var t;!function(t){var r={},i=function(){function t(){}return t.call=function(e,t){__global.ExternalInterface.call(e,t)},t.addCallback=function(e,t){r[e]=t},t.invokeCallback=function(t,i){var n=r[t];n?n.call(null,i):e.$warn(1050,t)},t}();t.WebViewExternalInterface=i,__reflect(i.prototype,"egret.web.WebViewExternalInterface",["egret.ExternalInterface"]);var n=navigator.userAgent.toLowerCase();n.indexOf("egretwebview")>=0&&(e.ExternalInterface=i)}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(){var e=r.call(this)||this;return e.loaded=!1,e}return __extends(i,r),Object.defineProperty(i.prototype,"length",{get:function(){if(this.originAudio)return this.originAudio.duration;throw new Error("sound not loaded!")},enumerable:!0,configurable:!0}),i.prototype.load=function(t){function r(){i.$recycle(o.url,s),a(),l.indexOf("firefox")>=0&&(s.pause(),s.muted=!1),c&&document.body.appendChild(s),o.loaded=!0,o.dispatchEventWith(e.Event.COMPLETE)}function n(){a(),o.dispatchEventWith(e.IOErrorEvent.IO_ERROR)}function a(){s.removeEventListener("canplaythrough",r),s.removeEventListener("error",n),c&&document.body.removeChild(s)}var o=this;this.url=t;var s=new Audio(t);s.addEventListener("canplaythrough",r),s.addEventListener("error",n);var l=navigator.userAgent.toLowerCase();l.indexOf("firefox")>=0&&(s.autoplay=!0,s.muted=!0);var c=l.indexOf("edge")>=0||l.indexOf("trident")>=0;c&&document.body.appendChild(s),s.load(),this.originAudio=s,i.clearAudios[this.url]&&delete i.clearAudios[this.url]},i.prototype.play=function(r,n){r=+r||0,n=+n||0;var a=i.$pop(this.url);null==a&&(a=this.originAudio.cloneNode()),a.autoplay=!0;var o=new t.HtmlSoundChannel(a);return o.$url=this.url,o.$loops=n,o.$startTime=r,o.$play(),e.sys.$pushSoundChannel(o),o},i.prototype.close=function(){this.loaded&&this.originAudio&&(this.originAudio.src=""),this.originAudio&&(this.originAudio=null),i.$clear(this.url),this.loaded=!1},i.$clear=function(e){i.clearAudios[e]=!0;var t=i.audios[e];t&&(t.length=0)},i.$pop=function(e){var t=i.audios[e];return t&&t.length>0?t.pop():null},i.$recycle=function(e,t){if(!i.clearAudios[e]){var r=i.audios[e];null==i.audios[e]&&(r=i.audios[e]=[]),r.push(t)}},i.MUSIC="music",i.EFFECT="effect",i.audios={},i.clearAudios={},i}(e.EventDispatcher);t.HtmlSound=r,__reflect(r.prototype,"egret.web.HtmlSound",["egret.Sound"])}(t=e.web||(e.web={}))}(egret||(egret={})); -var egret;!function(e){var t;!function(e){}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(){this.drawData=[],this.drawDataLen=0}return e.prototype.pushDrawRect=function(){if(0==this.drawDataLen||1!=this.drawData[this.drawDataLen-1].type){var e=this.drawData[this.drawDataLen]||{};e.type=1,e.count=0,this.drawData[this.drawDataLen]=e,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=2},e.prototype.pushDrawTexture=function(e,t,r,i,n){if(void 0===t&&(t=2),r){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.filter=r,a.count=t,a.textureWidth=i,a.textureHeight=n,this.drawData[this.drawDataLen]=a,this.drawDataLen++}else{if(0==this.drawDataLen||0!=this.drawData[this.drawDataLen-1].type||e!=this.drawData[this.drawDataLen-1].texture||this.drawData[this.drawDataLen-1].filter){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.count=0,this.drawData[this.drawDataLen]=a,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=t}},e.prototype.pushChangeSmoothing=function(e,t){e.smoothing=t;var r=this.drawData[this.drawDataLen]||{};r.type=10,r.texture=e,r.smoothing=t,this.drawData[this.drawDataLen]=r,this.drawDataLen++},e.prototype.pushPushMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=2,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushPopMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=3,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushSetBlend=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];if(n){if((0==n.type||1==n.type)&&(r=!0),!r&&4==n.type){this.drawData.splice(i,1),this.drawDataLen--;continue}if(4==n.type){if(n.value==e)return;break}}}var a=this.drawData[this.drawDataLen]||{};a.type=4,a.value=e,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushResize=function(e,t,r){var i=this.drawData[this.drawDataLen]||{};i.type=5,i.buffer=e,i.width=t,i.height=r,this.drawData[this.drawDataLen]=i,this.drawDataLen++},e.prototype.pushClearColor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=6,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.pushActivateBuffer=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];!n||(4!=n.type&&7!=n.type&&(r=!0),r||7!=n.type)||(this.drawData.splice(i,1),this.drawDataLen--)}var a=this.drawData[this.drawDataLen]||{};a.type=7,a.buffer=e,a.width=e.rootRenderTarget.width,a.height=e.rootRenderTarget.height,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushEnableScissor=function(e,t,r,i){var n=this.drawData[this.drawDataLen]||{};n.type=8,n.x=e,n.y=t,n.width=r,n.height=i,this.drawData[this.drawDataLen]=n,this.drawDataLen++},e.prototype.pushDisableScissor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=9,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.clear=function(){for(var e=0;er;r+=6,i+=4)this.indices[r+0]=i+0,this.indices[r+1]=i+1,this.indices[r+2]=i+2,this.indices[r+3]=i+0,this.indices[r+4]=i+2,this.indices[r+5]=i+3}return t.prototype.reachMaxSize=function(e,t){return void 0===e&&(e=4),void 0===t&&(t=6),this.vertexIndex>this.maxVertexCount-e||this.indexIndex>this.maxIndicesCount-t},t.prototype.getVertices=function(){var e=this.vertices.subarray(0,this.vertexIndex*this.vertSize);return e},t.prototype.getIndices=function(){return this.indices},t.prototype.getMeshIndices=function(){return this.indicesForMesh},t.prototype.changeToMeshIndices=function(){if(!this.hasMesh){for(var e=0,t=this.indexIndex;t>e;++e)this.indicesForMesh[e]=this.indices[e];this.hasMesh=!0}},t.prototype.isMesh=function(){return this.hasMesh},t.prototype.cacheArrays=function(t,r,i,n,a,o,s,l,c,h,u,d,f,p,v){var g=t.globalAlpha;g=Math.min(g,1);var x=t.globalTintColor||16777215,y=t.currentTexture;g=1>g&&y&&y[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]?e.WebGLUtils.premultiplyTint(x,g):x+(255*g<<24);var m=t.globalMatrix,b=m.a,w=m.b,T=m.c,E=m.d,_=m.tx,C=m.ty,S=t.$offsetX,R=t.$offsetY;if((0!=S||0!=R)&&(_=S*b+R*T+_,C=S*w+R*E+C),!f){(0!=o||0!=s)&&(_=o*b+s*T+_,C=o*w+s*E+C);var L=l/n;1!=L&&(b=L*b,w=L*w);var D=c/a;1!=D&&(T=D*T,E=D*E)}if(f){var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize,M=0,B=0,O=0,P=0,W=0,k=0,G=0;for(M=0,O=d.length;O>M;M+=2)B=$+5*M/2,k=f[M],G=f[M+1],P=d[M],W=d[M+1],A[B+0]=b*k+T*G+_,A[B+1]=w*k+E*G+C,v?(A[B+2]=(r+(1-W)*a)/h,A[B+3]=(i+P*n)/u):(A[B+2]=(r+P*n)/h,A[B+3]=(i+W*a)/u),I[B+4]=g;if(this.hasMesh)for(var H=0,F=p.length;F>H;++H)this.indicesForMesh[this.indexIndex+H]=p[H]+this.vertexIndex;this.vertexIndex+=d.length/2,this.indexIndex+=p.length}else{var U=h,N=u,X=n,z=a;r/=U,i/=N;var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize;if(v){var Y=n;n=a/U,a=Y/N,A[$++]=_,A[$++]=C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=i,I[$++]=g}else n/=U,a/=N,A[$++]=_,A[$++]=C,A[$++]=r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=a+i,I[$++]=g;if(this.hasMesh){var V=this.indicesForMesh;V[this.indexIndex+0]=0+this.vertexIndex,V[this.indexIndex+1]=1+this.vertexIndex,V[this.indexIndex+2]=2+this.vertexIndex,V[this.indexIndex+3]=0+this.vertexIndex,V[this.indexIndex+4]=2+this.vertexIndex,V[this.indexIndex+5]=3+this.vertexIndex}this.vertexIndex+=4,this.indexIndex+=6}},t.prototype.clear=function(){this.hasMesh=!1,this.vertexIndex=0,this.indexIndex=0},t}();t.WebGLVertexArrayObject=r,__reflect(r.prototype,"egret.web.WebGLVertexArrayObject")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(e,t,i){var n=r.call(this)||this;return n.clearColor=[0,0,0,0],n.useFrameBuffer=!0,n.gl=e,n._resize(t,i),n}return __extends(i,r),i.prototype._resize=function(e,t){e=e||1,t=t||1,1>e&&(e=1),1>t&&(t=1),this.width=e,this.height=t},i.prototype.resize=function(e,t){this._resize(e,t);var r=this.gl;this.frameBuffer&&(r.bindTexture(r.TEXTURE_2D,this.texture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.width,this.height,0,r.RGBA,r.UNSIGNED_BYTE,null)),this.stencilBuffer&&(r.deleteRenderbuffer(this.stencilBuffer),this.stencilBuffer=null)},i.prototype.activate=function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.getFrameBuffer())},i.prototype.getFrameBuffer=function(){return this.useFrameBuffer?this.frameBuffer:null},i.prototype.initFrameBuffer=function(){if(!this.frameBuffer){var e=this.gl;this.texture=this.createTexture(),this.frameBuffer=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.texture,0)}},i.prototype.createTexture=function(){var r=t.WebGLRenderContext.getInstance(0,0);return e.sys._createTexture(r,this.width,this.height,null)},i.prototype.clear=function(e){var t=this.gl;e&&this.activate(),t.colorMask(!0,!0,!0,!0),t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(t.COLOR_BUFFER_BIT)},i.prototype.enabledStencil=function(){if(this.frameBuffer&&!this.stencilBuffer){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),this.stencilBuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,this.width,this.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,this.stencilBuffer)}},i.prototype.dispose=function(){e.WebGLUtils.deleteWebGLTexture(this.texture)},i}(e.HashObject);t.WebGLRenderTarget=r,__reflect(r.prototype,"egret.web.WebGLRenderTarget")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r={},i=function(){function i(r,i){if(this._defaultEmptyTexture=null,this.glID=null,this.projectionX=0/0,this.projectionY=0/0,this.contextLost=!1,this._supportedCompressedTextureInfo=[],this.$scissorState=!1,this.vertSize=5,this.surface=e.sys.mainCanvas(r,i),!e.nativeRender){this.initWebGL(),this.$bufferStack=[];var n=this.context;this.vertexBuffer=n.createBuffer(),this.indexBuffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.vertexBuffer),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this.indexBuffer),this.drawCmdManager=new t.WebGLDrawCmdManager,this.vao=new t.WebGLVertexArrayObject,this.setGlobalCompositeOperation("source-over")}}return i.getInstance=function(e,t){return this.instance?this.instance:(this.instance=new i(e,t),this.instance)},i.prototype.pushBuffer=function(e){this.$bufferStack.push(e),e!=this.currentBuffer&&(this.currentBuffer,this.drawCmdManager.pushActivateBuffer(e)),this.currentBuffer=e},i.prototype.popBuffer=function(){if(!(this.$bufferStack.length<=1)){var e=this.$bufferStack.pop(),t=this.$bufferStack[this.$bufferStack.length-1];e!=t&&this.drawCmdManager.pushActivateBuffer(t),this.currentBuffer=t}},i.prototype.activateBuffer=function(e,t,r){e.rootRenderTarget.activate(),this.bindIndices||this.uploadIndicesArray(this.vao.getIndices()),e.restoreStencil(),e.restoreScissor(),this.onResize(t,r)},i.prototype.uploadVerticesArray=function(e){var t=this.context;t.bufferData(t.ARRAY_BUFFER,e,t.STREAM_DRAW)},i.prototype.uploadIndicesArray=function(e){var t=this.context;t.bufferData(t.ELEMENT_ARRAY_BUFFER,e,t.STATIC_DRAW),this.bindIndices=!0},i.prototype.destroy=function(){this.surface.width=this.surface.height=0},i.prototype.onResize=function(e,t){e=e||this.surface.width,t=t||this.surface.height,this.projectionX=e/2,this.projectionY=-t/2,this.context&&this.context.viewport(0,0,e,t)},i.prototype.resize=function(t,r,i){e.sys.resizeContext(this,t,r,i)},i.prototype._buildSupportedCompressedTextureInfo=function(e){for(var t=[],r=0,i=e;rr;++r)for(var n=e[r],a=n.supportedFormats,o=0,s=a.length;s>o;++o)if(a[o][1]===t)return!0;return!1},i.prototype.$debugLogCompressedTextureNotSupported=function(t,i){if(!r[i]){r[i]=!0,e.log("internalFormat = "+i+":0x"+i.toString(16)+", the current hardware does not support the corresponding compression format.");for(var n=0,a=t.length;a>n;++n){var o=t[n];if(o.supportedFormats.length>0){e.log("support = "+o.extensionName);for(var s=0,l=o.supportedFormats.length;l>s;++s){var c=o.supportedFormats[s];e.log(c[0]+" : "+c[1]+" : 0x"+c[1].toString(16))}}}}},i.prototype.createCompressedTexture=function(t,r,i,n,a){var o=this.checkCompressedTextureInternalFormat(this._supportedCompressedTextureInfo,a);if(!o)return this.$debugLogCompressedTextureNotSupported(this._supportedCompressedTextureInfo,a),this.defaultEmptyTexture;var s=this.context,l=s.createTexture();return l?(l[e.glContext]=s,l[e.is_compressed_texture]=!0,s.bindTexture(s.TEXTURE_2D,l),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),l[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]=!0,s.compressedTexImage2D(s.TEXTURE_2D,n,a,r,i,0,t),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.bindTexture(s.TEXTURE_2D,null),l):void(this.contextLost=!0)},i.prototype.updateTexture=function(e,t){var r=this.context;r.bindTexture(r.TEXTURE_2D,e),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t)},Object.defineProperty(i.prototype,"defaultEmptyTexture",{get:function(){if(!this._defaultEmptyTexture){var t=16,r=e.sys.createCanvas(t,t),i=e.sys.getContext2d(r);i.fillStyle="white",i.fillRect(0,0,t,t),this._defaultEmptyTexture=this.createTexture(r),this._defaultEmptyTexture[e.engine_default_empty_texture]=!0}return this._defaultEmptyTexture},enumerable:!0,configurable:!0}),i.prototype.getWebGLTexture=function(t){if(!t.webGLTexture){if("image"!=t.format||t.hasCompressed2d()){if(t.hasCompressed2d()){var r=t.getCompressed2dTextureData();t.webGLTexture=this.createCompressedTexture(r.byteArray,r.width,r.height,r.level,r.glInternalFormat);var i=t.etcAlphaMask;if(i){var n=this.getWebGLTexture(i);n&&(t.webGLTexture[e.etc_alpha_mask]=n)}}}else t.webGLTexture=this.createTexture(t.source);t.$deleteSource&&t.webGLTexture&&(t.source&&(t.source.src="",t.source=null),t.clearCompressedTextureData()),t.webGLTexture&&(t.webGLTexture.smoothing=!0)}return t.webGLTexture},i.prototype.clearRect=function(e,t,r,i){if(0!=e||0!=t||r!=this.surface.width||i!=this.surface.height){var n=this.currentBuffer;if(n.$hasScissor)this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over");else{var a=n.globalMatrix;0==a.b&&0==a.c?(e=e*a.a+a.tx,t=t*a.d+a.ty,r*=a.a,i*=a.d,this.enableScissor(e,-t-i+n.height,r,i),this.clear(),this.disableScissor()):(this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over"))}}else this.clear()},i.prototype.setGlobalCompositeOperation=function(e){this.drawCmdManager.pushSetBlend(e)},i.prototype.drawImage=function(e,t,r,i,n,a,o,s,l,c,h,u,d){var f=this.currentBuffer;if(!this.contextLost&&e&&f){var p,v,g;if(e.texture||e.source&&e.source.texture)p=e.texture||e.source.texture,f.saveTransform(),v=f.$offsetX,g=f.$offsetY,f.useOffset(),f.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;p=this.getWebGLTexture(e)}p&&(this.drawTexture(p,t,r,i,n,a,o,s,l,c,h,void 0,void 0,void 0,void 0,u,d),e.source&&e.source.texture&&(f.$offsetX=v,f.$offsetY=g,f.restoreTransform()))}},i.prototype.drawMesh=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){var y,m,b;if(e.texture||e.source&&e.source.texture)y=e.texture||e.source.texture,x.saveTransform(),m=x.$offsetX,b=x.$offsetY,x.useOffset(),x.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;y=this.getWebGLTexture(e)}y&&(this.drawTexture(y,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g),(e.texture||e.source&&e.source.texture)&&(x.$offsetX=m,x.$offsetY=b,x.restoreTransform()))}},i.prototype.drawTexture=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){d&&f?this.vao.reachMaxSize(d.length/2,f.length)&&this.$drawWebGL():this.vao.reachMaxSize()&&this.$drawWebGL(),void 0!=g&&e.smoothing!=g&&this.drawCmdManager.pushChangeSmoothing(e,g),u&&this.vao.changeToMeshIndices();var y=f?f.length/3:2;this.drawCmdManager.pushDrawTexture(e,y,this.$filter,c,h),x.currentTexture=e,this.vao.cacheArrays(x,t,r,i,n,a,o,s,l,c,h,u,d,f,v)}},i.prototype.drawRect=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushDrawRect(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.pushMask=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(n.$stencilList.push({x:e,y:t,width:r,height:i}),this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPushMask(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.popMask=function(){var e=this.currentBuffer;if(!this.contextLost&&e){var t=e.$stencilList.pop();this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPopMask(),e.currentTexture=null,this.vao.cacheArrays(e,0,0,t.width,t.height,t.x,t.y,t.width,t.height,t.width,t.height)}},i.prototype.clear=function(){this.drawCmdManager.pushClearColor()},i.prototype.enableScissor=function(e,t,r,i){var n=this.currentBuffer;this.drawCmdManager.pushEnableScissor(e,t,r,i),n.$hasScissor=!0},i.prototype.disableScissor=function(){var e=this.currentBuffer;this.drawCmdManager.pushDisableScissor(),e.$hasScissor=!1},i.prototype.$drawWebGL=function(){if(0!=this.drawCmdManager.drawDataLen&&!this.contextLost){this.uploadVerticesArray(this.vao.getVertices()),this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getMeshIndices());for(var e=this.drawCmdManager.drawDataLen,t=0,r=0;e>r;r++){var i=this.drawCmdManager.drawData[r];t=this.drawData(i,t),7==i.type&&(this.activatedBuffer=i.buffer),(0==i.type||1==i.type||2==i.type||3==i.type)&&this.activatedBuffer&&this.activatedBuffer.$computeDrawCall&&this.activatedBuffer.$drawCalls++}this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getIndices()),this.drawCmdManager.clear(),this.vao.clear()}},i.prototype.drawData=function(r,i){if(r){var n,a=this.context,o=r.filter;switch(r.type){case 0:o?"custom"===o.type?n=t.EgretWebGLProgram.getProgram(a,o.$vertexSrc,o.$fragmentSrc,o.$shaderKey):"colorTransform"===o.type?r.texture[e.etc_alpha_mask]?(a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask]),n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag_etc_alphamask_frag,"colorTransform_frag_etc_alphamask_frag")):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag,"colorTransform"):"blurX"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"blurY"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"glow"===o.type&&(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.glow_frag,"glow")):r.texture[e.etc_alpha_mask]?(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_etc_alphamask_frag,e.etc_alpha_mask),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask])):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_frag,"texture"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawTextureElements(r,i);break;case 1:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawRectElements(r,i);break;case 2:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPushMaskElements(r,i);break;case 3:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPopMaskElements(r,i);break;case 4:this.setBlendMode(r.value);break;case 5:r.buffer.rootRenderTarget.resize(r.width,r.height),this.onResize(r.width,r.height);break;case 6:if(this.activatedBuffer){var s=this.activatedBuffer.rootRenderTarget;(0!=s.width||0!=s.height)&&s.clear(!0)}break;case 7:this.activateBuffer(r.buffer,r.width,r.height);break;case 8:var l=this.activatedBuffer;l&&(l.rootRenderTarget&&l.rootRenderTarget.enabledStencil(),l.enableScissor(r.x,r.y,r.width,r.height));break;case 9:l=this.activatedBuffer,l&&l.disableScissor();break;case 10:a.bindTexture(a.TEXTURE_2D,r.texture),r.smoothing?(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR)):(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST))}return i}},i.prototype.activeProgram=function(e,t){if(t!=this.currentProgram){e.useProgram(t.id);var r=t.attributes;for(var i in r)"aVertexPosition"===i?(e.vertexAttribPointer(r.aVertexPosition.location,2,e.FLOAT,!1,20,0),e.enableVertexAttribArray(r.aVertexPosition.location)):"aTextureCoord"===i?(e.vertexAttribPointer(r.aTextureCoord.location,2,e.FLOAT,!1,20,8),e.enableVertexAttribArray(r.aTextureCoord.location)):"aColor"===i&&(e.vertexAttribPointer(r.aColor.location,4,e.UNSIGNED_BYTE,!0,20,16),e.enableVertexAttribArray(r.aColor.location));this.currentProgram=t}},i.prototype.syncUniforms=function(e,t,r,i){var n=e.uniforms;t&&"custom"===t.type;for(var a in n)if("projectionVector"===a)n[a].setValue({x:this.projectionX,y:this.projectionY});else if("uTextureSize"===a)n[a].setValue({x:r,y:i});else if("uSampler"===a)n[a].setValue(0);else if("uSamplerAlphaMask"===a)n[a].setValue(1);else{var o=t.$uniforms[a];void 0!==o&&n[a].setValue(o)}},i.prototype.drawTextureElements=function(t,r){return e.sys.drawTextureElements(this,t,r)},i.prototype.drawRectElements=function(e,t){var r=this.context,i=3*e.count;return r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),i},i.prototype.drawPushMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n){n.rootRenderTarget&&n.rootRenderTarget.enabledStencil(),0==n.stencilHandleCount&&(n.enableStencil(),r.clear(r.STENCIL_BUFFER_BIT));var a=n.stencilHandleCount;n.stencilHandleCount++,r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a,255),r.stencilOp(r.KEEP,r.KEEP,r.INCR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a+1,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.drawPopMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n)if(n.stencilHandleCount--,0==n.stencilHandleCount)n.disableStencil();else{var a=n.stencilHandleCount;r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a+1,255),r.stencilOp(r.KEEP,r.KEEP,r.DECR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.setBlendMode=function(e){var t=this.context,r=i.blendModesForGL[e];r&&t.blendFunc(r[0],r[1])},i.prototype.drawTargetWidthFilters=function(e,r){var i,n=r,a=e.length;if(a>1)for(var o=0;a-1>o;o++){var s=e[o],l=r.rootRenderTarget.width,c=r.rootRenderTarget.height;i=t.WebGLRenderBuffer.create(l,c),i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,this.drawToRenderTarget(s,r,i),r!=n&&t.WebGLRenderBuffer.release(r),r=i}var h=e[a-1];this.drawToRenderTarget(h,r,this.currentBuffer),r!=n&&t.WebGLRenderBuffer.release(r)},i.prototype.drawToRenderTarget=function(e,r,i){if(!this.contextLost){this.vao.reachMaxSize()&&this.$drawWebGL(),this.pushBuffer(i);var n,a=r,o=r.rootRenderTarget.width,s=r.rootRenderTarget.height;if("blur"==e.type){var l=e.blurXFilter,c=e.blurYFilter;0!=l.blurX&&0!=c.blurY?(n=t.WebGLRenderBuffer.create(o,s),n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,this.drawToRenderTarget(e.blurXFilter,r,n),r!=a&&t.WebGLRenderBuffer.release(r),r=n,e=c):e=0===l.blurX?c:l}i.saveTransform(),i.transform(1,0,0,-1,0,s),i.currentTexture=r.rootRenderTarget.texture,this.vao.cacheArrays(i,0,0,o,s,0,0,o,s,o,s),i.restoreTransform(),this.drawCmdManager.pushDrawTexture(r.rootRenderTarget.texture,2,e,o,s),r!=a&&t.WebGLRenderBuffer.release(r),this.popBuffer()}},i.initBlendMode=function(){i.blendModesForGL={},i.blendModesForGL["source-over"]=[1,771],i.blendModesForGL.lighter=[1,1],i.blendModesForGL["lighter-in"]=[770,771],i.blendModesForGL["destination-out"]=[0,771],i.blendModesForGL["destination-in"]=[0,770]},i.glContextId=0,i.blendModesForGL=null,i}();t.WebGLRenderContext=i,__reflect(i.prototype,"egret.web.WebGLRenderContext",["egret.sys.RenderContext"]),i.initBlendMode()}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function n(i,n,a){var o=r.call(this)||this;if(o.currentTexture=null,o.globalAlpha=1,o.globalTintColor=16777215,o.stencilState=!1,o.$stencilList=[],o.stencilHandleCount=0,o.$scissorState=!1,o.scissorRect=new e.Rectangle,o.$hasScissor=!1,o.$drawCalls=0,o.$computeDrawCall=!1,o.globalMatrix=new e.Matrix,o.savedGlobalMatrix=new e.Matrix,o.$offsetX=0,o.$offsetY=0,o.context=t.WebGLRenderContext.getInstance(i,n),e.nativeRender)return a?o.surface=o.context.surface:o.surface=new egret_native.NativeRenderSurface(o,i,n,a),o.rootRenderTarget=null,o;if(o.rootRenderTarget=new t.WebGLRenderTarget(o.context.context,3,3),i&&n&&o.resize(i,n),o.root=a,o.root)o.context.pushBuffer(o),o.surface=o.context.surface,o.$computeDrawCall=!0;else{var s=o.context.activatedBuffer;s&&s.rootRenderTarget.activate(),o.rootRenderTarget.initFrameBuffer(),o.surface=o.rootRenderTarget}return o}return __extends(n,r),n.prototype.enableStencil=function(){this.stencilState||(this.context.enableStencilTest(),this.stencilState=!0)},n.prototype.disableStencil=function(){this.stencilState&&(this.context.disableStencilTest(),this.stencilState=!1)},n.prototype.restoreStencil=function(){this.stencilState?this.context.enableStencilTest():this.context.disableStencilTest()},n.prototype.enableScissor=function(e,t,r,i){this.$scissorState||(this.$scissorState=!0,this.scissorRect.setTo(e,t,r,i),this.context.enableScissorTest(this.scissorRect))},n.prototype.disableScissor=function(){this.$scissorState&&(this.$scissorState=!1,this.scissorRect.setEmpty(),this.context.disableScissorTest())},n.prototype.restoreScissor=function(){this.$scissorState?this.context.enableScissorTest(this.scissorRect):this.context.disableScissorTest()},Object.defineProperty(n.prototype,"width",{get:function(){return e.nativeRender?this.surface.width:this.rootRenderTarget.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return e.nativeRender?this.surface.height:this.rootRenderTarget.height},enumerable:!0,configurable:!0}),n.prototype.resize=function(t,r,i){return t=t||1,r=r||1,e.nativeRender?void this.surface.resize(t,r):(this.context.pushBuffer(this),(t!=this.rootRenderTarget.width||r!=this.rootRenderTarget.height)&&(this.context.drawCmdManager.pushResize(this,t,r),this.rootRenderTarget.width=t,this.rootRenderTarget.height=r),this.root&&this.context.resize(t,r,i),this.context.clear(),void this.context.popBuffer())},n.prototype.getPixels=function(t,r,i,n){void 0===i&&(i=1),void 0===n&&(n=1);var a=new Uint8Array(4*i*n);if(e.nativeRender)egret_native.activateBuffer(this),egret_native.nrGetPixels(t,r,i,n,a),egret_native.activateBuffer(null);else{var o=this.rootRenderTarget.useFrameBuffer;this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.getPixels(t,r,i,n,a),this.rootRenderTarget.useFrameBuffer=o,this.rootRenderTarget.activate()}for(var s=new Uint8Array(4*i*n),l=0;n>l;l++)for(var c=0;i>c;c++){var h=4*(i*(n-l-1)+c),u=4*(i*l+c),d=a[u+3];s[h]=Math.round(a[u]/d*255),s[h+1]=Math.round(a[u+1]/d*255),s[h+2]=Math.round(a[u+2]/d*255),s[h+3]=a[u+3]}return s},n.prototype.toDataURL=function(e,t){return this.context.surface.toDataURL(e,t)},n.prototype.destroy=function(){this.context.destroy()},n.prototype.onRenderFinish=function(){this.$drawCalls=0},n.prototype.drawFrameBufferToSurface=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.rootRenderTarget,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.drawSurfaceToFrameBuffer=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.context.surface,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.clear=function(){this.context.pushBuffer(this),this.context.clear(),this.context.popBuffer()},n.prototype.setTransform=function(e,t,r,i,n,a){var o=this.globalMatrix;o.a=e,o.b=t,o.c=r,o.d=i,o.tx=n,o.ty=a},n.prototype.transform=function(e,t,r,i,n,a){var o=this.globalMatrix,s=o.a,l=o.b,c=o.c,h=o.d;(1!=e||0!=t||0!=r||1!=i)&&(o.a=e*s+t*c,o.b=e*l+t*h,o.c=r*s+i*c,o.d=r*l+i*h),o.tx=n*s+a*c+o.tx,o.ty=n*l+a*h+o.ty},n.prototype.useOffset=function(){var e=this;(0!=e.$offsetX||0!=e.$offsetY)&&(e.globalMatrix.append(1,0,0,1,e.$offsetX,e.$offsetY),e.$offsetX=e.$offsetY=0)},n.prototype.saveTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t.tx=e.tx,t.ty=e.ty},n.prototype.restoreTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e.tx=t.tx,e.ty=t.ty},n.create=function(e,t){var r=i.pop(); +var egret;!function(e){var t;!function(e){}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(){this.drawData=[],this.drawDataLen=0}return e.prototype.pushDrawRect=function(){if(0==this.drawDataLen||1!=this.drawData[this.drawDataLen-1].type){var e=this.drawData[this.drawDataLen]||{};e.type=1,e.count=0,this.drawData[this.drawDataLen]=e,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=2},e.prototype.pushDrawTexture=function(e,t,r,i,n){if(void 0===t&&(t=2),r){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.filter=r,a.count=t,a.textureWidth=i,a.textureHeight=n,this.drawData[this.drawDataLen]=a,this.drawDataLen++}else{if(0==this.drawDataLen||0!=this.drawData[this.drawDataLen-1].type||e!=this.drawData[this.drawDataLen-1].texture||this.drawData[this.drawDataLen-1].filter){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.count=0,this.drawData[this.drawDataLen]=a,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=t}},e.prototype.pushChangeSmoothing=function(e,t){e.smoothing=t;var r=this.drawData[this.drawDataLen]||{};r.type=10,r.texture=e,r.smoothing=t,this.drawData[this.drawDataLen]=r,this.drawDataLen++},e.prototype.pushPushMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=2,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushPopMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=3,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushSetBlend=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];if(n){if((0==n.type||1==n.type)&&(r=!0),!r&&4==n.type){this.drawData.splice(i,1),this.drawDataLen--;continue}if(4==n.type){if(n.value==e)return;break}}}var a=this.drawData[this.drawDataLen]||{};a.type=4,a.value=e,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushResize=function(e,t,r){var i=this.drawData[this.drawDataLen]||{};i.type=5,i.buffer=e,i.width=t,i.height=r,this.drawData[this.drawDataLen]=i,this.drawDataLen++},e.prototype.pushClearColor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=6,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.pushActivateBuffer=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];!n||(4!=n.type&&7!=n.type&&(r=!0),r||7!=n.type)||(this.drawData.splice(i,1),this.drawDataLen--)}var a=this.drawData[this.drawDataLen]||{};a.type=7,a.buffer=e,a.width=e.rootRenderTarget.width,a.height=e.rootRenderTarget.height,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushEnableScissor=function(e,t,r,i){var n=this.drawData[this.drawDataLen]||{};n.type=8,n.x=e,n.y=t,n.width=r,n.height=i,this.drawData[this.drawDataLen]=n,this.drawDataLen++},e.prototype.pushDisableScissor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=9,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.clear=function(){for(var e=0;er;r+=6,i+=4)this.indices[r+0]=i+0,this.indices[r+1]=i+1,this.indices[r+2]=i+2,this.indices[r+3]=i+0,this.indices[r+4]=i+2,this.indices[r+5]=i+3}return t.prototype.reachMaxSize=function(e,t){return void 0===e&&(e=4),void 0===t&&(t=6),this.vertexIndex>this.maxVertexCount-e||this.indexIndex>this.maxIndicesCount-t},t.prototype.getVertices=function(){var e=this.vertices.subarray(0,this.vertexIndex*this.vertSize);return e},t.prototype.getIndices=function(){return this.indices},t.prototype.getMeshIndices=function(){return this.indicesForMesh},t.prototype.changeToMeshIndices=function(){if(!this.hasMesh){for(var e=0,t=this.indexIndex;t>e;++e)this.indicesForMesh[e]=this.indices[e];this.hasMesh=!0}},t.prototype.isMesh=function(){return this.hasMesh},t.prototype.cacheArrays=function(t,r,i,n,a,o,s,l,c,h,u,d,f,p,v){var g=t.globalAlpha;g=Math.min(g,1);var x=t.globalTintColor||16777215,y=t.currentTexture;g=1>g&&y&&y[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]?e.WebGLUtils.premultiplyTint(x,g):x+(255*g<<24);var m=t.globalMatrix,b=m.a,w=m.b,T=m.c,E=m.d,_=m.tx,C=m.ty,S=t.$offsetX,R=t.$offsetY;if((0!=S||0!=R)&&(_=S*b+R*T+_,C=S*w+R*E+C),!f){(0!=o||0!=s)&&(_=o*b+s*T+_,C=o*w+s*E+C);var L=l/n;1!=L&&(b=L*b,w=L*w);var D=c/a;1!=D&&(T=D*T,E=D*E)}if(f){var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize,M=0,B=0,O=0,P=0,W=0,k=0,G=0;for(M=0,O=d.length;O>M;M+=2)B=$+5*M/2,k=f[M],G=f[M+1],P=d[M],W=d[M+1],A[B+0]=b*k+T*G+_,A[B+1]=w*k+E*G+C,v?(A[B+2]=(r+(1-W)*a)/h,A[B+3]=(i+P*n)/u):(A[B+2]=(r+P*n)/h,A[B+3]=(i+W*a)/u),I[B+4]=g;if(this.hasMesh)for(var H=0,F=p.length;F>H;++H)this.indicesForMesh[this.indexIndex+H]=p[H]+this.vertexIndex;this.vertexIndex+=d.length/2,this.indexIndex+=p.length}else{var U=h,N=u,X=n,z=a;r/=U,i/=N;var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize;if(v){var Y=n;n=a/U,a=Y/N,A[$++]=_,A[$++]=C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=i,I[$++]=g}else n/=U,a/=N,A[$++]=_,A[$++]=C,A[$++]=r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=a+i,I[$++]=g;if(this.hasMesh){var V=this.indicesForMesh;V[this.indexIndex+0]=0+this.vertexIndex,V[this.indexIndex+1]=1+this.vertexIndex,V[this.indexIndex+2]=2+this.vertexIndex,V[this.indexIndex+3]=0+this.vertexIndex,V[this.indexIndex+4]=2+this.vertexIndex,V[this.indexIndex+5]=3+this.vertexIndex}this.vertexIndex+=4,this.indexIndex+=6}},t.prototype.clear=function(){this.hasMesh=!1,this.vertexIndex=0,this.indexIndex=0},t}();t.WebGLVertexArrayObject=r,__reflect(r.prototype,"egret.web.WebGLVertexArrayObject")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(e,t,i){var n=r.call(this)||this;return n.clearColor=[0,0,0,0],n.useFrameBuffer=!0,n.gl=e,n._resize(t,i),n}return __extends(i,r),i.prototype._resize=function(e,t){e=e||1,t=t||1,1>e&&(e=1),1>t&&(t=1),this.width=e,this.height=t},i.prototype.resize=function(e,t){this._resize(e,t);var r=this.gl;this.frameBuffer&&(r.bindTexture(r.TEXTURE_2D,this.texture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.width,this.height,0,r.RGBA,r.UNSIGNED_BYTE,null)),this.stencilBuffer&&(r.deleteRenderbuffer(this.stencilBuffer),this.stencilBuffer=null)},i.prototype.activate=function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.getFrameBuffer())},i.prototype.getFrameBuffer=function(){return this.useFrameBuffer?this.frameBuffer:null},i.prototype.initFrameBuffer=function(){if(!this.frameBuffer){var e=this.gl;this.texture=this.createTexture(),this.frameBuffer=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.texture,0)}},i.prototype.createTexture=function(){var r=t.WebGLRenderContext.getInstance(0,0);return e.sys._createTexture(r,this.width,this.height,null)},i.prototype.clear=function(e){var t=this.gl;e&&this.activate(),t.colorMask(!0,!0,!0,!0),t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(t.COLOR_BUFFER_BIT)},i.prototype.enabledStencil=function(){if(this.frameBuffer&&!this.stencilBuffer){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),this.stencilBuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,this.width,this.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,this.stencilBuffer)}},i.prototype.dispose=function(){e.WebGLUtils.deleteWebGLTexture(this.texture)},i}(e.HashObject);t.WebGLRenderTarget=r,__reflect(r.prototype,"egret.web.WebGLRenderTarget")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r={},i=function(){function i(r,i){if(this._defaultEmptyTexture=null,this.glID=null,this.projectionX=0/0,this.projectionY=0/0,this.contextLost=!1,this._supportedCompressedTextureInfo=[],this.$scissorState=!1,this.vertSize=5,this.surface=e.sys.mainCanvas(r,i),!e.nativeRender){this.initWebGL(),this.$bufferStack=[];var n=this.context;this.vertexBuffer=n.createBuffer(),this.indexBuffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.vertexBuffer),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this.indexBuffer),this.drawCmdManager=new t.WebGLDrawCmdManager,this.vao=new t.WebGLVertexArrayObject,this.setGlobalCompositeOperation("source-over")}}return i.getInstance=function(e,t){return this.instance?this.instance:(this.instance=new i(e,t),this.instance)},i.prototype.pushBuffer=function(e){this.$bufferStack.push(e),e!=this.currentBuffer&&(this.currentBuffer,this.drawCmdManager.pushActivateBuffer(e)),this.currentBuffer=e},i.prototype.popBuffer=function(){if(!(this.$bufferStack.length<=1)){var e=this.$bufferStack.pop(),t=this.$bufferStack[this.$bufferStack.length-1];e!=t&&this.drawCmdManager.pushActivateBuffer(t),this.currentBuffer=t}},i.prototype.activateBuffer=function(e,t,r){e.rootRenderTarget.activate(),this.bindIndices||this.uploadIndicesArray(this.vao.getIndices()),e.restoreStencil(),e.restoreScissor(),this.onResize(t,r)},i.prototype.uploadVerticesArray=function(e){var t=this.context;t.bufferData(t.ARRAY_BUFFER,e,t.STREAM_DRAW)},i.prototype.uploadIndicesArray=function(e){var t=this.context;t.bufferData(t.ELEMENT_ARRAY_BUFFER,e,t.STATIC_DRAW),this.bindIndices=!0},i.prototype.destroy=function(){this.surface.width=this.surface.height=0},i.prototype.onResize=function(e,t){e=e||this.surface.width,t=t||this.surface.height,this.projectionX=e/2,this.projectionY=-t/2,this.context&&this.context.viewport(0,0,e,t)},i.prototype.resize=function(t,r,i){e.sys.resizeContext(this,t,r,i)},i.prototype._buildSupportedCompressedTextureInfo=function(e){for(var t=[],r=0,i=e;rr; ++r)for(var n=e[r],a=n.supportedFormats,o=0,s=a.length; s>o; ++o)if(a[o][1]===t)return!0;return!1},i.prototype.$debugLogCompressedTextureNotSupported=function(t,i){if(!r[i]){r[i]=!0,e.log("internalFormat = "+i+":0x"+i.toString(16)+", the current hardware does not support the corresponding compression format.");for(var n=0,a=t.length;a>n;++n){var o=t[n];if(o.supportedFormats.length>0){e.log("support = "+o.extensionName);for(var s=0,l=o.supportedFormats.length;l>s;++s){var c=o.supportedFormats[s];e.log(c[0]+" : "+c[1]+" : 0x"+c[1].toString(16))}}}}},i.prototype.createCompressedTexture=function(t,r,i,n,a){var o=this.checkCompressedTextureInternalFormat(this._supportedCompressedTextureInfo,a);if(!o)return this.$debugLogCompressedTextureNotSupported(this._supportedCompressedTextureInfo,a),this.defaultEmptyTexture;var s=this.context,l=s.createTexture();return l?(l[e.glContext]=s,l[e.is_compressed_texture]=!0,s.bindTexture(s.TEXTURE_2D,l),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),l[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]=!0,s.compressedTexImage2D(s.TEXTURE_2D,n,a,r,i,0,t),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.bindTexture(s.TEXTURE_2D,null),l):void(this.contextLost=!0)},i.prototype.updateTexture=function(e,t){var r=this.context;r.bindTexture(r.TEXTURE_2D,e),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t)},Object.defineProperty(i.prototype,"defaultEmptyTexture",{get:function(){if(!this._defaultEmptyTexture){var t=16,r=e.sys.createCanvas(t,t),i=e.sys.getContext2d(r);i.fillStyle="white",i.fillRect(0,0,t,t),this._defaultEmptyTexture=this.createTexture(r),this._defaultEmptyTexture[e.engine_default_empty_texture]=!0}return this._defaultEmptyTexture},enumerable:!0,configurable:!0}),i.prototype.getWebGLTexture=function(t){if(!t.webGLTexture){if("image"!=t.format||t.hasCompressed2d()){if(t.hasCompressed2d()){var r=t.getCompressed2dTextureData();t.webGLTexture=this.createCompressedTexture(r.byteArray,r.width,r.height,r.level,r.glInternalFormat);var i=t.etcAlphaMask;if(i){var n=this.getWebGLTexture(i);n&&(t.webGLTexture[e.etc_alpha_mask]=n)}}}else t.webGLTexture=this.createTexture(t.source);t.$deleteSource&&t.webGLTexture&&(t.source&&(t.source.src="",t.source=null),t.clearCompressedTextureData()),t.webGLTexture&&(t.webGLTexture.smoothing=!0)}return t.webGLTexture},i.prototype.clearRect=function(e,t,r,i){if(0!=e||0!=t||r!=this.surface.width||i!=this.surface.height){var n=this.currentBuffer;if(n.$hasScissor)this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over");else{var a=n.globalMatrix;0==a.b&&0==a.c?(e=e*a.a+a.tx,t=t*a.d+a.ty,r*=a.a,i*=a.d,this.enableScissor(e,-t-i+n.height,r,i),this.clear(),this.disableScissor()):(this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over"))}}else this.clear()},i.prototype.setGlobalCompositeOperation=function(e){this.drawCmdManager.pushSetBlend(e)},i.prototype.drawImage=function(e,t,r,i,n,a,o,s,l,c,h,u,d){var f=this.currentBuffer;if(!this.contextLost&&e&&f){var p,v,g;if(e.texture||e.source&&e.source.texture)p=e.texture||e.source.texture,f.saveTransform(),v=f.$offsetX,g=f.$offsetY,f.useOffset(),f.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;p=this.getWebGLTexture(e)}p&&(this.drawTexture(p,t,r,i,n,a,o,s,l,c,h,void 0,void 0,void 0,void 0,u,d),e.source&&e.source.texture&&(f.$offsetX=v,f.$offsetY=g,f.restoreTransform()))}},i.prototype.drawMesh=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){var y,m,b;if(e.texture||e.source&&e.source.texture)y=e.texture||e.source.texture,x.saveTransform(),m=x.$offsetX,b=x.$offsetY,x.useOffset(),x.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;y=this.getWebGLTexture(e)}y&&(this.drawTexture(y,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g),(e.texture||e.source&&e.source.texture)&&(x.$offsetX=m,x.$offsetY=b,x.restoreTransform()))}},i.prototype.drawTexture=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){d&&f?this.vao.reachMaxSize(d.length/2,f.length)&&this.$drawWebGL():this.vao.reachMaxSize()&&this.$drawWebGL(),void 0!=g&&e.smoothing!=g&&this.drawCmdManager.pushChangeSmoothing(e,g),u&&this.vao.changeToMeshIndices();var y=f?f.length/3:2;this.drawCmdManager.pushDrawTexture(e,y,this.$filter,c,h),x.currentTexture=e,this.vao.cacheArrays(x,t,r,i,n,a,o,s,l,c,h,u,d,f,v)}},i.prototype.drawRect=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushDrawRect(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.pushMask=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(n.$stencilList.push({x:e,y:t,width:r,height:i}),this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPushMask(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.popMask=function(){var e=this.currentBuffer;if(!this.contextLost&&e){var t=e.$stencilList.pop();this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPopMask(),e.currentTexture=null,this.vao.cacheArrays(e,0,0,t.width,t.height,t.x,t.y,t.width,t.height,t.width,t.height)}},i.prototype.clear=function(){this.drawCmdManager.pushClearColor()},i.prototype.enableScissor=function(e,t,r,i){var n=this.currentBuffer;this.drawCmdManager.pushEnableScissor(e,t,r,i),n.$hasScissor=!0},i.prototype.disableScissor=function(){var e=this.currentBuffer;this.drawCmdManager.pushDisableScissor(),e.$hasScissor=!1},i.prototype.$drawWebGL=function(){if(0!=this.drawCmdManager.drawDataLen&&!this.contextLost){this.uploadVerticesArray(this.vao.getVertices()),this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getMeshIndices());for(var e=this.drawCmdManager.drawDataLen,t=0,r=0;e>r;r++){var i=this.drawCmdManager.drawData[r];t=this.drawData(i,t),7==i.type&&(this.activatedBuffer=i.buffer),(0==i.type||1==i.type||2==i.type||3==i.type)&&this.activatedBuffer&&this.activatedBuffer.$computeDrawCall&&this.activatedBuffer.$drawCalls++}this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getIndices()),this.drawCmdManager.clear(),this.vao.clear()}},i.prototype.drawData=function(r,i){if(r){var n,a=this.context,o=r.filter;switch(r.type){case 0:o?"custom"===o.type?n=t.EgretWebGLProgram.getProgram(a,o.$vertexSrc,o.$fragmentSrc,o.$shaderKey):"colorTransform"===o.type?r.texture[e.etc_alpha_mask]?(a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask]),n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag_etc_alphamask_frag,"colorTransform_frag_etc_alphamask_frag")):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag,"colorTransform"):"blurX"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"blurY"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"glow"===o.type&&(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.glow_frag,"glow")):r.texture[e.etc_alpha_mask]?(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_etc_alphamask_frag,e.etc_alpha_mask),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask])):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_frag,"texture"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawTextureElements(r,i);break;case 1:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawRectElements(r,i);break;case 2:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPushMaskElements(r,i);break;case 3:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPopMaskElements(r,i);break;case 4:this.setBlendMode(r.value);break;case 5:r.buffer.rootRenderTarget.resize(r.width,r.height),this.onResize(r.width,r.height);break;case 6:if(this.activatedBuffer){var s=this.activatedBuffer.rootRenderTarget;(0!=s.width||0!=s.height)&&s.clear(!0)}break;case 7:this.activateBuffer(r.buffer,r.width,r.height);break;case 8:var l=this.activatedBuffer;l&&(l.rootRenderTarget&&l.rootRenderTarget.enabledStencil(),l.enableScissor(r.x,r.y,r.width,r.height));break;case 9:l=this.activatedBuffer,l&&l.disableScissor();break;case 10:a.bindTexture(a.TEXTURE_2D,r.texture),r.smoothing?(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR)):(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST))}return i}},i.prototype.activeProgram=function(e,t){if(t!=this.currentProgram){e.useProgram(t.id);var r=t.attributes;for(var i in r)"aVertexPosition"===i?(e.vertexAttribPointer(r.aVertexPosition.location,2,e.FLOAT,!1,20,0),e.enableVertexAttribArray(r.aVertexPosition.location)):"aTextureCoord"===i?(e.vertexAttribPointer(r.aTextureCoord.location,2,e.FLOAT,!1,20,8),e.enableVertexAttribArray(r.aTextureCoord.location)):"aColor"===i&&(e.vertexAttribPointer(r.aColor.location,4,e.UNSIGNED_BYTE,!0,20,16),e.enableVertexAttribArray(r.aColor.location));this.currentProgram=t}},i.prototype.syncUniforms=function(e,t,r,i){var n=e.uniforms;t&&"custom"===t.type;for(var a in n)if("projectionVector"===a)n[a].setValue({x:this.projectionX,y:this.projectionY});else if("uTextureSize"===a)n[a].setValue({x:r,y:i});else if("uSampler"===a)n[a].setValue(0);else if("uSamplerAlphaMask"===a)n[a].setValue(1);else{var o=t.$uniforms[a];void 0!==o&&n[a].setValue(o)}},i.prototype.drawTextureElements=function(t,r){return e.sys.drawTextureElements(this,t,r)},i.prototype.drawRectElements=function(e,t){var r=this.context,i=3*e.count;return r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),i},i.prototype.drawPushMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n){n.rootRenderTarget&&n.rootRenderTarget.enabledStencil(),0==n.stencilHandleCount&&(n.enableStencil(),r.clear(r.STENCIL_BUFFER_BIT));var a=n.stencilHandleCount;n.stencilHandleCount++,r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a,255),r.stencilOp(r.KEEP,r.KEEP,r.INCR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a+1,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.drawPopMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n)if(n.stencilHandleCount--,0==n.stencilHandleCount)n.disableStencil();else{var a=n.stencilHandleCount;r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a+1,255),r.stencilOp(r.KEEP,r.KEEP,r.DECR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.setBlendMode=function(e){var t=this.context,r=i.blendModesForGL[e];r&&t.blendFunc(r[0],r[1])},i.prototype.drawTargetWidthFilters=function(e,r){var i,n=r,a=e.length;if(a>1)for(var o=0;a-1>o;o++){var s=e[o],l=r.rootRenderTarget.width,c=r.rootRenderTarget.height;i=t.WebGLRenderBuffer.create(l,c),i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,this.drawToRenderTarget(s,r,i),r!=n&&t.WebGLRenderBuffer.release(r),r=i}var h=e[a-1];this.drawToRenderTarget(h,r,this.currentBuffer),r!=n&&t.WebGLRenderBuffer.release(r)},i.prototype.drawToRenderTarget=function(e,r,i){if(!this.contextLost){this.vao.reachMaxSize()&&this.$drawWebGL(),this.pushBuffer(i);var n,a=r,o=r.rootRenderTarget.width,s=r.rootRenderTarget.height;if("blur"==e.type){var l=e.blurXFilter,c=e.blurYFilter;0!=l.blurX&&0!=c.blurY?(n=t.WebGLRenderBuffer.create(o,s),n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,this.drawToRenderTarget(e.blurXFilter,r,n),r!=a&&t.WebGLRenderBuffer.release(r),r=n,e=c):e=0===l.blurX?c:l}i.saveTransform(),i.transform(1,0,0,-1,0,s),i.currentTexture=r.rootRenderTarget.texture,this.vao.cacheArrays(i,0,0,o,s,0,0,o,s,o,s),i.restoreTransform(),this.drawCmdManager.pushDrawTexture(r.rootRenderTarget.texture,2,e,o,s),r!=a&&t.WebGLRenderBuffer.release(r),this.popBuffer()}},i.initBlendMode=function(){i.blendModesForGL={},i.blendModesForGL["source-over"]=[1,771],i.blendModesForGL.lighter=[1,1],i.blendModesForGL["lighter-in"]=[770,771],i.blendModesForGL["destination-out"]=[0,771],i.blendModesForGL["destination-in"]=[0,770]},i.glContextId=0,i.blendModesForGL=null,i}();t.WebGLRenderContext=i,__reflect(i.prototype,"egret.web.WebGLRenderContext",["egret.sys.RenderContext"]),i.initBlendMode()}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function n(i,n,a){var o=r.call(this)||this;if(o.currentTexture=null,o.globalAlpha=1,o.globalTintColor=16777215,o.stencilState=!1,o.$stencilList=[],o.stencilHandleCount=0,o.$scissorState=!1,o.scissorRect=new e.Rectangle,o.$hasScissor=!1,o.$drawCalls=0,o.$computeDrawCall=!1,o.globalMatrix=new e.Matrix,o.savedGlobalMatrix=new e.Matrix,o.$offsetX=0,o.$offsetY=0,o.context=t.WebGLRenderContext.getInstance(i,n),e.nativeRender)return a?o.surface=o.context.surface:o.surface=new egret_native.NativeRenderSurface(o,i,n,a),o.rootRenderTarget=null,o;if(o.rootRenderTarget=new t.WebGLRenderTarget(o.context.context,3,3),i&&n&&o.resize(i,n),o.root=a,o.root)o.context.pushBuffer(o),o.surface=o.context.surface,o.$computeDrawCall=!0;else{var s=o.context.activatedBuffer;s&&s.rootRenderTarget.activate(),o.rootRenderTarget.initFrameBuffer(),o.surface=o.rootRenderTarget}return o}return __extends(n,r),n.prototype.enableStencil=function(){this.stencilState||(this.context.enableStencilTest(),this.stencilState=!0)},n.prototype.disableStencil=function(){this.stencilState&&(this.context.disableStencilTest(),this.stencilState=!1)},n.prototype.restoreStencil=function(){this.stencilState?this.context.enableStencilTest():this.context.disableStencilTest()},n.prototype.enableScissor=function(e,t,r,i){this.$scissorState||(this.$scissorState=!0,this.scissorRect.setTo(e,t,r,i),this.context.enableScissorTest(this.scissorRect))},n.prototype.disableScissor=function(){this.$scissorState&&(this.$scissorState=!1,this.scissorRect.setEmpty(),this.context.disableScissorTest())},n.prototype.restoreScissor=function(){this.$scissorState?this.context.enableScissorTest(this.scissorRect):this.context.disableScissorTest()},Object.defineProperty(n.prototype,"width",{get:function(){return e.nativeRender?this.surface.width:this.rootRenderTarget.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return e.nativeRender?this.surface.height:this.rootRenderTarget.height},enumerable:!0,configurable:!0}),n.prototype.resize=function(t,r,i){return t=t||1,r=r||1,e.nativeRender?void this.surface.resize(t,r):(this.context.pushBuffer(this),(t!=this.rootRenderTarget.width||r!=this.rootRenderTarget.height)&&(this.context.drawCmdManager.pushResize(this,t,r),this.rootRenderTarget.width=t,this.rootRenderTarget.height=r),this.root&&this.context.resize(t,r,i),this.context.clear(),void this.context.popBuffer())},n.prototype.getPixels=function(t,r,i,n){void 0===i&&(i=1),void 0===n&&(n=1);var a=new Uint8Array(4*i*n);if(e.nativeRender)egret_native.activateBuffer(this),egret_native.nrGetPixels(t,r,i,n,a),egret_native.activateBuffer(null);else{var o=this.rootRenderTarget.useFrameBuffer;this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.getPixels(t,r,i,n,a),this.rootRenderTarget.useFrameBuffer=o,this.rootRenderTarget.activate()}for(var s=new Uint8Array(4*i*n),l=0;n>l;l++)for(var c=0;i>c;c++){var h=4*(i*(n-l-1)+c),u=4*(i*l+c),d=a[u+3];s[h]=Math.round(a[u]/d*255),s[h+1]=Math.round(a[u+1]/d*255),s[h+2]=Math.round(a[u+2]/d*255),s[h+3]=a[u+3]}return s},n.prototype.toDataURL=function(e,t){return this.context.surface.toDataURL(e,t)},n.prototype.destroy=function(){this.context.destroy()},n.prototype.onRenderFinish=function(){this.$drawCalls=0},n.prototype.drawFrameBufferToSurface=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.rootRenderTarget,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.drawSurfaceToFrameBuffer=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.context.surface,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.clear=function(){this.context.pushBuffer(this),this.context.clear(),this.context.popBuffer()},n.prototype.setTransform=function(e,t,r,i,n,a){var o=this.globalMatrix;o.a=e,o.b=t,o.c=r,o.d=i,o.tx=n,o.ty=a},n.prototype.transform=function(e,t,r,i,n,a){var o=this.globalMatrix,s=o.a,l=o.b,c=o.c,h=o.d;(1!=e||0!=t||0!=r||1!=i)&&(o.a=e*s+t*c,o.b=e*l+t*h,o.c=r*s+i*c,o.d=r*l+i*h),o.tx=n*s+a*c+o.tx,o.ty=n*l+a*h+o.ty},n.prototype.useOffset=function(){var e=this;(0!=e.$offsetX||0!=e.$offsetY)&&(e.globalMatrix.append(1,0,0,1,e.$offsetX,e.$offsetY),e.$offsetX=e.$offsetY=0)},n.prototype.saveTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t.tx=e.tx,t.ty=e.ty},n.prototype.restoreTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e.tx=t.tx,e.ty=t.ty},n.create=function(e,t){var r=i.pop(); if(r){r.resize(e,t);var a=r.globalMatrix;a.a=1,a.b=0,a.c=0,a.d=1,a.tx=0,a.ty=0,r.globalAlpha=1,r.$offsetX=0,r.$offsetY=0}else r=new n(e,t),r.$computeDrawCall=!1;return r},n.release=function(e){i.push(e)},n.autoClear=!0,n}(e.HashObject);t.WebGLRenderBuffer=r,__reflect(r.prototype,"egret.web.WebGLRenderBuffer",["egret.sys.RenderBuffer"]);var i=[]}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=["source-over","lighter","destination-out"],i="source-over",n=[],a=function(){function a(){this.wxiOS10=!1,this.nestLevel=0}return a.prototype.render=function(t,r,i,a){this.nestLevel++;var o=r,s=o.context;s.pushBuffer(o),o.transform(i.a,i.b,i.c,i.d,0,0),this.drawDisplayObject(t,o,i.tx,i.ty,!0),s.$drawWebGL();var l=o.$drawCalls;o.onRenderFinish(),s.popBuffer();var c=e.Matrix.create();if(i.$invertInto(c),o.transform(c.a,c.b,c.c,c.d,0,0),e.Matrix.release(c),this.nestLevel--,0===this.nestLevel){n.length>6&&(n.length=6);for(var h=n.length,u=0;h>u;u++)n[u].resize(0,0)}return l},a.prototype.drawDisplayObject=function(t,r,i,n,a){var o,s=0,l=t.$displayList;if(l&&!a?((t.$cacheDirty||t.$renderDirty||l.$canvasScaleX!=e.sys.DisplayList.$canvasScaleX||l.$canvasScaleY!=e.sys.DisplayList.$canvasScaleY)&&(s+=l.drawToSurface()),o=l.$renderNode):o=t.$renderDirty?t.$getRenderNode():t.$renderNode,t.$cacheDirty=!1,o){switch(s++,r.$offsetX=i,r.$offsetY=n,o.type){case 1:this.renderBitmap(o,r);break;case 2:this.renderText(o,r);break;case 3:this.renderGraphics(o,r);break;case 4:this.renderGroup(o,r);break;case 5:this.renderMesh(o,r);break;case 6:this.renderNormalBitmap(o,r)}r.$offsetX=0,r.$offsetY=0}if(l&&!a)return s;var c=t.$children;if(c){t.sortableChildren&&t.$sortDirty&&t.sortChildren();for(var h=c.length,u=0;h>u;u++){var d=c[u],f=void 0,p=void 0,v=void 0,g=void 0;1!=d.$alpha&&(v=r.globalAlpha,r.globalAlpha*=d.$alpha),16777215!==d.tint&&(g=r.globalTintColor,r.globalTintColor=d.$tintRGB);var x=void 0;if(d.$useTranslate){var y=d.$getMatrix();f=i+d.$x,p=n+d.$y;var m=r.globalMatrix;x=e.Matrix.create(),x.a=m.a,x.b=m.b,x.c=m.c,x.d=m.d,x.tx=m.tx,x.ty=m.ty,r.transform(y.a,y.b,y.c,y.d,f,p),f=-d.$anchorOffsetX,p=-d.$anchorOffsetY}else f=i+d.$x-d.$anchorOffsetX,p=n+d.$y-d.$anchorOffsetY;switch(d.$renderMode){case 1:break;case 2:s+=this.drawWithFilter(d,r,f,p);break;case 3:s+=this.drawWithClip(d,r,f,p);break;case 4:s+=this.drawWithScrollRect(d,r,f,p);break;default:s+=this.drawDisplayObject(d,r,f,p)}if(v&&(r.globalAlpha=v),g&&(r.globalTintColor=g),x){var y=r.globalMatrix;y.a=x.a,y.b=x.b,y.c=x.c,y.d=x.d,y.tx=x.tx,y.ty=x.ty,e.Matrix.release(x)}}}return s},a.prototype.drawWithFilter=function(t,a,o,s){var l=0;if(t.$children&&0==t.$children.length&&(!t.$renderNode||0==t.$renderNode.$getRenderCount()))return l;var c,h=t.$filters,u=0!==t.$blendMode;u&&(c=r[t.$blendMode],c||(c=i));var d=t.$getOriginalBounds(),f=d.x,p=d.y,v=d.width,g=d.height;if(0>=v||0>=g)return l;if(!t.mask&&1==h.length&&("colorTransform"==h[0].type||"custom"===h[0].type&&0===h[0].padding)){var x=this.getRenderCount(t);if(!t.$children||1==x)return u&&a.context.setGlobalCompositeOperation(c),a.context.$filter=h[0],l+=t.$mask?this.drawWithClip(t,a,o,s):t.$scrollRect||t.$maskRect?this.drawWithScrollRect(t,a,o,s):this.drawDisplayObject(t,a,o,s),a.context.$filter=null,u&&a.context.setGlobalCompositeOperation(i),l}var y=this.createRenderBuffer(v,g);if(y.context.pushBuffer(y),l+=t.$mask?this.drawWithClip(t,y,-f,-p):t.$scrollRect||t.$maskRect?this.drawWithScrollRect(t,y,-f,-p):this.drawDisplayObject(t,y,-f,-p),y.context.popBuffer(),l>0){u&&a.context.setGlobalCompositeOperation(c),l++,a.$offsetX=o+f,a.$offsetY=s+p;var m=e.Matrix.create(),b=a.globalMatrix;m.a=b.a,m.b=b.b,m.c=b.c,m.d=b.d,m.tx=b.tx,m.ty=b.ty,a.useOffset(),a.context.drawTargetWidthFilters(h,y),b.a=m.a,b.b=m.b,b.c=m.c,b.d=m.d,b.tx=m.tx,b.ty=m.ty,e.Matrix.release(m),u&&a.context.setGlobalCompositeOperation(i)}return n.push(y),l},a.prototype.getRenderCount=function(e){var t=0,r=e.$getRenderNode();if(r&&(t+=r.$getRenderCount()),e.$children)for(var i=0,n=e.$children;i0)return 2;if(a.$children)t+=this.getRenderCount(a);else{var s=a.$getRenderNode();s&&(t+=s.$getRenderCount())}}return t},a.prototype.drawWithClip=function(t,a,o,s){var l,c=0,h=0!==t.$blendMode;h&&(l=r[t.$blendMode],l||(l=i));var u=t.$scrollRect?t.$scrollRect:t.$maskRect,d=t.$mask;if(d){var f=d.$getMatrix();if(0==f.a&&0==f.b||0==f.c&&0==f.d)return c}if(d||t.$children&&0!=t.$children.length){var p=t.$getOriginalBounds(),v=p.x,g=p.y,x=p.width,y=p.height;if(0>=x||0>=y)return c;var m=this.createRenderBuffer(x,y);if(m.context.pushBuffer(m),c+=this.drawDisplayObject(t,m,-v,-g),d){var b=this.createRenderBuffer(x,y);b.context.pushBuffer(b);var w=e.Matrix.create();w.copyFrom(d.$getConcatenatedMatrix()),d.$getConcatenatedMatrixAt(t,w),w.translate(-v,-g),b.setTransform(w.a,w.b,w.c,w.d,w.tx,w.ty),e.Matrix.release(w),c+=this.drawDisplayObject(d,b,0,0),b.context.popBuffer(),m.context.setGlobalCompositeOperation("destination-in"),m.setTransform(1,0,0,-1,0,b.height);var T=b.rootRenderTarget.width,E=b.rootRenderTarget.height;m.context.drawTexture(b.rootRenderTarget.texture,0,0,T,E,0,0,T,E,T,E),m.setTransform(1,0,0,1,0,0),m.context.setGlobalCompositeOperation("source-over"),b.setTransform(1,0,0,1,0,0),n.push(b)}if(m.context.setGlobalCompositeOperation(i),m.context.popBuffer(),c>0){c++,h&&a.context.setGlobalCompositeOperation(l),u&&a.context.pushMask(u.x+o,u.y+s,u.width,u.height);var _=e.Matrix.create(),C=a.globalMatrix;_.a=C.a,_.b=C.b,_.c=C.c,_.d=C.d,_.tx=C.tx,_.ty=C.ty,C.append(1,0,0,-1,o+v,s+g+m.height);var S=m.rootRenderTarget.width,R=m.rootRenderTarget.height;a.context.drawTexture(m.rootRenderTarget.texture,0,0,S,R,0,0,S,R,S,R),u&&m.context.popMask(),h&&a.context.setGlobalCompositeOperation(i);var L=a.globalMatrix;L.a=_.a,L.b=_.b,L.c=_.c,L.d=_.d,L.tx=_.tx,L.ty=_.ty,e.Matrix.release(_)}return n.push(m),c}return u&&a.context.pushMask(u.x+o,u.y+s,u.width,u.height),h&&a.context.setGlobalCompositeOperation(l),c+=this.drawDisplayObject(t,a,o,s),h&&a.context.setGlobalCompositeOperation(i),u&&a.context.popMask(),c},a.prototype.drawWithScrollRect=function(e,t,r,i){var n=0,a=e.$scrollRect?e.$scrollRect:e.$maskRect;if(a.isEmpty())return n;e.$scrollRect&&(r-=a.x,i-=a.y);var o=t.globalMatrix,s=t.context,l=!1;if(t.$hasScissor||0!=o.b||0!=o.c)t.context.pushMask(a.x+r,a.y+i,a.width,a.height);else{var c=o.a,h=o.d,u=o.tx,d=o.ty,f=a.x+r,p=a.y+i,v=f+a.width,g=p+a.height,x=void 0,y=void 0,m=void 0,b=void 0;if(1==c&&1==h)x=f+u,y=p+d,m=v+u,b=g+d;else{var w=c*f+u,T=h*p+d,E=c*v+u,_=h*p+d,C=c*v+u,S=h*g+d,R=c*f+u,L=h*g+d,D=0;w>E&&(D=w,w=E,E=D),C>R&&(D=C,C=R,R=D),x=C>w?w:C,m=E>R?E:R,T>_&&(D=T,T=_,_=D),S>L&&(D=S,S=L,L=D),y=S>T?T:S,b=_>L?_:L}s.enableScissor(x,-b+t.height,m-x,b-y),l=!0}return n+=this.drawDisplayObject(e,t,r,i),l?s.disableScissor():s.popMask(),n},a.prototype.drawNodeToBuffer=function(e,t,r,i){var n=t;n.context.pushBuffer(n),n.setTransform(r.a,r.b,r.c,r.d,r.tx,r.ty),this.renderNode(e,t,0,0,i),n.context.$drawWebGL(),n.onRenderFinish(),n.context.popBuffer()},a.prototype.drawDisplayToBuffer=function(e,t,r){t.context.pushBuffer(t),r&&t.setTransform(r.a,r.b,r.c,r.d,r.tx,r.ty);var i;i=e.$renderDirty?e.$getRenderNode():e.$renderNode;var n=0;if(i)switch(n++,i.type){case 1:this.renderBitmap(i,t);break;case 2:this.renderText(i,t);break;case 3:this.renderGraphics(i,t);break;case 4:this.renderGroup(i,t);break;case 5:this.renderMesh(i,t);break;case 6:this.renderNormalBitmap(i,t)}var a=e.$children;if(a)for(var o=a.length,s=0;o>s;s++){var l=a[s];switch(l.$renderMode){case 1:break;case 2:n+=this.drawWithFilter(l,t,0,0);break;case 3:n+=this.drawWithClip(l,t,0,0);break;case 4:n+=this.drawWithScrollRect(l,t,0,0);break;default:n+=this.drawDisplayObject(l,t,0,0)}}return t.context.$drawWebGL(),t.onRenderFinish(),t.context.popBuffer(),n},a.prototype.renderNode=function(e,t,r,i,n){switch(t.$offsetX=r,t.$offsetY=i,e.type){case 1:this.renderBitmap(e,t);break;case 2:this.renderText(e,t);break;case 3:this.renderGraphics(e,t,n);break;case 4:this.renderGroup(e,t);break;case 5:this.renderMesh(e,t);break;case 6:this.renderNormalBitmap(e,t)}},a.prototype.renderNormalBitmap=function(e,t){var r=e.image;r&&t.context.drawImage(r,e.sourceX,e.sourceY,e.sourceW,e.sourceH,e.drawX,e.drawY,e.drawW,e.drawH,e.imageWidth,e.imageHeight,e.rotated,e.smoothing)},a.prototype.renderBitmap=function(t,n){var a=t.image;if(a){var o,s,l,c=t.drawData,h=c.length,u=0,d=t.matrix,f=t.blendMode,p=t.alpha;if(d){o=e.Matrix.create();var v=n.globalMatrix;o.a=v.a,o.b=v.b,o.c=v.c,o.d=v.d,o.tx=v.tx,o.ty=v.ty,s=n.$offsetX,l=n.$offsetY,n.useOffset(),n.transform(d.a,d.b,d.c,d.d,d.tx,d.ty)}f&&n.context.setGlobalCompositeOperation(r[f]);var g;if(p==p&&(g=n.globalAlpha,n.globalAlpha*=p),t.filter){for(n.context.$filter=t.filter;h>u;)n.context.drawImage(a,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.rotated,t.smoothing);n.context.$filter=null}else for(;h>u;)n.context.drawImage(a,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.rotated,t.smoothing);if(f&&n.context.setGlobalCompositeOperation(i),p==p&&(n.globalAlpha=g),d){var x=n.globalMatrix;x.a=o.a,x.b=o.b,x.c=o.c,x.d=o.d,x.tx=o.tx,x.ty=o.ty,n.$offsetX=s,n.$offsetY=l,e.Matrix.release(o)}}},a.prototype.renderMesh=function(t,n){var a,o,s,l=t.image,c=t.drawData,h=c.length,u=0,d=t.matrix,f=t.blendMode,p=t.alpha;if(d){a=e.Matrix.create();var v=n.globalMatrix;a.a=v.a,a.b=v.b,a.c=v.c,a.d=v.d,a.tx=v.tx,a.ty=v.ty,o=n.$offsetX,s=n.$offsetY,n.useOffset(),n.transform(d.a,d.b,d.c,d.d,d.tx,d.ty)}f&&n.context.setGlobalCompositeOperation(r[f]);var g;if(p==p&&(g=n.globalAlpha,n.globalAlpha*=p),t.filter){for(n.context.$filter=t.filter;h>u;)n.context.drawMesh(l,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.uvs,t.vertices,t.indices,t.bounds,t.rotated,t.smoothing);n.context.$filter=null}else for(;h>u;)n.context.drawMesh(l,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.uvs,t.vertices,t.indices,t.bounds,t.rotated,t.smoothing);if(f&&n.context.setGlobalCompositeOperation(i),p==p&&(n.globalAlpha=g),d){var x=n.globalMatrix;x.a=a.a,x.b=a.b,x.c=a.c,x.d=a.d,x.tx=a.tx,x.ty=a.ty,n.$offsetX=o,n.$offsetY=s,e.Matrix.release(a)}},a.prototype.___renderText____=function(r,i){var n=r.width-r.x,a=r.height-r.y;if(!(0>=n||0>=a)&&n&&a&&0!==r.drawData.length){var o=e.sys.DisplayList.$canvasScaleX,s=e.sys.DisplayList.$canvasScaleY,l=i.context.$maxTextureSize;n*o>l&&(o*=l/(n*o)),a*s>l&&(s*=l/(a*s)),n*=o,a*=s;var c=r.x*o,h=r.y*s;(r.$canvasScaleX!==o||r.$canvasScaleY!==s)&&(r.$canvasScaleX=o,r.$canvasScaleY=s,r.dirtyRender=!0),(c||h)&&i.transform(1,0,0,1,c/o,h/s),r.dirtyRender&&t.TextAtlasRender.analysisTextNodeAndFlushDrawLabel(r);var u=r[t.property_drawLabel];if(u&&u.length>0){for(var d=i.$offsetX,f=i.$offsetY,p=null,v=0,g=0,x=null,y=null,m=null,b=0,w=u.length;w>b;++b){p=u[b],v=p.anchorX,g=p.anchorY,x=p.textBlocks,i.$offsetX=d+v;for(var T=0,E=x.length;E>T;++T)y=x[T],T>0&&(i.$offsetX-=y.canvasWidthOffset),i.$offsetY=f+g-(y.measureHeight+(y.stroke2?y.canvasHeightOffset:0))/2,m=y.line.page,i.context.drawTexture(m.webGLTexture,y.u,y.v,y.contentWidth,y.contentHeight,0,0,y.contentWidth,y.contentHeight,m.pageWidth,m.pageHeight),i.$offsetX+=y.contentWidth-y.canvasWidthOffset}i.$offsetX=d,i.$offsetY=f}(c||h)&&i.transform(1,0,0,1,-c/o,-h/s),r.dirtyRender=!1}},a.prototype.renderText=function(r,i){if(t.textAtlasRenderEnable)return void this.___renderText____(r,i);var n=r.width-r.x,a=r.height-r.y;if(!(0>=n||0>=a)&&n&&a&&0!=r.drawData.length){var o=e.sys.DisplayList.$canvasScaleX,s=e.sys.DisplayList.$canvasScaleY,l=i.context.$maxTextureSize;n*o>l&&(o*=l/(n*o)),a*s>l&&(s*=l/(a*s)),n*=o,a*=s;var c=r.x*o,h=r.y*s;if((r.$canvasScaleX!=o||r.$canvasScaleY!=s)&&(r.$canvasScaleX=o,r.$canvasScaleY=s,r.dirtyRender=!0),this.wxiOS10?(this.canvasRenderer||(this.canvasRenderer=new e.CanvasRenderer),r.dirtyRender&&(this.canvasRenderBuffer=new t.CanvasRenderBuffer(n,a))):this.canvasRenderBuffer&&this.canvasRenderBuffer.context?r.dirtyRender&&this.canvasRenderBuffer.resize(n,a):(this.canvasRenderer=new e.CanvasRenderer,this.canvasRenderBuffer=new t.CanvasRenderBuffer(n,a)),this.canvasRenderBuffer.context){if((1!=o||1!=s)&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,0,0),c||h?(r.dirtyRender&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,-c,-h),i.transform(1,0,0,1,c/o,h/s)):(1!=o||1!=s)&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,0,0),r.dirtyRender){var u=this.canvasRenderBuffer.surface;if(this.canvasRenderer.renderText(r,this.canvasRenderBuffer.context),this.wxiOS10)u.isCanvas=!0,r.$texture=u;else{var d=r.$texture;d?i.context.updateTexture(d,u):(d=i.context.createTexture(u),r.$texture=d)}r.$textureWidth=u.width,r.$textureHeight=u.height}var f=r.$textureWidth,p=r.$textureHeight;i.context.drawTexture(r.$texture,0,0,f,p,0,0,f/o,p/s,f,p),(c||h)&&(r.dirtyRender&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,0,0),i.transform(1,0,0,1,-c/o,-h/s)),r.dirtyRender=!1}}},a.prototype.renderGraphics=function(r,i,n){var a=r.width,o=r.height;if(!(0>=a||0>=o)&&a&&o&&0!=r.drawData.length){var s=e.sys.DisplayList.$canvasScaleX,l=e.sys.DisplayList.$canvasScaleY;(1>a*s||1>o*l)&&(s=l=1),(r.$canvasScaleX!=s||r.$canvasScaleY!=l)&&(r.$canvasScaleX=s,r.$canvasScaleY=l,r.dirtyRender=!0),a*=s,o*=l;var c=Math.ceil(a),h=Math.ceil(o);if(s*=c/a,l*=h/o,a=c,o=h,this.wxiOS10?(this.canvasRenderer||(this.canvasRenderer=new e.CanvasRenderer),r.dirtyRender&&(this.canvasRenderBuffer=new t.CanvasRenderBuffer(a,o))):this.canvasRenderBuffer&&this.canvasRenderBuffer.context?r.dirtyRender&&this.canvasRenderBuffer.resize(a,o):(this.canvasRenderer=new e.CanvasRenderer,this.canvasRenderBuffer=new t.CanvasRenderBuffer(a,o)),this.canvasRenderBuffer.context){(1!=s||1!=l)&&this.canvasRenderBuffer.context.setTransform(s,0,0,l,0,0),(r.x||r.y)&&((r.dirtyRender||n)&&this.canvasRenderBuffer.context.translate(-r.x,-r.y),i.transform(1,0,0,1,r.x,r.y));var u=this.canvasRenderBuffer.surface;if(n){this.canvasRenderer.renderGraphics(r,this.canvasRenderBuffer.context,!0);var d=void 0;this.wxiOS10?(u.isCanvas=!0,d=u):(e.WebGLUtils.deleteWebGLTexture(u),d=i.context.getWebGLTexture(u)),i.context.drawTexture(d,0,0,a,o,0,0,a,o,u.width,u.height)}else{if(r.dirtyRender){if(this.canvasRenderer.renderGraphics(r,this.canvasRenderBuffer.context),this.wxiOS10)u.isCanvas=!0,r.$texture=u;else{var d=r.$texture;d?i.context.updateTexture(d,u):(d=i.context.createTexture(u),r.$texture=d)}r.$textureWidth=u.width,r.$textureHeight=u.height}var f=r.$textureWidth,p=r.$textureHeight;i.context.drawTexture(r.$texture,0,0,f,p,0,0,f/s,p/l,f,p)}(r.x||r.y)&&((r.dirtyRender||n)&&this.canvasRenderBuffer.context.translate(r.x,r.y),i.transform(1,0,0,1,-r.x,-r.y)),n||(r.dirtyRender=!1)}}},a.prototype.renderGroup=function(t,r){var i,n,a,o=t.matrix;if(o){i=e.Matrix.create();var s=r.globalMatrix;i.a=s.a,i.b=s.b,i.c=s.c,i.d=s.d,i.tx=s.tx,i.ty=s.ty,n=r.$offsetX,a=r.$offsetY,r.useOffset(),r.transform(o.a,o.b,o.c,o.d,o.tx,o.ty)}for(var l=t.drawData,c=l.length,h=0;c>h;h++){var u=l[h];this.renderNode(u,r,r.$offsetX,r.$offsetY)}if(o){var d=r.globalMatrix;d.a=i.a,d.b=i.b,d.c=i.c,d.d=i.d,d.tx=i.tx,d.ty=i.ty,r.$offsetX=n,r.$offsetY=a,e.Matrix.release(i)}},a.prototype.createRenderBuffer=function(e,r){var i=n.pop();return i?i.resize(e,r):(i=new t.WebGLRenderBuffer(e,r),i.$computeDrawCall=!1),i},a}();t.WebGLRenderer=a,__reflect(a.prototype,"egret.web.WebGLRenderer",["egret.sys.SystemRenderer"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(e){function t(t,r,i,n,a,o,s,l){var c=e.call(this)||this;return c._width=0,c._height=0,c._border=0,c.line=null,c.x=0,c.y=0,c.u=0,c.v=0,c.tag="",c.measureWidth=0,c.measureHeight=0,c.canvasWidthOffset=0,c.canvasHeightOffset=0,c.stroke2=0,c._width=t,c._height=r,c._border=l,c.measureWidth=i,c.measureHeight=n,c.canvasWidthOffset=a,c.canvasHeightOffset=o,c.stroke2=s,c}return __extends(t,e),Object.defineProperty(t.prototype,"border",{get:function(){return this._border},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width+2*this.border},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height+2*this.border},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contentWidth",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contentHeight",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"page",{get:function(){return this.line?this.line.page:null},enumerable:!0,configurable:!0}),t.prototype.updateUV=function(){var e=this.line;return e?(this.u=e.x+this.x+1*this.border,this.v=e.y+this.y+1*this.border,!0):!1},Object.defineProperty(t.prototype,"subImageOffsetX",{get:function(){var e=this.line;return e?e.x+this.x+this.border:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"subImageOffsetY",{get:function(){var e=this.line;return e?e.y+this.y+this.border:0},enumerable:!0,configurable:!0}),t}(e.HashObject);t.TextBlock=r,__reflect(r.prototype,"egret.web.TextBlock");var i=function(e){function t(t){var r=e.call(this)||this;return r.page=null,r.textBlocks=[],r.dynamicMaxHeight=0,r.maxWidth=0,r.x=0,r.y=0,r.maxWidth=t,r}return __extends(t,e),t.prototype.isCapacityOf=function(e){if(!e)return!1;var t=0,r=0,i=this.lastTextBlock();return i&&(t=i.x+i.width,r=i.y),t+e.width>this.maxWidth?!1:this.dynamicMaxHeight>0&&(e.height>this.dynamicMaxHeight||e.height/this.dynamicMaxHeight<.5)?!1:!0},t.prototype.lastTextBlock=function(){var e=this.textBlocks;return e.length>0?e[e.length-1]:null},t.prototype.addTextBlock=function(e,t){if(!e)return!1;if(t&&!this.isCapacityOf(e))return!1;var r=0,i=0,n=this.lastTextBlock();return n&&(r=n.x+n.width,i=n.y),e.x=r,e.y=i,e.line=this,this.textBlocks.push(e),this.dynamicMaxHeight=Math.max(this.dynamicMaxHeight,e.height),!0},t}(e.HashObject);t.Line=i,__reflect(i.prototype,"egret.web.Line");var n=function(e){function t(t,r){var i=e.call(this)||this;return i.lines=[],i.pageWidth=0,i.pageHeight=0,i.webGLTexture=null,i.pageWidth=t,i.pageHeight=r,i}return __extends(t,e),t.prototype.addLine=function(e){if(!e)return!1;var t=0,r=0,i=this.lines;if(i.length>0){var n=i[i.length-1];t=n.x,r=n.y+n.dynamicMaxHeight}return e.maxWidth>this.pageWidth?(console.error("line.maxWidth = "+e.maxWidth+", this.pageWidth = "+this.pageWidth),!1):r+e.dynamicMaxHeight>this.pageHeight?!1:(e.x=t,e.y=r,e.page=this,this.lines.push(e),!0)},t}(e.HashObject);t.Page=n,__reflect(n.prototype,"egret.web.Page");var a=function(e){function t(t,r){var i=e.call(this)||this;return i._pages=[],i._sortLines=[],i._maxSize=1024,i._border=1,i._maxSize=t,i._border=r,i}return __extends(t,e),t.prototype.addTextBlock=function(e){var t=this._addTextBlock(e);if(!t)return!1;e.updateUV();for(var r=!1,i=t,n=this._sortLines,a=0,o=n;athis._maxSize||e.height>this._maxSize)return null;for(var t=this._sortLines,r=0,n=t.length;n>r;++r){var a=t[r];if(a.isCapacityOf(e)&&a.addTextBlock(e,!1))return[a.page,a]}var o=new i(this._maxSize);if(!o.addTextBlock(e,!0))return console.error("_addTextBlock !newLine.addTextBlock(textBlock, true)"),null;for(var s=this._pages,r=0,l=s.length;l>r;++r){var c=s[r];if(c.addLine(o))return[c,o]}var h=this.createPage(this._maxSize,this._maxSize);return h.addLine(o)?[h,o]:(console.error("_addText newPage.addLine failed"),null)},t.prototype.createPage=function(e,t){var r=new n(e,t);return this._pages.push(r),r},t.prototype.sort=function(){if(!(this._sortLines.length<=1)){var e=function(e,t){return e.dynamicMaxHeight=0)return void console.error("DrawLabel.back repeat");e.clear(),i.push(e)}},t.pool=[],t}(e.HashObject);t.DrawLabel=i,__reflect(i.prototype,"egret.web.DrawLabel");var n=function(t){function i(i,n){var a=t.call(this)||this;a.format=null;var o=0;r&&(o=i.textColor,i.textColor=16711680),a.textColor=i.textColor,a.strokeColor=i.strokeColor,a.size=i.size,a.stroke=i.stroke,a.bold=i.bold,a.italic=i.italic,a.fontFamily=i.fontFamily,a.format=n,a.font=e.getFontString(i,a.format);var s=n.textColor?n.textColor:i.textColor,l=n.strokeColor?n.strokeColor:i.strokeColor,c=n.stroke?n.stroke:i.stroke,h=n.size?n.size:i.size;return a.description=""+a.font+"-"+h,a.description+="-"+e.toColorString(s),a.description+="-"+e.toColorString(l),c&&(a.description+="-"+2*c),r&&(i.textColor=o),a}return __extends(i,t),i}(e.HashObject);__reflect(n.prototype,"StyleInfo");var a=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e["char"]="",e.styleInfo=null,e.hashCodeString="",e.charWithStyleHashCode=0,e.measureWidth=0,e.measureHeight=0,e.canvasWidthOffset=0,e.canvasHeightOffset=0,e.stroke2=0,e}return __extends(r,t),r.prototype.reset=function(t,r){return this["char"]=t,this.styleInfo=r,this.hashCodeString=t+":"+r.description,this.charWithStyleHashCode=e.NumberUtils.convertStringToHashCode(this.hashCodeString),this.canvasWidthOffset=0,this.canvasHeightOffset=0,this.stroke2=0,this},r.prototype.measureAndDraw=function(t){var r=t;if(r){var i=this["char"],n=this.styleInfo.format,a=n.textColor?n.textColor:this.styleInfo.textColor,o=n.strokeColor?n.strokeColor:this.styleInfo.strokeColor,s=n.stroke?n.stroke:this.styleInfo.stroke,l=n.size?n.size:this.styleInfo.size;this.measureWidth=this.measure(i,this.styleInfo,l),this.measureHeight=l;var c=this.measureWidth,h=this.measureHeight,u=2*s;u>0&&(c+=2*u,h+=2*u),this.stroke2=u,r.width=c=Math.ceil(c)+4,r.height=h=Math.ceil(h)+4,this.canvasWidthOffset=(r.width-this.measureWidth)/2,this.canvasHeightOffset=(r.height-this.measureHeight)/2;var d=3,f=Math.pow(10,d);this.canvasWidthOffset=Math.floor(this.canvasWidthOffset*f)/f,this.canvasHeightOffset=Math.floor(this.canvasHeightOffset*f)/f;var p=e.sys.getContext2d(r);p.save(),p.textAlign="center",p.textBaseline="middle",p.lineJoin="round",p.font=this.styleInfo.font,p.fillStyle=e.toColorString(a),p.strokeStyle=e.toColorString(o),p.clearRect(0,0,r.width,r.height),s&&(p.lineWidth=2*s,p.strokeText(i,r.width/2,r.height/2)),p.fillText(i,r.width/2,r.height/2),p.restore()}},r.prototype.measure=function(t,i,n){var a=r.chineseCharactersRegExp.test(t);if(a&&r.chineseCharacterMeasureFastMap[i.font])return r.chineseCharacterMeasureFastMap[i.font];var o=e.sys.measureText(t,i.fontFamily,n||i.size,i.bold,i.italic);return a&&(r.chineseCharacterMeasureFastMap[i.font]=o),o},r.chineseCharactersRegExp=new RegExp("^[一-龥]$"),r.chineseCharacterMeasureFastMap={},r}(e.HashObject);__reflect(a.prototype,"CharImageRender");var o=function(o){function s(e,r,i){var n=o.call(this)||this;return n.book=null,n.charImageRender=new a,n.textBlockMap={},n._canvas=null,n.textAtlasTextureCache=[],n.webglRenderContext=null,n.webglRenderContext=e,n.book=new t.Book(r,i),n}return __extends(s,o),s.analysisTextNodeAndFlushDrawLabel=function(a){if(a){if(!t.__textAtlasRender__){var o=e.web.WebGLRenderContext.getInstance(0,0);t.__textAtlasRender__=new s(o,512,r?12:1)}a[t.property_drawLabel]=a[t.property_drawLabel]||[];for(var l=a[t.property_drawLabel],c=0,h=l;cm;m+=d){p=f[m+0],v=f[m+1],g=f[m+2],x=f[m+3]||{},y.length=0,t.__textAtlasRender__.convertLabelStringToTextAtlas(g,new n(a,x),y);var u=i.create();u.anchorX=p,u.anchorY=v,u.textBlocks=[].concat(y),l.push(u)}}},s.prototype.convertLabelStringToTextAtlas=function(t,i,n){for(var a=this.canvas,o=this.charImageRender,s=this.textBlockMap,l=0,c=t;la;a++){var o=t.getActiveAttrib(r,a),s=o.name,l=new e.EgretWebGLAttribute(t,r,o);i[s]=l}return i}function n(t,r){for(var i={},n=t.getProgramParameter(r,t.ACTIVE_UNIFORMS),a=0;n>a;a++){var o=t.getActiveUniform(r,a),s=o.name,l=new e.EgretWebGLUniform(t,r,o);i[s]=l}return i}var a=function(){function e(e,a,o){this.vshaderSource=a,this.fshaderSource=o,this.vertexShader=t(e,e.VERTEX_SHADER,this.vshaderSource),this.fragmentShader=t(e,e.FRAGMENT_SHADER,this.fshaderSource),this.id=r(e,this.vertexShader,this.fragmentShader),this.uniforms=n(e,this.id),this.attributes=i(e,this.id)}return e.getProgram=function(t,r,i,n){return this.programCache[n]||(this.programCache[n]=new e(t,r,i)),this.programCache[n]},e.deleteProgram=function(e,t,r,i){},e.programCache={},e}();e.EgretWebGLProgram=a,__reflect(a.prototype,"egret.web.EgretWebGLProgram")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(e,t,r){this.gl=e,this.name=r.name,this.type=r.type,this.size=r.size,this.location=e.getUniformLocation(t,this.name),this.setDefaultValue(),this.generateSetValue(),this.generateUpload()}return e.prototype.setDefaultValue=function(){var e=this.type;switch(e){case 5126:case 35678:case 35680:case 35670:case 5124:this.value=0;break;case 35664:case 35671:case 35667:this.value=[0,0];break;case 35665:case 35672:case 35668:this.value=[0,0,0];break;case 35666:case 35673:case 35669:this.value=[0,0,0,0];break;case 35674:this.value=new Float32Array([1,0,0,1]);break;case 35675:this.value=new Float32Array([1,0,0,0,1,0,0,0,1]);break;case 35676:this.value=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}},e.prototype.generateSetValue=function(){var e=this.type;switch(e){case 5126:case 35678:case 35680:case 35670:case 5124:this.setValue=function(e){var t=this.value!==e;this.value=e,t&&this.upload()};break;case 35664:case 35671:case 35667:this.setValue=function(e){var t=this.value[0]!==e.x||this.value[1]!==e.y;this.value[0]=e.x,this.value[1]=e.y,t&&this.upload()};break;case 35665:case 35672:case 35668:this.setValue=function(e){this.value[0]=e.x,this.value[1]=e.y,this.value[2]=e.z,this.upload()};break;case 35666:case 35673:case 35669:this.setValue=function(e){this.value[0]=e.x,this.value[1]=e.y,this.value[2]=e.z,this.value[3]=e.w,this.upload()};break;case 35674:case 35675:case 35676:this.setValue=function(e){this.value.set(e),this.upload()}}},e.prototype.generateUpload=function(){var e=this.gl,t=this.type,r=this.location;switch(t){case 5126:this.upload=function(){var t=this.value;e.uniform1f(r,t)};break;case 35664:this.upload=function(){var t=this.value;e.uniform2f(r,t[0],t[1])};break;case 35665:this.upload=function(){var t=this.value;e.uniform3f(r,t[0],t[1],t[2])};break;case 35666:this.upload=function(){var t=this.value;e.uniform4f(r,t[0],t[1],t[2],t[3])};break;case 35678:case 35680:case 35670:case 5124:this.upload=function(){var t=this.value;e.uniform1i(r,t)};break;case 35671:case 35667:this.upload=function(){var t=this.value;e.uniform2i(r,t[0],t[1])};break;case 35672:case 35668:this.upload=function(){var t=this.value;e.uniform3i(r,t[0],t[1],t[2])};break;case 35673:case 35669:this.upload=function(){var t=this.value;e.uniform4i(r,t[0],t[1],t[2],t[3])};break;case 35674:this.upload=function(){var t=this.value;e.uniformMatrix2fv(r,!1,t)};break;case 35675:this.upload=function(){var t=this.value;e.uniformMatrix3fv(r,!1,t)};break;case 35676:this.upload=function(){var t=this.value;e.uniformMatrix4fv(r,!1,t)}}},e}();e.EgretWebGLUniform=t,__reflect(t.prototype,"egret.web.EgretWebGLUniform")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(){}return e.blur_frag="precision mediump float;\r\nuniform vec2 blur;\r\nuniform sampler2D uSampler;\r\nvarying vec2 vTextureCoord;\r\nuniform vec2 uTextureSize;\r\nvoid main()\r\n{\r\n const int sampleRadius = 5;\r\n const int samples = sampleRadius * 2 + 1;\r\n vec2 blurUv = blur / uTextureSize;\r\n vec4 color = vec4(0, 0, 0, 0);\r\n vec2 uv = vec2(0.0, 0.0);\r\n blurUv /= float(sampleRadius);\r\n\r\n for (int i = -sampleRadius; i <= sampleRadius; i++) {\r\n uv.x = vTextureCoord.x + float(i) * blurUv.x;\r\n uv.y = vTextureCoord.y + float(i) * blurUv.y;\r\n color += texture2D(uSampler, uv);\r\n }\r\n\r\n color /= float(samples);\r\n gl_FragColor = color;\r\n}",e.colorTransform_frag="precision mediump float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform mat4 matrix;\r\nuniform vec4 colorAdd;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n vec4 texColor = texture2D(uSampler, vTextureCoord);\r\n if(texColor.a > 0.) {\r\n // 抵消预乘的alpha通道\r\n texColor = vec4(texColor.rgb / texColor.a, texColor.a);\r\n }\r\n vec4 locColor = clamp(texColor * matrix + colorAdd, 0., 1.);\r\n gl_FragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);\r\n}",e.default_vert="attribute vec2 aVertexPosition;\r\nattribute vec2 aTextureCoord;\r\nattribute vec4 aColor;\r\n\r\nuniform vec2 projectionVector;\r\n// uniform vec2 offsetVector;\r\n\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nconst vec2 center = vec2(-1.0, 1.0);\r\n\r\nvoid main(void) {\r\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\r\n vTextureCoord = aTextureCoord;\r\n vColor = aColor;\r\n}",e.glow_frag="precision highp float;\r\nvarying vec2 vTextureCoord;\r\n\r\nuniform sampler2D uSampler;\r\n\r\nuniform float dist;\r\nuniform float angle;\r\nuniform vec4 color;\r\nuniform float alpha;\r\nuniform float blurX;\r\nuniform float blurY;\r\n// uniform vec4 quality;\r\nuniform float strength;\r\nuniform float inner;\r\nuniform float knockout;\r\nuniform float hideObject;\r\n\r\nuniform vec2 uTextureSize;\r\n\r\nfloat random(vec2 scale)\r\n{\r\n return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);\r\n}\r\n\r\nvoid main(void) {\r\n vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);\r\n // TODO 自动调节采样次数?\r\n const float linearSamplingTimes = 7.0;\r\n const float circleSamplingTimes = 12.0;\r\n vec4 ownColor = texture2D(uSampler, vTextureCoord);\r\n vec4 curColor;\r\n float totalAlpha = 0.0;\r\n float maxTotalAlpha = 0.0;\r\n float curDistanceX = 0.0;\r\n float curDistanceY = 0.0;\r\n float offsetX = dist * cos(angle) * px.x;\r\n float offsetY = dist * sin(angle) * px.y;\r\n\r\n const float PI = 3.14159265358979323846264;\r\n float cosAngle;\r\n float sinAngle;\r\n float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));\r\n float stepX = blurX * px.x / linearSamplingTimes;\r\n float stepY = blurY * px.y / linearSamplingTimes;\r\n for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {\r\n cosAngle = cos(a + offset);\r\n sinAngle = sin(a + offset);\r\n for (float i = 1.0; i <= linearSamplingTimes; i++) {\r\n curDistanceX = i * stepX * cosAngle;\r\n curDistanceY = i * stepY * sinAngle;\r\n if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0){\r\n curColor = texture2D(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));\r\n totalAlpha += (linearSamplingTimes - i) * curColor.a;\r\n }\r\n maxTotalAlpha += (linearSamplingTimes - i);\r\n }\r\n }\r\n\r\n ownColor.a = max(ownColor.a, 0.0001);\r\n ownColor.rgb = ownColor.rgb / ownColor.a;\r\n\r\n float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1. - inner) * max(min(hideObject, knockout), 1. - ownColor.a);\r\n float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;\r\n\r\n ownColor.a = max(ownColor.a * knockout * (1. - hideObject), 0.0001);\r\n vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));\r\n vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));\r\n float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.);\r\n gl_FragColor = vec4(mix2 * resultAlpha, resultAlpha);\r\n}",e.primitive_frag="precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n gl_FragColor = vColor;\r\n}",e.texture_frag="precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;\r\n}",e.texture_etc_alphamask_frag="precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uSampler;\r\nuniform sampler2D uSamplerAlphaMask;\r\nvoid main(void) {\r\nfloat alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r;\r\nif (alpha < 0.0039) { discard; }\r\nvec4 v4Color = texture2D(uSampler, vTextureCoord);\r\nv4Color.rgb = v4Color.rgb * alpha;\r\nv4Color.a = alpha;\r\ngl_FragColor = v4Color * vColor;\r\n}",e.colorTransform_frag_etc_alphamask_frag="precision mediump float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform mat4 matrix;\r\nuniform vec4 colorAdd;\r\nuniform sampler2D uSampler;\r\nuniform sampler2D uSamplerAlphaMask;\r\n\r\nvoid main(void){\r\nfloat alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r;\r\nif (alpha < 0.0039) { discard; }\r\nvec4 texColor = texture2D(uSampler, vTextureCoord);\r\nif(texColor.a > 0.0) {\r\n // 抵消预乘的alpha通道\r\ntexColor = vec4(texColor.rgb / texColor.a, texColor.a);\r\n}\r\nvec4 v4Color = clamp(texColor * matrix + colorAdd, 0.0, 1.0);\r\nv4Color.rgb = v4Color.rgb * alpha;\r\nv4Color.a = alpha;\r\ngl_FragColor = v4Color * vColor;\r\n}",e }();e.EgretShaderLib=t,__reflect(t.prototype,"egret.web.EgretShaderLib")}(t=e.web||(e.web={}))}(egret||(egret={})); \ No newline at end of file diff --git a/demo/src/game/MainScene.ts b/demo/src/game/MainScene.ts index 595e4b88..543c2f4d 100644 --- a/demo/src/game/MainScene.ts +++ b/demo/src/game/MainScene.ts @@ -18,11 +18,11 @@ class MainScene extends Scene { bg.addComponent(new BoxCollider()); bg.position = new Vector2(Math.random() * 200, Math.random() * 200); - for (let i = 0; i < 20; i++) { + for (let i = 0; i < 1; i++) { let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); let player2 = this.createEntity("player2"); player2.addComponent(new SpriteRenderer()).setSprite(sprite); - player2.position = new Vector2(Math.random() * 1000, Math.random() * 1000); + player2.position = new Vector2(Math.random() * 100, Math.random() * 100); player2.addComponent(new BoxCollider()); } diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index c4a9c71c..9ab1a179 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -245,7 +245,7 @@ declare class Entity extends egret.DisplayObjectContainer { getOrCreateComponent(type: T): T; getComponent(type: any): T; getComponents(typeName: string | any, componentList?: any): any; - private onEntityTransformChanged; + onEntityTransformChanged(comp: TransformComponent): void; removeComponentForType(type: any): boolean; removeComponent(component: Component): void; removeAllComponents(): void; @@ -300,6 +300,7 @@ declare class SceneManager { static emitter: Emitter; static content: ContentManager; private static _instnace; + private static timerRuler; static readonly Instance: SceneManager; constructor(stage: egret.Stage); static scene: Scene; @@ -309,6 +310,8 @@ declare class SceneManager { static startSceneTransition(sceneTransition: T): T; static registerActiveSceneChanged(current: Scene, next: Scene): void; onSceneChanged(): void; + private static startDebugUpdate; + private static endDebugUpdate; } declare class Camera extends Component { private _zoom; @@ -488,14 +491,10 @@ declare abstract class Collider extends Component { registeredPhysicsBounds: Rectangle; shouldColliderScaleAndRotateWithTransform: boolean; collidesWithLayers: number; - _localOffsetLength: number; protected _isParentEntityAddedToScene: any; protected _colliderRequiresAutoSizing: any; - protected _localOffset: Vector2; protected _isColliderRegistered: any; readonly bounds: Rectangle; - localOffset: Vector2; - setLocalOffset(offset: Vector2): void; registerColliderWithPhysicsSystem(): void; unregisterColliderWithPhysicsSystem(): void; overlaps(other: Collider): any; @@ -958,8 +957,8 @@ declare class Physics { } declare abstract class Shape extends egret.DisplayObject { abstract bounds: Rectangle; - position: Vector2; abstract center: Vector2; + abstract position: Vector2; abstract pointCollidesWithShape(point: Vector2): CollisionResult; abstract overlaps(other: Shape): any; abstract collidesWithShape(other: Shape): CollisionResult; @@ -970,6 +969,7 @@ declare class Polygon extends Shape { private _areEdgeNormalsDirty; protected _originalPoints: Vector2[]; center: Vector2; + readonly position: Vector2; readonly bounds: Rectangle; _edgeNormals: Vector2[]; readonly edgeNormals: Vector2[]; @@ -1003,6 +1003,7 @@ declare class Circle extends Shape { radius: number; _originalRadius: number; center: Vector2; + readonly position: Vector2; readonly bounds: Rectangle; constructor(radius: number); pointCollidesWithShape(point: Vector2): CollisionResult; @@ -1409,6 +1410,7 @@ declare class MarkerCollection { markCount: number; markerNests: number[]; nestCount: number; + constructor(); } declare class Marker { markerId: number; diff --git a/source/bin/framework.js b/source/bin/framework.js index 40a8a0d3..c729622d 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1403,6 +1403,7 @@ var SceneManager = (function () { SceneManager.content = new ContentManager(); SceneManager.stage = stage; SceneManager.initialize(stage); + SceneManager.timerRuler = new TimeRuler(); } Object.defineProperty(SceneManager, "Instance", { get: function () { @@ -1435,6 +1436,7 @@ var SceneManager = (function () { Input.initialize(stage); }; SceneManager.update = function () { + SceneManager.startDebugUpdate(); Time.update(egret.getTimer()); if (SceneManager._scene) { for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { @@ -1453,6 +1455,7 @@ var SceneManager = (function () { SceneManager._scene.begin(); } } + SceneManager.endDebugUpdate(); SceneManager.render(); }; SceneManager.render = function () { @@ -1493,6 +1496,13 @@ var SceneManager = (function () { SceneManager.emitter.emit(CoreEvents.SceneChanged); Time.sceneChanged(); }; + SceneManager.startDebugUpdate = function () { + TimeRuler.Instance.startFrame(); + TimeRuler.Instance.beginMark("update", 0x00FF00); + }; + SceneManager.endDebugUpdate = function () { + TimeRuler.Instance.endMark("update"); + }; return SceneManager; }()); var Camera = (function (_super) { @@ -1866,8 +1876,12 @@ var SpriteRenderer = (function (_super) { return this.isVisible; }; SpriteRenderer.prototype.render = function (camera) { - this.x = -camera.position.x + camera.origin.x; - this.y = -camera.position.y + camera.origin.y; + if (this.x != -camera.position.x + camera.origin.x || + this.y != -camera.position.y + camera.origin.y) { + this.x = -camera.position.x + camera.origin.x; + this.y = -camera.position.y + camera.origin.y; + this.entity.onEntityTransformChanged(TransformComponent.position); + } }; SpriteRenderer.prototype.onRemovedFromEntity = function () { if (this.parent) @@ -2192,36 +2206,17 @@ var Collider = (function (_super) { _this.registeredPhysicsBounds = new Rectangle(); _this.shouldColliderScaleAndRotateWithTransform = true; _this.collidesWithLayers = Physics.allLayers; - _this._localOffset = new Vector2(0, 0); return _this; } Object.defineProperty(Collider.prototype, "bounds", { get: function () { var shapeBounds = this.shape.bounds; - var colliderBuonds = new Rectangle(this.x + this.localOffset.x, this.y + this.localOffset.y, shapeBounds.width, shapeBounds.height); + var colliderBuonds = new Rectangle(this.entity.x, this.entity.y, shapeBounds.width, shapeBounds.height); return colliderBuonds; }, enumerable: true, configurable: true }); - Object.defineProperty(Collider.prototype, "localOffset", { - get: function () { - return this._localOffset; - }, - set: function (value) { - this.setLocalOffset(value); - }, - enumerable: true, - configurable: true - }); - Collider.prototype.setLocalOffset = function (offset) { - if (this._localOffset != offset) { - this.unregisterColliderWithPhysicsSystem(); - this._localOffset = offset; - this._localOffsetLength = this._localOffset.length(); - this.registerColliderWithPhysicsSystem(); - } - }; Collider.prototype.registerColliderWithPhysicsSystem = function () { if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { Physics.addCollider(this); @@ -2238,12 +2233,12 @@ var Collider = (function (_super) { return this.shape.overlaps(other.shape); }; Collider.prototype.collidesWith = function (collider, motion) { - var oldPosition = this.shape.position; - this.shape.position = Vector2.add(this.shape.position, motion); + var oldPosition = this.entity.position; + this.entity.position = Vector2.add(this.entity.position, motion); var result = this.shape.collidesWithShape(collider.shape); if (result) result.collider = collider; - this.shape.position = oldPosition; + this.entity.position = oldPosition; return result; }; Collider.prototype.onAddedToEntity = function () { @@ -2259,13 +2254,12 @@ var Collider = (function (_super) { if (this instanceof CircleCollider) { var circleCollider = this; circleCollider.radius = Math.max(width, height) * 0.5; - this.localOffset = bounds.location; } else { this.width = width; this.height = height; - this.localOffset = bounds.location; } + this.addChild(this.shape); } else { console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); @@ -2277,6 +2271,7 @@ var Collider = (function (_super) { Collider.prototype.onRemovedFromEntity = function () { this.unregisterColliderWithPhysicsSystem(); this._isParentEntityAddedToScene = false; + this.removeChild(this.shape); }; Collider.prototype.onEnabled = function () { this.registerColliderWithPhysicsSystem(); @@ -2291,8 +2286,8 @@ var Collider = (function (_super) { Collider.prototype.update = function () { var renderable = this.entity.getComponent(RenderableComponent); if (renderable) { - this.$setX(renderable.x + this.localOffset.x); - this.$setY(renderable.y + this.localOffset.y); + this.$setX(renderable.x); + this.$setY(renderable.y); } }; return Collider; @@ -2395,8 +2390,6 @@ var PolygonCollider = (function (_super) { var isPolygonClosed = points[0] == points[points.length - 1]; if (isPolygonClosed) points.splice(points.length - 1, 1); - var center = Polygon.findPolygonCenter(points); - _this.setLocalOffset(center); Polygon.recenterPolygonVerts(points); _this.shape = new Polygon(points); return _this; @@ -4697,9 +4690,7 @@ var Physics = (function () { var Shape = (function (_super) { __extends(Shape, _super); function Shape() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.position = Vector2.zero; - return _this; + return _super !== null && _super.apply(this, arguments) || this; } return Shape; }(egret.DisplayObject)); @@ -4713,9 +4704,16 @@ var Polygon = (function (_super) { _this.isBox = isBox; return _this; } + Object.defineProperty(Polygon.prototype, "position", { + get: function () { + return new Vector2(this.parent.x, this.parent.y); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Polygon.prototype, "bounds", { get: function () { - return new Rectangle(0, 0, this.width, this.height); + return new Rectangle(this.x, this.y, this.width, this.height); }, enumerable: true, configurable: true @@ -4903,6 +4901,13 @@ var Circle = (function (_super) { _this._originalRadius = radius; return _this; } + Object.defineProperty(Circle.prototype, "position", { + get: function () { + return new Vector2(this.parent.x, this.parent.y); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Circle.prototype, "bounds", { get: function () { return new Rectangle().setEgretRect(this.getBounds()); @@ -5175,7 +5180,8 @@ var SpatialHash = (function () { for (var x = p1.x; x <= p2.x; x++) { for (var y = p1.y; y <= p2.y; y++) { var c = this.cellAtPosition(x, y, true); - c.push(collider); + if (c.indexOf(collider) == -1) + c.push(collider); } } }; @@ -5185,7 +5191,6 @@ var SpatialHash = (function () { SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; - this._overlapTestCircle.position = circleCenter; var resultCounter = 0; var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); bounds = aabbBroadphaseResult.bounds; @@ -6618,6 +6623,8 @@ var TimeRuler = (function () { var lock = new LockUtils(this._frameKey); lock.lock().then(function () { _this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10); + if (isNaN(_this._updateCount)) + _this._updateCount = 0; var count = _this._updateCount; count += 1; egret.localStorage.setItem(_this._frameKey, count.toString()); @@ -6684,7 +6691,7 @@ var TimeRuler = (function () { throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); } var markerId = _this._markerNameToIdMap.get(markerName); - if (!markerId) { + if (isNaN(markerId)) { markerId = _this.markers.length; _this._markerNameToIdMap.set(markerName, markerId); } @@ -6707,7 +6714,7 @@ var TimeRuler = (function () { throw new Error("call beginMark method before calling endMark method"); } var markerId = _this._markerNameToIdMap.get(markerName); - if (!markerId) { + if (isNaN(markerId)) { throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method"); } var markerIdx = bar.markerNests[--bar.nestCount]; @@ -6780,7 +6787,7 @@ var TimeRuler = (function () { var startY = position.y - (height - TimeRuler.barHeight); var y = startY; }; - TimeRuler.maxBars = 0; + TimeRuler.maxBars = 8; TimeRuler.maxSamples = 256; TimeRuler.maxNestCall = 32; TimeRuler.barHeight = 8; @@ -6793,20 +6800,27 @@ var TimeRuler = (function () { var FrameLog = (function () { function FrameLog() { this.bars = new Array(TimeRuler.maxBars); - for (var i = 0; i < TimeRuler.maxBars; ++i) - this.bars[i] = new MarkerCollection(); + this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); } return FrameLog; }()); var MarkerCollection = (function () { function MarkerCollection() { this.markers = new Array(TimeRuler.maxSamples); + this.markCount = 0; this.markerNests = new Array(TimeRuler.maxNestCall); + this.nestCount = 0; + this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); + this.markerNests.fill(0, 0, TimeRuler.maxNestCall); } return MarkerCollection; }()); var Marker = (function () { function Marker() { + this.markerId = 0; + this.beginTime = 0; + this.endTime = 0; + this.color = 0x000000; } return Marker; }()); @@ -6814,11 +6828,21 @@ var MarkerInfo = (function () { function MarkerInfo(name) { this.logs = new Array(TimeRuler.maxBars); this.name = name; + this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); } return MarkerInfo; }()); var MarkerLog = (function () { function MarkerLog() { + this.snapMin = 0; + this.snapMax = 0; + this.snapAvg = 0; + this.min = 0; + this.max = 0; + this.avg = 0; + this.samples = 0; + this.color = 0x000000; + this.initialized = false; } return MarkerLog; }()); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index aade8e71..d6c96e6d 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enable=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.position=Vector2.zero,e}return __extends(e,t),e}(egret.DisplayObject),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(0,0,this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(Long.fromNumber(e,!1)).toString()},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);s||(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(!o)throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=0,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars);for(var t=0;t0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.endDebugUpdate(),t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t.startDebugUpdate=function(){TimeRuler.Instance.startFrame(),TimeRuler.Instance.beginMark("update",65280)},t.endDebugUpdate=function(){TimeRuler.Instance.endMark("update")},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x==-t.position.x+t.origin.x&&this.y==-t.position.y+t.origin.y||(this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y,this.entity.onEntityTransformChanged(TransformComponent.position))},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t, e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(egret.DisplayObject),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.parent.x,this.parent.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.x,this.y,this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(Long.fromNumber(e,!1)).toString()},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(isNaN(o))throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=8,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars),this.bars.fill(new MarkerCollection,0,TimeRuler.maxBars)}}(),MarkerCollection=function(){return function(){this.markers=new Array(TimeRuler.maxSamples),this.markCount=0,this.markerNests=new Array(TimeRuler.maxNestCall),this.nestCount=0,this.markers.fill(new Marker,0,TimeRuler.maxSamples),this.markerNests.fill(0,0,TimeRuler.maxNestCall)}}(),Marker=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}(),MarkerInfo=function(){return function(t){this.logs=new Array(TimeRuler.maxBars),this.name=t,this.logs.fill(new MarkerLog,0,TimeRuler.maxBars)}}(),MarkerLog=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}(); \ No newline at end of file diff --git a/source/src/ECS/Component.ts b/source/src/ECS/Component.ts index 9ee0a44b..da4dbcf1 100644 --- a/source/src/ECS/Component.ts +++ b/source/src/ECS/Component.ts @@ -1,96 +1,137 @@ -abstract class Component extends egret.DisplayObjectContainer { - public entity: Entity; - private _enabled: boolean = true; - public updateInterval: number = 1; - /** 允许用户为实体存入信息 */ - public userData: any; - private _updateOrder = 0; - - public get enabled(){ - return this.entity ? this.entity.enabled && this._enabled : this._enabled; - } - - public set enabled(value: boolean){ - this.setEnabled(value); - } - - public get localPosition(){ - return new Vector2(this.entity.x + this.x, this.entity.y + this.y); - } - - public setEnabled(isEnabled: boolean){ - if (this._enabled != isEnabled){ - this._enabled = isEnabled; - - if (this._enabled){ - this.onEnabled(); - }else{ - this.onDisabled(); - } - } - - return this; - } - - /** 更新此实体上组件的顺序 */ - public get updateOrder(){ - return this._updateOrder; - } - /** 更新此实体上组件的顺序 */ - public set updateOrder(value: number){ - this.setUpdateOrder(value); - } - public setUpdateOrder(updateOrder: number){ - if (this._updateOrder != updateOrder){ - this._updateOrder = updateOrder; - } - - return this; - } - - public initialize(){ - } - - public onAddedToEntity(){ - - } - - public onRemovedFromEntity(){ - - } - - public onEnabled(){ - - } - - public onDisabled(){ - - } - - public debugRender(){ - - } - - public update(){ - - } - +module es { /** - * 当实体的位置改变时调用。这允许组件知道它们由于父实体的移动而移动了。 - * @param comp + * 执行顺序 + * - onAddedToEntity + * - OnEnabled + * + * 删除执行顺序 + * - onRemovedFromEntity */ - public onEntityTransformChanged(comp: TransformComponent){ + export abstract class Component { + /** + * 此组件附加的实体 + */ + public entity: Entity; - } + /** + * 快速访问 this.entity.transform + */ + public get transform(): Transform { + return this.entity.transform; + } - /** 内部使用 运行时不应该调用 */ - public registerComponent(){ - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false); - this.entity.scene.entityProcessors.onComponentAdded(this.entity); - } + /** + * 如果组件和实体都已启用,则为。当启用该组件时,将调用该组件的生命周期方法。状态的改变会导致调用onEnabled/onDisable。 + */ + public get enabled() { + return this.entity ? this.entity.enabled && this._enabled : this._enabled; + } - public deregisterComponent(){ - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)); - this.entity.scene.entityProcessors.onComponentRemoved(this.entity); + /** + * 如果组件和实体都已启用,则为。当启用该组件时,将调用该组件的生命周期方法。状态的改变会导致调用onEnabled/onDisable。 + * @param value + */ + public set enabled(value: boolean) { + this.setEnabled(value); + } + + /** 更新此实体上组件的顺序 */ + public get updateOrder() { + return this._updateOrder; + } + + /** 更新此实体上组件的顺序 */ + public set updateOrder(value: number) { + this.setUpdateOrder(value); + } + + /** + * 更新该组件的时间间隔。这与实体的更新间隔无关。 + */ + public updateInterval: number = 1; + + private _enabled: boolean = true; + private _updateOrder = 0; + + /** + * 当此组件已分配其实体,但尚未添加到实体的活动组件列表时调用。有用的东西,如物理组件,需要访问转换来修改碰撞体的属性。 + */ + public initialize() { + } + + /** + * 在提交所有挂起的组件更改后,将该组件添加到场景时调用。此时,设置了实体字段和实体。场景也设定好了。 + */ + public onAddedToEntity() { + } + + /** + * 当此组件从其实体中移除时调用。在这里做所有的清理工作。 + */ + public onRemovedFromEntity() { + } + + /** + * 当实体的位置改变时调用。这允许组件知道它们由于父实体的移动而移动了。 + * @param comp + */ + public onEntityTransformChanged(comp: Transform.Component) { + } + + /** + * + */ + public debugRender() { + } + + /** + *当父实体或此组件启用时调用 + */ + public onEnabled() { + } + + /** + * 禁用父实体或此组件时调用 + */ + public onDisabled() { + } + + /** + * 当该组件启用时每帧进行调用 + */ + public update() { + } + + public setEnabled(isEnabled: boolean) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + + if (this._enabled) { + this.onEnabled(); + } else { + this.onDisabled(); + } + } + + return this; + } + + public setUpdateOrder(updateOrder: number) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; + } + + return this; + } + + /** + * 创建此组件的克隆 + */ + public clone(): Component { + let component = ObjectUtils.clone(this); + component.entity = null; + + return component; + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Camera.ts b/source/src/ECS/Components/Camera.ts index 7468acad..d6a1f354 100644 --- a/source/src/ECS/Components/Camera.ts +++ b/source/src/ECS/Components/Camera.ts @@ -1,234 +1,236 @@ -class Camera extends Component { - private _zoom; - private _origin: Vector2 = Vector2.zero; +module es { + export class Camera extends Component { + private _zoom; + private _origin: Vector2 = Vector2.zero; - private _minimumZoom = 0.3; - private _maximumZoom = 3; + private _minimumZoom = 0.3; + private _maximumZoom = 3; - private _position: Vector2 = Vector2.zero; - /** - * 如果相机模式为cameraWindow 则会进行缓动移动 - * 该值为移动速度 - */ - public followLerp = 0.1; - public deadzone: Rectangle = new Rectangle(); - /** 锁定偏移量 默认中心 */ - public focusOffset: Vector2 = new Vector2(); - /** 是否地图锁定 如果锁定则需要设置mapSize属性 */ - public mapLockEnabled: boolean = false; - /** 设置地图大小 默认从0 0左上角开始 只需要输入地图宽高 */ - public mapSize: Vector2 = new Vector2(); - /** 跟随的实体 设置后镜头将锁定目标为中心 */ - public targetEntity: Entity; - private _worldSpaceDeadZone: Rectangle = new Rectangle(); - private _desiredPositionDelta: Vector2 = new Vector2(); - private _targetCollider: Collider; - /** 相机模式 */ - public cameraStyle: CameraStyle = CameraStyle.lockOn; + private _position: Vector2 = Vector2.zero; + /** + * 如果相机模式为cameraWindow 则会进行缓动移动 + * 该值为移动速度 + */ + public followLerp = 0.1; + public deadzone: Rectangle = new Rectangle(); + /** 锁定偏移量 默认中心 */ + public focusOffset: Vector2 = new Vector2(); + /** 是否地图锁定 如果锁定则需要设置mapSize属性 */ + public mapLockEnabled: boolean = false; + /** 设置地图大小 默认从0 0左上角开始 只需要输入地图宽高 */ + public mapSize: Vector2 = new Vector2(); + /** 跟随的实体 设置后镜头将锁定目标为中心 */ + public targetEntity: Entity; + private _worldSpaceDeadZone: Rectangle = new Rectangle(); + private _desiredPositionDelta: Vector2 = new Vector2(); + private _targetCollider: Collider; + /** 相机模式 */ + public cameraStyle: CameraStyle = CameraStyle.lockOn; - public get zoom(){ - if (this._zoom == 0) - return 1; + public get zoom(){ + if (this._zoom == 0) + return 1; - if (this._zoom < 1) - return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); + if (this._zoom < 1) + return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); - return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); - } - - public set zoom(value: number){ - this.setZoom(value); - } - - public get minimumZoom(){ - return this._minimumZoom; - } - - public set minimumZoom(value: number){ - this.setMinimumZoom(value); - } - - public get maximumZoom(){ - return this._maximumZoom; - } - - public set maximumZoom(value: number){ - this.setMaximumZoom(value); - } - - public get origin(){ - return this._origin; - } - - public set origin(value: Vector2){ - if (this._origin != value){ - this._origin = value; - } - } - - public get position(){ - return this._position; - } - - public set position(value: Vector2){ - this._position = value; - } - - public get x(){ - return this._position.x; - } - public set x(value: number){ - this._position.x = value; - } - public get y(){ - return this._position.y; - } - public set y(value: number){ - this._position.y = value; - } - - constructor() { - super(); - - this.width = SceneManager.stage.stageWidth; - this.height = SceneManager.stage.stageHeight; - this.setZoom(0); - } - - public onSceneSizeChanged(newWidth: number, newHeight: number){ - let oldOrigin = this._origin; - this.origin = new Vector2(newWidth / 2, newHeight / 2); - - this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); - } - - public setMinimumZoom(minZoom: number): Camera{ - if (this._zoom < minZoom) - this._zoom = this.minimumZoom; - - this._minimumZoom = minZoom; - return this; - } - - public setMaximumZoom(maxZoom: number): Camera { - if (this._zoom > maxZoom) - this._zoom = maxZoom; - - this._maximumZoom = maxZoom; - return this; - } - - public setZoom(zoom: number): Camera{ - let newZoom = MathHelper.clamp(zoom, -1, 1); - if (newZoom == 0){ - this._zoom = 1; - } else if(newZoom < 0){ - this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); - } else { - this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); + return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); } - SceneManager.scene.scaleX = this._zoom; - SceneManager.scene.scaleY = this._zoom; - return this; - } - - public setRotation(rotation: number): Camera { - SceneManager.scene.rotation = rotation; - return this; - } - - public setPosition(position: Vector2){ - this.entity.position = position; - - return this; - } - - public follow(targetEntity: Entity, cameraStyle: CameraStyle = CameraStyle.cameraWindow){ - this.targetEntity = targetEntity; - this.cameraStyle = cameraStyle; - let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - - switch (this.cameraStyle){ - case CameraStyle.cameraWindow: - let w = cameraBounds.width / 6; - let h = cameraBounds.height / 3; - this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10); - break; + public set zoom(value: number){ + this.setZoom(value); } - } - public update(){ - let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - let halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); - this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; - this._worldSpaceDeadZone.width = this.deadzone.width; - this._worldSpaceDeadZone.height = this.deadzone.height; + public get minimumZoom(){ + return this._minimumZoom; + } - if (this.targetEntity) - this.updateFollow(); + public set minimumZoom(value: number){ + this.setMinimumZoom(value); + } - this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); - this.entity.roundPosition(); + public get maximumZoom(){ + return this._maximumZoom; + } - if (this.mapLockEnabled){ - this.position = this.clampToMapSize(this.position); + public set maximumZoom(value: number){ + this.setMaximumZoom(value); + } + + public get origin(){ + return this._origin; + } + + public set origin(value: Vector2){ + if (this._origin != value){ + this._origin = value; + } + } + + public get position(){ + return this._position; + } + + public set position(value: Vector2){ + this._position = value; + } + + public get x(){ + return this._position.x; + } + public set x(value: number){ + this._position.x = value; + } + public get y(){ + return this._position.y; + } + public set y(value: number){ + this._position.y = value; + } + + constructor() { + super(); + + this.width = SceneManager.stage.stageWidth; + this.height = SceneManager.stage.stageHeight; + this.setZoom(0); + } + + public onSceneSizeChanged(newWidth: number, newHeight: number){ + let oldOrigin = this._origin; + this.origin = new Vector2(newWidth / 2, newHeight / 2); + + this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); + } + + public setMinimumZoom(minZoom: number): Camera{ + if (this._zoom < minZoom) + this._zoom = this.minimumZoom; + + this._minimumZoom = minZoom; + return this; + } + + public setMaximumZoom(maxZoom: number): Camera { + if (this._zoom > maxZoom) + this._zoom = maxZoom; + + this._maximumZoom = maxZoom; + return this; + } + + public setZoom(zoom: number): Camera{ + let newZoom = MathHelper.clamp(zoom, -1, 1); + if (newZoom == 0){ + this._zoom = 1; + } else if(newZoom < 0){ + this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); + } else { + this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); + } + + SceneManager.scene.scaleX = this._zoom; + SceneManager.scene.scaleY = this._zoom; + return this; + } + + public setRotation(rotation: number): Camera { + SceneManager.scene.rotation = rotation; + return this; + } + + public setPosition(position: Vector2){ + this.entity.position = position; + + return this; + } + + public follow(targetEntity: Entity, cameraStyle: CameraStyle = CameraStyle.cameraWindow){ + this.targetEntity = targetEntity; + this.cameraStyle = cameraStyle; + let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + + switch (this.cameraStyle){ + case CameraStyle.cameraWindow: + let w = cameraBounds.width / 6; + let h = cameraBounds.height / 3; + this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h); + break; + case CameraStyle.lockOn: + this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10); + break; + } + } + + public update(){ + let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + let halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.width = this.deadzone.width; + this._worldSpaceDeadZone.height = this.deadzone.height; + + if (this.targetEntity) + this.updateFollow(); + + this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); this.entity.roundPosition(); + + if (this.mapLockEnabled){ + this.position = this.clampToMapSize(this.position); + this.entity.roundPosition(); + } + } + + private clampToMapSize(position: Vector2){ + let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + let halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); + let cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); + + return Vector2.clamp(position, halfScreen, cameraMax); + } + + private updateFollow(){ + this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; + + if (this.cameraStyle == CameraStyle.lockOn){ + let targetX = this.targetEntity.position.x; + let targetY = this.targetEntity.position.y; + + if (this._worldSpaceDeadZone.x > targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + else if(this._worldSpaceDeadZone.x < targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + + if (this._worldSpaceDeadZone.y < targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + else if(this._worldSpaceDeadZone.y > targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + } else { + if (!this._targetCollider){ + this._targetCollider = this.targetEntity.getComponent(Collider); + if (!this._targetCollider) + return; + } + + let targetBounds = this.targetEntity.getComponent(Collider).bounds; + if (!this._worldSpaceDeadZone.containsRect(targetBounds)){ + if (this._worldSpaceDeadZone.left > targetBounds.left) + this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; + else if(this._worldSpaceDeadZone.right < targetBounds.right) + this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; + + if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) + this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; + else if(this._worldSpaceDeadZone.top > targetBounds.top) + this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; + } + } } } - private clampToMapSize(position: Vector2){ - let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - let halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); - let cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); - - return Vector2.clamp(position, halfScreen, cameraMax); - } - - private updateFollow(){ - this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; - - if (this.cameraStyle == CameraStyle.lockOn){ - let targetX = this.targetEntity.position.x; - let targetY = this.targetEntity.position.y; - - if (this._worldSpaceDeadZone.x > targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - else if(this._worldSpaceDeadZone.x < targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - - if (this._worldSpaceDeadZone.y < targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - else if(this._worldSpaceDeadZone.y > targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - } else { - if (!this._targetCollider){ - this._targetCollider = this.targetEntity.getComponent(Collider); - if (!this._targetCollider) - return; - } - - let targetBounds = this.targetEntity.getComponent(Collider).bounds; - if (!this._worldSpaceDeadZone.containsRect(targetBounds)){ - if (this._worldSpaceDeadZone.left > targetBounds.left) - this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; - else if(this._worldSpaceDeadZone.right < targetBounds.right) - this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; - - if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) - this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; - else if(this._worldSpaceDeadZone.top > targetBounds.top) - this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; - } - } + export enum CameraStyle { + lockOn, + cameraWindow, } } - -enum CameraStyle { - lockOn, - cameraWindow, -} \ No newline at end of file diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index 438a727d..c6fe6d02 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -1,6 +1,14 @@ abstract class Collider extends Component { /** 对撞机的基本形状 */ public shape: Shape; + protected _localOffset: Vector2 = Vector2.zero; + public get localOffset(){ + return this._localOffset; + } + public set localOffset(){ + + } + public _localOffsetLength: number; /** 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法。 */ public physicsLayer = 1 << 0; /** 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件 */ @@ -15,38 +23,32 @@ abstract class Collider extends Component { /** 默认为所有层。 */ public collidesWithLayers = Physics.allLayers; - public _localOffsetLength: number; /** 标记来跟踪我们的实体是否被添加到场景中 */ protected _isParentEntityAddedToScene; protected _colliderRequiresAutoSizing; - protected _localOffset: Vector2 = new Vector2(0, 0); /** 标记来记录我们是否注册了物理系统 */ protected _isColliderRegistered; public get bounds(): Rectangle { let shapeBounds = this.shape.bounds; - let colliderBuonds = new Rectangle(this.x + this.localOffset.x, this.y + this.localOffset.y, shapeBounds.width, shapeBounds.height); + let colliderBuonds = new Rectangle(this.entity.x, this.entity.y, shapeBounds.width, shapeBounds.height); return colliderBuonds; } - public get localOffset() { - return this._localOffset; - } - /** - * 将localOffset添加到实体。获取碰撞器的最终位置。这允许您向一个实体添加多个碰撞器并分别定位它们。 + * 将localOffset添加到实体。获取碰撞器的最终位置。 + * 这允许您向一个实体添加多个碰撞器并分别定位它们。 + * @param offset */ - public set localOffset(value: Vector2) { - this.setLocalOffset(value); - } - - public setLocalOffset(offset: Vector2) { - if (this._localOffset != offset) { + public setLocalOffset(offset: Vector2): Collider{ + if (this._localOffset != offset){ this.unregisterColliderWithPhysicsSystem(); this._localOffset = offset; this._localOffsetLength = this._localOffset.length(); this.registerColliderWithPhysicsSystem(); } + + return this; } /** @@ -85,15 +87,15 @@ abstract class Collider extends Component { */ public collidesWith(collider: Collider, motion: Vector2) { // 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠 - let oldPosition = this.shape.position; - this.shape.position = Vector2.add(this.shape.position, motion); + let oldPosition = this.entity.position; + this.entity.position = Vector2.add(this.entity.position, motion); let result = this.shape.collidesWithShape(collider.shape); if (result) result.collider = collider; // 将图形位置返回到检查前的位置 - this.shape.position = oldPosition; + this.entity.position = oldPosition; return result; } @@ -111,19 +113,17 @@ abstract class Collider extends Component { // 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染 let width = bounds.width / this.entity.scale.x; let height = bounds.height / this.entity.scale.y; - // 圆碰撞器需要特别注意原点 if (this instanceof CircleCollider){ let circleCollider = this as CircleCollider; circleCollider.radius = Math.max(width, height) * 0.5; - - this.localOffset = bounds.location; } else { this.width = width; this.height = height; - - this.localOffset = bounds.location; } + + // 获取渲染的中心,将其转移到本地坐标,并使用它作为碰撞器的localOffset + this.localOffset = Vector2.subtract(bounds.center, this.entity.position); } else { console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); } @@ -154,8 +154,8 @@ abstract class Collider extends Component { public update(){ let renderable = this.entity.getComponent(RenderableComponent); if (renderable){ - this.$setX(renderable.x + this.localOffset.x); - this.$setY(renderable.y + this.localOffset.y); + this.$setX(renderable.x); + this.$setY(renderable.y); } } } \ No newline at end of file diff --git a/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts b/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts index fd6ca8cf..e0a934f2 100644 --- a/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts @@ -16,8 +16,6 @@ class PolygonCollider extends Collider { if (isPolygonClosed) points.splice(points.length - 1, 1); - let center = Polygon.findPolygonCenter(points); - this.setLocalOffset(center); Polygon.recenterPolygonVerts(points); this.shape = new Polygon(points); } diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts index 13e39523..32df55cf 100644 --- a/source/src/ECS/Components/SpriteRenderer.ts +++ b/source/src/ECS/Components/SpriteRenderer.ts @@ -1,17 +1,17 @@ -class SpriteRenderer extends RenderableComponent{ +class SpriteRenderer extends RenderableComponent { private _sprite: Sprite; protected bitmap: egret.Bitmap; /** 应该由这个精灵显示的精灵 */ - public get sprite(): Sprite{ + public get sprite(): Sprite { return this._sprite; } /** 应该由这个精灵显示的精灵 */ - public set sprite(value: Sprite){ + public set sprite(value: Sprite) { this.setSprite(value); } - public setSprite(sprite: Sprite): SpriteRenderer{ + public setSprite(sprite: Sprite): SpriteRenderer { this.removeChildren(); this._sprite = sprite; if (this._sprite) { @@ -24,7 +24,7 @@ class SpriteRenderer extends RenderableComponent{ return this; } - public setColor(color: number): SpriteRenderer{ + public setColor(color: number): SpriteRenderer { let colorMatrix = [ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, @@ -40,23 +40,27 @@ class SpriteRenderer extends RenderableComponent{ return this; } - public isVisibleFromCamera(camera: Camera): boolean{ + public isVisibleFromCamera(camera: Camera): boolean { this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); this.visible = this.isVisible; return this.isVisible; } /** 渲染处理 在每个模块中处理各自的渲染逻辑 */ - public render(camera: Camera){ - this.x = -camera.position.x + camera.origin.x; - this.y = -camera.position.y + camera.origin.y; + public render(camera: Camera) { + if (this.x != -camera.position.x + camera.origin.x || + this.y != -camera.position.y + camera.origin.y) { + this.x = -camera.position.x + camera.origin.x; + this.y = -camera.position.y + camera.origin.y; + this.entity.onEntityTransformChanged(TransformComponent.position); + } } - public onRemovedFromEntity(){ + public onRemovedFromEntity() { if (this.parent) this.parent.removeChild(this); } - public reset(){ + public reset() { } } diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index bbec4903..82f9fb0c 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -1,237 +1,377 @@ -class Entity extends egret.DisplayObjectContainer { - private static _idGenerator: number; +module es { + export class Entity { + public static _idGenerator: number; - public name: string; - public readonly id: number; - /** 当前实体所属的场景 */ - public scene: Scene; - /** 当前附加到此实体的所有组件的列表 */ - public readonly components: ComponentList; - private _updateOrder: number = 0; - private _enabled: boolean = true; - public _isDestoryed: boolean; - private _tag: number = 0; + /** + * 当前实体所属的场景 + */ + public scene: Scene; + /** + * 实体名称。用于在场景范围内搜索实体 + */ + public name: string; + /** + * 此实体的唯一标识 + */ + public readonly id: number; + /** + * 封装实体的位置/旋转/缩放,并允许设置一个高层结构 + */ + public readonly transform: Transform; + /** + * 当前附加到此实体的所有组件的列表 + */ + public readonly components: ComponentList; - public componentBits: BitSet; - - public get isDestoryed(){ - return this._isDestoryed; - } - - public get position(){ - return new Vector2(this.x, this.y); - } - - public set position(value: Vector2){ - this.$setX(value.x); - this.$setY(value.y); - this.onEntityTransformChanged(TransformComponent.position); - } - - public get scale(){ - return new Vector2(this.scaleX, this.scaleY); - } - - public set scale(value: Vector2){ - this.$setScaleX(value.x); - this.$setScaleY(value.y); - this.onEntityTransformChanged(TransformComponent.scale); - } - - public set rotation(value: number){ - this.$setRotation(value); - this.onEntityTransformChanged(TransformComponent.rotation); - } - - public get rotation(){ - return this.$getRotation(); - } - - public get enabled(){ - return this._enabled; - } - - public set enabled(value: boolean){ - this.setEnabled(value); - } - - public setEnabled(isEnabled: boolean){ - if (this._enabled != isEnabled){ - this._enabled = isEnabled; + /** + * 你可以随意使用。稍后可以使用它来查询场景中具有特定标记的所有实体 + */ + public get tag(): number { + return this._tag; } - return this; - } + /** + * 你可以随意使用。稍后可以使用它来查询场景中具有特定标记的所有实体 + * @param value + */ + public set tag(value: number) { + this.setTag(value); + } - public get tag(){ - return this._tag; - } + /** + * 指定应该调用这个entity update方法的频率。1表示每一帧,2表示每一帧,以此类推 + */ + public updateInterval: number = 1; - public set tag(value: number){ - this.setTag(value); - } + /** + * 启用/禁用实体。当禁用碰撞器从物理系统和组件中移除时,方法将不会被调用 + */ + public get enabled() { + return this._enabled; + } - public get stage(){ - if (!this.scene) - return null; - - return this.scene.stage; - } + /** + * 启用/禁用实体。当禁用碰撞器从物理系统和组件中移除时,方法将不会被调用 + * @param value + */ + public set enabled(value: boolean) { + this.setEnabled(value); + } - constructor(name: string){ - super(); - this.name = name; - this.components = new ComponentList(this); - this.id = Entity._idGenerator ++; + /** + * 更新此实体的顺序。updateOrder还用于对scene.entities上的标签列表进行排序 + */ + public get updateOrder() { + return this._updateOrder; + } - this.componentBits = new BitSet(); - this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); - } + /** + * 更新此实体的顺序。updateOrder还用于对scene.entities上的标签列表进行排序 + * @param value + */ + public set updateOrder(value: number) { + this.setUpdateOrder(value); + } - private onAddToStage(){ - this.onEntityTransformChanged(TransformComponent.position); - } + public _isDestroyed: boolean; + /** + * 如果调用了destroy,那么在下一次处理实体之前这将一直为true + */ + public get isDestroyed() { + return this._isDestroyed; + } - public get updateOrder(){ - return this._updateOrder; - } + public componentBits: BitSet; - public set updateOrder(value: number){ - this.setUpdateOrder(value); - } + private _tag: number = 0; + private _enabled: boolean = true; + private _updateOrder: number = 0; - public roundPosition(){ - this.position = Vector2Ext.round(this.position); - } + public get parent(): Transform { + return this.transform.parent; + } - public setUpdateOrder(updateOrder: number){ - if (this._updateOrder != updateOrder){ - this._updateOrder = updateOrder; - if (this.scene){ - + public set parent(value: Transform) { + this.transform.setParent(value); + } + + public get childCount() { + return this.transform.childCount; + } + + public get position(): Vector2 { + return this.transform.position; + } + + public set position(value: Vector2) { + this.transform.setPosition(value.x, value.y); + } + + public get rotation(): number { + return this.transform.rotation; + } + + public set rotation(value: number) { + this.transform.setRotation(value); + } + + + public get scale(): Vector2 { + return this.transform.scale; + } + + public set scale(value: Vector2) { + this.transform.setScale(value); + } + + constructor(name: string) { + this.components = new ComponentList(this); + this.transform = new Transform(this); + this.name = name; + this.id = Entity._idGenerator++; + + this.componentBits = new BitSet(); + } + + public onTransformChanged(comp: Transform.Component) { + // 通知我们的子项改变了位置 + this.components.onEntityTransformChanged(comp); + } + + /** + * 设置实体的标记 + * @param tag + */ + public setTag(tag: number): Entity { + if (this._tag != tag) { + // 我们只有在已经有场景的情况下才会调用entityTagList。如果我们还没有场景,我们会被添加到entityTagList + if (this.scene) + this.scene.entities.removeFromTagList(this); + this._tag = tag; + if (this.scene) + this.scene.entities.addToTagList(this); } return this; } - } - public setTag(tag: number): Entity{ - if (this._tag != tag){ - if (this.scene){ - this.scene.entities.removeFromTagList(this); + /** + * 设置实体的启用状态。当禁用碰撞器从物理系统和组件中移除时,方法将不会被调用 + * @param isEnabled + */ + public setEnabled(isEnabled: boolean) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + + if (this._enabled) + this.components.onEntityEnabled(); + else + this.components.onEntityDisabled(); } - this._tag = tag; - if (this.scene){ - this.scene.entities.addToTagList(this); + + return this; + } + + /** + * 设置此实体的更新顺序。updateOrder还用于对scene.entities上的标签列表进行排序 + * @param updateOrder + */ + public setUpdateOrder(updateOrder: number) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; + if (this.scene) { + // TODO: markEntityListSorted + // markTagUnsorted + } + + return this; } } - return this; - } + /** + * 从场景中删除实体并销毁所有子元素 + */ + public destroy() { + this._isDestroyed = true; + this.scene.entities.remove(this); + this.transform.parent = null; - public attachToScene(newScene: Scene){ - this.scene = newScene; - newScene.entities.add(this); - this.components.registerAllComponents(); - - for (let i = 0; i < this.numChildren; i ++){ - (this.getChildAt(i) as Component).entity.attachToScene(newScene); - } - } - - public detachFromScene(){ - this.scene.entities.remove(this); - this.components.deregisterAllComponents(); - - for (let i = 0; i < this.numChildren; i ++) - (this.getChildAt(i) as Component).entity.detachFromScene(); - } - - public addComponent(component: T): T{ - component.entity = this; - this.components.add(component); - this.addChild(component); - component.initialize(); - return component; - } - - public hasComponent(type){ - return this.components.getComponent(type, false) != null; - } - - public getOrCreateComponent(type: T){ - let comp = this.components.getComponent(type, true); - if (!comp){ - comp = this.addComponent(type); + // 销毁所有子项 + for (let i = this.transform.childCount - 1; i >= 0; i--) { + let child = this.transform.getChild(i); + child.entity.destroy(); + } } - return comp; - } + /** + * 将实体从场景中分离。下面的生命周期方法将被调用在组件上:OnRemovedFromEntity + */ + public detachFromScene() { + this.scene.entities.remove(this); + this.components.deregisterAllComponents(); - public getComponent(type): T{ - return this.components.getComponent(type, false) as T; - } - - public getComponents(typeName: string | any, componentList?){ - return this.components.getComponents(typeName, componentList); - } - - private onEntityTransformChanged(comp: TransformComponent){ - this.components.onEntityTransformChanged(comp); - } - - public removeComponentForType(type){ - let comp = this.getComponent(type); - if (comp){ - this.removeComponent(comp); - return true; + for (let i = 0; i < this.transform.childCount; i++) + this.transform.getChild(i).entity.detachFromScene(); } - return false; - } + /** + * 将一个先前分离的实体附加到一个新的场景 + * @param newScene + */ + public attachToScene(newScene: Scene) { + this.scene = newScene; + newScene.entities.add(this); + this.components.registerAllComponents(); - public removeComponent(component: Component){ - this.components.remove(component); - } - - public removeAllComponents(){ - for (let i = 0; i < this.components.count; i ++){ - this.removeComponent(this.components.buffer[i]); + for (let i = 0; i < this.transform.childCount; i++) { + this.transform.getChild(i).entity.attachToScene(newScene); + } } - } - public update(){ - this.components.update(); - } + /** + * 创建此实体的深层克隆。子类可以重写此方法来复制任何自定义字段。 + * 当重写时,应该调用CopyFrom方法,它将为您克隆所有组件、碰撞器和转换子组件。 + * 注意克隆的实体不会被添加到任何场景中!你必须自己添加它们! + * @param position + */ + public clone(position: Vector2 = new Vector2()): Entity { + let entity = new Entity(this.name + "(clone)"); + entity.copyFrom(this); + entity.transform.position = position; - public onAddedToScene(){ + return entity; + } - } + /** + * 将实体的属性、组件和碰撞器复制到此实例 + * @param entity + */ + protected copyFrom(entity: Entity) { + this.tag = entity.tag; + this.updateInterval = entity.updateInterval; + this.updateOrder = entity.updateOrder; + this.enabled = entity.enabled; - public onRemovedFromScene(){ - if (this._isDestoryed) - this.components.removeAllComponents(); - } + this.transform.scale = entity.transform.scale; + this.transform.rotation = entity.transform.rotation; - public destroy(){ - this._isDestoryed = true; - this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); + for (let i = 0; i < entity.components.count; i++) + this.addComponent(entity.components.buffer[i].clone()); + for (let i = 0; i < entity.components._componentsToAdd.length; i++) + this.addComponent(entity.components._componentsToAdd[i].clone()); - this.scene.entities.remove(this); - this.removeChildren(); + for (let i = 0; i < entity.transform.childCount; i++) { + let child = entity.transform.getChild(i).entity; + let childClone = child.clone(); + childClone.transform.copyFrom(child.transform); + childClone.transform.parent = this.transform; + } + } - if (this.parent) - this.parent.removeChild(this); + /** + * 在提交了所有挂起的实体更改后,将此实体添加到场景时调用 + */ + public onAddedToScene() { + } - for (let i = this.numChildren - 1; i >= 0; i --){ - let child = this.getChildAt(i); - (child as Component).entity.destroy(); + /** + * 当此实体从场景中删除时调用 + */ + public onRemovedFromScene() { + // 如果已经被销毁了,移走我们的组件。如果我们只是分离,我们需要保持我们的组件在实体上。 + if (this._isDestroyed) + this.components.removeAllComponents(); + } + + /** + * 每帧进行调用进行更新组件 + */ + public update() { + this.components.update(); + } + + /** + * 将组件添加到组件列表中。返回组件。 + * @param component + */ + public addComponent(component: T): T { + component.entity = this; + this.components.add(component); + component.initialize(); + return component; + } + + /** + * 获取类型T的第一个组件并返回它。如果没有找到组件,则返回null。 + * @param type + */ + public getComponent(type): T { + return this.components.getComponent(type, false) as T; + } + + /** + * 检查实体是否具有该组件 + * @param type + */ + public hasComponent(type) { + return this.components.getComponent(type, false) != null; + } + + /** + * 获取类型T的第一个组件并返回它。如果没有找到组件,将创建组件。 + * @param type + */ + public getOrCreateComponent(type: T) { + let comp = this.components.getComponent(type, true); + if (!comp) { + comp = this.addComponent(type); + } + + return comp; + } + + /** + * 获取typeName类型的所有组件,但不使用列表分配 + * @param typeName + * @param componentList + */ + public getComponents(typeName: string | any, componentList?) { + return this.components.getComponents(typeName, componentList); + } + + /** + * 从组件列表中删除组件 + * @param component + */ + public removeComponent(component: Component) { + this.components.remove(component); + } + + /** + * 从组件列表中删除类型为T的第一个组件 + * @param type + */ + public removeComponentForType(type) { + let comp = this.getComponent(type); + if (comp) { + this.removeComponent(comp); + return true; + } + + return false; + } + + /** + * 从实体中删除所有组件 + */ + public removeAllComponents() { + for (let i = 0; i < this.components.count; i++) { + this.removeComponent(this.components.buffer[i]); + } + } + + public toString(): string { + return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`; } } } - -enum TransformComponent { - rotation, - scale, - position -} \ No newline at end of file diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index 9bf9100e..d5c85859 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -1,213 +1,360 @@ -/** 场景 */ -class Scene extends egret.DisplayObjectContainer { - public camera: Camera; - public readonly entities: EntityList; - public readonly renderableComponents: RenderableComponentList; - public readonly content: ContentManager; - public enablePostProcessing = true; +module es { + /** 场景 */ + export class Scene extends egret.DisplayObjectContainer { + /** + * 默认场景摄像机 + */ + public camera: Camera; + /** + * 场景特定内容管理器。使用它来加载仅由这个场景需要的任何资源。如果你有全局/多场景资源,你可以使用SceneManager.content。 + * contentManager来加载它们,因为Nez不会卸载它们。 + */ + public readonly content: ContentManager; + /** + * 全局切换后处理器 + */ + public enablePostProcessing = true; + /** + * 这个场景中的实体列表 + */ + public readonly entities: EntityList; + /** + * 管理当前在场景实体上的所有可呈现组件的列表 + */ + public readonly renderableComponents: RenderableComponentList; + /** + * 管理所有实体处理器 + */ + public readonly entityProcessors: EntityProcessorList; - private _renderers: Renderer[] = []; - private _postProcessors: PostProcessor[] = []; - private _didSceneBegin; + public _renderers: Renderer[] = []; + public readonly _postProcessors: PostProcessor[] = []; + public _didSceneBegin; - public readonly entityProcessors: EntityProcessorList; - - constructor() { - super(); - this.entityProcessors = new EntityProcessorList(); - this.renderableComponents = new RenderableComponentList(); - this.entities = new EntityList(this); - this.content = new ContentManager(); - this.width = SceneManager.stage.stageWidth; - this.height = SceneManager.stage.stageHeight; - - this.addEventListener(egret.Event.ACTIVATE, this.onActive, this); - this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - } - - public createEntity(name: string) { - let entity = new Entity(name); - entity.position = new Vector2(0, 0); - return this.addEntity(entity); - } - - public addEntity(entity: Entity) { - this.entities.add(entity); - entity.scene = this; - this.addChild(entity); - - for (let i = 0; i < entity.numChildren; i++) - this.addEntity((entity.getChildAt(i) as Component).entity); - - return entity; - } - - public destroyAllEntities() { - for (let i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destroy(); - } - } - - public findEntity(name: string): Entity { - return this.entities.findEntity(name); - } - - /** - * 在场景中添加一个EntitySystem处理器 - * @param processor 处理器 - */ - public addEntityProcessor(processor: EntitySystem) { - processor.scene = this; - this.entityProcessors.add(processor); - return processor; - } - - public removeEntityProcessor(processor: EntitySystem) { - this.entityProcessors.remove(processor); - } - - public getEntityProcessor(): T { - return this.entityProcessors.getProcessor(); - } - - public addRenderer(renderer: T) { - this._renderers.push(renderer); - this._renderers.sort(); - - renderer.onAddedToScene(this); - - return renderer; - } - - public getRenderer(type): T { - for (let i = 0; i < this._renderers.length; i++) { - if (this._renderers[i] instanceof type) - return this._renderers[i] as T; + /** + * 辅助器,创建一个场景与DefaultRenderer附加并准备使用 + */ + public static createWithDefaultRenderer(){ + let scene = new Scene(); + scene.addRenderer(new DefaultRenderer()); + return scene; } - return null; - } + constructor() { + super(); + this.entities = new EntityList(this); + this.renderableComponents = new RenderableComponentList(); + this.content = new ContentManager(); - public removeRenderer(renderer: Renderer) { - this._renderers.remove(renderer); - renderer.unload(); - } + this.entityProcessors = new EntityProcessorList(); - public begin() { - if (SceneManager.sceneTransition){ - SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); - }else{ - SceneManager.stage.addChild(this); - } - - if (this._renderers.length == 0) { - this.addRenderer(new DefaultRenderer()); - console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); - } - /** 初始化默认相机 */ - this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); + this.width = SceneManager.stage.stageWidth; + this.height = SceneManager.stage.stageHeight; - Physics.reset(); - - if (this.entityProcessors) - this.entityProcessors.begin(); - - this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); - - this._didSceneBegin = true; - this.onStart(); - } - - public end() { - this._didSceneBegin = false; - - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - - for (let i = 0; i < this._renderers.length; i++) { - this._renderers[i].unload(); + this.initialize(); } - for (let i = 0; i < this._postProcessors.length; i++) { - this._postProcessors[i].unload(); + /** + * 在场景子类中重写这个并在这里进行加载。在场景设置好之后,在调用begin之前,从构造器中调用。 + */ + public initialize(){} + + /** + * 在场景子类中重写这个。当SceneManager将此场景设置为活动场景时,将调用此操作。 + */ + public async onStart() {} + + /** + * 在场景子类中重写这个,并在这里做任何必要的卸载。当SceneManager从活动槽中删除此场景时调用。 + */ + public unload() { } + + + /** + * 在场景子类中重写这个,当该场景当获得焦点时调用 + */ + public onActive() {} + + /** + * 在场景子类中重写这个,当该场景当失去焦点时调用 + */ + public onDeactive() {} + + public async begin() { + // 如果是场景转换需要在最顶层 + if (SceneManager.sceneTransition){ + SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); + }else{ + SceneManager.stage.addChild(this); + } + + if (this._renderers.length == 0) { + this.addRenderer(new DefaultRenderer()); + console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); + } + + this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); + + Physics.reset(); + + if (this.entityProcessors) + this.entityProcessors.begin(); + + this.addEventListener(egret.Event.ACTIVATE, this.onActive, this); + this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + + this._didSceneBegin = true; + this.onStart(); } - this.entities.removeAllEntities(); - this.removeChildren(); + public end() { + this._didSceneBegin = false; - Physics.clear(); + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - this.camera = null; - this.content.dispose(); + for (let i = 0; i < this._renderers.length; i++) { + this._renderers[i].unload(); + } - if (this.entityProcessors) - this.entityProcessors.end(); - - this.unload(); - - if (this.parent) - this.parent.removeChild(this); - } - - protected async onStart() { - - } - - /** 场景激活 */ - protected onActive() { - - } - - /** 场景失去焦点 */ - protected onDeactive() { - - } - - protected unload() { } - - public update() { - this.entities.updateLists(); - - if (this.entityProcessors) - this.entityProcessors.update() - - this.entities.update(); - - if (this.entityProcessors) - this.entityProcessors.lateUpdate(); - - this.renderableComponents.updateList(); - } - - public postRender() { - let enabledCounter = 0; - if (this.enablePostProcessing) { for (let i = 0; i < this._postProcessors.length; i++) { - if (this._postProcessors[i].enable) { - let isEven = MathHelper.isEven(enabledCounter); - enabledCounter ++; + this._postProcessors[i].unload(); + } - this._postProcessors[i].process(); + this.entities.removeAllEntities(); + this.removeChildren(); + + this.camera = null; + this.content.dispose(); + + if (this.entityProcessors) + this.entityProcessors.end(); + + if (this.parent) + this.parent.removeChild(this); + + this.unload(); + } + + public update() { + // 更新我们的列表,以防它们有任何变化 + this.entities.updateLists(); + + // 更新我们的实体解析器 + if (this.entityProcessors) + this.entityProcessors.update(); + + // 更新我们的实体组 + this.entities.update(); + + if (this.entityProcessors) + this.entityProcessors.lateUpdate(); + + // 我们在实体之后更新我们的呈现。如果添加了任何新的渲染,请进行更新 + this.renderableComponents.updateList(); + } + + public render() { + if (this._renderers.length == 0){ + console.error("there are no renderers in the scene!"); + return; + } + + for (let i = 0; i < this._renderers.length; i++) { + this._renderers[i].render(this); + } + } + + /** + * 现在的任何后处理器都要完成它的处理 + * 只有在SceneTransition请求渲染时,它才会有一个值。 + */ + public postRender() { + if (this.enablePostProcessing) { + for (let i = 0; i < this._postProcessors.length; i++) { + if (this._postProcessors[i].enabled) { + this._postProcessors[i].process(); + } } } } - } - public render() { - for (let i = 0; i < this._renderers.length; i++) { - this._renderers[i].render(this); - } - } + /** + * 为场景添加一个渲染器 + * @param renderer + */ + public addRenderer(renderer: T) { + this._renderers.push(renderer); + this._renderers.sort(); - public addPostProcessor(postProcessor: T): T{ - this._postProcessors.push(postProcessor); - this._postProcessors.sort(); - postProcessor.onAddedToScene(this); + renderer.onAddedToScene(this); - if (this._didSceneBegin){ - postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + return renderer; } - return postProcessor; + /** + * 获取类型为T的第一个渲染器 + * @param type + */ + public getRenderer(type): T { + for (let i = 0; i < this._renderers.length; i++) { + if (this._renderers[i] instanceof type) + return this._renderers[i] as T; + } + + return null; + } + + /** + * 从场景中移除渲染器 + * @param renderer + */ + public removeRenderer(renderer: Renderer) { + if (!this._renderers.contains(renderer)) + return; + this._renderers.remove(renderer); + renderer.unload(); + } + + /** + * 添加一个后处理器到场景。设置场景字段并调用后处理器。onAddedToScene使后处理器可以使用场景ContentManager加载资源。 + * @param postProcessor + */ + public addPostProcessor(postProcessor: T): T{ + this._postProcessors.push(postProcessor); + this._postProcessors.sort(); + postProcessor.onAddedToScene(this); + + if (this._didSceneBegin){ + postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + } + + return postProcessor; + } + + /** + * 获取类型为T的第一个后处理器 + * @param type + */ + public getPostProcessor(type): T{ + for (let i = 0; i < this._postProcessors.length; i ++){ + if (this._postProcessors[i] instanceof type) + return this._postProcessors[i] as T; + } + + return null; + } + + /** + * 删除一个后处理程序。注意,在删除时不会调用unload,因此如果不再需要PostProcessor,请确保调用unload来释放资源。 + * @param postProcessor + */ + public removePostProcessor(postProcessor: PostProcessor){ + if (!this._postProcessors.contains(postProcessor)) + return; + + this._postProcessors.remove(postProcessor); + postProcessor.unload(); + } + + /** + * 将实体添加到此场景,并返回它 + * @param name + */ + public createEntity(name: string) { + let entity = new Entity(name); + return this.addEntity(entity); + } + + /** + * 在场景的实体列表中添加一个实体 + * @param entity + */ + public addEntity(entity: Entity) { + if (this.entities.buffer.contains(entity)) + console.warn(`You are attempting to add the same entity to a scene twice: ${entity}`); + this.entities.add(entity); + entity.scene = this; + + for (let i = 0; i < entity.transform.childCount; i++) + this.addEntity(entity.transform.getChild(i).entity); + + return entity; + } + + /** + * 从场景中删除所有实体 + */ + public destroyAllEntities() { + for (let i = 0; i < this.entities.count; i++) { + this.entities.buffer[i].destroy(); + } + } + + /** + * 搜索并返回第一个具有名称的实体 + * @param name + */ + public findEntity(name: string): Entity { + return this.entities.findEntity(name); + } + + /** + * 返回具有给定标记的所有实体 + * @param tag + */ + public findEntitiesWithTag(tag: number): Entity[]{ + return this.entities.entitiesWithTag(tag); + } + + /** + * 返回类型为T的所有实体 + * @param type + */ + public entitiesOfType(type): T[]{ + return this.entities.entitiesOfType(type); + } + + /** + * 返回第一个启用加载的类型为T的组件 + * @param type + */ + public findComponentOfType(type): T { + return this.entities.findComponentOfType(type); + } + + /** + * 返回类型为T的所有已启用已加载组件的列表 + * @param type + */ + public findComponentsOfType(type): T[] { + return this.entities.findComponentsOfType(type); + } + + /** + * 在场景中添加一个EntitySystem处理器 + * @param processor 处理器 + */ + public addEntityProcessor(processor: EntitySystem) { + processor.scene = this; + this.entityProcessors.add(processor); + return processor; + } + + /** + * 从场景中删除EntitySystem处理器 + * @param processor + */ + public removeEntityProcessor(processor: EntitySystem) { + this.entityProcessors.remove(processor); + } + + /** + * 获取EntitySystem处理器 + */ + public getEntityProcessor(): T { + return this.entityProcessors.getProcessor(); + } } } \ No newline at end of file diff --git a/source/src/ECS/SceneManager.ts b/source/src/ECS/SceneManager.ts index 8ea697f9..37c726f5 100644 --- a/source/src/ECS/SceneManager.ts +++ b/source/src/ECS/SceneManager.ts @@ -12,6 +12,7 @@ class SceneManager { public static content: ContentManager; /** 简化对内部类的全局内容实例的访问 */ private static _instnace: SceneManager; + private static timerRuler: TimeRuler; public static get Instance(){ return this._instnace; } @@ -25,6 +26,7 @@ class SceneManager { SceneManager.stage = stage; SceneManager.initialize(stage); + SceneManager.timerRuler = new TimeRuler(); } public static get scene() { @@ -50,6 +52,7 @@ class SceneManager { } public static update() { + SceneManager.startDebugUpdate(); Time.update(egret.getTimer()); if (SceneManager._scene) { @@ -74,6 +77,7 @@ class SceneManager { } } + SceneManager.endDebugUpdate(); SceneManager.render(); } @@ -128,4 +132,13 @@ class SceneManager { SceneManager.emitter.emit(CoreEvents.SceneChanged); Time.sceneChanged(); } + + private static startDebugUpdate(){ + TimeRuler.Instance.startFrame(); + TimeRuler.Instance.beginMark("update", 0x00FF00); + } + + private static endDebugUpdate(){ + TimeRuler.Instance.endMark("update"); + } } \ No newline at end of file diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts new file mode 100644 index 00000000..94a3e2bc --- /dev/null +++ b/source/src/ECS/Transform.ts @@ -0,0 +1,138 @@ +module es { + export class Transform { + /** 与此转换关联的实体 */ + public readonly entity: Entity; + + private _parent: Transform; + /** + * 获取此转换的父转换 + */ + public get parent() { + return this._parent; + } + + /** + * 设置此转换的父转换 + * @param value + */ + public set parent(value: Transform) { + this.setParent(value); + } + + /** + * 这个转换的所有子元素 + */ + public get childCount() { + return this._children.length; + } + + /** + * 变换在世界空间中的位置 + */ + public position: Vector2; + /** + * 变换在世界空间的旋转度 + */ + public rotation: number; + /** + * 变换在世界空间的缩放 + */ + public scale: Vector2; + public _children: Transform[]; + + constructor(entity: Entity) { + this.entity = entity; + this.scale = Vector2.one; + this._children = []; + } + + /** + * 返回在索引处的转换子元素 + * @param index + */ + public getChild(index: number): Transform { + return this._children[index]; + } + + /** + * 设置此转换的父转换 + * @param parent + */ + public setParent(parent: Transform): Transform { + if (this._parent == parent) + return this; + + if (!this._parent) { + this._parent._children.remove(this); + this._parent._children.push(this); + } + + this._parent = parent; + + return this; + } + + /** + * 设置转换在世界空间中的位置 + * @param x + * @param y + */ + public setPosition(x: number, y: number): Transform { + this.position = new Vector2(x, y); + return this; + } + + /** + * 设置变换在世界空间的旋转度 + * @param degrees + */ + public setRotation(degrees: number): Transform { + this.rotation = degrees; + return this; + } + + /** + * 设置变换在世界空间中的缩放 + * @param scale + */ + public setScale(scale: Vector2): Transform { + this.scale = scale; + return this; + } + + /** + * 旋转精灵的顶部,使其朝向位置 + * @param pos + */ + public lookAt(pos: Vector2) { + let sign = this.position.x > pos.x ? -1 : 1; + let vectorToAlignTo = Vector2.normalize(Vector2.subtract(this.position, pos)); + this.rotation = sign * Math.acos(Vector2.dot(vectorToAlignTo, Vector2.unitY)); + } + + /** + * 对精灵坐标进行四舍五入 + */ + public roundPosition() { + this.position = this.position.round(); + } + + /** + * 从另一个transform属性进行拷贝 + * @param transform + */ + public copyFrom(transform: Transform) { + this.position = transform.position; + this.rotation = transform.rotation; + this.scale = transform.scale; + } + } +} + +module Transform { + export enum Component { + position, + scale, + rotation, + } +} \ No newline at end of file diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index ef8ce78b..0b1ae9f4 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -1,224 +1,241 @@ -class ComponentList { - private _entity: Entity; - /** 添加到实体的组件列表 */ - private _components: Component[] = []; - /** 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 */ - private _componentsToAdd: Component[] = []; - /** 标记要删除此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 */ - private _componentsToRemove: Component[] = []; - private _tempBufferList: Component[] = []; +module es { + export class ComponentList { + public _entity: Entity; - constructor(entity: Entity) { - this._entity = entity; - } + /** + * 添加到实体的组件列表 + */ + public _components: Component[] = []; + /** + * 添加到此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + */ + public _componentsToAdd: Component[] = []; + /** + * 标记要删除此框架的组件列表。用来对组件进行分组,这样我们就可以同时进行加工 + */ + public _componentsToRemove: Component[] = []; + public _tempBufferList: Component[] = []; - public get count() { - return this._components.length; - } - - public get buffer() { - return this._components; - } - - public add(component: Component) { - this._componentsToAdd.push(component); - } - - public remove(component: Component) { - if (this._componentsToRemove.contains(component)) - console.warn(`You are trying to remove a Component (${component}) that you already removed`) - - // 这可能不是一个活动的组件,所以我们必须注意它是否还没有被处理,它可能正在同一帧中被删除 - if (this._componentsToAdd.contains(component)) { - this._componentsToAdd.remove(component); - return; + constructor(entity: Entity) { + this._entity = entity; } - this._componentsToRemove.push(component); - } - - /** - * 立即从组件列表中删除所有组件 - */ - public removeAllComponents() { - for (let i = 0; i < this._components.length; i++) { - this.handleRemove(this._components[i]); + public get count() { + return this._components.length; } - this._components.length = 0; - this._componentsToAdd.length = 0; - this._componentsToRemove.length = 0; - } + public get buffer() { + return this._components; + } - public deregisterAllComponents() { - for (let i = 0; i < this._components.length; i++) { - let component = this._components[i]; + public add(component: Component) { + this._componentsToAdd.push(component); + } + public remove(component: Component) { + if (this._componentsToRemove.contains(component)) + console.warn(`You are trying to remove a Component (${component}) that you already removed`) + + // 这可能不是一个活动的组件,所以我们必须注意它是否还没有被处理,它可能正在同一帧中被删除 + if (this._componentsToAdd.contains(component)) { + this._componentsToAdd.remove(component); + return; + } + + this._componentsToRemove.push(component); + } + + /** + * 立即从组件列表中删除所有组件 + */ + public removeAllComponents() { + for (let i = 0; i < this._components.length; i++) { + this.handleRemove(this._components[i]); + } + + this._components.length = 0; + this._componentsToAdd.length = 0; + this._componentsToRemove.length = 0; + } + + public deregisterAllComponents() { + for (let i = 0; i < this._components.length; i++) { + let component = this._components[i]; + + // 处理渲染层列表 + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + } + } + + public registerAllComponents() { + for (let i = 0; i < this._components.length; i++) { + let component = this._components[i]; + + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.add(component); + + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + } + } + + /** + * 处理任何需要删除或添加的组件 + */ + public updateLists() { + if (this._componentsToRemove.length > 0) { + for (let i = 0; i < this._componentsToRemove.length; i++) { + this.handleRemove(this._componentsToRemove[i]); + this._components.remove(this._componentsToRemove[i]); + } + + this._componentsToRemove.length = 0; + } + + if (this._componentsToAdd.length > 0) { + for (let i = 0, count = this._componentsToAdd.length; i < count; i++) { + let component = this._componentsToAdd[i]; + if (component instanceof RenderableComponent) + this._entity.scene.renderableComponents.add(component); + + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + + this._components.push(component); + this._tempBufferList.push(component); + } + + // 在调用onAddedToEntity之前清除,以防添加更多组件 + this._componentsToAdd.length = 0; + + // 现在所有的组件都添加到了场景中,我们再次循环并调用onAddedToEntity/onEnabled + for (let i = 0; i < this._tempBufferList.length; i++) { + let component = this._tempBufferList[i]; + component.onAddedToEntity(); + + // enabled检查实体和组件 + if (component.enabled) { + component.onEnabled(); + } + } + + this._tempBufferList.length = 0; + } + } + + public handleRemove(component: Component) { // 处理渲染层列表 if (component instanceof RenderableComponent) this._entity.scene.renderableComponents.remove(component); this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - } - } - public registerAllComponents() { - for (let i = 0; i < this._components.length; i++) { - let component = this._components[i]; - - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - } - } - - /** - * 处理任何需要删除或添加的组件 - */ - public updateLists() { - if (this._componentsToRemove.length > 0) { - for (let i = 0; i < this._componentsToRemove.length; i++) { - this.handleRemove(this._componentsToRemove[i]); - this._components.remove(this._componentsToRemove[i]); - } - - this._componentsToRemove.length = 0; + component.onRemovedFromEntity(); + component.entity = null; } - if (this._componentsToAdd.length > 0) { - for (let i = 0, count = this._componentsToAdd.length; i < count; i++) { - let component = this._componentsToAdd[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - - this._components.push(component); - this._tempBufferList.push(component); - } - - // 在调用onAddedToEntity之前清除,以防添加更多组件 - this._componentsToAdd.length = 0; - - // 现在所有的组件都添加到了场景中,我们再次循环并调用onAddedToEntity/onEnabled - for (let i = 0; i < this._tempBufferList.length; i++) { - let component = this._tempBufferList[i]; - component.onAddedToEntity(); - - // enabled检查实体和组件 - if (component.enabled) { - component.onEnabled(); - } - } - - this._tempBufferList.length = 0; - } - } - - public onEntityTransformChanged(comp: TransformComponent) { - for (let i = 0; i < this._components.length; i++) { - if (this._components[i].enabled) - this._components[i].onEntityTransformChanged(comp); - } - - for (let i = 0; i < this._componentsToAdd.length; i++) { - if (this._componentsToAdd[i].enabled) - this._componentsToAdd[i].onEntityTransformChanged(comp); - } - } - - private handleRemove(component: Component) { - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - - component.onRemovedFromEntity(); - component.entity = null; - } - - /** - * 获取类型T的第一个组件并返回它 - * 可以选择跳过检查未初始化的组件(尚未调用onAddedToEntity方法的组件) - * 如果没有找到组件,则返回null。 - * @param type - * @param onlyReturnInitializedComponents - */ - public getComponent(type, onlyReturnInitializedComponents: boolean): T { - for (let i = 0; i < this._components.length; i++) { - let component = this._components[i]; - if (component instanceof type) - return component as T; - } - - // 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用 - if (!onlyReturnInitializedComponents) { - for (let i = 0; i < this._componentsToAdd.length; i++) { - let component = this._componentsToAdd[i]; + /** + * 获取类型T的第一个组件并返回它 + * 可以选择跳过检查未初始化的组件(尚未调用onAddedToEntity方法的组件) + * 如果没有找到组件,则返回null。 + * @param type + * @param onlyReturnInitializedComponents + */ + public getComponent(type, onlyReturnInitializedComponents: boolean): T { + for (let i = 0; i < this._components.length; i++) { + let component = this._components[i]; if (component instanceof type) return component as T; } + + // 我们可以选择检查挂起的组件,以防addComponent和getComponent在同一个框架中被调用 + if (!onlyReturnInitializedComponents) { + for (let i = 0; i < this._componentsToAdd.length; i++) { + let component = this._componentsToAdd[i]; + if (component instanceof type) + return component as T; + } + } + + return null; } - return null; - } + /** + * 获取T类型的所有组件,但不使用列表分配 + * @param typeName + * @param components + */ + public getComponents(typeName: string | any, components?) { + if (!components) + components = []; - /** - * 获取T类型的所有组件,但不使用列表分配 - * @param typeName - * @param components - */ - public getComponents(typeName: string | any, components?) { - if (!components) - components = []; + for (let i = 0; i < this._components.length; i++) { + let component = this._components[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } else { + if (component instanceof typeName) { + components.push(component); + } + } + } - for (let i = 0; i < this._components.length; i++) { - let component = this._components[i]; - if (typeof (typeName) == "string") { - if (egret.is(component, typeName)) { - components.push(component); - } - } else { - if (component instanceof typeName) { - components.push(component); + for (let i = 0; i < this._componentsToAdd.length; i++) { + let component = this._componentsToAdd[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } else { + if (component instanceof typeName) { + components.push(component); + } } } + + return components; + } + + public update() { + this.updateLists(); + for (let i = 0; i < this._components.length; i++) { + let updatableComponent = this._components[i]; + + if (updatableComponent.enabled && + (updatableComponent.updateInterval == 1 || + Time.frameCount % updatableComponent.updateInterval == 0)) + updatableComponent.update(); + } } - for (let i = 0; i < this._componentsToAdd.length; i++) { - let component = this._componentsToAdd[i]; - if (typeof (typeName) == "string") { - if (egret.is(component, typeName)) { - components.push(component); - } - } else { - if (component instanceof typeName) { - components.push(component); - } + public onEntityTransformChanged(comp: Transform.Component) { + for (let i = 0; i < this._components.length; i++) { + if (this._components[i].enabled) + this._components[i].onEntityTransformChanged(comp); + } + + for (let i = 0; i < this._componentsToAdd.length; i++) { + if (this._componentsToAdd[i].enabled) + this._componentsToAdd[i].onEntityTransformChanged(comp); } } - return components; - } + public onEntityEnabled() { + for (let i = 0; i < this._components.length; i++) + this._components[i].onEnabled(); + } - public update() { - this.updateLists(); - for (let i = 0; i < this._components.length; i++) { - let updatable = this._components[i]; - let updateableComponent; - if (updatable instanceof Component) - updateableComponent = updatable as Component; - - if (updatable.enabled && - updateableComponent.enabled && - (updateableComponent.updateInterval == 1 || - Time.frameCount % updateableComponent.updateInterval == 0)) - updatable.update(); + public onEntityDisabled() { + for (let i = 0; i < this._components.length; i++) + this._components[i].onDisabled(); } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Utils/EntityList.ts b/source/src/ECS/Utils/EntityList.ts index 1aae3886..943e78e0 100644 --- a/source/src/ECS/Utils/EntityList.ts +++ b/source/src/ECS/Utils/EntityList.ts @@ -1,134 +1,213 @@ -class EntityList{ - public scene: Scene; - private _entitiesToRemove: Entity[] = []; - private _entitiesToAdded: Entity[] = []; - private _tempEntityList: Entity[] = []; - private _entities: Entity[] = []; - private _entityDict: Map = new Map(); - private _unsortedTags: number[] = []; +module es { + export class EntityList{ + public scene: Scene; + private _entitiesToRemove: Entity[] = []; + private _entitiesToAdded: Entity[] = []; + private _tempEntityList: Entity[] = []; + private _entities: Entity[] = []; + private _entityDict: Map = new Map(); + private _unsortedTags: number[] = []; - constructor(scene: Scene){ - this.scene = scene; - } - - public get count(){ - return this._entities.length; - } - - public get buffer(){ - return this._entities; - } - - public add(entity: Entity){ - if (this._entitiesToAdded.indexOf(entity) == -1) - this._entitiesToAdded.push(entity); - } - - public remove(entity: Entity){ - if (this._entitiesToAdded.contains(entity)){ - this._entitiesToAdded.remove(entity); - return; + constructor(scene: Scene){ + this.scene = scene; } - if (!this._entitiesToRemove.contains(entity)) - this._entitiesToRemove.push(entity); - } - - public findEntity(name: string){ - for (let i = 0; i < this._entities.length; i ++){ - if (this._entities[i].name == name) - return this._entities[i]; + public get count(){ + return this._entities.length; } - return this._entitiesToAdded.firstOrDefault(entity => entity.name == name); - } - - public getTagList(tag: number){ - let list = this._entityDict.get(tag); - if (!list){ - list = []; - this._entityDict.set(tag, list); + public get buffer(){ + return this._entities; } - return this._entityDict.get(tag); - } - - public addToTagList(entity: Entity){ - let list = this.getTagList(entity.tag); - if (!list.contains(entity)){ - list.push(entity); - this._unsortedTags.push(entity.tag); - } - } - - public removeFromTagList(entity: Entity){ - let list = this._entityDict.get(entity.tag); - if (list){ - list.remove(entity); - } - } - - public update(){ - for (let i = 0; i < this._entities.length; i++){ - let entity = this._entities[i]; - if (entity.enabled) - entity.update(); - } - } - - public removeAllEntities(){ - this._entitiesToAdded.length = 0; - - this.updateLists(); - - for (let i = 0; i < this._entities.length; i ++){ - this._entities[i]._isDestoryed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; + public add(entity: Entity){ + if (this._entitiesToAdded.indexOf(entity) == -1) + this._entitiesToAdded.push(entity); } - this._entities.length = 0; - this._entityDict.clear(); - } + public remove(entity: Entity){ + if (this._entitiesToAdded.contains(entity)){ + this._entitiesToAdded.remove(entity); + return; + } - public updateLists(){ - if (this._entitiesToRemove.length > 0){ - let temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(entity => { - this._entities.remove(entity); - entity.scene = null; + if (!this._entitiesToRemove.contains(entity)) + this._entitiesToRemove.push(entity); + } - this.scene.entityProcessors.onEntityRemoved(entity); + public findEntity(name: string){ + for (let i = 0; i < this._entities.length; i ++){ + if (this._entities[i].name == name) + return this._entities[i]; + } + + return this._entitiesToAdded.firstOrDefault(entity => entity.name == name); + } + + /** + * 返回带有标记的所有实体的列表。如果没有实体具有标记,则返回一个空列表。可以通过ListPool.free将返回的列表放回池中。 + * @param tag + */ + public entitiesWithTag(tag: number){ + let list = this.getTagList(tag); + + let returnList = ListPool.obtain(); + for (let i = 0; i < list.length; i ++) + returnList.push(list[i]); + + return returnList; + } + + /** + * 返回t类型的所有实体的列表。返回的列表可以通过ListPool.free放回池中。 + * @param type + */ + public entitiesOfType(type): T[]{ + let list = ListPool.obtain(); + for (let i = 0; i < this._entities.length; i ++){ + if (this._entities[i] instanceof type) + list.push(this._entities[i] as T); + } + this._entitiesToAdded.forEach(entity => { + if (entity instanceof type) + list.push(entity as T); }); - this._tempEntityList.length = 0; + return list; } - if (this._entitiesToAdded.length > 0){ - let temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(entity => { - if (!this._entities.contains(entity)){ - this._entities.push(entity); - entity.scene = this.scene; - - this.scene.entityProcessors.onEntityAdded(entity) + /** + * 返回在类型为T的场景中找到的第一个组件 + * @param type + */ + public findComponentOfType(type): T { + for (let i = 0; i < this._entities.length; i ++){ + if (this._entities[i].enabled){ + let comp = this._entities[i].getComponent(type); + if (comp) + return comp; } - }); + } - this._tempEntityList.forEach(entity => entity.onAddedToScene()); - this._tempEntityList.length = 0; + for (let i = 0; i < this._entitiesToAdded.length; i ++){ + let entity = this._entitiesToAdded[i]; + if (entity.enabled){ + let comp = entity.getComponent(type); + if (comp) + return comp; + } + } + + return null; } - if (this._unsortedTags.length > 0){ - this._unsortedTags.forEach(tag => { - this._entityDict.get(tag).sort(); - }); + /** + * 返回在类型t的场景中找到的所有组件。返回的列表可以通过ListPool.free放回池中。 + * @param type + */ + public findComponentsOfType(type): T[]{ + let comps = ListPool.obtain(); + for (let i = 0; i < this._entities.length; i ++){ + if (this._entities[i].enabled) + this._entities[i].getComponents(type, comps); + } - this._unsortedTags.length = 0; + for (let i = 0; i < this._entitiesToAdded.length; i ++){ + let entity = this._entitiesToAdded[i]; + if (entity.enabled) + entity.getComponents(type,comps); + } + + return comps; + } + + public getTagList(tag: number){ + let list = this._entityDict.get(tag); + if (!list){ + list = []; + this._entityDict.set(tag, list); + } + + return this._entityDict.get(tag); + } + + public addToTagList(entity: Entity){ + let list = this.getTagList(entity.tag); + if (!list.contains(entity)){ + list.push(entity); + this._unsortedTags.push(entity.tag); + } + } + + public removeFromTagList(entity: Entity){ + let list = this._entityDict.get(entity.tag); + if (list){ + list.remove(entity); + } + } + + public update(){ + for (let i = 0; i < this._entities.length; i++){ + let entity = this._entities[i]; + if (entity.enabled) + entity.update(); + } + } + + public removeAllEntities(){ + this._entitiesToAdded.length = 0; + + this.updateLists(); + + for (let i = 0; i < this._entities.length; i ++){ + this._entities[i]._isDestoryed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + + this._entities.length = 0; + this._entityDict.clear(); + } + + public updateLists(){ + if (this._entitiesToRemove.length > 0){ + let temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(entity => { + this._entities.remove(entity); + entity.scene = null; + + this.scene.entityProcessors.onEntityRemoved(entity); + }); + + this._tempEntityList.length = 0; + } + + if (this._entitiesToAdded.length > 0){ + let temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(entity => { + if (!this._entities.contains(entity)){ + this._entities.push(entity); + entity.scene = this.scene; + + this.scene.entityProcessors.onEntityAdded(entity) + } + }); + + this._tempEntityList.forEach(entity => entity.onAddedToScene()); + this._tempEntityList.length = 0; + } + + if (this._unsortedTags.length > 0){ + this._unsortedTags.forEach(tag => { + this._entityDict.get(tag).sort(); + }); + + this._unsortedTags.length = 0; + } } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/PostProcessing/PostProcessor.ts b/source/src/Graphics/PostProcessing/PostProcessor.ts index a1249150..41202f5a 100644 --- a/source/src/Graphics/PostProcessing/PostProcessor.ts +++ b/source/src/Graphics/PostProcessing/PostProcessor.ts @@ -1,5 +1,5 @@ class PostProcessor { - public enable: boolean; + public enabled: boolean; public effect: egret.Filter; public scene: Scene; public shape: egret.Shape; @@ -23,7 +23,7 @@ class PostProcessor { "}"; constructor(effect: egret.Filter = null){ - this.enable = true; + this.enabled = true; this.effect = effect; } diff --git a/source/src/Physics/Shapes/Circle.ts b/source/src/Physics/Shapes/Circle.ts index 593616a3..2ad27222 100644 --- a/source/src/Physics/Shapes/Circle.ts +++ b/source/src/Physics/Shapes/Circle.ts @@ -3,6 +3,9 @@ class Circle extends Shape { public radius: number; public _originalRadius: number; public center = new Vector2(); + public get position(){ + return new Vector2(this.parent.x, this.parent.y); + } public get bounds(){ return new Rectangle().setEgretRect(this.getBounds()); diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index 57f37a17..c034d1b9 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -1,13 +1,22 @@ /// +/** + * 多边形 + */ class Polygon extends Shape { + /** 组成多边形的点。它们应该是CW和凸的。 */ public points: Vector2[]; private _polygonCenter: Vector2; private _areEdgeNormalsDirty = true; protected _originalPoints: Vector2[]; public center = new Vector2(); + /** + * 多边形坐标 + * 此为内部字段 可访问 + */ + public position: Vector2 = Vector2.zero; public get bounds(){ - return new Rectangle(0, 0, this.width, this.height); + return new Rectangle(this.position.x, this.position.y, 0, 0); } public _edgeNormals: Vector2[]; @@ -158,6 +167,11 @@ class Polygon extends Shape { return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; } + public recalculateBounds(collider: Collider){ + // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始 + + } + public pointCollidesWithShape(point: Vector2): CollisionResult { return ShapeCollisions.pointToPoly(point, this); } diff --git a/source/src/Physics/Shapes/Shape.ts b/source/src/Physics/Shapes/Shape.ts index 2e249b9d..6f351c4b 100644 --- a/source/src/Physics/Shapes/Shape.ts +++ b/source/src/Physics/Shapes/Shape.ts @@ -1,8 +1,20 @@ -abstract class Shape extends egret.DisplayObject { - public abstract bounds: Rectangle; - public position: Vector2 = Vector2.zero; - public abstract center: Vector2; +abstract class Shape { + /** 缓存的形状边界 内部字段 */ + public bounds: Rectangle; + /** + * 这不是中心。这个值不一定是物体的中心。对撞机更准确。 + * 应用任何转换旋转的localOffset + * 内部字段 + */ + public center: Vector2; + /** + * 有一个单独的位置字段可以让我们改变形状的位置来进行碰撞检查,而不是改变entity.position。 + * 触发碰撞器/边界/散列更新的位置。 + * 内部字段 + */ + public position: Vector2; + public abstract recalculateBounds(collider: Collider); public abstract pointCollidesWithShape(point: Vector2): CollisionResult; public abstract overlaps(other: Shape); public abstract collidesWithShape(other: Shape): CollisionResult; diff --git a/source/src/Physics/Verlet/SpatialHash.ts b/source/src/Physics/Verlet/SpatialHash.ts index 11d63581..ca7b10f1 100644 --- a/source/src/Physics/Verlet/SpatialHash.ts +++ b/source/src/Physics/Verlet/SpatialHash.ts @@ -63,7 +63,8 @@ class SpatialHash { for (let y = p1.y; y <= p2.y; y++) { // 如果没有单元格,我们需要创建它 let c = this.cellAtPosition(x, y, true); - c.push(collider); + if (c.indexOf(collider) == -1) + c.push(collider); } } } @@ -83,7 +84,7 @@ class SpatialHash { let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; - this._overlapTestCircle.position = circleCenter; + // this._overlapTestCircle.position = circleCenter; let resultCounter = 0; let aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); diff --git a/source/src/Utils/Analysis/TimeRuler.ts b/source/src/Utils/Analysis/TimeRuler.ts index 562588f3..b4ca2e78 100644 --- a/source/src/Utils/Analysis/TimeRuler.ts +++ b/source/src/Utils/Analysis/TimeRuler.ts @@ -3,7 +3,7 @@ */ class TimeRuler { /** 最大条数 8 */ - public static readonly maxBars = 0; + public static readonly maxBars = 8; /** */ public static readonly maxSamples = 256; /** 每条的最大嵌套调用 */ @@ -78,6 +78,8 @@ class TimeRuler { let lock = new LockUtils(this._frameKey); lock.lock().then(() => { this._updateCount = parseInt(egret.localStorage.getItem(this._frameKey), 10); + if (isNaN(this._updateCount)) + this._updateCount = 0; let count = this._updateCount; count += 1; egret.localStorage.setItem(this._frameKey, count.toString()); @@ -163,7 +165,7 @@ class TimeRuler { // 获取注册的标记 let markerId = this._markerNameToIdMap.get(markerName); - if (!markerId) { + if (isNaN(markerId)) { // 如果此标记未注册,则注册此标记。 markerId = this.markers.length; this._markerNameToIdMap.set(markerName, markerId); @@ -194,7 +196,7 @@ class TimeRuler { } let markerId = this._markerNameToIdMap.get(markerName); - if (!markerId) { + if (isNaN(markerId)) { throw new Error(`Marker ${markerName} is not registered. Make sure you specifed same name as you used for beginMark method`); } @@ -298,8 +300,7 @@ class FrameLog { constructor() { this.bars = new Array(TimeRuler.maxBars); - for (let i = 0; i < TimeRuler.maxBars; ++i) - this.bars[i] = new MarkerCollection(); + this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); } } @@ -308,16 +309,21 @@ class FrameLog { */ class MarkerCollection { public markers: Marker[] = new Array(TimeRuler.maxSamples); - public markCount: number; + public markCount: number = 0; public markerNests: number[] = new Array(TimeRuler.maxNestCall); - public nestCount: number; + public nestCount: number = 0; + + constructor(){ + this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); + this.markerNests.fill(0, 0, TimeRuler.maxNestCall); + } } class Marker { - public markerId: number; - public beginTime: number; - public endTime: number; - public color: number; + public markerId: number = 0; + public beginTime: number = 0; + public endTime: number = 0; + public color: number = 0x000000; } class MarkerInfo { @@ -326,17 +332,18 @@ class MarkerInfo { constructor(name) { this.name = name; + this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); } } class MarkerLog { - public snapMin: number; - public snapMax: number; - public snapAvg: number; - public min: number; - public max: number; - public avg: number; - public samples: number; - public color: number; - public initialized: boolean; + public snapMin: number = 0; + public snapMax: number = 0; + public snapAvg: number = 0; + public min: number = 0; + public max: number = 0; + public avg: number = 0; + public samples: number = 0; + public color: number = 0x000000; + public initialized: boolean = false; } \ No newline at end of file diff --git a/source/src/Utils/ListPool.ts b/source/src/Utils/ListPool.ts index 1a871f11..a208a76f 100644 --- a/source/src/Utils/ListPool.ts +++ b/source/src/Utils/ListPool.ts @@ -36,7 +36,7 @@ class ListPool { /** * 如果可以的话,从堆栈中弹出一个项 */ - public static obtain(): Array{ + public static obtain(): T[] { if (this._objectQueue.length > 0) return this._objectQueue.shift(); From 15c0844e297a48a70ae495f7f3def381a79a700b Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Wed, 22 Jul 2020 23:30:31 +0800 Subject: [PATCH 03/15] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=A8=A1=E5=9D=97=E8=87=B3es=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/src/ECS/Component.ts | 2 +- source/src/ECS/Components/Camera.ts | 335 +++++++++----- .../src/ECS/Components/IUpdatableComparer.ts | 10 + .../Components/Physics/Colliders/Collider.ts | 325 ++++++++------ source/src/ECS/Components/PooledComponent.ts | 10 +- .../src/ECS/Components/RenderableComponent.ts | 196 +++++++-- source/src/ECS/Components/Sprite.ts | 2 +- source/src/ECS/Components/SpriteRenderer.ts | 170 ++++--- source/src/ECS/Entity.ts | 2 +- source/src/ECS/Transform.ts | 61 ++- source/src/ECS/Utils/ComponentList.ts | 23 +- .../src/ECS/Utils/RenderableComponentList.ts | 111 ++++- source/src/Graphics/Renderers/IRenderable.ts | 54 ++- source/src/Math/Rectangle.ts | 7 + source/src/Physics/Shapes/Box.ts | 141 +++--- source/src/Physics/Shapes/Polygon.ts | 415 ++++++++++-------- source/src/Physics/Shapes/Shape.ts | 42 +- source/src/Utils/DrawUtils.ts | 13 + 18 files changed, 1245 insertions(+), 674 deletions(-) create mode 100644 source/src/ECS/Components/IUpdatableComparer.ts diff --git a/source/src/ECS/Component.ts b/source/src/ECS/Component.ts index da4dbcf1..ce3af7ba 100644 --- a/source/src/ECS/Component.ts +++ b/source/src/ECS/Component.ts @@ -75,7 +75,7 @@ module es { * 当实体的位置改变时调用。这允许组件知道它们由于父实体的移动而移动了。 * @param comp */ - public onEntityTransformChanged(comp: Transform.Component) { + public onEntityTransformChanged(comp: transform.Component) { } /** diff --git a/source/src/ECS/Components/Camera.ts b/source/src/ECS/Components/Camera.ts index d6a1f354..49f0d259 100644 --- a/source/src/ECS/Components/Camera.ts +++ b/source/src/ECS/Components/Camera.ts @@ -1,33 +1,45 @@ module es { + export enum CameraStyle { + lockOn, + cameraWindow, + } + export class Camera extends Component { - private _zoom; - private _origin: Vector2 = Vector2.zero; - - private _minimumZoom = 0.3; - private _maximumZoom = 3; - - private _position: Vector2 = Vector2.zero; /** - * 如果相机模式为cameraWindow 则会进行缓动移动 - * 该值为移动速度 + * 对entity.transform.position的快速访问 */ - public followLerp = 0.1; - public deadzone: Rectangle = new Rectangle(); - /** 锁定偏移量 默认中心 */ - public focusOffset: Vector2 = new Vector2(); - /** 是否地图锁定 如果锁定则需要设置mapSize属性 */ - public mapLockEnabled: boolean = false; - /** 设置地图大小 默认从0 0左上角开始 只需要输入地图宽高 */ - public mapSize: Vector2 = new Vector2(); - /** 跟随的实体 设置后镜头将锁定目标为中心 */ - public targetEntity: Entity; - private _worldSpaceDeadZone: Rectangle = new Rectangle(); - private _desiredPositionDelta: Vector2 = new Vector2(); - private _targetCollider: Collider; - /** 相机模式 */ - public cameraStyle: CameraStyle = CameraStyle.lockOn; + public get position() { + return this.entity.transform.position; + } - public get zoom(){ + /** + * 对entity.transform.position的快速访问 + * @param value + */ + public set position(value: Vector2) { + this.entity.transform.position = value; + } + + /** + * 对entity.transform.rotation的快速访问 + */ + public get rotation(): number { + return this.entity.transform.rotation; + } + + /** + * 对entity.transform.rotation的快速访问 + * @param value + */ + public set rotation(value: number) { + this.entity.transform.rotation = value; + } + + /** + * 缩放值应该在-1和1之间、然后将该值从minimumZoom转换为maximumZoom。 + * 允许你设置适当的最小/最大值,然后使用更直观的-1到1的映射来更改缩放 + */ + public get zoom() { if (this._zoom == 0) return 1; @@ -37,93 +49,143 @@ module es { return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); } - public set zoom(value: number){ + /** + * 缩放值应该在-1和1之间、然后将该值从minimumZoom转换为maximumZoom。 + * 允许你设置适当的最小/最大值,然后使用更直观的-1到1的映射来更改缩放 + * @param value + */ + public set zoom(value: number) { this.setZoom(value); } - public get minimumZoom(){ + /** + * 相机变焦可以达到的最小非缩放值(0-number.max)。默认为0.3 + */ + public get minimumZoom() { return this._minimumZoom; } - public set minimumZoom(value: number){ + /** + * 相机变焦可以达到的最小非缩放值(0-number.max)。默认为0.3 + * @param value + */ + public set minimumZoom(value: number) { this.setMinimumZoom(value); } - public get maximumZoom(){ + /** + * 相机变焦可以达到的最大非缩放值(0-number.max)。默认为3 + */ + public get maximumZoom() { return this._maximumZoom; } - public set maximumZoom(value: number){ + /** + * 相机变焦可以达到的最大非缩放值(0-number.max)。默认为3 + * @param value + */ + public set maximumZoom(value: number) { this.setMaximumZoom(value); } - public get origin(){ + /** + * 相机的边框 + */ + public get bounds(){ + return new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + } + + public get origin() { return this._origin; } - public set origin(value: Vector2){ - if (this._origin != value){ + public set origin(value: Vector2) { + if (this._origin != value) { this._origin = value; } } - public get position(){ - return this._position; - } + private _zoom; + private _minimumZoom = 0.3; + private _maximumZoom = 3; + private _origin: Vector2 = Vector2.zero; + /** + * 如果相机模式为cameraWindow 则会进行缓动移动 + * 该值为移动速度 + */ + public followLerp = 0.1; + /** + * 在cameraWindow模式下,宽度/高度被用做边界框,允许在不移动相机的情况下移动 + * 在lockOn模式下,只使用deadZone的x/y值 你可以通过直接setCenteredDeadzone重写它来自定义deadZone + */ + public deadzone: Rectangle = new Rectangle(); + /** + * 相机聚焦于屏幕中心的偏移 + */ + public focusOffset: Vector2 = new Vector2(); + /** + * 如果为true 相机位置则不会超出地图矩形(0, 0, mapwidth, mapheight) + */ + public mapLockEnabled: boolean = false; + /** + * 當前地圖映射的寬度和高度 + */ + public mapSize: Vector2 = new Vector2(); - public set position(value: Vector2){ - this._position = value; - } + public _targetEntity: Entity; + public _targetCollider: Collider; + public _desiredPositionDelta: Vector2 = new Vector2(); + public _cameraStyle: CameraStyle; + public _worldSpaceDeadZone: Rectangle = new Rectangle(); - public get x(){ - return this._position.x; - } - public set x(value: number){ - this._position.x = value; - } - public get y(){ - return this._position.y; - } - public set y(value: number){ - this._position.y = value; - } - - constructor() { + constructor(targetEntity: Entity = null, cameraStyle: CameraStyle = CameraStyle.lockOn) { super(); - this.width = SceneManager.stage.stageWidth; - this.height = SceneManager.stage.stageHeight; + this._targetEntity = targetEntity; + this._cameraStyle = cameraStyle; this.setZoom(0); } - public onSceneSizeChanged(newWidth: number, newHeight: number){ + /** + * 当场景渲染目标的大小发生变化时,我们会更新相机的原点并调整它的位置以保持它原来的位置 + * @param newWidth + * @param newHeight + */ + public onSceneSizeChanged(newWidth: number, newHeight: number) { let oldOrigin = this._origin; this.origin = new Vector2(newWidth / 2, newHeight / 2); - this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); + this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin)); } - public setMinimumZoom(minZoom: number): Camera{ - if (this._zoom < minZoom) - this._zoom = this.minimumZoom; - - this._minimumZoom = minZoom; + /** + * 对entity.transform.setPosition快速访问 + * @param position + */ + public setPosition(position: Vector2) { + this.entity.transform.setPosition(position.x, position.y); return this; } - public setMaximumZoom(maxZoom: number): Camera { - if (this._zoom > maxZoom) - this._zoom = maxZoom; - - this._maximumZoom = maxZoom; + /** + * 对entity.transform.setRotation的快速访问 + * @param rotation + */ + public setRotation(rotation: number): Camera { + this.entity.transform.setRotation(rotation); return this; } - public setZoom(zoom: number): Camera{ + /** + * 设置缩放值,缩放值应该在-1到1之间。然后将该值从minimumZoom转换为maximumZoom + * 允许您设置适当的最小/最大值。使用更直观的-1到1的映射来更改缩放 + * @param zoom + */ + public setZoom(zoom: number): Camera { let newZoom = MathHelper.clamp(zoom, -1, 1); - if (newZoom == 0){ + if (newZoom == 0) { this._zoom = 1; - } else if(newZoom < 0){ + } else if (newZoom < 0) { this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); } else { this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); @@ -134,103 +196,138 @@ module es { return this; } - public setRotation(rotation: number): Camera { - SceneManager.scene.rotation = rotation; + /** + * 相机变焦可以达到的最小非缩放值(0-number.max) 默认为0.3 + * @param minZoom + */ + public setMinimumZoom(minZoom: number): Camera { + if (this._zoom < minZoom) + this._zoom = this.minimumZoom; + + this._minimumZoom = minZoom; return this; } - public setPosition(position: Vector2){ - this.entity.position = position; - - return this; - } - - public follow(targetEntity: Entity, cameraStyle: CameraStyle = CameraStyle.cameraWindow){ - this.targetEntity = targetEntity; - this.cameraStyle = cameraStyle; - let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - - switch (this.cameraStyle){ - case CameraStyle.cameraWindow: - let w = cameraBounds.width / 6; - let h = cameraBounds.height / 3; - this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10); - break; + /** + * 相机变焦可以达到的最大非缩放值(0-number.max) 默认为3 + * @param maxZoom + */ + public setMaximumZoom(maxZoom: number): Camera { + if (maxZoom <= 0) { + console.error("maximumZoom must be greater than zero"); + return; } + + if (this._zoom > maxZoom) + this._zoom = maxZoom; + + this._maximumZoom = maxZoom; + return this; } - public update(){ - let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - let halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); - this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; + public zoomIn(deltaZoom: number) { + this.zoom += deltaZoom; + } + + public zoomOut(deltaZoom: number) { + this.zoom -= deltaZoom; + } + + public onAddedToEntity() { + this.follow(this._targetEntity, this._cameraStyle); + } + + public update() { + let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5)); + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; this._worldSpaceDeadZone.width = this.deadzone.width; this._worldSpaceDeadZone.height = this.deadzone.height; - if (this.targetEntity) + if (this._targetEntity) this.updateFollow(); this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); - this.entity.roundPosition(); + this.entity.transform.roundPosition(); - if (this.mapLockEnabled){ + if (this.mapLockEnabled) { this.position = this.clampToMapSize(this.position); - this.entity.roundPosition(); + this.entity.transform.roundPosition(); } } - private clampToMapSize(position: Vector2){ - let cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - let halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); + /** + * 固定相机 永远不会离开地图的可见区域 + * @param position + */ + public clampToMapSize(position: Vector2) { + let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5)); let cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); return Vector2.clamp(position, halfScreen, cameraMax); } - private updateFollow(){ + public updateFollow() { this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; - if (this.cameraStyle == CameraStyle.lockOn){ - let targetX = this.targetEntity.position.x; - let targetY = this.targetEntity.position.y; + if (this._cameraStyle == CameraStyle.lockOn) { + let targetX = this._targetEntity.transform.position.x; + let targetY = this._targetEntity.transform.position.y; if (this._worldSpaceDeadZone.x > targetX) this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - else if(this._worldSpaceDeadZone.x < targetX) + else if (this._worldSpaceDeadZone.x < targetX) this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; if (this._worldSpaceDeadZone.y < targetY) this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - else if(this._worldSpaceDeadZone.y > targetY) + else if (this._worldSpaceDeadZone.y > targetY) this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; } else { - if (!this._targetCollider){ - this._targetCollider = this.targetEntity.getComponent(Collider); + if (!this._targetCollider) { + this._targetCollider = this._targetEntity.getComponent(Collider); if (!this._targetCollider) return; } - let targetBounds = this.targetEntity.getComponent(Collider).bounds; - if (!this._worldSpaceDeadZone.containsRect(targetBounds)){ + let targetBounds = this._targetEntity.getComponent(Collider).bounds; + if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { if (this._worldSpaceDeadZone.left > targetBounds.left) this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; - else if(this._worldSpaceDeadZone.right < targetBounds.right) + else if (this._worldSpaceDeadZone.right < targetBounds.right) this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; - else if(this._worldSpaceDeadZone.top > targetBounds.top) + else if (this._worldSpaceDeadZone.top > targetBounds.top) this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; } } } - } - export enum CameraStyle { - lockOn, - cameraWindow, + public follow(targetEntity: Entity, cameraStyle: CameraStyle = CameraStyle.cameraWindow) { + this._targetEntity = targetEntity; + this._cameraStyle = cameraStyle; + + switch (this._cameraStyle) { + case CameraStyle.cameraWindow: + let w = this.bounds.width / 6; + let h = this.bounds.height / 3; + this.deadzone = new Rectangle((this.bounds.width - w) / 2, (this.bounds.height - h) / 2, w, h); + break; + case CameraStyle.lockOn: + this.deadzone = new Rectangle(this.bounds.width / 2, this.bounds.height / 2, 10, 10); + break; + } + } + + /** + * 以给定的尺寸设置当前相机边界中心的死区 + * @param width + * @param height + */ + public setCenteredDeadzone(width: number, height: number) { + this.deadzone = new Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height); + } } } diff --git a/source/src/ECS/Components/IUpdatableComparer.ts b/source/src/ECS/Components/IUpdatableComparer.ts new file mode 100644 index 00000000..46a4f90a --- /dev/null +++ b/source/src/ECS/Components/IUpdatableComparer.ts @@ -0,0 +1,10 @@ +module es { + /** + * 用于比较组件更新排序 + */ + export class IUpdatableComparer { + public compare(a: Component, b: Component){ + return a.updateOrder - b.updateOrder; + } + } +} \ No newline at end of file diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index c6fe6d02..5b482e79 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -1,161 +1,210 @@ -abstract class Collider extends Component { - /** 对撞机的基本形状 */ - public shape: Shape; - protected _localOffset: Vector2 = Vector2.zero; - public get localOffset(){ - return this._localOffset; - } - public set localOffset(){ +module es { + export abstract class Collider extends Component { + /** + * 对撞机的基本形状 + */ + public shape: Shape; + /** + * 将localOffset添加到实体。获取碰撞器几何图形的最终位置。 + * 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转 + */ + public get localOffset(): Vector2{ + return this._localOffset; + } - } - public _localOffsetLength: number; - /** 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法。 */ - public physicsLayer = 1 << 0; - /** 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件 */ - public isTrigger: boolean; - /** - * 这个对撞机在物理系统注册时的边界。 - * 存储这个允许我们始终能够安全地从物理系统中移除对撞机,即使它在试图移除它之前已经被移动了。 - */ - public registeredPhysicsBounds: Rectangle = new Rectangle(); - /** 如果为true,碰撞器将根据附加的变换缩放和旋转 */ - public shouldColliderScaleAndRotateWithTransform = true; - /** 默认为所有层。 */ - public collidesWithLayers = Physics.allLayers; + /** + * 将localOffset添加到实体。获取碰撞器几何图形的最终位置。 + * 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转 + * @param value + */ + public set localOffset(value: Vector2){ + this.setLocalOffset(value); + } - /** 标记来跟踪我们的实体是否被添加到场景中 */ - protected _isParentEntityAddedToScene; - protected _colliderRequiresAutoSizing; - /** 标记来记录我们是否注册了物理系统 */ - protected _isColliderRegistered; + /** + * 镖师碰撞器的绝对位置 + */ + public get absolutePosition(): Vector2{ + return Vector2.add(this.entity.transform.position, this._localOffset); + } - public get bounds(): Rectangle { - let shapeBounds = this.shape.bounds; - let colliderBuonds = new Rectangle(this.entity.x, this.entity.y, shapeBounds.width, shapeBounds.height); - return colliderBuonds; - } + /** + * 封装变换。如果碰撞器没和实体一起旋转 则返回transform.rotation + */ + public get rotation(): number{ + if (this.shouldColliderScaleAndRotateWithTransform && this.entity) + return this.entity.transform.rotation; - /** - * 将localOffset添加到实体。获取碰撞器的最终位置。 - * 这允许您向一个实体添加多个碰撞器并分别定位它们。 - * @param offset - */ - public setLocalOffset(offset: Vector2): Collider{ - if (this._localOffset != offset){ - this.unregisterColliderWithPhysicsSystem(); - this._localOffset = offset; - this._localOffsetLength = this._localOffset.length(); + return 0; + } + + /** + * 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件 + */ + public isTrigger: boolean; + /** + * 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法 + */ + public physicsLayer = 1 << 0; + /** + * 碰撞器在使用移动器移动时应该碰撞的层 + * 默认为所有层 + */ + public collidesWithLayers = Physics.allLayers; + + /** + * 如果为true,碰撞器将根据附加的变换缩放和旋转 + */ + public shouldColliderScaleAndRotateWithTransform = true; + + public get bounds(): Rectangle { + this.shape.recalculateBounds(this); + + return this.shape.bounds; + } + + /** + * 这个对撞机在物理系统注册时的边界。 + * 存储这个允许我们始终能够安全地从物理系统中移除对撞机,即使它在试图移除它之前已经被移动了。 + */ + public registeredPhysicsBounds: Rectangle = new Rectangle(); + protected _colliderRequiresAutoSizing; + protected _localOffset: Vector2 = Vector2.zero; + public _localOffsetLength: number; + + /** + * 标记来跟踪我们的实体是否被添加到场景中 + */ + protected _isParentEntityAddedToScene; + /** + * 标记来记录我们是否注册了物理系统 + */ + protected _isColliderRegistered; + + /** + * 将localOffset添加到实体。获取碰撞器的最终位置。 + * 这允许您向一个实体添加多个碰撞器并分别定位它们。 + * @param offset + */ + public setLocalOffset(offset: Vector2): Collider{ + if (this._localOffset != offset){ + this.unregisterColliderWithPhysicsSystem(); + this._localOffset = offset; + this._localOffsetLength = this._localOffset.length(); + this.registerColliderWithPhysicsSystem(); + } + + return this; + } + + /** + * 如果为true,碰撞器将根据附加的变换缩放和旋转 + * @param shouldColliderScaleAndRotationWithTransform + */ + public setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider { + this.shouldColliderScaleAndRotateWithTransform = shouldColliderScaleAndRotationWithTransform; + return this; + } + + public onAddedToEntity() { + if (this._colliderRequiresAutoSizing) { + if (!(this instanceof BoxCollider || this instanceof CircleCollider)) { + console.error("Only box and circle colliders can be created automatically"); + return; + } + + let renderable = this.entity.getComponent(RenderableComponent); + if (renderable) { + let bounds = renderable.bounds; + + // 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染 + let width = bounds.width / this.entity.scale.x; + let height = bounds.height / this.entity.scale.y; + // 圆碰撞器需要特别注意原点 + if (this instanceof CircleCollider){ + let circleCollider = this as CircleCollider; + circleCollider.radius = Math.max(width, height) * 0.5; + } else { + this.width = width; + this.height = height; + } + + // 获取渲染的中心,将其转移到本地坐标,并使用它作为碰撞器的localOffset + this.localOffset = Vector2.subtract(bounds.center, this.entity.transform.position); + } else { + console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); + } + } + + this._isParentEntityAddedToScene = true; this.registerColliderWithPhysicsSystem(); } - return this; - } - - /** - * 父实体会在不同的时间调用它(当添加到场景,启用,等等) - */ - public registerColliderWithPhysicsSystem() { - // 如果在将我们添加到实体之前更改了origin等属性,则实体可以为null - if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { - Physics.addCollider(this); - this._isColliderRegistered = true; + public onRemovedFromEntity() { + this.unregisterColliderWithPhysicsSystem(); + this._isParentEntityAddedToScene = false; } - } - /** - * 父实体会在不同的时候调用它(从场景中移除,禁用,等等) - */ - public unregisterColliderWithPhysicsSystem() { - if (this._isParentEntityAddedToScene && this._isColliderRegistered) { - Physics.removeCollider(this); + public onEntityTransformChanged(comp: transform.Component) { + if (this._isColliderRegistered) + Physics.updateCollider(this); } - this._isColliderRegistered = false; - } - /** - * 检查这个形状是否与物理系统中的其他对撞机重叠 - * @param other - */ - public overlaps(other: Collider) { - return this.shape.overlaps(other.shape); - } + public onEnabled() { + this.registerColliderWithPhysicsSystem(); + } - /** - * 检查这个与运动应用的碰撞器(移动向量)是否与碰撞器碰撞。如果是这样,将返回true,并且结果将填充碰撞数据。 - * @param collider - * @param motion - */ - public collidesWith(collider: Collider, motion: Vector2) { - // 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠 - let oldPosition = this.entity.position; - this.entity.position = Vector2.add(this.entity.position, motion); + public onDisabled() { + this.unregisterColliderWithPhysicsSystem(); + } - let result = this.shape.collidesWithShape(collider.shape); - if (result) - result.collider = collider; - - // 将图形位置返回到检查前的位置 - this.entity.position = oldPosition; - - return result; - } - - public onAddedToEntity() { - if (this._colliderRequiresAutoSizing) { - if (!(this instanceof BoxCollider || this instanceof CircleCollider)) { - console.error("Only box and circle colliders can be created automatically"); - } - - let renderable = this.entity.getComponent(RenderableComponent); - if (renderable) { - let bounds = renderable.bounds; - - // 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染 - let width = bounds.width / this.entity.scale.x; - let height = bounds.height / this.entity.scale.y; - // 圆碰撞器需要特别注意原点 - if (this instanceof CircleCollider){ - let circleCollider = this as CircleCollider; - circleCollider.radius = Math.max(width, height) * 0.5; - } else { - this.width = width; - this.height = height; - } - - // 获取渲染的中心,将其转移到本地坐标,并使用它作为碰撞器的localOffset - this.localOffset = Vector2.subtract(bounds.center, this.entity.position); - } else { - console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); + /** + * 父实体会在不同的时间调用它(当添加到场景,启用,等等) + */ + public registerColliderWithPhysicsSystem() { + // 如果在将我们添加到实体之前更改了origin等属性,则实体可以为null + if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { + Physics.addCollider(this); + this._isColliderRegistered = true; } } - this._isParentEntityAddedToScene = true; - this.registerColliderWithPhysicsSystem(); - } + /** + * 父实体会在不同的时候调用它(从场景中移除,禁用,等等) + */ + public unregisterColliderWithPhysicsSystem() { + if (this._isParentEntityAddedToScene && this._isColliderRegistered) { + Physics.removeCollider(this); + } + this._isColliderRegistered = false; + } - public onRemovedFromEntity() { - this.unregisterColliderWithPhysicsSystem(); - this._isParentEntityAddedToScene = false; - } + /** + * 检查这个形状是否与物理系统中的其他对撞机重叠 + * @param other + */ + public overlaps(other: Collider) { + return this.shape.overlaps(other.shape); + } - public onEnabled() { - this.registerColliderWithPhysicsSystem(); - } + /** + * 检查这个与运动应用的碰撞器(移动向量)是否与碰撞器碰撞。如果是这样,将返回true,并且结果将填充碰撞数据。 + * @param collider + * @param motion + */ + public collidesWith(collider: Collider, motion: Vector2) { + // 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠 + let oldPosition = this.entity.position; + this.entity.position = Vector2.add(this.entity.position, motion); - public onDisabled() { - this.unregisterColliderWithPhysicsSystem(); - } + let result = this.shape.collidesWithShape(collider.shape); + if (result) + result.collider = collider; - public onEntityTransformChanged(comp: TransformComponent) { - if (this._isColliderRegistered) - Physics.updateCollider(this); - } + // 将图形位置返回到检查前的位置 + this.entity.position = oldPosition; - public update(){ - let renderable = this.entity.getComponent(RenderableComponent); - if (renderable){ - this.$setX(renderable.x); - this.$setY(renderable.y); + return result; } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/PooledComponent.ts b/source/src/ECS/Components/PooledComponent.ts index 91fd8e1d..1d289140 100644 --- a/source/src/ECS/Components/PooledComponent.ts +++ b/source/src/ECS/Components/PooledComponent.ts @@ -1,4 +1,6 @@ -/** 回收实例的组件类型。 */ -abstract class PooledComponent extends Component { - public abstract reset(); -} \ No newline at end of file +module es { + /** 回收实例的组件类型。 */ + export abstract class PooledComponent extends Component { + public abstract reset(); + } +} diff --git a/source/src/ECS/Components/RenderableComponent.ts b/source/src/ECS/Components/RenderableComponent.ts index 9a1940a3..8a961eb1 100644 --- a/source/src/ECS/Components/RenderableComponent.ts +++ b/source/src/ECS/Components/RenderableComponent.ts @@ -1,56 +1,172 @@ /// -/** - * 所有可渲染组件的基类 - */ -abstract class RenderableComponent extends PooledComponent implements IRenderable { - private _isVisible: boolean; - protected _areBoundsDirty = true; - protected _bounds: Rectangle = new Rectangle(); - protected _localOffset: Vector2 = Vector2.zero; +module es { + /** + * 所有可渲染组件的基类 + */ + export abstract class RenderableComponent extends Component implements IRenderable { + /** + * renderableComponent的宽度 + * 如果你不重写bounds属性则需要实现这个 + */ + public get width() { + return this.bounds.width; + } - public color: number = 0x000000; + /** + * renderableComponent的高度 + * 如果你不重写bounds属性则需要实现这个 + */ + public get height() { + return this.bounds.height; + } - public get width(){ - return this.getWidth(); - } + /** + * 这个物体的AABB, 用于相机剔除 + */ + public get bounds(): Rectangle { + if (this._areBoundsDirty){ + this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, Vector2.zero, + this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height); + this._areBoundsDirty = false; + } - public get height(){ - return this.getHeight(); - } + return this._bounds; + } - public get isVisible(){ - return this._isVisible; - } + /** + * 较低的渲染层在前面,较高的在后面 + */ + public get renderLayer(): number{ + return this._renderLayer; + } - public set isVisible(value: boolean){ - this._isVisible = value; + public set renderLayer(value: number){ - if (this._isVisible) - this.onBecameVisible(); - else - this.onBecameInvisible(); - } + } - public get bounds(): Rectangle{ - return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); - } + /** + * 用于着色器处理精灵 + */ + public color: number = 0x000000; - protected getWidth(){ - return this.bounds.width; - } + /** + * 从父实体的偏移量。用于向需要特定定位的实体 + */ + public get localOffset(): Vector2{ + return this._localOffset; + } - protected getHeight(){ - return this.bounds.height; - } + /** + * 从父实体的偏移量。用于向需要特定定位的实体 + * @param value + */ + public set localOffset(value: Vector2){ + this.setLocalOffset(value); + } - protected onBecameVisible(){} + /** + * 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法 + */ + public get isVisible() { + return this._isVisible; + } - protected onBecameInvisible(){} + /** + * 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法 + * @param value + */ + public set isVisible(value: boolean) { + if (this._isVisible != value){ + this._isVisible = value; - public abstract render(camera: Camera); + if (this._isVisible) + this.onBecameVisible(); + else + this.onBecameInvisible(); + } + } - public isVisibleFromCamera(camera: Camera): boolean{ - this.isVisible = camera.getBounds().intersects(this.getBounds()); - return this.isVisible; + protected _localOffset: Vector2 = Vector2.zero; + protected _renderLayer: number = 0; + protected _bounds: Rectangle = new Rectangle(); + private _isVisible: boolean; + protected _areBoundsDirty = true; + + public onEntityTransformChanged(comp: transform.Component) { + this._areBoundsDirty = true; + } + + /** + * 由渲染器调用。可以使用摄像机进行剔除 + * @param camera + */ + public abstract render(camera: Camera); + + /** + * 当renderableComponent进入相机框架时调用 + * 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用 + */ + protected onBecameVisible() { + } + + /** + * 当renderableComponent离开相机框架时调用 + * 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用 + */ + protected onBecameInvisible() { + } + + /** + * 如果renderableComponent的边界与camera.bounds相交 返回true + * 用于处理isVisible标志的状态开关 + * 在渲染方法中使用这个方法来决定是否渲染 + * @param camera + */ + public isVisibleFromCamera(camera: Camera): boolean { + this.isVisible = camera.bounds.intersects(this.bounds); + return this.isVisible; + } + + /** + * 较低的渲染层在前面,较高的在后面 + * @param renderLayer + */ + public setRenderLayer(renderLayer: number): RenderableComponent{ + if (renderLayer != this._renderLayer){ + let oldRenderLayer = this._renderLayer; + this._renderLayer = renderLayer; + + // 如果该组件拥有一个实体,那么是由ComponentList管理,需要通知它改变了渲染层 + if (this.entity && this.entity.scene) + this.entity.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer); + } + + return this; + } + + /** + * 用于着色器处理精灵 + * @param color + */ + public setColor(color: number): RenderableComponent{ + this.color = color; + return this; + } + + /** + * 从父实体的偏移量。用于向需要特定定位的实体 + * @param offset + */ + public setLocalOffset(offset: Vector2): RenderableComponent{ + if (this._localOffset != offset){ + this._localOffset = offset; + } + + return this; + } + + public toString(){ + return `[RenderableComponent] ${this}, renderLayer: ${this.renderLayer}`; + } } } \ No newline at end of file diff --git a/source/src/ECS/Components/Sprite.ts b/source/src/ECS/Components/Sprite.ts index b9c2f7a8..ba8ced5e 100644 --- a/source/src/ECS/Components/Sprite.ts +++ b/source/src/ECS/Components/Sprite.ts @@ -14,7 +14,7 @@ class Sprite { this.origin = origin; let inverseTexW = 1 / texture.textureWidth; - let inverseTexH = 1 / texture.textureHeight + let inverseTexH = 1 / texture.textureHeight; this.uvs.x = sourceRect.x * inverseTexW; this.uvs.y = sourceRect.y * inverseTexH; diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts index 32df55cf..6db35138 100644 --- a/source/src/ECS/Components/SpriteRenderer.ts +++ b/source/src/ECS/Components/SpriteRenderer.ts @@ -1,66 +1,120 @@ -class SpriteRenderer extends RenderableComponent { - private _sprite: Sprite; - protected bitmap: egret.Bitmap; +module es { + export class SpriteRenderer extends RenderableComponent { + public get bounds(){ + if (this._areBoundsDirty){ + if (this._sprite){ + this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, + this.entity.transform.scale, this.entity.transform.rotation, this._sprite.sourceRect.width, + this._sprite.sourceRect.height); + this._areBoundsDirty = false; + } - /** 应该由这个精灵显示的精灵 */ - public get sprite(): Sprite { - return this._sprite; - } - /** 应该由这个精灵显示的精灵 */ - public set sprite(value: Sprite) { - this.setSprite(value); - } - - public setSprite(sprite: Sprite): SpriteRenderer { - this.removeChildren(); - this._sprite = sprite; - if (this._sprite) { - this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width; - this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height; + return this._bounds; + } } - this.bitmap = new egret.Bitmap(sprite.texture2D); - this.addChild(this.bitmap); - return this; - } - - public setColor(color: number): SpriteRenderer { - let colorMatrix = [ - 1, 0, 0, 0, 0, - 0, 1, 0, 0, 0, - 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0 - ]; - colorMatrix[0] = Math.floor(color / 256 / 256) / 255; - colorMatrix[6] = Math.floor(color / 256 % 256) / 255; - colorMatrix[12] = color % 256 / 255; - let colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this.filters = [colorFilter]; - - return this; - } - - public isVisibleFromCamera(camera: Camera): boolean { - this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); - this.visible = this.isVisible; - return this.isVisible; - } - - /** 渲染处理 在每个模块中处理各自的渲染逻辑 */ - public render(camera: Camera) { - if (this.x != -camera.position.x + camera.origin.x || - this.y != -camera.position.y + camera.origin.y) { - this.x = -camera.position.x + camera.origin.x; - this.y = -camera.position.y + camera.origin.y; - this.entity.onEntityTransformChanged(TransformComponent.position); + /** + * 精灵的原点。这是在设置精灵时自动设置的 + */ + public get origin(): Vector2{ + return this._origin; } - } - public onRemovedFromEntity() { - if (this.parent) - this.parent.removeChild(this); - } + /** + * 精灵的原点。这是在设置精灵时自动设置的 + * @param value + */ + public set origin(value: Vector2){ + this.setOrigin(value); + } - public reset() { + /** + * 用归一化方法设置原点 + * x/y 均为 0-1 + */ + public get originNormalized(): Vector2{ + return new Vector2(this._origin.x / this.width * this.entity.transform.scale.x, + this._origin.y / this.height * this.entity.transform.scale.y); + } + + /** + * 用归一化方法设置原点 + * x/y 均为 0-1 + * @param value + */ + public set originNormalized(value: Vector2){ + this.setOrigin(new Vector2(value.x * this.width / this.entity.transform.scale.x, + value.y * this.height / this.entity.transform.scale.y)); + } + + /** + * 应该由这个精灵显示的精灵 + * 当设置时,精灵的原点也被设置为精灵的origin + */ + public get sprite(): Sprite { + return this._sprite; + } + + /** + * 应该由这个精灵显示的精灵 + * 当设置时,精灵的原点也被设置为精灵的origin + * @param value + */ + public set sprite(value: Sprite) { + this.setSprite(value); + } + + protected _origin: Vector2; + protected _sprite: Sprite; + + constructor(sprite: Sprite | egret.Texture) { + super(); + if (sprite instanceof Sprite) + this.setSprite(sprite); + else if(sprite instanceof egret.Texture) + this.setSprite(new Sprite(sprite)); + } + + /** + * 设置精灵并更新精灵的原点以匹配sprite.origin + * @param sprite + */ + public setSprite(sprite: Sprite): SpriteRenderer { + this._sprite = sprite; + if (this._sprite) { + this._origin = this._sprite.origin; + } + + return this; + } + + /** + * 设置可渲染的原点 + * @param origin + */ + public setOrigin(origin: Vector2): SpriteRenderer{ + if (this._origin != origin){ + this._origin = origin; + this._areBoundsDirty = true; + } + + return this; + } + + /** + * 用归一化方法设置原点 + * x/y 均为 0-1 + * @param value + */ + public setOriginNormalized(value: Vector2): SpriteRenderer{ + this.setOrigin(new Vector2(value.x * this.width / this.entity.transform.scale.x, + value.y * this.height / this.entity.transform.scale.y)); + return this; + } + + public render(camera: Camera) { + // TODO: render + } } } + diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 82f9fb0c..0aa137d2 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -133,7 +133,7 @@ module es { this.componentBits = new BitSet(); } - public onTransformChanged(comp: Transform.Component) { + public onTransformChanged(comp: transform.Component) { // 通知我们的子项改变了位置 this.components.onEntityTransformChanged(comp); } diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts index 94a3e2bc..1a69464a 100644 --- a/source/src/ECS/Transform.ts +++ b/source/src/ECS/Transform.ts @@ -1,9 +1,22 @@ +module transform { + export enum Component { + position, + scale, + rotation, + } +} + module es { + export enum DirtyType { + clean, + positionDirty, + scaleDirty, + rotationDirty, + } + export class Transform { /** 与此转换关联的实体 */ public readonly entity: Entity; - - private _parent: Transform; /** * 获取此转换的父转换 */ @@ -38,6 +51,9 @@ module es { * 变换在世界空间的缩放 */ public scale: Vector2; + + public _parent: Transform; + public hierarchyDirty: DirtyType; public _children: Transform[]; constructor(entity: Entity) { @@ -68,6 +84,7 @@ module es { } this._parent = parent; + this.setDirty(DirtyType.positionDirty); return this; } @@ -79,6 +96,7 @@ module es { */ public setPosition(x: number, y: number): Transform { this.position = new Vector2(x, y); + this.setDirty(DirtyType.positionDirty); return this; } @@ -88,6 +106,7 @@ module es { */ public setRotation(degrees: number): Transform { this.rotation = degrees; + this.setDirty(DirtyType.rotationDirty); return this; } @@ -97,6 +116,7 @@ module es { */ public setScale(scale: Vector2): Transform { this.scale = scale; + this.setDirty(DirtyType.scaleDirty); return this; } @@ -117,6 +137,31 @@ module es { this.position = this.position.round(); } + public setDirty(dirtyFlagType: DirtyType){ + if ((this.hierarchyDirty & dirtyFlagType) == 0){ + this.hierarchyDirty |= dirtyFlagType; + + switch (dirtyFlagType) { + case es.DirtyType.positionDirty: + this.entity.onTransformChanged(transform.Component.position); + break; + case es.DirtyType.rotationDirty: + this.entity.onTransformChanged(transform.Component.rotation); + break; + case es.DirtyType.scaleDirty: + this.entity.onTransformChanged(transform.Component.scale); + break; + } + + if (!this._children) + this._children = []; + + // 告诉子项发生了变换 + for (let i = 0; i < this._children.length; i ++) + this._children[i].setDirty(dirtyFlagType); + } + } + /** * 从另一个transform属性进行拷贝 * @param transform @@ -125,14 +170,10 @@ module es { this.position = transform.position; this.rotation = transform.rotation; this.scale = transform.scale; + + this.setDirty(DirtyType.positionDirty); + this.setDirty(DirtyType.rotationDirty); + this.setDirty(DirtyType.scaleDirty); } } -} - -module Transform { - export enum Component { - position, - scale, - rotation, - } } \ No newline at end of file diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index 0b1ae9f4..38769848 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -1,5 +1,10 @@ +/// module es { export class ComponentList { + /** + * 组件列表的全局updateOrder排序 + */ + public static compareUpdatableOrder: IUpdatableComparer = new IUpdatableComparer(); public _entity: Entity; /** @@ -15,6 +20,10 @@ module es { */ public _componentsToRemove: Component[] = []; public _tempBufferList: Component[] = []; + /** + * 用于确定是否需要对该框架中的组件进行排序的标志 + */ + public _isComponentListUnsorted: boolean; constructor(entity: Entity) { this._entity = entity; @@ -28,13 +37,17 @@ module es { return this._components; } + public markEntityListUnsorted(){ + this._isComponentListUnsorted = true; + } + public add(component: Component) { this._componentsToAdd.push(component); } public remove(component: Component) { if (this._componentsToRemove.contains(component)) - console.warn(`You are trying to remove a Component (${component}) that you already removed`) + console.warn(`You are trying to remove a Component (${component}) that you already removed`); // 这可能不是一个活动的组件,所以我们必须注意它是否还没有被处理,它可能正在同一帧中被删除 if (this._componentsToAdd.contains(component)) { @@ -111,6 +124,7 @@ module es { // 在调用onAddedToEntity之前清除,以防添加更多组件 this._componentsToAdd.length = 0; + this._isComponentListUnsorted = true; // 现在所有的组件都添加到了场景中,我们再次循环并调用onAddedToEntity/onEnabled for (let i = 0; i < this._tempBufferList.length; i++) { @@ -125,6 +139,11 @@ module es { this._tempBufferList.length = 0; } + + if (this._isComponentListUnsorted){ + this._components.sort(ComponentList.compareUpdatableOrder.compare); + this._isComponentListUnsorted = false; + } } public handleRemove(component: Component) { @@ -216,7 +235,7 @@ module es { } } - public onEntityTransformChanged(comp: Transform.Component) { + public onEntityTransformChanged(comp: transform.Component) { for (let i = 0; i < this._components.length; i++) { if (this._components[i].enabled) this._components[i].onEntityTransformChanged(comp); diff --git a/source/src/ECS/Utils/RenderableComponentList.ts b/source/src/ECS/Utils/RenderableComponentList.ts index df443385..74746f76 100644 --- a/source/src/ECS/Utils/RenderableComponentList.ts +++ b/source/src/ECS/Utils/RenderableComponentList.ts @@ -1,22 +1,101 @@ -class RenderableComponentList { - private _components: IRenderable[] = []; - public get count(){ - return this._components.length; - } +/// +module es { + export class RenderableComponentList { + /** + * IRenderable列表的全局updatePrder排序 + */ + public static compareUpdatableOrder = new RenderableComparer(); + /** + * 添加到实体的组件列表 + */ + public _components: IRenderable[] = []; + /** + * 通过渲染层跟踪组件,便于检索 + */ + public _componentsByRenderLayer: Map = new Map(); + public _unsortedRenderLayers: number[] = []; + public _componentsNeedSort: boolean = true; - public get buffer(){ - return this._components; - } + public get count() { + return this._components.length; + } - public add(component: IRenderable){ - this._components.push(component); - } + public get buffer() { + return this._components; + } - public remove(component: IRenderable){ - this._components.remove(component); - } + public add(component: IRenderable) { + this._components.push(component); + this.addToRenderLayerList(component, component.renderLayer); + } - public updateList(){ + public remove(component: IRenderable) { + this._components.remove(component); + this._componentsByRenderLayer.get(component.renderLayer).remove(component); + } + public updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number) { + // 需要注意的是,如果渲染层在组件update之前发生了改变 + if (this._componentsByRenderLayer.has(oldRenderLayer) && this._componentsByRenderLayer.get(oldRenderLayer).contains(component)) { + this._componentsByRenderLayer.get(oldRenderLayer).remove(component); + this.addToRenderLayerList(component, newRenderLayer); + } + } + + /** + * 将渲染层排序标志弄脏,让所有组件重新排序 + * @param renderLayer + */ + public setRenderLayerNeedsComponentSort(renderLayer: number) { + if (!this._unsortedRenderLayers.contains(renderLayer)) + this._unsortedRenderLayers.push(renderLayer); + this._componentsNeedSort = true; + } + + public setNeedsComponentSort() { + this._componentsNeedSort = true; + } + + public addToRenderLayerList(component: IRenderable, renderLayer: number) { + let list = this.componentsWithRenderLayer(renderLayer); + if (!list.contains(component)) { + console.warn("Component renderLayer list already contains this component"); + return; + } + + list.push(component); + if (!this._unsortedRenderLayers.contains(renderLayer)) + this._unsortedRenderLayers.push(renderLayer); + this._componentsNeedSort = true; + } + + /** + * 使用给定的渲染层获取所有组件。组件列表是预先排序的 + * @param renderLayer + */ + public componentsWithRenderLayer(renderLayer: number): IRenderable[] { + if (!this._componentsByRenderLayer.get(renderLayer)) { + this._componentsByRenderLayer.set(renderLayer, []); + } + return this._componentsByRenderLayer.get(renderLayer); + } + + public updateList() { + if (this._componentsNeedSort) { + this._components.sort(RenderableComponentList.compareUpdatableOrder.compare); + this._componentsNeedSort = false; + } + + if (this._unsortedRenderLayers.length > 0) { + for (let i = 0, count = this._unsortedRenderLayers.length; i < count; i++) { + let renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]); + if (renderLayerComponents) { + renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare); + } + } + + this._unsortedRenderLayers.length = 0; + } + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Renderers/IRenderable.ts b/source/src/Graphics/Renderers/IRenderable.ts index c19dd59d..cb1a2b9d 100644 --- a/source/src/Graphics/Renderers/IRenderable.ts +++ b/source/src/Graphics/Renderers/IRenderable.ts @@ -1,7 +1,47 @@ -interface IRenderable { - bounds: Rectangle; - enabled: boolean; - isVisible: boolean; - isVisibleFromCamera(camera: Camera); - render(camera: Camera); -} \ No newline at end of file +module es { + /** + * 当该接口应用到组件时,它将注册组件以场景渲染器显示 + * 该接口请谨慎实现 + */ + export interface IRenderable { + /** + * 对象的AABB用于相机剔除 + */ + bounds: Rectangle; + /** + * 这个组件是否应该被渲染 + */ + enabled: boolean; + /** + * 较低的渲染层在前面,较高的在后面 + */ + renderLayer: number; + /** + * 可渲染的可见性。状态的改变会调用onBecameVisible/onBecameInvisible方法 + */ + isVisible: boolean; + + /** + * 如果renderableComponent的边界与camera.bounds相交 返回true + * 用于处理isVisible标志的状态开关 + * 在渲染方法中使用这个方法来决定是否渲染 + * @param camera + */ + isVisibleFromCamera(camera: Camera); + + /** + * 由渲染器调用。可以使用摄像机进行剔除 + * @param camera + */ + render(camera: Camera); + } + + /** + * 用于排序IRenderables的比较器 + */ + export class RenderableComparer { + public compare(self: IRenderable, other: IRenderable){ + return other.renderLayer - self.renderLayer; + } + } +} diff --git a/source/src/Math/Rectangle.ts b/source/src/Math/Rectangle.ts index 7db9bc97..694b553a 100644 --- a/source/src/Math/Rectangle.ts +++ b/source/src/Math/Rectangle.ts @@ -138,6 +138,13 @@ class Rectangle extends egret.Rectangle { return boundsPoint; } + public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number){ + this.x = parentPosition.x + position.x - origin.x * scale.x; + this.y = parentPosition.y + position.y - origin.y * scale.y; + this.width = width * scale.x; + this.height = height * scale.y; + } + /** * 将egret矩形转化为Rectangle * @param rect diff --git a/source/src/Physics/Shapes/Box.ts b/source/src/Physics/Shapes/Box.ts index 1871a244..e9e23c13 100644 --- a/source/src/Physics/Shapes/Box.ts +++ b/source/src/Physics/Shapes/Box.ts @@ -1,81 +1,88 @@ /// -/** - * 多边形的特殊情况。在进行SAT碰撞检查时,我们只需要检查2个轴而不是8个轴 - */ -class Box extends Polygon { - constructor(width: number, height: number){ - super(Box.buildBox(width, height), true); - this.width = width; - this.height = height; - } - +module es { /** - * 在一个盒子的形状中建立多边形需要的点的帮助方法 - * @param width - * @param height + * 多边形的特殊情况。在进行SAT碰撞检查时,我们只需要检查2个轴而不是8个轴 */ - private static buildBox(width: number, height: number): Vector2[]{ - // 我们在(0,0)的中心周围创建点 - let halfWidth = width / 2; - let halfHeight = height / 2; - let verts = new Array(4); - verts[0] = new Vector2(-halfWidth, -halfHeight); - verts[1] = new Vector2(halfWidth, -halfHeight); - verts[2] = new Vector2(halfWidth, halfHeight); - verts[3] = new Vector2(-halfWidth, halfHeight); + export class Box extends Polygon { + public width: number; + public height: number; - return verts; - } - - public overlaps(other: Shape){ - // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测 - if (other instanceof Box) - return this.bounds.intersects(other.bounds); - - if (other instanceof Circle) - return Collisions.isRectToCircle(this.bounds, other.position, other.radius); - - return super.overlaps(other); - } - - public collidesWithShape(other: Shape){ - // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测 - if (other instanceof Box){ - return ShapeCollisions.boxToBox(this, other); + constructor(width: number, height: number){ + super(Box.buildBox(width, height), true); + this.width = width; + this.height = height; } - // TODO: 让 minkowski 运行于 cricleToBox + /** + * 在一个盒子的形状中建立多边形需要的点的帮助方法 + * @param width + * @param height + */ + private static buildBox(width: number, height: number): Vector2[]{ + // 我们在(0,0)的中心周围创建点 + let halfWidth = width / 2; + let halfHeight = height / 2; + let verts = new Array(4); + verts[0] = new Vector2(-halfWidth, -halfHeight); + verts[1] = new Vector2(halfWidth, -halfHeight); + verts[2] = new Vector2(halfWidth, halfHeight); + verts[3] = new Vector2(-halfWidth, halfHeight); - return super.collidesWithShape(other); - } + return verts; + } - /** - * 更新框点,重新计算中心,设置宽度/高度 - * @param width - * @param height - */ - public updateBox(width: number, height: number){ - this.width = width; - this.height = height; + /** + * 更新框点,重新计算中心,设置宽度/高度 + * @param width + * @param height + */ + public updateBox(width: number, height: number){ + this.width = width; + this.height = height; - // 我们在(0,0)的中心周围创建点 - let halfWidth = width / 2; - let halfHeight = height / 2; + // 我们在(0,0)的中心周围创建点 + let halfWidth = width / 2; + let halfHeight = height / 2; - this.points[0] = new Vector2(-halfWidth, -halfHeight); - this.points[1] = new Vector2(halfWidth, -halfHeight); - this.points[2] = new Vector2(halfWidth, halfHeight); - this.points[3] = new Vector2(-halfWidth, halfHeight); + this.points[0] = new Vector2(-halfWidth, -halfHeight); + this.points[1] = new Vector2(halfWidth, -halfHeight); + this.points[2] = new Vector2(halfWidth, halfHeight); + this.points[3] = new Vector2(-halfWidth, halfHeight); - for (let i = 0; i < this.points.length; i ++) - this._originalPoints[i] = this.points[i]; - } + for (let i = 0; i < this.points.length; i ++) + this._originalPoints[i] = this.points[i]; + } - /** - * - * @param point - */ - public containsPoint(point: Vector2){ - return this.bounds.contains(point.x, point.y); + public overlaps(other: Shape){ + // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测 + if (other instanceof Box) + return this.bounds.intersects(other.bounds); + + if (other instanceof Circle) + return Collisions.isRectToCircle(this.bounds, other.position, other.radius); + + return super.overlaps(other); + } + + public collidesWithShape(other: Shape){ + // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测 + if (other instanceof Box){ + return ShapeCollisions.boxToBox(this, other); + } + + // TODO: 让 minkowski 运行于 cricleToBox + + return super.collidesWithShape(other); + } + + + + /** + * + * @param point + */ + public containsPoint(point: Vector2){ + return this.bounds.contains(point.x, point.y); + } } } \ No newline at end of file diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index c034d1b9..d6991b19 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -1,215 +1,250 @@ /// -/** - * 多边形 - */ -class Polygon extends Shape { - /** 组成多边形的点。它们应该是CW和凸的。 */ - public points: Vector2[]; - private _polygonCenter: Vector2; - private _areEdgeNormalsDirty = true; - protected _originalPoints: Vector2[]; - public center = new Vector2(); - /** - * 多边形坐标 - * 此为内部字段 可访问 - */ - public position: Vector2 = Vector2.zero; - - public get bounds(){ - return new Rectangle(this.position.x, this.position.y, 0, 0); - } - - public _edgeNormals: Vector2[]; - public get edgeNormals(){ - if (this._areEdgeNormalsDirty) - this.buildEdgeNormals(); - return this._edgeNormals; - } - public isBox: boolean; - - constructor(points: Vector2[], isBox?: boolean){ - super(); - - this.setPoints(points); - this.isBox = isBox; - } - - private buildEdgeNormals(){ - let totalEdges = this.isBox ? 2 : this.points.length; - if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) - this._edgeNormals = new Array(totalEdges); - - let p2: Vector2; - for (let i = 0; i < totalEdges; i ++){ - let p1 = this.points[i]; - if (i + 1 >= this.points.length) - p2 = this.points[0]; - else - p2 = this.points[i + 1]; - - let perp = Vector2Ext.perpendicular(p1, p2); - perp = Vector2.normalize(perp); - this._edgeNormals[i] = perp; - } - } - - public setPoints(points: Vector2[]) { - this.points = points; - this.recalculateCenterAndEdgeNormals(); - - this._originalPoints = []; - for (let i = 0; i < this.points.length; i ++){ - this._originalPoints.push(this.points[i]); - } - } - - public collidesWithShape(other: Shape){ - let result = new CollisionResult(); - if (other instanceof Polygon){ - return ShapeCollisions.polygonToPolygon(this, other); - } - - if (other instanceof Circle){ - result = ShapeCollisions.circleToPolygon(other, this); - if (result){ - result.invertResult(); - return result; - } - - return null; - } - - throw new Error(`overlaps of Polygon to ${other} are not supported`); - } - - public recalculateCenterAndEdgeNormals() { - this._polygonCenter = Polygon.findPolygonCenter(this.points); - this._areEdgeNormalsDirty = true; - } - - public overlaps(other: Shape){ - let result: CollisionResult; - if (other instanceof Polygon) - return ShapeCollisions.polygonToPolygon(this, other); - - if (other instanceof Circle){ - result = ShapeCollisions.circleToPolygon(other, this); - if (result){ - result.invertResult(); - return true; - } - - return false; - } - - throw new Error(`overlaps of Pologon to ${other} are not supported`); - } - +module es { /** - * 找到多边形的中心。注意,这对于正则多边形是准确的。不规则多边形没有中心。 - * @param points + * 多边形 */ - public static findPolygonCenter(points: Vector2[]) { - let x = 0, y = 0; + export class Polygon extends Shape { + /** + * 组成多边形的点 + * 保持顺时针与凸边形 + */ + public points: Vector2[]; - for (let i = 0; i < points.length; i++) { - x += points[i].x; - y += points[i].y; + /** + * 边缘法线用于SAT碰撞检测。缓存它们用于避免squareRoots + * box只有两个边缘 因为其他两边是平行的 + */ + public get edgeNormals(){ + if (this._areEdgeNormalsDirty) + this.buildEdgeNormals(); + return this._edgeNormals; } - return new Vector2(x / points.length, y / points.length); - } + public _areEdgeNormalsDirty = true; + public _edgeNormals: Vector2[]; + /** + * 多边形的原始数据 + */ + public _originalPoints: Vector2[]; + public _polygonCenter: Vector2; + /** + * 用于优化未旋转box碰撞 + */ + public isBox: boolean; + public isUnrotated: boolean = true; - /** - * 重定位多边形的点 - * @param points - */ - public static recenterPolygonVerts(points: Vector2[]){ - let center = this.findPolygonCenter(points); - for (let i = 0; i < points.length; i ++) - points[i] = Vector2.subtract(points[i], center); - } + /** + * 从点构造一个多边形 + * 多边形应该以顺时针方式指定 不能重复第一个/最后一个点,它们以0 0为中心 + * @param points + * @param isBox + */ + constructor(points: Vector2[], isBox?: boolean){ + super(); - /** - * 迭代多边形的所有边,并得到任意边上离点最近的点。 - * 通过最近点的平方距离和它所在的边的法线返回。 - * 点应该在多边形的空间中(点-多边形.位置) - * @param points - * @param point - */ - public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { closestPoint, distanceSquared, edgeNormal } { - let distanceSquared = Number.MAX_VALUE; - let edgeNormal = new Vector2(0, 0); - let closestPoint = new Vector2(0, 0); + this.setPoints(points); + this.isBox = isBox; + } - let tempDistanceSquared; - for (let i = 0; i < points.length; i++) { - let j = i + 1; - if (j == points.length) - j = 0; + /** + * 重置点并重新计算中心和边缘法线 + * @param points + */ + public setPoints(points: Vector2[]) { + this.points = points; + this.recalculateCenterAndEdgeNormals(); - let closest = ShapeCollisions.closestPointOnLine(points[i], points[j], point); - tempDistanceSquared = Vector2.distanceSquared(point, closest); - - if (tempDistanceSquared < distanceSquared) { - distanceSquared = tempDistanceSquared; - closestPoint = closest; - - // 求直线的法线 - let line = Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; + this._originalPoints = []; + for (let i = 0; i < this.points.length; i ++){ + this._originalPoints.push(this.points[i]); } } - edgeNormal = Vector2.normalize(edgeNormal); + /** + * 重新计算多边形中心 + * 如果点数改变必须调用该方法 + */ + public recalculateCenterAndEdgeNormals() { + this._polygonCenter = Polygon.findPolygonCenter(this.points); + this._areEdgeNormalsDirty = true; + } - return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; - } + /** + * 建立多边形边缘法线 + * 它们仅由edgeNormals getter惰性创建和更新 + */ + public buildEdgeNormals(){ + // 对于box 我们只需要两条边,因为另外两条边是平行的 + let totalEdges = this.isBox ? 2 : this.points.length; + if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) + this._edgeNormals = new Array(totalEdges); - public recalculateBounds(collider: Collider){ - // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始 - - } + let p2: Vector2; + for (let i = 0; i < totalEdges; i ++){ + let p1 = this.points[i]; + if (i + 1 >= this.points.length) + p2 = this.points[0]; + else + p2 = this.points[i + 1]; - public pointCollidesWithShape(point: Vector2): CollisionResult { - return ShapeCollisions.pointToPoly(point, this); - } - - /** - * 本质上,这个算法所做的就是从一个点发射一条射线。 - * 如果它与奇数条多边形边相交,我们就知道它在多边形内部。 - * @param point - */ - public containsPoint(point: Vector2) { - // 将点归一化到多边形坐标空间中 - point = Vector2.subtract(point, this.position); - - let isInside = false; - for (let i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { - if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && - (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + - this.points[i].x)) { - isInside = !isInside; + let perp = Vector2Ext.perpendicular(p1, p2); + perp = Vector2.normalize(perp); + this._edgeNormals[i] = perp; } } - return isInside; - } - /** - * 建立一个对称的多边形(六边形,八角形,n角形)并返回点 - * @param vertCount - * @param radius - */ - public static buildSymmertricalPolygon(vertCount: number, radius: number) { - let verts = new Array(vertCount); + /** + * 建立一个对称的多边形(六边形,八角形,n角形)并返回点 + * @param vertCount + * @param radius + */ + public static buildSymmetricalPolygon(vertCount: number, radius: number) { + let verts = new Array(vertCount); - for (let i = 0; i < vertCount; i++) { - let a = 2 * Math.PI * (i / vertCount); - verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); + for (let i = 0; i < vertCount; i++) { + let a = 2 * Math.PI * (i / vertCount); + verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); + } + + return verts; } - return verts; + /** + * 重定位多边形的点 + * @param points + */ + public static recenterPolygonVerts(points: Vector2[]){ + let center = this.findPolygonCenter(points); + for (let i = 0; i < points.length; i ++) + points[i] = Vector2.subtract(points[i], center); + } + + /** + * 找到多边形的中心。注意,这对于正则多边形是准确的。不规则多边形没有中心。 + * @param points + */ + public static findPolygonCenter(points: Vector2[]) { + let x = 0, y = 0; + + for (let i = 0; i < points.length; i++) { + x += points[i].x; + y += points[i].y; + } + + return new Vector2(x / points.length, y / points.length); + } + + /** + * 迭代多边形的所有边,并得到任意边上离点最近的点。 + * 通过最近点的平方距离和它所在的边的法线返回。 + * 点应该在多边形的空间中(点-多边形.位置) + * @param points + * @param point + */ + public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { closestPoint, distanceSquared, edgeNormal } { + let distanceSquared = Number.MAX_VALUE; + let edgeNormal = new Vector2(0, 0); + let closestPoint = new Vector2(0, 0); + + let tempDistanceSquared; + for (let i = 0; i < points.length; i++) { + let j = i + 1; + if (j == points.length) + j = 0; + + let closest = ShapeCollisions.closestPointOnLine(points[i], points[j], point); + tempDistanceSquared = Vector2.distanceSquared(point, closest); + + if (tempDistanceSquared < distanceSquared) { + distanceSquared = tempDistanceSquared; + closestPoint = closest; + + // 求直线的法线 + let line = Vector2.subtract(points[j], points[i]); + edgeNormal.x = -line.y; + edgeNormal.y = line.x; + } + } + + edgeNormal = Vector2.normalize(edgeNormal); + + return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + } + + public recalculateBounds(collider: Collider){ + // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始 + this.center = collider.localOffset; + + if (collider.shouldColliderScaleAndRotateWithTransform){ + this.isUnrotated = collider.entity.transform.rotation == 0; + } + + this.position = Vector2.add(collider.entity.transform.position, this.center); + this.bounds = Rectangle.rectEncompassingPoints(this.points); + this.bounds.location = Vector2.add(this.bounds.location, this.position); + } + + public overlaps(other: Shape){ + let result: CollisionResult; + if (other instanceof Polygon) + return ShapeCollisions.polygonToPolygon(this, other); + + if (other instanceof Circle){ + result = ShapeCollisions.circleToPolygon(other, this); + if (result){ + result.invertResult(); + return true; + } + + return false; + } + + throw new Error(`overlaps of Pologon to ${other} are not supported`); + } + + public collidesWithShape(other: Shape){ + let result = new CollisionResult(); + if (other instanceof Polygon){ + return ShapeCollisions.polygonToPolygon(this, other); + } + + if (other instanceof Circle){ + result = ShapeCollisions.circleToPolygon(other, this); + if (result){ + result.invertResult(); + return result; + } + + return null; + } + + throw new Error(`overlaps of Polygon to ${other} are not supported`); + } + + /** + * 本质上,这个算法所做的就是从一个点发射一条射线。 + * 如果它与奇数条多边形边相交,我们就知道它在多边形内部。 + * @param point + */ + public containsPoint(point: Vector2) { + // 将点归一化到多边形坐标空间中 + point = Vector2.subtract(point, this.position); + + let isInside = false; + for (let i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { + if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && + (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + + this.points[i].x)) { + isInside = !isInside; + } + } + + return isInside; + } + + public pointCollidesWithShape(point: Vector2): CollisionResult { + return ShapeCollisions.pointToPoly(point, this); + } } } \ No newline at end of file diff --git a/source/src/Physics/Shapes/Shape.ts b/source/src/Physics/Shapes/Shape.ts index 6f351c4b..1dcb1951 100644 --- a/source/src/Physics/Shapes/Shape.ts +++ b/source/src/Physics/Shapes/Shape.ts @@ -1,21 +1,23 @@ -abstract class Shape { - /** 缓存的形状边界 内部字段 */ - public bounds: Rectangle; - /** - * 这不是中心。这个值不一定是物体的中心。对撞机更准确。 - * 应用任何转换旋转的localOffset - * 内部字段 - */ - public center: Vector2; - /** - * 有一个单独的位置字段可以让我们改变形状的位置来进行碰撞检查,而不是改变entity.position。 - * 触发碰撞器/边界/散列更新的位置。 - * 内部字段 - */ - public position: Vector2; +module es { + export abstract class Shape { + /** + * 有一个单独的位置字段可以让我们改变形状的位置来进行碰撞检查,而不是改变entity.position。 + * 触发碰撞器/边界/散列更新的位置。 + * 内部字段 + */ + public position: Vector2; + /** + * 这不是中心。这个值不一定是物体的中心。对撞机更准确。 + * 应用任何转换旋转的localOffset + * 内部字段 + */ + public center: Vector2; + /** 缓存的形状边界 内部字段 */ + public bounds: Rectangle; - public abstract recalculateBounds(collider: Collider); - public abstract pointCollidesWithShape(point: Vector2): CollisionResult; - public abstract overlaps(other: Shape); - public abstract collidesWithShape(other: Shape): CollisionResult; -} \ No newline at end of file + public abstract recalculateBounds(collider: Collider); + public abstract pointCollidesWithShape(point: Vector2): CollisionResult; + public abstract overlaps(other: Shape); + public abstract collidesWithShape(other: Shape): CollisionResult; + } +} diff --git a/source/src/Utils/DrawUtils.ts b/source/src/Utils/DrawUtils.ts index 3775c611..54be26fd 100644 --- a/source/src/Utils/DrawUtils.ts +++ b/source/src/Utils/DrawUtils.ts @@ -43,4 +43,17 @@ class DrawUtils { shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height); shape.graphics.endFill(); } + + public static getColorMatrix(color: number): egret.ColorMatrixFilter{ + let colorMatrix = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 + ]; + colorMatrix[0] = Math.floor(color / 256 / 256) / 255; + colorMatrix[6] = Math.floor(color / 256 % 256) / 255; + colorMatrix[12] = color % 256 / 255; + return new egret.ColorMatrixFilter(colorMatrix); + } } \ No newline at end of file From 814234ca610c681714cf424a6ff5b2351732518e Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Thu, 23 Jul 2020 09:10:27 +0800 Subject: [PATCH 04/15] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=B1=BB=E8=87=B3es?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/src/ECS/Components/ComponentPool.ts | 38 +- source/src/ECS/Components/Mesh.ts | 48 +- .../Physics/Colliders/BoxCollider.ts | 147 +++--- .../Physics/Colliders/CircleCollider.ts | 83 ++-- .../Physics/Colliders/PolygonCollider.ts | 36 +- .../Components/Physics/ITriggerListener.ts | 27 +- source/src/ECS/Components/Physics/Mover.ts | 152 +++--- .../ECS/Components/Physics/ProjectileMover.ts | 96 ++-- .../ECS/Components/ScrollingSpriteRenderer.ts | 68 +-- source/src/ECS/Components/Sprite.ts | 42 +- source/src/ECS/Components/SpriteAnimation.ts | 16 +- source/src/ECS/Components/SpriteAnimator.ts | 246 +++++----- source/src/ECS/Components/SpriteRenderer.ts | 24 +- .../src/ECS/Components/TiledSpriteRenderer.ts | 108 ++--- source/src/ECS/Utils/BitSet.ts | 222 ++++----- source/src/ECS/Utils/ComponentTypeManager.ts | 30 +- source/src/ECS/Utils/EntityProcessorList.ts | 132 ++--- source/src/Physics/Shapes/Box.ts | 23 +- source/src/Physics/Shapes/Circle.ts | 103 ++-- source/src/Physics/Verlet/SpatialHash.ts | 458 +++++++++--------- 20 files changed, 1101 insertions(+), 998 deletions(-) diff --git a/source/src/ECS/Components/ComponentPool.ts b/source/src/ECS/Components/ComponentPool.ts index df1d66f2..bcac36fb 100644 --- a/source/src/ECS/Components/ComponentPool.ts +++ b/source/src/ECS/Components/ComponentPool.ts @@ -1,22 +1,24 @@ -class ComponentPool{ - private _cache: T[]; - private _type: any; +module es { + export class ComponentPool{ + private _cache: T[]; + private _type: any; - constructor(typeClass: any){ - this._type = typeClass; - this._cache = []; - } + constructor(typeClass: any){ + this._type = typeClass; + this._cache = []; + } - public obtain(): T{ - try { - return this._cache.length > 0 ? this._cache.shift() : new this._type(); - } catch(err){ - throw new Error(this._type + err); + public obtain(): T{ + try { + return this._cache.length > 0 ? this._cache.shift() : new this._type(); + } catch(err){ + throw new Error(this._type + err); + } + } + + public free(component: T){ + component.reset(); + this._cache.push(component); } } - - public free(component: T){ - component.reset(); - this._cache.push(component); - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Mesh.ts b/source/src/ECS/Components/Mesh.ts index bea8a9c9..211d50e2 100644 --- a/source/src/ECS/Components/Mesh.ts +++ b/source/src/ECS/Components/Mesh.ts @@ -1,32 +1,24 @@ /// -class Mesh extends RenderableComponent { - private _mesh: egret.Mesh; +module es { + export class Mesh extends RenderableComponent { + private _mesh: egret.Mesh; - constructor(){ - super(); + constructor(){ + super(); - this._mesh = new egret.Mesh(); + this._mesh = new egret.Mesh(); + } + + public setTexture(texture: egret.Texture): Mesh{ + this._mesh.texture = texture; + + return this; + } + + public reset() { + } + + render(camera: es.Camera) { + } } - - public setTexture(texture: egret.Texture): Mesh{ - this._mesh.texture = texture; - - return this; - } - - public onAddedToEntity(){ - this.addChild(this._mesh); - } - - public onRemovedFromEntity(){ - this.removeChild(this._mesh); - } - - public render(camera: Camera){ - this.x = this.entity.position.x - camera.position.x + camera.origin.x; - this.y = this.entity.position.y - camera.position.y + camera.origin.y; - } - - public reset() { - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts index 14e56800..504d59f3 100644 --- a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts @@ -1,74 +1,85 @@ /// -class BoxCollider extends Collider { - public get width(){ - return (this.shape as Box).width; - } - - public set width(value: number){ - this.setWidth(value); - } - - /** - * 设置BoxCollider的宽度 - * @param width - */ - public setWidth(width: number): BoxCollider{ - this._colliderRequiresAutoSizing = false; - let box = this.shape as Box; - if (width != box.width){ - // 更新框,改变边界,如果我们需要更新物理系统中的边界 - box.updateBox(width, box.height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); +module es { + export class BoxCollider extends Collider { + public get width(){ + return (this.shape as Box).width; } - return this; - } - - public get height(){ - return (this.shape as Box).height; - } - - public set height(value: number){ - this.setHeight(value); - } - - /** - * 设置BoxCollider的高度 - * @param height - */ - public setHeight(height: number){ - this._colliderRequiresAutoSizing = false; - let box = this.shape as Box; - if (height != box.height){ - // 更新框,改变边界,如果我们需要更新物理系统中的边界 - box.updateBox(box.width, height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - } - - /** - * 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。 - */ - constructor(){ - super(); - - // 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据 - this.shape = new Box(1, 1); - this._colliderRequiresAutoSizing = true; - } - - public setSize(width: number, height: number){ - this._colliderRequiresAutoSizing = false; - let box = this.shape as Box; - if (width != box.width || height != box.height){ - // 更新框,改变边界,如果我们需要更新物理系统中的边界 - box.updateBox(width, height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); + public set width(value: number){ + this.setWidth(value); } - return this; + public get height(){ + return (this.shape as Box).height; + } + + public set height(value: number){ + this.setHeight(value); + } + + /** + * 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。 + */ + constructor(){ + super(); + + // 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据 + this.shape = new Box(1, 1); + this._colliderRequiresAutoSizing = true; + } + + /** + * 设置BoxCollider的大小 + * @param width + * @param height + */ + public setSize(width: number, height: number){ + this._colliderRequiresAutoSizing = false; + let box = this.shape as Box; + if (width != box.width || height != box.height){ + // 更新框,改变边界,如果我们需要更新物理系统中的边界 + box.updateBox(width, height); + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + + return this; + } + + /** + * 设置BoxCollider的宽度 + * @param width + */ + public setWidth(width: number): BoxCollider{ + this._colliderRequiresAutoSizing = false; + let box = this.shape as Box; + if (width != box.width){ + // 更新框,改变边界,如果我们需要更新物理系统中的边界 + box.updateBox(width, box.height); + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + + return this; + } + + /** + * 设置BoxCollider的高度 + * @param height + */ + public setHeight(height: number){ + this._colliderRequiresAutoSizing = false; + let box = this.shape as Box; + if (height != box.height){ + // 更新框,改变边界,如果我们需要更新物理系统中的边界 + box.updateBox(box.width, height); + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + } + + public toString(){ + return `[BoxCollider: bounds: ${this.bounds}]`; + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts b/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts index f5d4bb05..26df381b 100644 --- a/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/CircleCollider.ts @@ -1,41 +1,48 @@ -class CircleCollider extends Collider { - public get radius(): number{ - return (this.shape as Circle).radius; - } - public set radius(value: number){ - this.setRadius(value); - } - - /** - * 创建一个有半径的圆 - * - * @param radius - */ - constructor(radius?: number){ - super(); - - if (radius) - this._colliderRequiresAutoSizing = true; - // 我们在这里插入一个1px的圆圈作为占位符 - // 直到碰撞器被添加到实体并可以获得更精确的自动调整大小数据的下一帧 - this.shape = new Circle(radius ? radius : 1); - } - - /** - * 设置圆的半径 - * @param radius - */ - public setRadius(radius: number): CircleCollider{ - this._colliderRequiresAutoSizing = false; - let circle = this.shape as Circle; - if (radius != circle.radius){ - circle.radius = radius; - circle._originalRadius = radius; - - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); +module es { + export class CircleCollider extends Collider { + public get radius(): number { + return (this.shape as Circle).radius; } - return this; + public set radius(value: number) { + this.setRadius(value); + } + + /** + * 创建一个有半径的圆 + * + * @param radius + */ + constructor(radius?: number) { + super(); + + if (radius) + this._colliderRequiresAutoSizing = true; + // 我们在这里插入一个1px的圆圈作为占位符 + // 直到碰撞器被添加到实体并可以获得更精确的自动调整大小数据的下一帧 + this.shape = new Circle(radius ? radius : 1); + } + + /** + * 设置圆的半径 + * @param radius + */ + public setRadius(radius: number): CircleCollider { + this._colliderRequiresAutoSizing = false; + let circle = this.shape as Circle; + if (radius != circle.radius) { + circle.radius = radius; + circle._originalRadius = radius; + + if (this.entity && this._isParentEntityAddedToScene) + Physics.updateCollider(this); + } + + return this; + } + + public toString() { + return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]` + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts b/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts index e0a934f2..9e6732f4 100644 --- a/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts +++ b/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts @@ -1,22 +1,26 @@ -/** - * 多边形应该以顺时针方式定义 - */ -class PolygonCollider extends Collider { +module es { /** - * 如果这些点没有居中,它们将以localOffset的差异为居中。 - * @param points + * 多边形应该以顺时针方式定义 */ - constructor(points: Vector2[]){ - super(); + export class PolygonCollider extends Collider { + /** + * 如果这些点没有居中,它们将以localOffset的差异为居中。 + * @param points + */ + constructor(points: Vector2[]) { + super(); - // 第一点和最后一点决不能相同。我们想要一个开放的多边形 - let isPolygonClosed = points[0] == points[points.length - 1]; + // 第一点和最后一点决不能相同。我们想要一个开放的多边形 + let isPolygonClosed = points[0] == points[points.length - 1]; - // 最后一个移除 - if (isPolygonClosed) - points.splice(points.length - 1, 1); + // 最后一个移除 + if (isPolygonClosed) + points.splice(points.length - 1, 1); - Polygon.recenterPolygonVerts(points); - this.shape = new Polygon(points); + let center = Polygon.findPolygonCenter(points); + this.setLocalOffset(center); + Polygon.recenterPolygonVerts(points); + this.shape = new Polygon(points); + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Physics/ITriggerListener.ts b/source/src/ECS/Components/Physics/ITriggerListener.ts index a04f150c..dd7e2ff0 100644 --- a/source/src/ECS/Components/Physics/ITriggerListener.ts +++ b/source/src/ECS/Components/Physics/ITriggerListener.ts @@ -1,4 +1,23 @@ -interface ITriggerListener { - onTriggerEnter(other: Collider, local: Collider); - onTriggerExit(other: Collider, local: Collider); -} \ No newline at end of file +module es{ + /** + * 当添加到组件时,每当实体上的冲突器与另一个组件重叠/退出时,将调用这些方法。 + * ITriggerListener方法将在实现接口的触发器实体上的任何组件上调用。 + * 注意,这个接口只与Mover类一起工作 + */ + export interface ITriggerListener { + /** + * 当碰撞器与触发碰撞器相交时调用。这是在触发碰撞器和触发碰撞器上调用的。 + * 移动必须由Mover/ProjectileMover方法处理,以使其自动工作。 + * @param other + * @param local + */ + onTriggerEnter(other: Collider, local: Collider); + + /** + * 当另一个碰撞器离开触发碰撞器时调用 + * @param other + * @param local + */ + onTriggerExit(other: Collider, local: Collider); + } +} diff --git a/source/src/ECS/Components/Physics/Mover.ts b/source/src/ECS/Components/Physics/Mover.ts index f1acc291..0de3dba3 100644 --- a/source/src/ECS/Components/Physics/Mover.ts +++ b/source/src/ECS/Components/Physics/Mover.ts @@ -1,93 +1,95 @@ -/** - * 辅助类说明了一种处理移动的方法,它考虑了包括触发器在内的所有冲突。 - * ITriggerListener接口用于管理对移动过程中违反的任何触发器的回调。 - * 一个物体只能通过移动器移动。要正确报告触发器的move方法。 - * - * 请注意,多个移动者相互交互将多次调用ITriggerListener。 - */ -class Mover extends Component { - private _triggerHelper: ColliderTriggerHelper; - - public onAddedToEntity(){ - this._triggerHelper = new ColliderTriggerHelper(this.entity); - } - +module es { /** - * 计算修改运动矢量的运动,以考虑移动时可能发生的碰撞 - * @param motion + * 辅助类说明了一种处理移动的方法,它考虑了包括触发器在内的所有冲突。 + * ITriggerListener接口用于管理对移动过程中违反的任何触发器的回调。 + * 一个物体只能通过移动器移动。要正确报告触发器的move方法。 + * + * 请注意,多个移动者相互交互将多次调用ITriggerListener。 */ - public calculateMovement(motion: Vector2){ - let collisionResult = new CollisionResult(); + export class Mover extends Component { + private _triggerHelper: ColliderTriggerHelper; - if (!this.entity.getComponent(Collider) || !this._triggerHelper){ - return null; + public onAddedToEntity(){ + this._triggerHelper = new ColliderTriggerHelper(this.entity); } - // 移动所有的非触发碰撞器并获得最近的碰撞 - let colliders: Collider[] = this.entity.getComponents(Collider); - for (let i = 0; i < colliders.length; i ++){ - let collider = colliders[i]; + /** + * 计算修改运动矢量的运动,以考虑移动时可能发生的碰撞 + * @param motion + */ + public calculateMovement(motion: Vector2){ + let collisionResult = new CollisionResult(); - // 不检测触发器 在我们移动后会重新访问它 - if (collider.isTrigger) - continue; + if (!this.entity.getComponent(Collider) || !this._triggerHelper){ + return null; + } - // 获取我们在新位置可能发生碰撞的任何东西 - let bounds = collider.bounds; - bounds.x += motion.x; - bounds.y += motion.y; - let boxcastResult = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); - bounds = boxcastResult.bounds; - let neighbors = boxcastResult.tempHashSet; + // 移动所有的非触发碰撞器并获得最近的碰撞 + let colliders: Collider[] = this.entity.getComponents(Collider); + for (let i = 0; i < colliders.length; i ++){ + let collider = colliders[i]; - for (let j = 0; j < neighbors.length; j ++){ - let neighbor = neighbors[j]; - // 不检测触发器 - if (neighbor.isTrigger) + // 不检测触发器 在我们移动后会重新访问它 + if (collider.isTrigger) continue; - let _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult){ - // 如果碰撞 则退回之前的移动量 - motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); + // 获取我们在新位置可能发生碰撞的任何东西 + let bounds = collider.bounds; + bounds.x += motion.x; + bounds.y += motion.y; + let boxcastResult = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); + bounds = boxcastResult.bounds; + let neighbors = boxcastResult.tempHashSet; - // 如果我们碰到多个对象,为了简单起见,只取第一个。 - if (_internalcollisionResult.collider){ - collisionResult = _internalcollisionResult; + for (let j = 0; j < neighbors.length; j ++){ + let neighbor = neighbors[j]; + // 不检测触发器 + if (neighbor.isTrigger) + continue; + + let _internalcollisionResult = collider.collidesWith(neighbor, motion); + if (_internalcollisionResult){ + // 如果碰撞 则退回之前的移动量 + motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); + + // 如果我们碰到多个对象,为了简单起见,只取第一个。 + if (_internalcollisionResult.collider){ + collisionResult = _internalcollisionResult; + } } } } + + ListPool.free(colliders); + + return {collisionResult: collisionResult, motion: motion}; } - ListPool.free(colliders); + /** + * 将calculatemomovement应用到实体并更新triggerHelper + * @param motion + */ + public applyMovement(motion: Vector2){ + // 移动实体到它的新位置,如果我们有一个碰撞,否则移动全部数量。当碰撞发生时,运动被更新 + this.entity.position = Vector2.add(this.entity.position, motion); - return {collisionResult: collisionResult, motion: motion}; + // 对所有是触发器的碰撞器与所有宽相位碰撞器进行重叠检查。任何重叠都会导致触发事件。 + if (this._triggerHelper) + this._triggerHelper.update(); + } + + /** + * 通过调用calculateMovement和applyMovement来移动考虑碰撞的实体; + * @param motion + */ + public move(motion: Vector2){ + let movementResult = this.calculateMovement(motion); + let collisionResult = movementResult.collisionResult; + motion = movementResult.motion; + + this.applyMovement(motion); + + return collisionResult; + } } - - /** - * 将calculatemomovement应用到实体并更新triggerHelper - * @param motion - */ - public applyMovement(motion: Vector2){ - // 移动实体到它的新位置,如果我们有一个碰撞,否则移动全部数量。当碰撞发生时,运动被更新 - this.entity.position = Vector2.add(this.entity.position, motion); - - // 对所有是触发器的碰撞器与所有宽相位碰撞器进行重叠检查。任何重叠都会导致触发事件。 - if (this._triggerHelper) - this._triggerHelper.update(); - } - - /** - * 通过调用calculateMovement和applyMovement来移动考虑碰撞的实体; - * @param motion - */ - public move(motion: Vector2){ - let movementResult = this.calculateMovement(motion); - let collisionResult = movementResult.collisionResult; - motion = movementResult.motion; - - this.applyMovement(motion); - - return collisionResult; - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Physics/ProjectileMover.ts b/source/src/ECS/Components/Physics/ProjectileMover.ts index 3d5b8f7b..72e10eec 100644 --- a/source/src/ECS/Components/Physics/ProjectileMover.ts +++ b/source/src/ECS/Components/Physics/ProjectileMover.ts @@ -1,56 +1,58 @@ -/** - * 只向itriggerlistener报告冲突的移动器 - * 该对象将始终移动完整的距离 - */ -class ProjectileMover extends Component { - private _tempTriggerList: ITriggerListener[] = []; - private _collider: Collider; - - public onAddedToEntity(){ - this._collider = this.entity.getComponent(Collider); - if (!this._collider) - console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!"); - } - +module es { /** - * 移动考虑碰撞的实体 - * @param motion + * 只向itriggerlistener报告冲突的移动器 + * 该对象将始终移动完整的距离 */ - public move(motion: Vector2): boolean{ - if (!this._collider) - return false; + export class ProjectileMover extends Component { + private _tempTriggerList: ITriggerListener[] = []; + private _collider: Collider; - let didCollide = false; + public onAddedToEntity(){ + this._collider = this.entity.getComponent(Collider); + if (!this._collider) + console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!"); + } - // 获取我们在新位置可能发生碰撞的任何东西 - this.entity.position = Vector2.add(this.entity.position, motion); + /** + * 移动考虑碰撞的实体 + * @param motion + */ + public move(motion: Vector2): boolean{ + if (!this._collider) + return false; - // 获取任何可能在新位置发生碰撞的东西 - let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); - for (let i = 0; i < neighbors.colliders.length; i ++){ - let neighbor = neighbors.colliders[i]; - if (this._collider.overlaps(neighbor) && neighbor.enabled){ - didCollide = true; - this.notifyTriggerListeners(this._collider, neighbor); + let didCollide = false; + + // 获取我们在新位置可能发生碰撞的任何东西 + this.entity.position = Vector2.add(this.entity.position, motion); + + // 获取任何可能在新位置发生碰撞的东西 + let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); + for (let i = 0; i < neighbors.colliders.length; i ++){ + let neighbor = neighbors.colliders[i]; + if (this._collider.overlaps(neighbor) && neighbor.enabled){ + didCollide = true; + this.notifyTriggerListeners(this._collider, neighbor); + } } + + return didCollide; } - return didCollide; + private notifyTriggerListeners(self: Collider, other: Collider){ + // 通知我们重叠的碰撞器实体上的任何侦听器 + other.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (let i = 0; i < this._tempTriggerList.length; i ++){ + this._tempTriggerList[i].onTriggerEnter(self, other); + } + this._tempTriggerList.length = 0; + + // 通知此实体上的任何侦听器 + this.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (let i = 0; i < this._tempTriggerList.length; i ++){ + this._tempTriggerList[i].onTriggerEnter(other, self); + } + this._tempTriggerList.length = 0; + } } - - private notifyTriggerListeners(self: Collider, other: Collider){ - // 通知我们重叠的碰撞器实体上的任何侦听器 - other.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (let i = 0; i < this._tempTriggerList.length; i ++){ - this._tempTriggerList[i].onTriggerEnter(self, other); - } - this._tempTriggerList.length = 0; - - // 通知此实体上的任何侦听器 - this.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (let i = 0; i < this._tempTriggerList.length; i ++){ - this._tempTriggerList[i].onTriggerEnter(other, self); - } - this._tempTriggerList.length = 0; - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/ScrollingSpriteRenderer.ts b/source/src/ECS/Components/ScrollingSpriteRenderer.ts index f2e1ba30..9b8e38d2 100644 --- a/source/src/ECS/Components/ScrollingSpriteRenderer.ts +++ b/source/src/ECS/Components/ScrollingSpriteRenderer.ts @@ -1,37 +1,37 @@ /// -class ScrollingSpriteRenderer extends TiledSpriteRenderer { - public scrollSpeedX = 15; - public scroolSpeedY = 0; - private _scrollX = 0; - private _scrollY = 0; +module es { + export class ScrollingSpriteRenderer extends TiledSpriteRenderer { + public scrollSpeedX = 15; + public scroolSpeedY = 0; + private _scrollX = 0; + private _scrollY = 0; - public update(){ - this._scrollX += this.scrollSpeedX * Time.deltaTime; - this._scrollY += this.scroolSpeedY * Time.deltaTime; - this.sourceRect.x = this._scrollX; - this.sourceRect.y = this._scrollY; + public update(){ + this._scrollX += this.scrollSpeedX * Time.deltaTime; + this._scrollY += this.scroolSpeedY * Time.deltaTime; + this.sourceRect.x = this._scrollX; + this.sourceRect.y = this._scrollY; + } + + public render(camera: Camera) { + if (!this.sprite) + return; + + super.render(camera); + + let renderTexture = new egret.RenderTexture(); + let cacheBitmap = new egret.DisplayObjectContainer(); + cacheBitmap.removeChildren(); + cacheBitmap.addChild(this.leftTexture); + cacheBitmap.addChild(this.rightTexture); + + this.leftTexture.x = this.sourceRect.x; + this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; + this.leftTexture.y = this.sourceRect.y; + this.rightTexture.y = this.sourceRect.y; + + cacheBitmap.cacheAsBitmap = true; + renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); + } } - - public render(camera: Camera) { - if (!this.sprite) - return; - - super.render(camera); - - let renderTexture = new egret.RenderTexture(); - let cacheBitmap = new egret.DisplayObjectContainer(); - cacheBitmap.removeChildren(); - cacheBitmap.addChild(this.leftTexture); - cacheBitmap.addChild(this.rightTexture); - - this.leftTexture.x = this.sourceRect.x; - this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; - this.leftTexture.y = this.sourceRect.y; - this.rightTexture.y = this.sourceRect.y; - - cacheBitmap.cacheAsBitmap = true; - renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); - - this.bitmap.texture = renderTexture; - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/Sprite.ts b/source/src/ECS/Components/Sprite.ts index ba8ced5e..19c54fb4 100644 --- a/source/src/ECS/Components/Sprite.ts +++ b/source/src/ECS/Components/Sprite.ts @@ -1,24 +1,26 @@ -class Sprite { - public texture2D: egret.Texture; - public readonly sourceRect: Rectangle; - public readonly center: Vector2; - public origin: Vector2; - public readonly uvs: Rectangle = new Rectangle(); +module es { + export class Sprite { + public texture2D: egret.Texture; + public readonly sourceRect: Rectangle; + public readonly center: Vector2; + public origin: Vector2; + public readonly uvs: Rectangle = new Rectangle(); - constructor(texture: egret.Texture, - sourceRect: Rectangle = new Rectangle(0, 0, texture.textureWidth, texture.textureHeight), - origin: Vector2 = sourceRect.getHalfSize()) { - this.texture2D = texture; - this.sourceRect = sourceRect; - this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); - this.origin = origin; + constructor(texture: egret.Texture, + sourceRect: Rectangle = new Rectangle(0, 0, texture.textureWidth, texture.textureHeight), + origin: Vector2 = sourceRect.getHalfSize()) { + this.texture2D = texture; + this.sourceRect = sourceRect; + this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); + this.origin = origin; - let inverseTexW = 1 / texture.textureWidth; - let inverseTexH = 1 / texture.textureHeight; + let inverseTexW = 1 / texture.textureWidth; + let inverseTexH = 1 / texture.textureHeight; - this.uvs.x = sourceRect.x * inverseTexW; - this.uvs.y = sourceRect.y * inverseTexH; - this.uvs.width = sourceRect.width * inverseTexW; - this.uvs.height = sourceRect.height * inverseTexH; + this.uvs.x = sourceRect.x * inverseTexW; + this.uvs.y = sourceRect.y * inverseTexH; + this.uvs.width = sourceRect.width * inverseTexW; + this.uvs.height = sourceRect.height * inverseTexH; + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/SpriteAnimation.ts b/source/src/ECS/Components/SpriteAnimation.ts index 15ee5ea3..77e33923 100644 --- a/source/src/ECS/Components/SpriteAnimation.ts +++ b/source/src/ECS/Components/SpriteAnimation.ts @@ -1,9 +1,11 @@ -class SpriteAnimation { - public readonly sprites: Sprite[]; - public readonly frameRate: number; +module es { + export class SpriteAnimation { + public readonly sprites: Sprite[]; + public readonly frameRate: number; - constructor(sprites: Sprite[], frameRate: number){ - this.sprites = sprites; - this.frameRate = frameRate; + constructor(sprites: Sprite[], frameRate: number){ + this.sprites = sprites; + this.frameRate = frameRate; + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Components/SpriteAnimator.ts b/source/src/ECS/Components/SpriteAnimator.ts index dc3ee505..f4b6af29 100644 --- a/source/src/ECS/Components/SpriteAnimator.ts +++ b/source/src/ECS/Components/SpriteAnimator.ts @@ -1,108 +1,84 @@ /// -class SpriteAnimator extends SpriteRenderer { - /** 在动画完成时触发,包括动画名称; */ - public onAnimationCompletedEvent: Function; - /** 动画播放速度 */ - public speed = 1; - /** 动画的当前状态 */ - public animationState = State.none; - /** 当前动画 */ - public currentAnimation: SpriteAnimation; - /** 当前动画的名称 */ - public currentAnimationName: string; - /** 当前动画的精灵数组中当前帧的索引 */ - public currentFrame: number; - /** 检查当前动画是否正在运行 */ - public get isRunning(): boolean{ - return this.animationState == State.running; +module es { + export enum LoopMode { + /** 在一个循环序列[A][B][C][A][B][C][A][B][C]... */ + loop, + /** [A][B][C]然后暂停,设置时间为0 [A] */ + once, + /** [A][B][C]。当它到达终点时,它会继续播放最后一帧,并且不会停止播放 */ + clampForever, + /** 以一个乒乓循环的方式永远播放这个序列 [A][B][C][B][A][B][C][B]... */ + pingPong, + /** 将顺序向前播放一次,然后返回到开始[A][B][C][B][A],然后暂停并设置时间为0 */ + pingPongOnce, } - /** 提供对可用动画列表的访问 */ - public get animations(){ - return this._animations; - } - private _animations: Map = new Map(); - private _elapsedTime: number = 0; - private _loopMode: LoopMode; - - constructor(sprite?: Sprite){ - super(); - - if (sprite) this.setSprite(sprite); + export enum State { + none, + running, + paused, + completed, } - /** - * 添加一个SpriteAnimation - * @param name - * @param animation - */ - public addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator{ - if (!this.sprite && animation.sprites.length > 0) - this.setSprite(animation.sprites[0]); - this._animations[name] = animation; - return this; - } + export class SpriteAnimator extends SpriteRenderer { + /** + * 在动画完成时触发,包括动画名称 + */ + public onAnimationCompletedEvent: (string) => {}; + /** + * 动画播放速度 + */ + public speed = 1; + /** + * 动画的当前状态 + */ + public animationState = State.none; + /** + * 当前动画 + */ + public currentAnimation: SpriteAnimation; + /** + * 当前动画的名称 + */ + public currentAnimationName: string; + /** + * 当前动画的精灵数组中当前帧的索引 + */ + public currentFrame: number; - /** - * 以给定的名称放置动画。如果没有指定循环模式,则默认为循环 - * @param name - * @param loopMode - */ - public play(name: string, loopMode: LoopMode = null){ - this.currentAnimation = this._animations[name]; - this.currentAnimationName = name; - this.currentFrame = 0; - this.animationState = State.running; + /** + * 检查当前动画是否正在运行 + */ + public get isRunning(): boolean { + return this.animationState == State.running; + } - this.sprite = this.currentAnimation.sprites[0]; - this._elapsedTime = 0; - this._loopMode = loopMode ? loopMode : LoopMode.loop; - } + /** 提供对可用动画列表的访问 */ + public get animations() { + return this._animations; + } - /** - * 检查动画是否正在播放(即动画是活动的)。它可能仍然处于暂停状态) - * @param name - */ - public isAnimationActive(name: string): boolean{ - return this.currentAnimation && this.currentAnimationName == name; - } + private _animations: Map = new Map(); + public _elapsedTime: number = 0; + public _loopMode: LoopMode; - /** - * 暂停动画 - */ - public pause(){ - this.animationState = State.paused; - } + constructor(sprite?: Sprite) { + super(sprite); + } - /** - * 继续动画 - */ - public unPause(){ - this.animationState = State.running; - } + public update() { + if (this.animationState != State.running || !this.currentAnimation) return; - /** - * 停止当前动画并将其设为null - */ - public stop(){ - this.currentAnimation = null; - this.currentAnimationName = null; - this.currentFrame = 0; - this.animationState = State.none; - } + let animation = this.currentAnimation; + let secondsPerFrame = 1 / (animation.frameRate * this.speed); + let iterationDuration = secondsPerFrame * animation.sprites.length; - public update(){ - if (this.animationState != State.running || !this.currentAnimation) return; + this._elapsedTime += Time.deltaTime; + let time = Math.abs(this._elapsedTime); - let animation = this.currentAnimation; - let secondsPerFrame = 1 / (animation.frameRate * this.speed); - let iterationDuration = secondsPerFrame * animation.sprites.length; - - this._elapsedTime += Time.deltaTime; - let time = Math.abs(this._elapsedTime); - - if (this._loopMode == LoopMode.once && time > iterationDuration || - this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2){ + // Once和PingPongOnce完成后重置为Time = 0 + if (this._loopMode == LoopMode.once && time > iterationDuration || + this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) { this.animationState = State.completed; this._elapsedTime = 0; this.currentFrame = 0; @@ -113,34 +89,76 @@ class SpriteAnimator extends SpriteRenderer { // 弄清楚我们在哪个坐标系上 let i = Math.floor(time / secondsPerFrame); let n = animation.sprites.length; - if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)){ + if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) { // pingpong let maxIndex = n - 1; this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2)); - }else{ + } else { this.currentFrame = i % n; } this.sprite = animation.sprites[this.currentFrame]; + } + + /** + * 添加一个SpriteAnimation + * @param name + * @param animation + */ + public addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator { + // 如果我们没有精灵,使用我们找到的第一帧 + if (!this.sprite && animation.sprites.length > 0) + this.setSprite(animation.sprites[0]); + this._animations[name] = animation; + return this; + } + + /** + * 以给定的名称放置动画。如果没有指定循环模式,则默认为循环 + * @param name + * @param loopMode + */ + public play(name: string, loopMode: LoopMode = null) { + this.currentAnimation = this._animations[name]; + this.currentAnimationName = name; + this.currentFrame = 0; + this.animationState = State.running; + + this.sprite = this.currentAnimation.sprites[0]; + this._elapsedTime = 0; + this._loopMode = loopMode ? loopMode : LoopMode.loop; + } + + /** + * 检查动画是否正在播放(即动画是活动的)。它可能仍然处于暂停状态) + * @param name + */ + public isAnimationActive(name: string): boolean { + return this.currentAnimation && this.currentAnimationName == name; + } + + /** + * 暂停动画 + */ + public pause() { + this.animationState = State.paused; + } + + /** + * 继续动画 + */ + public unPause() { + this.animationState = State.running; + } + + /** + * 停止当前动画并将其设为null + */ + public stop() { + this.currentAnimation = null; + this.currentAnimationName = null; + this.currentFrame = 0; + this.animationState = State.none; + } } } - -enum LoopMode { - /** 在一个循环序列[A][B][C][A][B][C][A][B][C]... */ - loop, - /** [A][B][C]然后暂停,设置时间为0 [A] */ - once, - /** [A][B][C]。当它到达终点时,它会继续播放最后一帧,并且不会停止播放 */ - clampForever, - /** 以一个乒乓循环的方式永远播放这个序列 [A][B][C][B][A][B][C][B]... */ - pingPong, - /** 将顺序向前播放一次,然后返回到开始[A][B][C][B][A],然后暂停并设置时间为0 */ - pingPongOnce, -} - -enum State { - none, - running, - paused, - completed, -} \ No newline at end of file diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts index 6db35138..f57f66e8 100644 --- a/source/src/ECS/Components/SpriteRenderer.ts +++ b/source/src/ECS/Components/SpriteRenderer.ts @@ -1,8 +1,8 @@ module es { export class SpriteRenderer extends RenderableComponent { - public get bounds(){ - if (this._areBoundsDirty){ - if (this._sprite){ + public get bounds() { + if (this._areBoundsDirty) { + if (this._sprite) { this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.sourceRect.width, this._sprite.sourceRect.height); @@ -16,7 +16,7 @@ module es { /** * 精灵的原点。这是在设置精灵时自动设置的 */ - public get origin(): Vector2{ + public get origin(): Vector2 { return this._origin; } @@ -24,7 +24,7 @@ module es { * 精灵的原点。这是在设置精灵时自动设置的 * @param value */ - public set origin(value: Vector2){ + public set origin(value: Vector2) { this.setOrigin(value); } @@ -32,7 +32,7 @@ module es { * 用归一化方法设置原点 * x/y 均为 0-1 */ - public get originNormalized(): Vector2{ + public get originNormalized(): Vector2 { return new Vector2(this._origin.x / this.width * this.entity.transform.scale.x, this._origin.y / this.height * this.entity.transform.scale.y); } @@ -42,7 +42,7 @@ module es { * x/y 均为 0-1 * @param value */ - public set originNormalized(value: Vector2){ + public set originNormalized(value: Vector2) { this.setOrigin(new Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y)); } @@ -67,11 +67,11 @@ module es { protected _origin: Vector2; protected _sprite: Sprite; - constructor(sprite: Sprite | egret.Texture) { + constructor(sprite: Sprite | egret.Texture = null) { super(); if (sprite instanceof Sprite) this.setSprite(sprite); - else if(sprite instanceof egret.Texture) + else if (sprite instanceof egret.Texture) this.setSprite(new Sprite(sprite)); } @@ -92,8 +92,8 @@ module es { * 设置可渲染的原点 * @param origin */ - public setOrigin(origin: Vector2): SpriteRenderer{ - if (this._origin != origin){ + public setOrigin(origin: Vector2): SpriteRenderer { + if (this._origin != origin) { this._origin = origin; this._areBoundsDirty = true; } @@ -106,7 +106,7 @@ module es { * x/y 均为 0-1 * @param value */ - public setOriginNormalized(value: Vector2): SpriteRenderer{ + public setOriginNormalized(value: Vector2): SpriteRenderer { this.setOrigin(new Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y)); return this; diff --git a/source/src/ECS/Components/TiledSpriteRenderer.ts b/source/src/ECS/Components/TiledSpriteRenderer.ts index e5b097f4..a9316e09 100644 --- a/source/src/ECS/Components/TiledSpriteRenderer.ts +++ b/source/src/ECS/Components/TiledSpriteRenderer.ts @@ -1,57 +1,57 @@ /// -/** - * 滚动由两张图片组合而成 - */ -class TiledSpriteRenderer extends SpriteRenderer { - protected sourceRect: Rectangle; - protected leftTexture: egret.Bitmap; - protected rightTexture: egret.Bitmap; +module es { + /** + * 滚动由两张图片组合而成 + */ + export class TiledSpriteRenderer extends SpriteRenderer { + protected sourceRect: Rectangle; + protected leftTexture: egret.Bitmap; + protected rightTexture: egret.Bitmap; - public get scrollX() { - return this.sourceRect.x; + public get scrollX() { + return this.sourceRect.x; + } + public set scrollX(value: number) { + this.sourceRect.x = value; + } + public get scrollY() { + return this.sourceRect.y; + } + public set scrollY(value: number) { + this.sourceRect.y = value; + } + + constructor(sprite: Sprite) { + super(sprite); + + this.leftTexture = new egret.Bitmap(); + this.rightTexture = new egret.Bitmap(); + this.leftTexture.texture = sprite.texture2D; + this.rightTexture.texture = sprite.texture2D; + + this.setSprite(sprite); + this.sourceRect = sprite.sourceRect; + } + + public render(camera: es.Camera) { + if (!this.sprite) + return; + + super.render(camera); + + let renderTexture = new egret.RenderTexture(); + let cacheBitmap = new egret.DisplayObjectContainer(); + cacheBitmap.removeChildren(); + cacheBitmap.addChild(this.leftTexture); + cacheBitmap.addChild(this.rightTexture); + + this.leftTexture.x = this.sourceRect.x; + this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; + this.leftTexture.y = this.sourceRect.y; + this.rightTexture.y = this.sourceRect.y; + + cacheBitmap.cacheAsBitmap = true; + renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); + } } - public set scrollX(value: number) { - this.sourceRect.x = value; - } - public get scrollY() { - return this.sourceRect.y; - } - public set scrollY(value: number) { - this.sourceRect.y = value; - } - - constructor(sprite: Sprite) { - super(); - - this.leftTexture = new egret.Bitmap(); - this.rightTexture = new egret.Bitmap(); - this.leftTexture.texture = sprite.texture2D; - this.rightTexture.texture = sprite.texture2D; - - this.setSprite(sprite); - this.sourceRect = sprite.sourceRect; - } - - public render(camera: Camera) { - if (!this.sprite) - return; - - super.render(camera); - - let renderTexture = new egret.RenderTexture(); - let cacheBitmap = new egret.DisplayObjectContainer(); - cacheBitmap.removeChildren(); - cacheBitmap.addChild(this.leftTexture); - cacheBitmap.addChild(this.rightTexture); - - this.leftTexture.x = this.sourceRect.x; - this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; - this.leftTexture.y = this.sourceRect.y; - this.rightTexture.y = this.sourceRect.y; - - cacheBitmap.cacheAsBitmap = true; - renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); - - this.bitmap.texture = renderTexture; - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Utils/BitSet.ts b/source/src/ECS/Utils/BitSet.ts index d75c2f35..7dcd6544 100644 --- a/source/src/ECS/Utils/BitSet.ts +++ b/source/src/ECS/Utils/BitSet.ts @@ -1,133 +1,135 @@ -/** - * 这个类可以从两方面来考虑。你可以把它看成一个位向量或者一组非负整数。这个名字有点误导人。 - * - * 它是由一个位向量实现的,但同样可以把它看成是一个非负整数的集合;集合中的每个整数由对应索引处的集合位表示。该结构的大小由集合中的最大整数决定。 - */ -class BitSet{ - private static LONG_MASK: number = 0x3f; - private _bits: number[]; +module es { + /** + * 这个类可以从两方面来考虑。你可以把它看成一个位向量或者一组非负整数。这个名字有点误导人。 + * + * 它是由一个位向量实现的,但同样可以把它看成是一个非负整数的集合;集合中的每个整数由对应索引处的集合位表示。该结构的大小由集合中的最大整数决定。 + */ + export class BitSet{ + private static LONG_MASK: number = 0x3f; + private _bits: number[]; - constructor(nbits: number = 64){ - let length = nbits >> 6; - if ((nbits & BitSet.LONG_MASK) != 0) - length ++; + constructor(nbits: number = 64){ + let length = nbits >> 6; + if ((nbits & BitSet.LONG_MASK) != 0) + length ++; - this._bits = new Array(length); - } + this._bits = new Array(length); + } - public and(bs: BitSet){ - let max = Math.min(this._bits.length, bs._bits.length); - let i; - for (let i = 0; i < max; ++i) - this._bits[i] &= bs._bits[i]; + public and(bs: BitSet){ + let max = Math.min(this._bits.length, bs._bits.length); + let i; + for (let i = 0; i < max; ++i) + this._bits[i] &= bs._bits[i]; - while (i < this._bits.length) - this._bits[i ++] = 0; - } + while (i < this._bits.length) + this._bits[i ++] = 0; + } - public andNot(bs: BitSet){ - let i = Math.min(this._bits.length, bs._bits.length); - while(--i >= 0) - this._bits[i] &= ~bs._bits[i]; - } + public andNot(bs: BitSet){ + let i = Math.min(this._bits.length, bs._bits.length); + while(--i >= 0) + this._bits[i] &= ~bs._bits[i]; + } - public cardinality(): number{ - let card = 0; - for (let i = this._bits.length - 1; i >= 0; i --){ - let a = this._bits[i]; + public cardinality(): number{ + let card = 0; + for (let i = this._bits.length - 1; i >= 0; i --){ + let a = this._bits[i]; - if (a == 0) - continue; + if (a == 0) + continue; - if (a == -1){ - card += 64; - continue; + if (a == -1){ + card += 64; + continue; + } + + a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); + a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); + let b = ((a >> 32) + a); + b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); + b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); + card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); } - a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); - a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); - let b = ((a >> 32) + a); - b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); - b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); - card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); + return card; } - return card; - } + public clear(pos?: number){ + if (pos != undefined){ + let offset = pos >> 6; + this.ensure(offset); + this._bits[offset] &= ~(1 << pos); + }else{ + for (let i = 0; i < this._bits.length; i ++) + this._bits[i] = 0; + } + } - public clear(pos?: number){ - if (pos != undefined){ + private ensure(lastElt: number){ + if (lastElt >= this._bits.length){ + let nd = new Number[lastElt + 1]; + nd = this._bits.copyWithin(0, 0, this._bits.length); + this._bits = nd; + } + } + + public get(pos: number): boolean{ let offset = pos >> 6; - this.ensure(offset); - this._bits[offset] &= ~(1 << pos); - }else{ - for (let i = 0; i < this._bits.length; i ++) - this._bits[i] = 0; - } - } - - private ensure(lastElt: number){ - if (lastElt >= this._bits.length){ - let nd = new Number[lastElt + 1]; - nd = this._bits.copyWithin(0, 0, this._bits.length); - this._bits = nd; - } - } - - public get(pos: number): boolean{ - let offset = pos >> 6; - if (offset >= this._bits.length) - return false; - - return (this._bits[offset] & (1 << pos)) != 0; - } - - public intersects(set: BitSet){ - let i = Math.min(this._bits.length, set._bits.length); - while (--i >= 0){ - if ((this._bits[i] & set._bits[i]) != 0) - return true; - } - - return false; - } - - public isEmpty(): boolean{ - for (let i = this._bits.length - 1; i >= 0; i --){ - if (this._bits[i]) + if (offset >= this._bits.length) return false; + + return (this._bits[offset] & (1 << pos)) != 0; } - return true; - } + public intersects(set: BitSet){ + let i = Math.min(this._bits.length, set._bits.length); + while (--i >= 0){ + if ((this._bits[i] & set._bits[i]) != 0) + return true; + } - public nextSetBit(from: number){ - let offset = from >> 6; - let mask = 1 << from; - while (offset < this._bits.length){ - let h = this._bits[offset]; - do { - if ((h & mask) != 0) - return from; - - mask <<= 1; - from ++; - } while (mask != 0); - - mask = 1; - offset ++; + return false; } - return -1; - } + public isEmpty(): boolean{ + for (let i = this._bits.length - 1; i >= 0; i --){ + if (this._bits[i]) + return false; + } - public set(pos: number, value: boolean = true){ - if (value){ - let offset = pos >> 6; - this.ensure(offset); - this._bits[offset] |= 1 << pos; - }else{ - this.clear(pos); + return true; + } + + public nextSetBit(from: number){ + let offset = from >> 6; + let mask = 1 << from; + while (offset < this._bits.length){ + let h = this._bits[offset]; + do { + if ((h & mask) != 0) + return from; + + mask <<= 1; + from ++; + } while (mask != 0); + + mask = 1; + offset ++; + } + + return -1; + } + + public set(pos: number, value: boolean = true){ + if (value){ + let offset = pos >> 6; + this.ensure(offset); + this._bits[offset] |= 1 << pos; + }else{ + this.clear(pos); + } } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Utils/ComponentTypeManager.ts b/source/src/ECS/Utils/ComponentTypeManager.ts index f8ca330c..7dc20b4b 100644 --- a/source/src/ECS/Utils/ComponentTypeManager.ts +++ b/source/src/ECS/Utils/ComponentTypeManager.ts @@ -1,18 +1,20 @@ -class ComponentTypeManager{ - private static _componentTypesMask: Map = new Map(); +module es { + export class ComponentTypeManager{ + private static _componentTypesMask: Map = new Map(); - public static add(type){ - if (!this._componentTypesMask.has(type)) - this._componentTypesMask[type] = this._componentTypesMask.size; - } - - public static getIndexFor(type){ - let v = -1; - if (!this._componentTypesMask.has(type)){ - this.add(type); - v = this._componentTypesMask.get(type); + public static add(type){ + if (!this._componentTypesMask.has(type)) + this._componentTypesMask[type] = this._componentTypesMask.size; } - return v; + public static getIndexFor(type){ + let v = -1; + if (!this._componentTypesMask.has(type)){ + this.add(type); + v = this._componentTypesMask.get(type); + } + + return v; + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Utils/EntityProcessorList.ts b/source/src/ECS/Utils/EntityProcessorList.ts index eedd5fdd..148f08b7 100644 --- a/source/src/ECS/Utils/EntityProcessorList.ts +++ b/source/src/ECS/Utils/EntityProcessorList.ts @@ -1,69 +1,71 @@ -class EntityProcessorList { - private _processors: EntitySystem[] = []; +module es { + export class EntityProcessorList { + private _processors: EntitySystem[] = []; - public add(processor: EntitySystem){ - this._processors.push(processor); - } - - public remove(processor: EntitySystem){ - this._processors.remove(processor); - } - - public onComponentAdded(entity: Entity){ - this.notifyEntityChanged(entity); - } - - public onComponentRemoved(entity: Entity){ - this.notifyEntityChanged(entity); - } - - public onEntityAdded(entity: Entity){ - this.notifyEntityChanged(entity); - } - - public onEntityRemoved(entity: Entity){ - this.removeFromProcessors(entity); - } - - protected notifyEntityChanged(entity: Entity){ - for (let i = 0; i < this._processors.length; i ++){ - this._processors[i].onChanged(entity); - } - } - - protected removeFromProcessors(entity: Entity){ - for (let i = 0; i < this._processors.length; i ++){ - this._processors[i].remove(entity); - } - } - - public begin(){ - - } - - public update(){ - for (let i = 0; i < this._processors.length; i++){ - this._processors[i].update(); - } - } - - public lateUpdate(){ - for (let i = 0; i < this._processors.length; i ++){ - this._processors[i].lateUpdate(); - } - } - - public end(){ - - } - - public getProcessor(): T{ - for (let i = 0; i < this._processors.length; i ++){ - let processor = this._processors[i]; - if (processor instanceof EntitySystem) - return processor as T; + public add(processor: EntitySystem){ + this._processors.push(processor); } - return null; + public remove(processor: EntitySystem){ + this._processors.remove(processor); + } + + public onComponentAdded(entity: Entity){ + this.notifyEntityChanged(entity); + } + + public onComponentRemoved(entity: Entity){ + this.notifyEntityChanged(entity); + } + + public onEntityAdded(entity: Entity){ + this.notifyEntityChanged(entity); + } + + public onEntityRemoved(entity: Entity){ + this.removeFromProcessors(entity); + } + + protected notifyEntityChanged(entity: Entity){ + for (let i = 0; i < this._processors.length; i ++){ + this._processors[i].onChanged(entity); + } + } + + protected removeFromProcessors(entity: Entity){ + for (let i = 0; i < this._processors.length; i ++){ + this._processors[i].remove(entity); + } + } + + public begin(){ + + } + + public update(){ + for (let i = 0; i < this._processors.length; i++){ + this._processors[i].update(); + } + } + + public lateUpdate(){ + for (let i = 0; i < this._processors.length; i ++){ + this._processors[i].lateUpdate(); + } + } + + public end(){ + + } + + public getProcessor(): T{ + for (let i = 0; i < this._processors.length; i ++){ + let processor = this._processors[i]; + if (processor instanceof EntitySystem) + return processor as T; + } + + return null; + } } -} \ No newline at end of file +} diff --git a/source/src/Physics/Shapes/Box.ts b/source/src/Physics/Shapes/Box.ts index e9e23c13..27d98e3d 100644 --- a/source/src/Physics/Shapes/Box.ts +++ b/source/src/Physics/Shapes/Box.ts @@ -55,18 +55,20 @@ module es { public overlaps(other: Shape){ // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测 - if (other instanceof Box) - return this.bounds.intersects(other.bounds); + if (this.isUnrotated){ + if (other instanceof Box) + return this.bounds.intersects(other.bounds); - if (other instanceof Circle) - return Collisions.isRectToCircle(this.bounds, other.position, other.radius); + if (other instanceof Circle) + return Collisions.isRectToCircle(this.bounds, other.position, other.radius); + } return super.overlaps(other); } public collidesWithShape(other: Shape){ // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测 - if (other instanceof Box){ + if (other instanceof Box && (other as Box).isUnrotated){ return ShapeCollisions.boxToBox(this, other); } @@ -75,14 +77,11 @@ module es { return super.collidesWithShape(other); } - - - /** - * - * @param point - */ public containsPoint(point: Vector2){ - return this.bounds.contains(point.x, point.y); + if (this.isUnrotated) + return this.bounds.contains(point.x, point.y); + + return super.containsPoint(point); } } } \ No newline at end of file diff --git a/source/src/Physics/Shapes/Circle.ts b/source/src/Physics/Shapes/Circle.ts index 2ad27222..70e19752 100644 --- a/source/src/Physics/Shapes/Circle.ts +++ b/source/src/Physics/Shapes/Circle.ts @@ -1,52 +1,69 @@ /// -class Circle extends Shape { - public radius: number; - public _originalRadius: number; - public center = new Vector2(); - public get position(){ - return new Vector2(this.parent.x, this.parent.y); - } +module es { + export class Circle extends Shape { + public radius: number; + public _originalRadius: number; - public get bounds(){ - return new Rectangle().setEgretRect(this.getBounds()); - } - - constructor(radius: number) { - super(); - this.radius = radius; - this._originalRadius = radius; - } - - public pointCollidesWithShape(point: Vector2): CollisionResult { - return ShapeCollisions.pointToCircle(point, this); - } - - public collidesWithShape(other: Shape): CollisionResult { - if (other instanceof Box) { - return ShapeCollisions.circleToBox(this, other); + constructor(radius: number) { + super(); + this.radius = radius; + this._originalRadius = radius; } - if (other instanceof Circle) { - return ShapeCollisions.circleToCircle(this, other); + public recalculateBounds(collider: es.Collider) { + // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心 + this.center = collider.localOffset; + + if (collider.shouldColliderScaleAndRotateWithTransform) { + // 我们只将直线缩放为一个圆,所以我们将使用最大值 + let scale = collider.entity.transform.scale; + let hasUnitScale = scale.x == 1 && scale.y == 1; + let maxScale = Math.max(scale.x, scale.y); + this.radius = this._originalRadius * maxScale; + + if (collider.entity.transform.rotation != 0) { + // 为了处理偏移原点的旋转,我们只需要将圆心围绕(0,0)在一个圆上移动,我们的偏移量就是0角 + let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; + let offsetLength = hasUnitScale ? collider._localOffsetLength : Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); + } + } + + this.position = Vector2.add(collider.transform.position, this.center); + this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); } - if (other instanceof Polygon) { - return ShapeCollisions.circleToPolygon(this, other); + public overlaps(other: Shape) { + if (other instanceof Box && (other as Box).isUnrotated) + return Collisions.isRectToCircle(other.bounds, this.position, this.radius); + + if (other instanceof Circle) + return Collisions.isCircleToCircle(this.position, this.radius, other.position, (other as Circle).radius); + + if (other instanceof Polygon) + return ShapeCollisions.circleToPolygon(this, other); + + throw new Error(`overlaps of circle to ${other} are not supported`); } - throw new Error(`Collisions of Circle to ${other} are not supported`); + public collidesWithShape(other: Shape): CollisionResult { + if (other instanceof Box && (other as Box).isUnrotated) { + return ShapeCollisions.circleToBox(this, other); + } + + if (other instanceof Circle) { + return ShapeCollisions.circleToCircle(this, other); + } + + if (other instanceof Polygon) { + return ShapeCollisions.circleToPolygon(this, other); + } + + throw new Error(`Collisions of Circle to ${other} are not supported`); + } + + public pointCollidesWithShape(point: Vector2): CollisionResult { + return ShapeCollisions.pointToCircle(point, this); + } } - - public overlaps(other: Shape){ - if (other instanceof Box) - return Collisions.isRectToCircle(other.bounds, this.position, this.radius); - - if (other instanceof Circle) - return Collisions.isCircleToCircle(this.position, this.radius, other.position, (other as Circle).radius); - - if (other instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, other); - - throw new Error(`overlaps of circle to ${other} are not supported`); - } -} \ No newline at end of file +} diff --git a/source/src/Physics/Verlet/SpatialHash.ts b/source/src/Physics/Verlet/SpatialHash.ts index ca7b10f1..015c5786 100644 --- a/source/src/Physics/Verlet/SpatialHash.ts +++ b/source/src/Physics/Verlet/SpatialHash.ts @@ -1,249 +1,269 @@ -class SpatialHash { - public gridBounds: Rectangle = new Rectangle(); +module es { + export class SpatialHash { + public gridBounds: Rectangle = new Rectangle(); - private _raycastParser: RaycastResultParser; - /** 散列中每个单元格的大小 */ - private _cellSize: number; - /** 1除以单元格大小。缓存结果,因为它被大量使用。 */ - private _inverseCellSize: number; - /** 缓存的循环用于重叠检查 */ - private _overlapTestCircle: Circle = new Circle(0); - /** 用于返回冲突信息的共享HashSet */ - private _tempHashSet: Collider[] = []; - /** 保存所有数据的字典 */ - private _cellDict: NumberDictionary = new NumberDictionary(); + public _raycastParser: RaycastResultParser; + /** + * 散列中每个单元格的大小 + */ + public _cellSize: number; + /** + * 1除以单元格大小。缓存结果,因为它被大量使用。 + */ + public _inverseCellSize: number; + /** + * 缓存的循环用于重叠检查 + */ + public _overlapTestCircle: Circle = new Circle(0); + /** + * 保存所有数据的字典 + */ + public _cellDict: NumberDictionary = new NumberDictionary(); + /** + * 用于返回冲突信息的共享HashSet + */ + public _tempHashSet: Collider[] = []; - constructor(cellSize: number = 100) { - this._cellSize = cellSize; - this._inverseCellSize = 1 / this._cellSize; - this._raycastParser = new RaycastResultParser(); - } - - /** - * 从SpatialHash中删除对象 - * @param collider - */ - public remove(collider: Collider) { - let bounds = collider.registeredPhysicsBounds; - let p1 = this.cellCoords(bounds.x, bounds.y); - let p2 = this.cellCoords(bounds.right, bounds.bottom); - - for (let x = p1.x; x <= p2.x; x++) { - for (let y = p1.y; y <= p2.y; y++) { - // 单元格应该始终存在,因为这个碰撞器应该在所有查询的单元格中 - let cell = this.cellAtPosition(x, y); - if (!cell) - console.error(`removing Collider [${collider}] from a cell that it is not present in`); - else - cell.remove(collider); - } - } - } - - /** - * 将对象添加到SpatialHash - * @param collider - */ - public register(collider: Collider) { - let bounds = collider.bounds; - collider.registeredPhysicsBounds = bounds; - let p1 = this.cellCoords(bounds.x, bounds.y); - let p2 = this.cellCoords(bounds.right, bounds.bottom); - - // 更新边界以跟踪网格大小 - if (!this.gridBounds.contains(p1.x, p1.y)) { - this.gridBounds = RectangleExt.union(this.gridBounds, p1); + constructor(cellSize: number = 100) { + this._cellSize = cellSize; + this._inverseCellSize = 1 / this._cellSize; + this._raycastParser = new RaycastResultParser(); } - if (!this.gridBounds.contains(p2.x, p2.y)) { - this.gridBounds = RectangleExt.union(this.gridBounds, p2); + /** + * 获取单元格的x,y值作为世界空间的x,y值 + * @param x + * @param y + */ + private cellCoords(x: number, y: number): Vector2 { + return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); } - for (let x = p1.x; x <= p2.x; x++) { - for (let y = p1.y; y <= p2.y; y++) { - // 如果没有单元格,我们需要创建它 - let c = this.cellAtPosition(x, y, true); - if (c.indexOf(collider) == -1) - c.push(collider); - } - } - } - - public clear(){ - this._cellDict.clear(); - } - - /** - * 获取位于指定圆内的所有碰撞器 - * @param circleCenter - * @param radius - * @param results - * @param layerMask - */ - public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask) { - let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); - - this._overlapTestCircle.radius = radius; - // this._overlapTestCircle.position = circleCenter; - - let resultCounter = 0; - let aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); - bounds = aabbBroadphaseResult.bounds; - let potentials = aabbBroadphaseResult.tempHashSet; - for (let i = 0; i < potentials.length; i++) { - let collider = potentials[i]; - if (collider instanceof BoxCollider) { - results[resultCounter] = collider; - resultCounter++; - } else if (collider instanceof CircleCollider) { - if (collider.shape.overlaps(this._overlapTestCircle)){ - results[resultCounter] = collider; - resultCounter ++; + /** + * 获取世界空间x,y值的单元格。 + * 如果单元格为空且createCellIfEmpty为true,则会创建一个新的单元格 + * @param x + * @param y + * @param createCellIfEmpty + */ + private cellAtPosition(x: number, y: number, createCellIfEmpty: boolean = false) { + let cell: Collider[] = this._cellDict.tryGetValue(x, y); + if (!cell) { + if (createCellIfEmpty) { + cell = []; + this._cellDict.add(x, y, cell); } - } else if(collider instanceof PolygonCollider) { - if (collider.shape.overlaps(this._overlapTestCircle)){ - results[resultCounter] = collider; - resultCounter ++; - } - } else { - throw new Error("overlapCircle against this collider type is not implemented!"); } - - // 如果我们所有的结果数据有了则返回 - if (resultCounter == results.length) - return resultCounter; + return cell; } - return resultCounter; - } + /** + * 将对象添加到SpatialHash + * @param collider + */ + public register(collider: Collider) { + let bounds = collider.bounds; + collider.registeredPhysicsBounds = bounds; + let p1 = this.cellCoords(bounds.x, bounds.y); + let p2 = this.cellCoords(bounds.right, bounds.bottom); - /** - * 返回边框与单元格相交的所有对象 - * @param bounds - * @param excludeCollider - * @param layerMask - */ - public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number) { - this._tempHashSet.length = 0; + // 更新边界以跟踪网格大小 + if (!this.gridBounds.contains(p1.x, p1.y)) { + this.gridBounds = RectangleExt.union(this.gridBounds, p1); + } - let p1 = this.cellCoords(bounds.x, bounds.y); - let p2 = this.cellCoords(bounds.right, bounds.bottom); + if (!this.gridBounds.contains(p2.x, p2.y)) { + this.gridBounds = RectangleExt.union(this.gridBounds, p2); + } - for (let x = p1.x; x <= p2.x; x++) { - for (let y = p1.y; y <= p2.y; y++) { - let cell = this.cellAtPosition(x, y); - if (!cell) - continue; + for (let x = p1.x; x <= p2.x; x++) { + for (let y = p1.y; y <= p2.y; y++) { + // 如果没有单元格,我们需要创建它 + let c = this.cellAtPosition(x, y, true); + if (c.indexOf(collider) == -1) + c.push(collider); + } + } + } - // 当cell不为空。循环并取回所有碰撞器 - for (let i = 0; i < cell.length; i++) { - let collider = cell[i]; + /** + * 从SpatialHash中删除对象 + * @param collider + */ + public remove(collider: Collider) { + let bounds = collider.registeredPhysicsBounds; + let p1 = this.cellCoords(bounds.x, bounds.y); + let p2 = this.cellCoords(bounds.right, bounds.bottom); - // 如果它是自身或者如果它不匹配我们的层掩码 跳过这个碰撞器 - if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer)) + for (let x = p1.x; x <= p2.x; x++) { + for (let y = p1.y; y <= p2.y; y++) { + // 单元格应该始终存在,因为这个碰撞器应该在所有查询的单元格中 + let cell = this.cellAtPosition(x, y); + if (!cell) + console.error(`removing Collider [${collider}] from a cell that it is not present in`); + else + cell.remove(collider); + } + } + } + + /** + * 使用蛮力方法从SpatialHash中删除对象 + * @param obj + */ + public removeWithBruteForce(obj: Collider){ + this._cellDict.remove(obj); + } + + public clear(){ + this._cellDict.clear(); + } + + /** + * debug绘制空间散列的内容 + * @param secondsToDisplay + * @param textScale + */ + public debugDraw(secondsToDisplay: number, textScale: number = 1){ + for (let x = this.gridBounds.x; x <= this.gridBounds.right; x ++){ + for (let y = this.gridBounds.y; y <= this.gridBounds.bottom; y ++){ + let cell = this.cellAtPosition(x, y); + if (cell && cell.length > 0) + this.debugDrawCellDetails(x, y, cell.length, secondsToDisplay, textScale); + } + } + } + + private debugDrawCellDetails(x: number, y: number, cellCount: number, secondsToDisplay = 0.5, textScale = 1){ + + } + + /** + * 返回边框与单元格相交的所有对象 + * @param bounds + * @param excludeCollider + * @param layerMask + */ + public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number) { + this._tempHashSet.length = 0; + + let p1 = this.cellCoords(bounds.x, bounds.y); + let p2 = this.cellCoords(bounds.right, bounds.bottom); + + for (let x = p1.x; x <= p2.x; x++) { + for (let y = p1.y; y <= p2.y; y++) { + let cell = this.cellAtPosition(x, y); + if (!cell) continue; - if (bounds.intersects(collider.bounds)){ - if (this._tempHashSet.indexOf(collider) == -1) - this._tempHashSet.push(collider); + // 当cell不为空。循环并取回所有碰撞器 + for (let i = 0; i < cell.length; i++) { + let collider = cell[i]; + + // 如果它是自身或者如果它不匹配我们的层掩码 跳过这个碰撞器 + if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer)) + continue; + + if (bounds.intersects(collider.bounds)){ + if (this._tempHashSet.indexOf(collider) == -1) + this._tempHashSet.push(collider); + } } } } + + return {tempHashSet: this._tempHashSet, bounds: bounds}; } - return {tempHashSet: this._tempHashSet, bounds: bounds}; - } + /** + * 获取位于指定圆内的所有碰撞器 + * @param circleCenter + * @param radius + * @param results + * @param layerMask + */ + public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask) { + let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); - /** - * 获取世界空间x,y值的单元格。 - * 如果单元格为空且createCellIfEmpty为true,则会创建一个新的单元格 - * @param x - * @param y - * @param createCellIfEmpty - */ - private cellAtPosition(x: number, y: number, createCellIfEmpty: boolean = false) { - let cell: Collider[] = this._cellDict.tryGetValue(x, y); - if (!cell) { - if (createCellIfEmpty) { - cell = []; - this._cellDict.add(x, y, cell); + this._overlapTestCircle.radius = radius; + this._overlapTestCircle.position = circleCenter; + + let resultCounter = 0; + let aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); + bounds = aabbBroadphaseResult.bounds; + let potentials = aabbBroadphaseResult.tempHashSet; + for (let i = 0; i < potentials.length; i++) { + let collider = potentials[i]; + if (collider instanceof BoxCollider) { + results[resultCounter] = collider; + resultCounter++; + } else if (collider instanceof CircleCollider) { + if (collider.shape.overlaps(this._overlapTestCircle)){ + results[resultCounter] = collider; + resultCounter ++; + } + } else if(collider instanceof PolygonCollider) { + if (collider.shape.overlaps(this._overlapTestCircle)){ + results[resultCounter] = collider; + resultCounter ++; + } + } else { + throw new Error("overlapCircle against this collider type is not implemented!"); + } + + // 如果我们所有的结果数据有了则返回 + if (resultCounter == results.length) + return resultCounter; } - } - return cell; - } - /** - * 获取单元格的x,y值作为世界空间的x,y值 - * @param x - * @param y - */ - private cellCoords(x: number, y: number): Vector2 { - return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); - } - - /** - * debug绘制空间散列的内容 - * @param secondsToDisplay - * @param textScale - */ - public debugDraw(secondsToDisplay: number, textScale: number = 1){ - for (let x = this.gridBounds.x; x <= this.gridBounds.right; x ++){ - for (let y = this.gridBounds.y; y <= this.gridBounds.bottom; y ++){ - let cell = this.cellAtPosition(x, y); - if (cell && cell.length > 0) - this.debugDrawCellDetails(x, y, cell.length, secondsToDisplay, textScale); - } + return resultCounter; } } - private debugDrawCellDetails(x: number, y: number, cellCount: number, secondsToDisplay = 0.5, textScale = 1){ - + /** + * 包装一个Unit32,列表碰撞器字典 + * 它的主要目的是将int、int x、y坐标散列到单个Uint32键中,使用O(1)查找。 + */ + export class NumberDictionary { + public _store: Map = new Map(); + + /** + * 根据x和y值计算并返回散列键 + * @param x + * @param y + */ + private getKey(x: number, y: number): string { + return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); + } + + public add(x: number, y: number, list: Collider[]) { + this._store.set(this.getKey(x, y), list); + } + + /** + * 使用蛮力方法从字典存储列表中移除碰撞器 + * @param obj + */ + public remove(obj: Collider) { + this._store.forEach(list => { + if (list.contains(obj)) + list.remove(obj); + }) + } + + public tryGetValue(x: number, y: number): Collider[] { + return this._store.get(this.getKey(x, y)); + } + + /** + * 清除字典数据 + */ + public clear() { + this._store.clear(); + } + } + + export class RaycastResultParser { + } } - -class RaycastResultParser { - -} - -/** - * 包装一个Unit32,列表碰撞器字典 - * 它的主要目的是将int、int x、y坐标散列到单个Uint32键中,使用O(1)查找。 - */ -class NumberDictionary { - private _store: Map = new Map(); - - /** - * 根据x和y值计算并返回散列键 - * @param x - * @param y - */ - private getKey(x: number, y: number): string { - return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); - } - - public add(x: number, y: number, list: Collider[]) { - this._store.set(this.getKey(x, y), list); - } - - /** - * 使用蛮力方法从字典存储列表中移除碰撞器 - * @param obj - */ - public remove(obj: Collider) { - this._store.forEach(list => { - if (list.contains(obj)) - list.remove(obj); - }) - } - - public tryGetValue(x: number, y: number): Collider[] { - return this._store.get(this.getKey(x, y)); - } - - /** - * 清除字典数据 - */ - public clear() { - this._store.clear(); - } -} \ No newline at end of file From 1b52bc5fd1da879f8427f61bde88dc346f8cc51d Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Thu, 23 Jul 2020 11:00:46 +0800 Subject: [PATCH 05/15] =?UTF-8?q?=E5=85=A8=E9=83=A8=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E8=87=B3es=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.d.ts | 2542 ++-- demo/libs/framework/framework.js | 11493 +++++++++------- demo/libs/framework/framework.min.js | 2 +- source/bin/framework.d.ts | 2542 ++-- source/bin/framework.js | 11493 +++++++++------- source/bin/framework.min.js | 2 +- source/lib/wxgame.d.ts | 122 + .../AI/Pathfinding/AStar/AStarPathfinder.ts | 154 +- .../AI/Pathfinding/AStar/AstarGridGraph.ts | 140 +- .../src/AI/Pathfinding/AStar/IAstarGraph.ts | 42 +- .../src/AI/Pathfinding/AStar/PriorityQueue.ts | 418 +- .../AI/Pathfinding/AStar/PriorityQueueNode.ts | 30 +- .../BreadthFirst/BreadthFirstPathfinder.ts | 66 +- .../BreadthFirst/IUnweightedGraph.ts | 16 +- .../BreadthFirst/UnweightedGraph.ts | 28 +- .../BreadthFirst/UnweightedGridGraph.ts | 110 +- .../AI/Pathfinding/Dijkstra/IWeightedGraph.ts | 28 +- .../Pathfinding/Dijkstra/WeightedGridGraph.ts | 124 +- .../Dijkstra/WeightedPathfinder.ts | 130 +- source/src/Debug/Debug.ts | 34 +- source/src/Debug/DebugDefaults.ts | 10 +- source/src/Debug/DebugDrawItem.ts | 81 +- source/src/ECS/CoreEvents.ts | 10 +- source/src/ECS/Scene.ts | 2 +- source/src/ECS/SceneManager.ts | 242 +- .../src/ECS/Systems/EntityProcessingSystem.ts | 54 +- source/src/ECS/Systems/EntitySystem.ts | 156 +- source/src/ECS/Systems/PassiveSystem.ts | 18 +- source/src/ECS/Systems/ProcessingSystem.ts | 26 +- source/src/ECS/Utils/EntityList.ts | 2 +- source/src/ECS/Utils/Matcher.ts | 114 +- source/src/ECS/Utils/TextureUtils.ts | 270 +- source/src/ECS/Utils/Time.ts | 72 +- .../Graphics/Effects/GaussianBlurEffect.ts | 130 +- .../Graphics/Effects/PolygonLightEffect.ts | 52 +- source/src/Graphics/GraphicsCapabilities.ts | 46 +- source/src/Graphics/GraphicsDevice.ts | 16 +- .../Graphics/PostProcessing/PostProcessor.ts | 100 +- .../GaussianBlurPostProcessor.ts | 12 +- .../src/Graphics/Renderers/DefaultRenderer.ts | 20 +- .../Renderers/PolygonLight/PolyLight.ts | 80 +- source/src/Graphics/Renderers/Renderer.ts | 70 +- .../Graphics/Renderers/ScreenSpaceRenderer.ts | 14 +- .../Graphics/Transitions/FadeTransition.ts | 56 +- .../Graphics/Transitions/SceneTransition.ts | 126 +- .../Graphics/Transitions/WindTransition.ts | 128 +- source/src/Graphics/Viewport.ts | 64 +- source/src/Math/Bezier.ts | 238 +- source/src/Math/Flags.ts | 110 +- source/src/Math/MathHelper.ts | 154 +- source/src/Math/Matrix2D.ts | 430 +- source/src/Math/Rectangle.ts | 308 +- source/src/Math/Vector2.ts | 364 +- source/src/Math/Vector3.ts | 20 +- source/src/Physics/ColliderTriggerHelper.ts | 166 +- source/src/Physics/Collision.ts | 318 +- source/src/Physics/Physics.ts | 110 +- source/src/Physics/Shapes/CollisionResult.ts | 20 +- .../Shapes/ShapeCollisions/ShapeCollisions.ts | 552 +- source/src/Utils/Analysis/Layout.ts | 130 +- source/src/Utils/Analysis/TimeRuler.ts | 640 +- source/src/Utils/ContentManager.ts | 78 +- source/src/Utils/DrawUtils.ts | 112 +- source/src/Utils/Emitter.ts | 119 +- source/src/Utils/GlobalManager.ts | 74 +- source/src/Utils/Input.ts | 266 +- source/src/Utils/ListPool.ts | 90 +- source/src/Utils/Pair.ts | 34 +- source/src/Utils/RectangleExt.ts | 34 +- source/src/Utils/Triangulator.ts | 182 +- source/src/Utils/Vector2Ext.ts | 144 +- 71 files changed, 19273 insertions(+), 16907 deletions(-) diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index 9ab1a179..6c72ef06 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -17,648 +17,842 @@ declare interface Array { groupBy(keySelector: Function): Array; sum(selector: any): any; } -declare class PriorityQueueNode { - priority: number; - insertionIndex: number; - queueIndex: number; +declare module es { + class PriorityQueueNode { + priority: number; + insertionIndex: number; + queueIndex: number; + } } -declare class AStarPathfinder { - static search(graph: IAstarGraph, start: T, goal: T): T[]; - private static hasKey; - private static getKey; - static recontructPath(cameFrom: Map, start: T, goal: T): T[]; +declare module es { + class AStarPathfinder { + static search(graph: IAstarGraph, start: T, goal: T): T[]; + private static hasKey; + private static getKey; + static recontructPath(cameFrom: Map, start: T, goal: T): T[]; + } + class AStarNode extends PriorityQueueNode { + data: T; + constructor(data: T); + } } -declare class AStarNode extends PriorityQueueNode { - data: T; - constructor(data: T); +declare module es { + class AstarGridGraph implements IAstarGraph { + dirs: Vector2[]; + walls: Vector2[]; + weightedNodes: Vector2[]; + defaultWeight: number; + weightedNodeWeight: number; + private _width; + private _height; + private _neighbors; + constructor(width: number, height: number); + isNodeInBounds(node: Vector2): boolean; + isNodePassable(node: Vector2): boolean; + search(start: Vector2, goal: Vector2): Vector2[]; + getNeighbors(node: Vector2): Vector2[]; + cost(from: Vector2, to: Vector2): number; + heuristic(node: Vector2, goal: Vector2): number; + } } -declare class AstarGridGraph implements IAstarGraph { - dirs: Vector2[]; - walls: Vector2[]; - weightedNodes: Vector2[]; - defaultWeight: number; - weightedNodeWeight: number; - private _width; - private _height; - private _neighbors; - constructor(width: number, height: number); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - search(start: Vector2, goal: Vector2): Vector2[]; - getNeighbors(node: Vector2): Vector2[]; - cost(from: Vector2, to: Vector2): number; - heuristic(node: Vector2, goal: Vector2): number; +declare module es { + interface IAstarGraph { + getNeighbors(node: T): Array; + cost(from: T, to: T): number; + heuristic(node: T, goal: T): any; + } } -interface IAstarGraph { - getNeighbors(node: T): Array; - cost(from: T, to: T): number; - heuristic(node: T, goal: T): any; +declare module es { + class PriorityQueue { + private _numNodes; + private _nodes; + private _numNodesEverEnqueued; + constructor(maxNodes: number); + clear(): void; + readonly count: number; + readonly maxSize: number; + contains(node: T): boolean; + enqueue(node: T, priority: number): void; + dequeue(): T; + remove(node: T): void; + isValidQueue(): boolean; + private onNodeUpdated; + private cascadeDown; + private cascadeUp; + private swap; + private hasHigherPriority; + } } -declare class PriorityQueue { - private _numNodes; - private _nodes; - private _numNodesEverEnqueued; - constructor(maxNodes: number); - clear(): void; - readonly count: number; - readonly maxSize: number; - contains(node: T): boolean; - enqueue(node: T, priority: number): void; - dequeue(): T; - remove(node: T): void; - isValidQueue(): boolean; - private onNodeUpdated; - private cascadeDown; - private cascadeUp; - private swap; - private hasHigherPriority; +declare module es { + class BreadthFirstPathfinder { + static search(graph: IUnweightedGraph, start: T, goal: T): T[]; + private static hasKey; + } } -declare class BreadthFirstPathfinder { - static search(graph: IUnweightedGraph, start: T, goal: T): T[]; - private static hasKey; +declare module es { + interface IUnweightedGraph { + getNeighbors(node: T): T[]; + } } -interface IUnweightedGraph { - getNeighbors(node: T): T[]; +declare module es { + class UnweightedGraph implements IUnweightedGraph { + edges: Map; + addEdgesForNode(node: T, edges: T[]): this; + getNeighbors(node: T): T[]; + } } -declare class UnweightedGraph implements IUnweightedGraph { - edges: Map; - addEdgesForNode(node: T, edges: T[]): this; - getNeighbors(node: T): T[]; +declare module es { + class Vector2 { + x: number; + y: number; + private static readonly unitYVector; + private static readonly unitXVector; + private static readonly unitVector2; + private static readonly zeroVector2; + static readonly zero: Vector2; + static readonly one: Vector2; + static readonly unitX: Vector2; + static readonly unitY: Vector2; + constructor(x?: number, y?: number); + static add(value1: Vector2, value2: Vector2): Vector2; + static divide(value1: Vector2, value2: Vector2): Vector2; + static multiply(value1: Vector2, value2: Vector2): Vector2; + static subtract(value1: Vector2, value2: Vector2): Vector2; + normalize(): void; + length(): number; + round(): Vector2; + static normalize(value: Vector2): Vector2; + static dot(value1: Vector2, value2: Vector2): number; + static distanceSquared(value1: Vector2, value2: Vector2): number; + static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2; + static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2; + static transform(position: Vector2, matrix: Matrix2D): Vector2; + static distance(value1: Vector2, value2: Vector2): number; + static negate(value: Vector2): Vector2; + } } -declare class Vector2 { - x: number; - y: number; - private static readonly unitYVector; - private static readonly unitXVector; - private static readonly unitVector2; - private static readonly zeroVector2; - static readonly zero: Vector2; - static readonly one: Vector2; - static readonly unitX: Vector2; - static readonly unitY: Vector2; - constructor(x?: number, y?: number); - static add(value1: Vector2, value2: Vector2): Vector2; - static divide(value1: Vector2, value2: Vector2): Vector2; - static multiply(value1: Vector2, value2: Vector2): Vector2; - static subtract(value1: Vector2, value2: Vector2): Vector2; - normalize(): void; - length(): number; - round(): Vector2; - static normalize(value: Vector2): Vector2; - static dot(value1: Vector2, value2: Vector2): number; - static distanceSquared(value1: Vector2, value2: Vector2): number; - static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2; - static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2; - static transform(position: Vector2, matrix: Matrix2D): Vector2; - static distance(value1: Vector2, value2: Vector2): number; - static negate(value: Vector2): Vector2; +declare module es { + class UnweightedGridGraph implements IUnweightedGraph { + private static readonly CARDINAL_DIRS; + private static readonly COMPASS_DIRS; + walls: Vector2[]; + private _width; + private _hegiht; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Vector2): boolean; + isNodePassable(node: Vector2): boolean; + getNeighbors(node: Vector2): Vector2[]; + search(start: Vector2, goal: Vector2): Vector2[]; + } } -declare class UnweightedGridGraph implements IUnweightedGraph { - private static readonly CARDINAL_DIRS; - private static readonly COMPASS_DIRS; - walls: Vector2[]; - private _width; - private _hegiht; - private _dirs; - private _neighbors; - constructor(width: number, height: number, allowDiagonalSearch?: boolean); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - getNeighbors(node: Vector2): Vector2[]; - search(start: Vector2, goal: Vector2): Vector2[]; +declare module es { + interface IWeightedGraph { + getNeighbors(node: T): T[]; + cost(from: T, to: T): number; + } } -interface IWeightedGraph { - getNeighbors(node: T): T[]; - cost(from: T, to: T): number; +declare module es { + class WeightedGridGraph implements IWeightedGraph { + static readonly CARDINAL_DIRS: Vector2[]; + private static readonly COMPASS_DIRS; + walls: Vector2[]; + weightedNodes: Vector2[]; + defaultWeight: number; + weightedNodeWeight: number; + private _width; + private _height; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Vector2): boolean; + isNodePassable(node: Vector2): boolean; + search(start: Vector2, goal: Vector2): Vector2[]; + getNeighbors(node: Vector2): Vector2[]; + cost(from: Vector2, to: Vector2): number; + } } -declare class WeightedGridGraph implements IWeightedGraph { - static readonly CARDINAL_DIRS: Vector2[]; - private static readonly COMPASS_DIRS; - walls: Vector2[]; - weightedNodes: Vector2[]; - defaultWeight: number; - weightedNodeWeight: number; - private _width; - private _height; - private _dirs; - private _neighbors; - constructor(width: number, height: number, allowDiagonalSearch?: boolean); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - search(start: Vector2, goal: Vector2): Vector2[]; - getNeighbors(node: Vector2): Vector2[]; - cost(from: Vector2, to: Vector2): number; +declare module es { + class WeightedNode extends PriorityQueueNode { + data: T; + constructor(data: T); + } + class WeightedPathfinder { + static search(graph: IWeightedGraph, start: T, goal: T): T[]; + private static hasKey; + private static getKey; + static recontructPath(cameFrom: Map, start: T, goal: T): T[]; + } } -declare class WeightedNode extends PriorityQueueNode { - data: T; - constructor(data: T); +declare module es { + class Debug { + private static _debugDrawItems; + static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void; + static render(): void; + } } -declare class WeightedPathfinder { - static search(graph: IWeightedGraph, start: T, goal: T): T[]; - private static hasKey; - private static getKey; - static recontructPath(cameFrom: Map, start: T, goal: T): T[]; +declare module es { + class DebugDefaults { + static verletParticle: number; + static verletConstraintEdge: number; + } } -declare class Debug { - private static _debugDrawItems; - static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void; - static render(): void; +declare module es { + enum DebugDrawType { + line = 0, + hollowRectangle = 1, + pixel = 2, + text = 3 + } + class DebugDrawItem { + rectangle: Rectangle; + color: number; + duration: number; + drawType: DebugDrawType; + text: string; + start: Vector2; + end: Vector2; + x: number; + y: number; + size: number; + constructor(rectangle: Rectangle, color: number, duration: number); + draw(shape: egret.Shape): boolean; + } } -declare class DebugDefaults { - static verletParticle: number; - static verletConstraintEdge: number; +declare module es { + abstract class Component { + entity: Entity; + readonly transform: Transform; + enabled: boolean; + updateOrder: number; + updateInterval: number; + private _enabled; + private _updateOrder; + initialize(): void; + onAddedToEntity(): void; + onRemovedFromEntity(): void; + onEntityTransformChanged(comp: transform.Component): void; + debugRender(): void; + onEnabled(): void; + onDisabled(): void; + update(): void; + setEnabled(isEnabled: boolean): this; + setUpdateOrder(updateOrder: number): this; + clone(): Component; + } } -declare enum DebugDrawType { - line = 0, - hollowRectangle = 1, - pixel = 2, - text = 3 +declare module es { + enum CoreEvents { + SceneChanged = 0 + } } -declare class DebugDrawItem { - rectangle: Rectangle; - color: number; - duration: number; - drawType: DebugDrawType; - text: string; - start: Vector2; - end: Vector2; - x: number; - y: number; - size: number; - constructor(rectangle: Rectangle, color: number, duration: number); - draw(shape: egret.Shape): boolean; +declare module es { + class Entity { + static _idGenerator: number; + scene: Scene; + name: string; + readonly id: number; + readonly transform: Transform; + readonly components: ComponentList; + tag: number; + updateInterval: number; + enabled: boolean; + updateOrder: number; + _isDestroyed: boolean; + readonly isDestroyed: boolean; + componentBits: BitSet; + private _tag; + private _enabled; + private _updateOrder; + parent: Transform; + readonly childCount: number; + position: Vector2; + rotation: number; + scale: Vector2; + constructor(name: string); + onTransformChanged(comp: transform.Component): void; + setTag(tag: number): Entity; + setEnabled(isEnabled: boolean): this; + setUpdateOrder(updateOrder: number): this; + destroy(): void; + detachFromScene(): void; + attachToScene(newScene: Scene): void; + clone(position?: Vector2): Entity; + protected copyFrom(entity: Entity): void; + onAddedToScene(): void; + onRemovedFromScene(): void; + update(): void; + addComponent(component: T): T; + getComponent(type: any): T; + hasComponent(type: any): boolean; + getOrCreateComponent(type: T): T; + getComponents(typeName: string | any, componentList?: any): any; + removeComponent(component: Component): void; + removeComponentForType(type: any): boolean; + removeAllComponents(): void; + toString(): string; + } } -declare abstract class Component extends egret.DisplayObjectContainer { - entity: Entity; - private _enabled; - updateInterval: number; - userData: any; - private _updateOrder; - enabled: boolean; - readonly localPosition: Vector2; - setEnabled(isEnabled: boolean): this; - updateOrder: number; - setUpdateOrder(updateOrder: number): this; - initialize(): void; - onAddedToEntity(): void; - onRemovedFromEntity(): void; - onEnabled(): void; - onDisabled(): void; - debugRender(): void; - update(): void; - onEntityTransformChanged(comp: TransformComponent): void; - registerComponent(): void; - deregisterComponent(): void; +declare module es { + class Scene extends egret.DisplayObjectContainer { + camera: Camera; + readonly content: ContentManager; + enablePostProcessing: boolean; + readonly entities: EntityList; + readonly renderableComponents: RenderableComponentList; + readonly entityProcessors: EntityProcessorList; + _renderers: Renderer[]; + readonly _postProcessors: PostProcessor[]; + _didSceneBegin: any; + static createWithDefaultRenderer(): Scene; + constructor(); + initialize(): void; + onStart(): Promise; + unload(): void; + onActive(): void; + onDeactive(): void; + begin(): Promise; + end(): void; + update(): void; + render(): void; + postRender(): void; + addRenderer(renderer: T): T; + getRenderer(type: any): T; + removeRenderer(renderer: Renderer): void; + addPostProcessor(postProcessor: T): T; + getPostProcessor(type: any): T; + removePostProcessor(postProcessor: PostProcessor): void; + createEntity(name: string): Entity; + addEntity(entity: Entity): Entity; + destroyAllEntities(): void; + findEntity(name: string): Entity; + findEntitiesWithTag(tag: number): Entity[]; + entitiesOfType(type: any): T[]; + findComponentOfType(type: any): T; + findComponentsOfType(type: any): T[]; + addEntityProcessor(processor: EntitySystem): EntitySystem; + removeEntityProcessor(processor: EntitySystem): void; + getEntityProcessor(): T; + } } -declare enum CoreEvents { - SceneChanged = 0 +declare module es { + class SceneManager { + private static _scene; + private static _nextScene; + static sceneTransition: SceneTransition; + static stage: egret.Stage; + static activeSceneChanged: Function; + static emitter: Emitter; + static content: ContentManager; + private static _instnace; + private static timerRuler; + static readonly Instance: SceneManager; + constructor(stage: egret.Stage); + static scene: Scene; + static initialize(stage: egret.Stage): void; + static update(): void; + static render(): void; + static startSceneTransition(sceneTransition: T): T; + static registerActiveSceneChanged(current: Scene, next: Scene): void; + onSceneChanged(): void; + private static startDebugUpdate; + private static endDebugUpdate; + } } -declare class Entity extends egret.DisplayObjectContainer { - private static _idGenerator; - name: string; - readonly id: number; - scene: Scene; - readonly components: ComponentList; - private _updateOrder; - private _enabled; - _isDestoryed: boolean; - private _tag; - componentBits: BitSet; - readonly isDestoryed: boolean; - position: Vector2; - scale: Vector2; - rotation: number; - enabled: boolean; - setEnabled(isEnabled: boolean): this; - tag: number; - readonly stage: egret.Stage; - constructor(name: string); - private onAddToStage; - updateOrder: number; - roundPosition(): void; - setUpdateOrder(updateOrder: number): this; - setTag(tag: number): Entity; - attachToScene(newScene: Scene): void; - detachFromScene(): void; - addComponent(component: T): T; - hasComponent(type: any): boolean; - getOrCreateComponent(type: T): T; - getComponent(type: any): T; - getComponents(typeName: string | any, componentList?: any): any; - onEntityTransformChanged(comp: TransformComponent): void; - removeComponentForType(type: any): boolean; - removeComponent(component: Component): void; - removeAllComponents(): void; - update(): void; - onAddedToScene(): void; - onRemovedFromScene(): void; - destroy(): void; +declare module transform { + enum Component { + position = 0, + scale = 1, + rotation = 2 + } } -declare enum TransformComponent { - rotation = 0, - scale = 1, - position = 2 +declare module es { + enum DirtyType { + clean = 0, + positionDirty = 1, + scaleDirty = 2, + rotationDirty = 3 + } + class Transform { + readonly entity: Entity; + parent: Transform; + readonly childCount: number; + position: Vector2; + rotation: number; + scale: Vector2; + _parent: Transform; + hierarchyDirty: DirtyType; + _children: Transform[]; + constructor(entity: Entity); + getChild(index: number): Transform; + setParent(parent: Transform): Transform; + setPosition(x: number, y: number): Transform; + setRotation(degrees: number): Transform; + setScale(scale: Vector2): Transform; + lookAt(pos: Vector2): void; + roundPosition(): void; + setDirty(dirtyFlagType: DirtyType): void; + copyFrom(transform: Transform): void; + } } -declare class Scene extends egret.DisplayObjectContainer { - camera: Camera; - readonly entities: EntityList; - readonly renderableComponents: RenderableComponentList; - readonly content: ContentManager; - enablePostProcessing: boolean; - private _renderers; - private _postProcessors; - private _didSceneBegin; - readonly entityProcessors: EntityProcessorList; - constructor(); - createEntity(name: string): Entity; - addEntity(entity: Entity): Entity; - destroyAllEntities(): void; - findEntity(name: string): Entity; - addEntityProcessor(processor: EntitySystem): EntitySystem; - removeEntityProcessor(processor: EntitySystem): void; - getEntityProcessor(): T; - addRenderer(renderer: T): T; - getRenderer(type: any): T; - removeRenderer(renderer: Renderer): void; - begin(): void; - end(): void; - protected onStart(): Promise; - protected onActive(): void; - protected onDeactive(): void; - protected unload(): void; - update(): void; - postRender(): void; - render(): void; - addPostProcessor(postProcessor: T): T; +declare module es { + enum CameraStyle { + lockOn = 0, + cameraWindow = 1 + } + class Camera extends Component { + position: Vector2; + rotation: number; + zoom: number; + minimumZoom: number; + maximumZoom: number; + readonly bounds: Rectangle; + origin: Vector2; + private _zoom; + private _minimumZoom; + private _maximumZoom; + private _origin; + followLerp: number; + deadzone: Rectangle; + focusOffset: Vector2; + mapLockEnabled: boolean; + mapSize: Vector2; + _targetEntity: Entity; + _targetCollider: Collider; + _desiredPositionDelta: Vector2; + _cameraStyle: CameraStyle; + _worldSpaceDeadZone: Rectangle; + constructor(targetEntity?: Entity, cameraStyle?: CameraStyle); + onSceneSizeChanged(newWidth: number, newHeight: number): void; + setPosition(position: Vector2): this; + setRotation(rotation: number): Camera; + setZoom(zoom: number): Camera; + setMinimumZoom(minZoom: number): Camera; + setMaximumZoom(maxZoom: number): Camera; + zoomIn(deltaZoom: number): void; + zoomOut(deltaZoom: number): void; + onAddedToEntity(): void; + update(): void; + clampToMapSize(position: Vector2): Vector2; + updateFollow(): void; + follow(targetEntity: Entity, cameraStyle?: CameraStyle): void; + setCenteredDeadzone(width: number, height: number): void; + } } -declare class SceneManager { - private static _scene; - private static _nextScene; - static sceneTransition: SceneTransition; - static stage: egret.Stage; - static activeSceneChanged: Function; - static emitter: Emitter; - static content: ContentManager; - private static _instnace; - private static timerRuler; - static readonly Instance: SceneManager; - constructor(stage: egret.Stage); - static scene: Scene; - static initialize(stage: egret.Stage): void; - static update(): void; - static render(): void; - static startSceneTransition(sceneTransition: T): T; - static registerActiveSceneChanged(current: Scene, next: Scene): void; - onSceneChanged(): void; - private static startDebugUpdate; - private static endDebugUpdate; +declare module es { + class ComponentPool { + private _cache; + private _type; + constructor(typeClass: any); + obtain(): T; + free(component: T): void; + } } -declare class Camera extends Component { - private _zoom; - private _origin; - private _minimumZoom; - private _maximumZoom; - private _position; - followLerp: number; - deadzone: Rectangle; - focusOffset: Vector2; - mapLockEnabled: boolean; - mapSize: Vector2; - targetEntity: Entity; - private _worldSpaceDeadZone; - private _desiredPositionDelta; - private _targetCollider; - cameraStyle: CameraStyle; - zoom: number; - minimumZoom: number; - maximumZoom: number; - origin: Vector2; - position: Vector2; - x: number; - y: number; - constructor(); - onSceneSizeChanged(newWidth: number, newHeight: number): void; - setMinimumZoom(minZoom: number): Camera; - setMaximumZoom(maxZoom: number): Camera; - setZoom(zoom: number): Camera; - setRotation(rotation: number): Camera; - setPosition(position: Vector2): this; - follow(targetEntity: Entity, cameraStyle?: CameraStyle): void; - update(): void; - private clampToMapSize; - private updateFollow; +declare module es { + class IUpdatableComparer { + compare(a: Component, b: Component): number; + } } -declare enum CameraStyle { - lockOn = 0, - cameraWindow = 1 +declare module es { + abstract class PooledComponent extends Component { + abstract reset(): any; + } } -declare class ComponentPool { - private _cache; - private _type; - constructor(typeClass: any); - obtain(): T; - free(component: T): void; +declare module es { + abstract class RenderableComponent extends Component implements IRenderable { + readonly width: number; + readonly height: number; + readonly bounds: Rectangle; + renderLayer: number; + color: number; + localOffset: Vector2; + isVisible: boolean; + protected _localOffset: Vector2; + protected _renderLayer: number; + protected _bounds: Rectangle; + private _isVisible; + protected _areBoundsDirty: boolean; + onEntityTransformChanged(comp: transform.Component): void; + abstract render(camera: Camera): any; + protected onBecameVisible(): void; + protected onBecameInvisible(): void; + isVisibleFromCamera(camera: Camera): boolean; + setRenderLayer(renderLayer: number): RenderableComponent; + setColor(color: number): RenderableComponent; + setLocalOffset(offset: Vector2): RenderableComponent; + toString(): string; + } } -declare abstract class PooledComponent extends Component { - abstract reset(): any; +declare module es { + class Mesh extends RenderableComponent { + private _mesh; + constructor(); + setTexture(texture: egret.Texture): Mesh; + reset(): void; + render(camera: es.Camera): void; + } } -declare abstract class RenderableComponent extends PooledComponent implements IRenderable { - private _isVisible; - protected _areBoundsDirty: boolean; - protected _bounds: Rectangle; - protected _localOffset: Vector2; - color: number; - readonly width: number; - readonly height: number; - isVisible: boolean; - readonly bounds: Rectangle; - protected getWidth(): number; - protected getHeight(): number; - protected onBecameVisible(): void; - protected onBecameInvisible(): void; - abstract render(camera: Camera): any; - isVisibleFromCamera(camera: Camera): boolean; +declare module es { + class SpriteRenderer extends RenderableComponent { + readonly bounds: Rectangle; + origin: Vector2; + originNormalized: Vector2; + sprite: Sprite; + protected _origin: Vector2; + protected _sprite: Sprite; + constructor(sprite?: Sprite | egret.Texture); + setSprite(sprite: Sprite): SpriteRenderer; + setOrigin(origin: Vector2): SpriteRenderer; + setOriginNormalized(value: Vector2): SpriteRenderer; + render(camera: Camera): void; + } } -declare class Mesh extends RenderableComponent { - private _mesh; - constructor(); - setTexture(texture: egret.Texture): Mesh; - onAddedToEntity(): void; - onRemovedFromEntity(): void; - render(camera: Camera): void; - reset(): void; +declare module es { + class TiledSpriteRenderer extends SpriteRenderer { + protected sourceRect: Rectangle; + protected leftTexture: egret.Bitmap; + protected rightTexture: egret.Bitmap; + scrollX: number; + scrollY: number; + constructor(sprite: Sprite); + render(camera: es.Camera): void; + } } -declare class SpriteRenderer extends RenderableComponent { - private _sprite; - protected bitmap: egret.Bitmap; - sprite: Sprite; - setSprite(sprite: Sprite): SpriteRenderer; - setColor(color: number): SpriteRenderer; - isVisibleFromCamera(camera: Camera): boolean; - render(camera: Camera): void; - onRemovedFromEntity(): void; - reset(): void; +declare module es { + class ScrollingSpriteRenderer extends TiledSpriteRenderer { + scrollSpeedX: number; + scroolSpeedY: number; + private _scrollX; + private _scrollY; + update(): void; + render(camera: Camera): void; + } } -declare class TiledSpriteRenderer extends SpriteRenderer { - protected sourceRect: Rectangle; - protected leftTexture: egret.Bitmap; - protected rightTexture: egret.Bitmap; - scrollX: number; - scrollY: number; - constructor(sprite: Sprite); - render(camera: Camera): void; +declare module es { + class Sprite { + texture2D: egret.Texture; + readonly sourceRect: Rectangle; + readonly center: Vector2; + origin: Vector2; + readonly uvs: Rectangle; + constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2); + } } -declare class ScrollingSpriteRenderer extends TiledSpriteRenderer { - scrollSpeedX: number; - scroolSpeedY: number; - private _scrollX; - private _scrollY; - update(): void; - render(camera: Camera): void; +declare module es { + class SpriteAnimation { + readonly sprites: Sprite[]; + readonly frameRate: number; + constructor(sprites: Sprite[], frameRate: number); + } } -declare class Sprite { - texture2D: egret.Texture; - readonly sourceRect: Rectangle; - readonly center: Vector2; - origin: Vector2; - readonly uvs: Rectangle; - constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2); +declare module es { + enum LoopMode { + loop = 0, + once = 1, + clampForever = 2, + pingPong = 3, + pingPongOnce = 4 + } + enum State { + none = 0, + running = 1, + paused = 2, + completed = 3 + } + class SpriteAnimator extends SpriteRenderer { + onAnimationCompletedEvent: (string: any) => {}; + speed: number; + animationState: State; + currentAnimation: SpriteAnimation; + currentAnimationName: string; + currentFrame: number; + readonly isRunning: boolean; + readonly animations: Map; + private _animations; + _elapsedTime: number; + _loopMode: LoopMode; + constructor(sprite?: Sprite); + update(): void; + addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator; + play(name: string, loopMode?: LoopMode): void; + isAnimationActive(name: string): boolean; + pause(): void; + unPause(): void; + stop(): void; + } } -declare class SpriteAnimation { - readonly sprites: Sprite[]; - readonly frameRate: number; - constructor(sprites: Sprite[], frameRate: number); +declare module es { + interface ITriggerListener { + onTriggerEnter(other: Collider, local: Collider): any; + onTriggerExit(other: Collider, local: Collider): any; + } } -declare class SpriteAnimator extends SpriteRenderer { - onAnimationCompletedEvent: Function; - speed: number; - animationState: State; - currentAnimation: SpriteAnimation; - currentAnimationName: string; - currentFrame: number; - readonly isRunning: boolean; - readonly animations: Map; - private _animations; - private _elapsedTime; - private _loopMode; - constructor(sprite?: Sprite); - addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator; - play(name: string, loopMode?: LoopMode): void; - isAnimationActive(name: string): boolean; - pause(): void; - unPause(): void; - stop(): void; - update(): void; +declare module es { + class Mover extends Component { + private _triggerHelper; + onAddedToEntity(): void; + calculateMovement(motion: Vector2): { + collisionResult: CollisionResult; + motion: Vector2; + }; + applyMovement(motion: Vector2): void; + move(motion: Vector2): CollisionResult; + } } -declare enum LoopMode { - loop = 0, - once = 1, - clampForever = 2, - pingPong = 3, - pingPongOnce = 4 +declare module es { + class ProjectileMover extends Component { + private _tempTriggerList; + private _collider; + onAddedToEntity(): void; + move(motion: Vector2): boolean; + private notifyTriggerListeners; + } } -declare enum State { - none = 0, - running = 1, - paused = 2, - completed = 3 +declare module es { + abstract class Collider extends Component { + shape: Shape; + localOffset: Vector2; + readonly absolutePosition: Vector2; + readonly rotation: number; + isTrigger: boolean; + physicsLayer: number; + collidesWithLayers: number; + shouldColliderScaleAndRotateWithTransform: boolean; + readonly bounds: Rectangle; + registeredPhysicsBounds: Rectangle; + protected _colliderRequiresAutoSizing: any; + protected _localOffset: Vector2; + _localOffsetLength: number; + protected _isParentEntityAddedToScene: any; + protected _isColliderRegistered: any; + setLocalOffset(offset: Vector2): Collider; + setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider; + onAddedToEntity(): void; + onRemovedFromEntity(): void; + onEntityTransformChanged(comp: transform.Component): void; + onEnabled(): void; + onDisabled(): void; + registerColliderWithPhysicsSystem(): void; + unregisterColliderWithPhysicsSystem(): void; + overlaps(other: Collider): any; + collidesWith(collider: Collider, motion: Vector2): CollisionResult; + } } -interface ITriggerListener { - onTriggerEnter(other: Collider, local: Collider): any; - onTriggerExit(other: Collider, local: Collider): any; +declare module es { + class BoxCollider extends Collider { + width: number; + height: number; + constructor(); + setSize(width: number, height: number): this; + setWidth(width: number): BoxCollider; + setHeight(height: number): void; + toString(): string; + } } -declare class Mover extends Component { - private _triggerHelper; - onAddedToEntity(): void; - calculateMovement(motion: Vector2): { - collisionResult: CollisionResult; - motion: Vector2; - }; - applyMovement(motion: Vector2): void; - move(motion: Vector2): CollisionResult; +declare module es { + class CircleCollider extends Collider { + radius: number; + constructor(radius?: number); + setRadius(radius: number): CircleCollider; + toString(): string; + } } -declare class ProjectileMover extends Component { - private _tempTriggerList; - private _collider; - onAddedToEntity(): void; - move(motion: Vector2): boolean; - private notifyTriggerListeners; +declare module es { + class PolygonCollider extends Collider { + constructor(points: Vector2[]); + } } -declare abstract class Collider extends Component { - shape: Shape; - physicsLayer: number; - isTrigger: boolean; - registeredPhysicsBounds: Rectangle; - shouldColliderScaleAndRotateWithTransform: boolean; - collidesWithLayers: number; - protected _isParentEntityAddedToScene: any; - protected _colliderRequiresAutoSizing: any; - protected _isColliderRegistered: any; - readonly bounds: Rectangle; - registerColliderWithPhysicsSystem(): void; - unregisterColliderWithPhysicsSystem(): void; - overlaps(other: Collider): any; - collidesWith(collider: Collider, motion: Vector2): CollisionResult; - onAddedToEntity(): void; - onRemovedFromEntity(): void; - onEnabled(): void; - onDisabled(): void; - onEntityTransformChanged(comp: TransformComponent): void; - update(): void; +declare module es { + class EntitySystem { + private _scene; + private _entities; + private _matcher; + readonly matcher: Matcher; + scene: Scene; + constructor(matcher?: Matcher); + initialize(): void; + onChanged(entity: Entity): void; + add(entity: Entity): void; + onAdded(entity: Entity): void; + remove(entity: Entity): void; + onRemoved(entity: Entity): void; + update(): void; + lateUpdate(): void; + protected begin(): void; + protected process(entities: Entity[]): void; + protected lateProcess(entities: Entity[]): void; + protected end(): void; + } } -declare class BoxCollider extends Collider { - width: number; - setWidth(width: number): BoxCollider; - height: number; - setHeight(height: number): void; - constructor(); - setSize(width: number, height: number): this; +declare module es { + abstract class EntityProcessingSystem extends EntitySystem { + constructor(matcher: Matcher); + abstract processEntity(entity: Entity): any; + lateProcessEntity(entity: Entity): void; + protected process(entities: Entity[]): void; + protected lateProcess(entities: Entity[]): void; + } } -declare class CircleCollider extends Collider { - radius: number; - constructor(radius?: number); - setRadius(radius: number): CircleCollider; +declare module es { + abstract class PassiveSystem extends EntitySystem { + onChanged(entity: Entity): void; + protected process(entities: Entity[]): void; + } } -declare class PolygonCollider extends Collider { - constructor(points: Vector2[]); +declare module es { + abstract class ProcessingSystem extends EntitySystem { + onChanged(entity: Entity): void; + protected process(entities: Entity[]): void; + abstract processSystem(): any; + } } -declare class EntitySystem { - private _scene; - private _entities; - private _matcher; - readonly matcher: Matcher; - scene: Scene; - constructor(matcher?: Matcher); - initialize(): void; - onChanged(entity: Entity): void; - add(entity: Entity): void; - onAdded(entity: Entity): void; - remove(entity: Entity): void; - onRemoved(entity: Entity): void; - update(): void; - lateUpdate(): void; - protected begin(): void; - protected process(entities: Entity[]): void; - protected lateProcess(entities: Entity[]): void; - protected end(): void; +declare module es { + class BitSet { + private static LONG_MASK; + private _bits; + constructor(nbits?: number); + and(bs: BitSet): void; + andNot(bs: BitSet): void; + cardinality(): number; + clear(pos?: number): void; + private ensure; + get(pos: number): boolean; + intersects(set: BitSet): boolean; + isEmpty(): boolean; + nextSetBit(from: number): number; + set(pos: number, value?: boolean): void; + } } -declare abstract class EntityProcessingSystem extends EntitySystem { - constructor(matcher: Matcher); - abstract processEntity(entity: Entity): any; - lateProcessEntity(entity: Entity): void; - protected process(entities: Entity[]): void; - protected lateProcess(entities: Entity[]): void; +declare module es { + class ComponentList { + static compareUpdatableOrder: IUpdatableComparer; + _entity: Entity; + _components: Component[]; + _componentsToAdd: Component[]; + _componentsToRemove: Component[]; + _tempBufferList: Component[]; + _isComponentListUnsorted: boolean; + constructor(entity: Entity); + readonly count: number; + readonly buffer: Component[]; + markEntityListUnsorted(): void; + add(component: Component): void; + remove(component: Component): void; + removeAllComponents(): void; + deregisterAllComponents(): void; + registerAllComponents(): void; + updateLists(): void; + handleRemove(component: Component): void; + getComponent(type: any, onlyReturnInitializedComponents: boolean): T; + getComponents(typeName: string | any, components?: any): any; + update(): void; + onEntityTransformChanged(comp: transform.Component): void; + onEntityEnabled(): void; + onEntityDisabled(): void; + } } -declare abstract class PassiveSystem extends EntitySystem { - onChanged(entity: Entity): void; - protected process(entities: Entity[]): void; +declare module es { + class ComponentTypeManager { + private static _componentTypesMask; + static add(type: any): void; + static getIndexFor(type: any): number; + } } -declare abstract class ProcessingSystem extends EntitySystem { - onChanged(entity: Entity): void; - protected process(entities: Entity[]): void; - abstract processSystem(): any; +declare module es { + class EntityList { + scene: Scene; + private _entitiesToRemove; + private _entitiesToAdded; + private _tempEntityList; + private _entities; + private _entityDict; + private _unsortedTags; + constructor(scene: Scene); + readonly count: number; + readonly buffer: Entity[]; + add(entity: Entity): void; + remove(entity: Entity): void; + findEntity(name: string): Entity; + entitiesWithTag(tag: number): Entity[]; + entitiesOfType(type: any): T[]; + findComponentOfType(type: any): T; + findComponentsOfType(type: any): T[]; + getTagList(tag: number): Entity[]; + addToTagList(entity: Entity): void; + removeFromTagList(entity: Entity): void; + update(): void; + removeAllEntities(): void; + updateLists(): void; + } } -declare class BitSet { - private static LONG_MASK; - private _bits; - constructor(nbits?: number); - and(bs: BitSet): void; - andNot(bs: BitSet): void; - cardinality(): number; - clear(pos?: number): void; - private ensure; - get(pos: number): boolean; - intersects(set: BitSet): boolean; - isEmpty(): boolean; - nextSetBit(from: number): number; - set(pos: number, value?: boolean): void; +declare module es { + class EntityProcessorList { + private _processors; + add(processor: EntitySystem): void; + remove(processor: EntitySystem): void; + onComponentAdded(entity: Entity): void; + onComponentRemoved(entity: Entity): void; + onEntityAdded(entity: Entity): void; + onEntityRemoved(entity: Entity): void; + protected notifyEntityChanged(entity: Entity): void; + protected removeFromProcessors(entity: Entity): void; + begin(): void; + update(): void; + lateUpdate(): void; + end(): void; + getProcessor(): T; + } } -declare class ComponentList { - private _entity; - private _components; - private _componentsToAdd; - private _componentsToRemove; - private _tempBufferList; - constructor(entity: Entity); - readonly count: number; - readonly buffer: Component[]; - add(component: Component): void; - remove(component: Component): void; - removeAllComponents(): void; - deregisterAllComponents(): void; - registerAllComponents(): void; - updateLists(): void; - onEntityTransformChanged(comp: TransformComponent): void; - private handleRemove; - getComponent(type: any, onlyReturnInitializedComponents: boolean): T; - getComponents(typeName: string | any, components?: any): any; - update(): void; -} -declare class ComponentTypeManager { - private static _componentTypesMask; - static add(type: any): void; - static getIndexFor(type: any): number; -} -declare class EntityList { - scene: Scene; - private _entitiesToRemove; - private _entitiesToAdded; - private _tempEntityList; - private _entities; - private _entityDict; - private _unsortedTags; - constructor(scene: Scene); - readonly count: number; - readonly buffer: Entity[]; - add(entity: Entity): void; - remove(entity: Entity): void; - findEntity(name: string): Entity; - getTagList(tag: number): Entity[]; - addToTagList(entity: Entity): void; - removeFromTagList(entity: Entity): void; - update(): void; - removeAllEntities(): void; - updateLists(): void; -} -declare class EntityProcessorList { - private _processors; - add(processor: EntitySystem): void; - remove(processor: EntitySystem): void; - onComponentAdded(entity: Entity): void; - onComponentRemoved(entity: Entity): void; - onEntityAdded(entity: Entity): void; - onEntityRemoved(entity: Entity): void; - protected notifyEntityChanged(entity: Entity): void; - protected removeFromProcessors(entity: Entity): void; - begin(): void; - update(): void; - lateUpdate(): void; - end(): void; - getProcessor(): T; -} -declare class Matcher { - protected allSet: BitSet; - protected exclusionSet: BitSet; - protected oneSet: BitSet; - static empty(): Matcher; - getAllSet(): BitSet; - getExclusionSet(): BitSet; - getOneSet(): BitSet; - IsIntersted(e: Entity): boolean; - all(...types: any[]): Matcher; - exclude(...types: any[]): this; - one(...types: any[]): this; +declare module es { + class Matcher { + protected allSet: BitSet; + protected exclusionSet: BitSet; + protected oneSet: BitSet; + static empty(): Matcher; + getAllSet(): BitSet; + getExclusionSet(): BitSet; + getOneSet(): BitSet; + IsIntersted(e: Entity): boolean; + all(...types: any[]): Matcher; + exclude(...types: any[]): this; + one(...types: any[]): this; + } } declare class ObjectUtils { static clone(p: any, c?: T): T; } -declare class RenderableComponentList { - private _components; - readonly count: number; - readonly buffer: IRenderable[]; - add(component: IRenderable): void; - remove(component: IRenderable): void; - updateList(): void; +declare module es { + interface IRenderable { + bounds: Rectangle; + enabled: boolean; + renderLayer: number; + isVisible: boolean; + isVisibleFromCamera(camera: Camera): any; + render(camera: Camera): any; + } + class RenderableComparer { + compare(self: IRenderable, other: IRenderable): number; + } +} +declare module es { + class RenderableComponentList { + static compareUpdatableOrder: RenderableComparer; + _components: IRenderable[]; + _componentsByRenderLayer: Map; + _unsortedRenderLayers: number[]; + _componentsNeedSort: boolean; + readonly count: number; + readonly buffer: IRenderable[]; + add(component: IRenderable): void; + remove(component: IRenderable): void; + updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number): void; + setRenderLayerNeedsComponentSort(renderLayer: number): void; + setNeedsComponentSort(): void; + addToRenderLayerList(component: IRenderable, renderLayer: number): void; + componentsWithRenderLayer(renderLayer: number): IRenderable[]; + updateList(): void; + } } declare class StringUtils { static matchChineseWord(str: string): string[]; @@ -674,25 +868,29 @@ declare class StringUtils { static cutOff(str: string, start: number, len: number, order?: boolean): string; static strReplace(str: string, rStr: string[]): string; } -declare class TextureUtils { - static sharedCanvas: HTMLCanvasElement; - static sharedContext: CanvasRenderingContext2D; - static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement; - static toDataURL(type: string, texture: egret.Texture, rect?: egret.Rectangle, encoderOptions?: any): string; - static eliFoTevas(type: string, texture: egret.Texture, filePath: string, rect?: egret.Rectangle, encoderOptions?: any): void; - static getPixel32(texture: egret.Texture, x: number, y: number): number[]; - static getPixels(texture: egret.Texture, x: number, y: number, width?: number, height?: number): number[]; +declare module es { + class TextureUtils { + static sharedCanvas: HTMLCanvasElement; + static sharedContext: CanvasRenderingContext2D; + static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement; + static toDataURL(type: string, texture: egret.Texture, rect?: egret.Rectangle, encoderOptions?: any): string; + static eliFoTevas(type: string, texture: egret.Texture, filePath: string, rect?: egret.Rectangle, encoderOptions?: any): void; + static getPixel32(texture: egret.Texture, x: number, y: number): number[]; + static getPixels(texture: egret.Texture, x: number, y: number, width?: number, height?: number): number[]; + } } -declare class Time { - static unscaledDeltaTime: any; - static deltaTime: number; - static timeScale: number; - static frameCount: number; - private static _lastTime; - static _timeSinceSceneLoad: any; - static update(currentTime: number): void; - static sceneChanged(): void; - static checkEvery(interval: number): boolean; +declare module es { + class Time { + static unscaledDeltaTime: any; + static deltaTime: number; + static timeScale: number; + static frameCount: number; + private static _lastTime; + static _timeSinceSceneLoad: any; + static update(currentTime: number): void; + static sceneChanged(): void; + static checkEvery(interval: number): boolean; + } } declare class TimeUtils { static monthId(d?: Date): number; @@ -708,362 +906,417 @@ declare class TimeUtils { static secondToTime(time?: number, partition?: string, showHour?: boolean): string; static timeToMillisecond(time: string, partition?: string): string; } -declare class GraphicsCapabilities extends egret.Capabilities { - initialize(device: GraphicsDevice): void; - private platformInitialize; +declare module es { + class GraphicsCapabilities extends egret.Capabilities { + initialize(device: GraphicsDevice): void; + private platformInitialize; + } } -declare class GraphicsDevice { - private viewport; - graphicsCapabilities: GraphicsCapabilities; - constructor(); +declare module es { + class GraphicsDevice { + private viewport; + graphicsCapabilities: GraphicsCapabilities; + constructor(); + } } -declare class Viewport { - private _x; - private _y; - private _width; - private _height; - private _minDepth; - private _maxDepth; - readonly aspectRatio: number; - bounds: Rectangle; - constructor(x: number, y: number, width: number, height: number); -} -declare class GaussianBlurEffect extends egret.CustomFilter { - private static blur_frag; - constructor(); -} -declare class PolygonLightEffect extends egret.CustomFilter { - private static vertSrc; - private static fragmentSrc; - constructor(); -} -declare class PostProcessor { - enable: boolean; - effect: egret.Filter; - scene: Scene; - shape: egret.Shape; - static default_vert: string; - constructor(effect?: egret.Filter); - onAddedToScene(scene: Scene): void; - process(): void; - onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; - protected drawFullscreenQuad(): void; - unload(): void; -} -declare class GaussianBlurPostProcessor extends PostProcessor { - onAddedToScene(scene: Scene): void; -} -declare abstract class Renderer { - camera: Camera; - onAddedToScene(scene: Scene): void; - protected beginRender(cam: Camera): void; - abstract render(scene: Scene): any; - unload(): void; - protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void; -} -declare class DefaultRenderer extends Renderer { - render(scene: Scene): void; -} -interface IRenderable { - bounds: Rectangle; - enabled: boolean; - isVisible: boolean; - isVisibleFromCamera(camera: Camera): any; - render(camera: Camera): any; -} -declare class ScreenSpaceRenderer extends Renderer { - render(scene: Scene): void; -} -declare class PolyLight extends RenderableComponent { - power: number; - protected _radius: number; - private _lightEffect; - private _indices; - radius: number; - constructor(radius: number, color: number, power: number); - private computeTriangleIndices; - setRadius(radius: number): void; - render(camera: Camera): void; - reset(): void; -} -declare abstract class SceneTransition { - private _hasPreviousSceneRender; - loadsNewScene: boolean; - isNewSceneLoaded: boolean; - protected sceneLoadAction: Function; - onScreenObscured: Function; - onTransitionCompleted: Function; - readonly hasPreviousSceneRender: boolean; - constructor(sceneLoadAction: Function); - preRender(): void; - render(): void; - onBeginTransition(): Promise; - protected transitionComplete(): void; - protected loadNextScene(): Promise; - tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise; -} -declare class FadeTransition extends SceneTransition { - fadeToColor: number; - fadeOutDuration: number; - fadeEaseType: Function; - delayBeforeFadeInDuration: number; - private _mask; - private _alpha; - constructor(sceneLoadAction: Function); - onBeginTransition(): Promise; - render(): void; -} -declare class WindTransition extends SceneTransition { - private _mask; - private _windEffect; - duration: number; - windSegments: number; - size: number; - easeType: (t: number) => number; - constructor(sceneLoadAction: Function); - onBeginTransition(): Promise; -} -declare class Bezier { - static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; - static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; - static getFirstDerivativeThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; - static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; - static getOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, end: Vector2, distanceTolerance?: number): Vector2[]; - private static recursiveGetOptimizedDrawingPoints; -} -declare class Flags { - static isFlagSet(self: number, flag: number): boolean; - static isUnshiftedFlagSet(self: number, flag: number): boolean; - static setFlagExclusive(self: number, flag: number): number; - static setFlag(self: number, flag: number): number; - static unsetFlag(self: number, flag: number): number; - static invertFlags(self: number): number; -} -declare class MathHelper { - static readonly Epsilon: number; - static readonly Rad2Deg: number; - static readonly Deg2Rad: number; - static toDegrees(radians: number): number; - static toRadians(degrees: number): number; - static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number; - static lerp(value1: number, value2: number, amount: number): number; - static clamp(value: number, min: number, max: number): number; - static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2; - static isEven(value: number): boolean; - static clamp01(value: number): number; - static angleBetweenVectors(from: Vector2, to: Vector2): number; -} -declare class Matrix2D { - m11: number; - m12: number; - m21: number; - m22: number; - m31: number; - m32: number; - private static _identity; - static readonly identity: Matrix2D; - constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number); - translation: Vector2; - rotation: number; - rotationDegrees: number; - scale: Vector2; - static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static divide(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D; - determinant(): number; - static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D; - static createTranslation(xPosition: number, yPosition: number): Matrix2D; - static createTranslationVector(position: Vector2): Matrix2D; - static createRotation(radians: number, result?: Matrix2D): Matrix2D; - static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; - toEgretMatrix(): egret.Matrix; -} -declare class Rectangle extends egret.Rectangle { - readonly max: Vector2; - readonly center: Vector2; - location: Vector2; - size: Vector2; - intersects(value: egret.Rectangle): boolean; - containsRect(value: Rectangle): boolean; - getHalfSize(): Vector2; - static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; - getClosestPointOnRectangleBorderToPoint(point: Vector2): { - res: Vector2; - edgeNormal: Vector2; - }; - getClosestPointOnBoundsToOrigin(): Vector2; - setEgretRect(rect: egret.Rectangle): Rectangle; - static rectEncompassingPoints(points: Vector2[]): Rectangle; -} -declare class Vector3 { - x: number; - y: number; - z: number; - constructor(x: number, y: number, z: number); -} -declare class ColliderTriggerHelper { - private _entity; - private _activeTriggerIntersections; - private _previousTriggerIntersections; - private _tempTriggerList; - constructor(entity: Entity); - update(): void; - private checkForExitedColliders; - private notifyTriggerListeners; -} -declare enum PointSectors { - center = 0, - top = 1, - bottom = 2, - topLeft = 9, - topRight = 5, - left = 8, - right = 4, - bottomLeft = 10, - bottomRight = 6 -} -declare class Collisions { - static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean; - static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2; - static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; - static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean; - static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean; - static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean; - static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean; - static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean; - static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean; - static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors; -} -declare class Physics { - private static _spatialHash; - static spatialHashCellSize: number; - static readonly allLayers: number; - static reset(): void; - static clear(): void; - static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; - static boxcastBroadphase(rect: Rectangle, layerMask?: number): { - colliders: Collider[]; - rect: Rectangle; - }; - static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): { - tempHashSet: Collider[]; +declare module es { + class Viewport { + private _x; + private _y; + private _width; + private _height; + private _minDepth; + private _maxDepth; + readonly aspectRatio: number; bounds: Rectangle; - }; - static addCollider(collider: Collider): void; - static removeCollider(collider: Collider): void; - static updateCollider(collider: Collider): void; - static debugDraw(secondsToDisplay: any): void; + constructor(x: number, y: number, width: number, height: number); + } } -declare abstract class Shape extends egret.DisplayObject { - abstract bounds: Rectangle; - abstract center: Vector2; - abstract position: Vector2; - abstract pointCollidesWithShape(point: Vector2): CollisionResult; - abstract overlaps(other: Shape): any; - abstract collidesWithShape(other: Shape): CollisionResult; +declare module es { + class GaussianBlurEffect extends egret.CustomFilter { + private static blur_frag; + constructor(); + } } -declare class Polygon extends Shape { - points: Vector2[]; - private _polygonCenter; - private _areEdgeNormalsDirty; - protected _originalPoints: Vector2[]; - center: Vector2; - readonly position: Vector2; - readonly bounds: Rectangle; - _edgeNormals: Vector2[]; - readonly edgeNormals: Vector2[]; - isBox: boolean; - constructor(points: Vector2[], isBox?: boolean); - private buildEdgeNormals; - setPoints(points: Vector2[]): void; - collidesWithShape(other: Shape): any; - recalculateCenterAndEdgeNormals(): void; - overlaps(other: Shape): any; - static findPolygonCenter(points: Vector2[]): Vector2; - static recenterPolygonVerts(points: Vector2[]): void; - static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { - closestPoint: any; - distanceSquared: any; - edgeNormal: any; - }; - pointCollidesWithShape(point: Vector2): CollisionResult; - containsPoint(point: Vector2): boolean; - static buildSymmertricalPolygon(vertCount: number, radius: number): any[]; +declare module es { + class PolygonLightEffect extends egret.CustomFilter { + private static vertSrc; + private static fragmentSrc; + constructor(); + } } -declare class Box extends Polygon { - constructor(width: number, height: number); - private static buildBox; - overlaps(other: Shape): any; - collidesWithShape(other: Shape): any; - updateBox(width: number, height: number): void; - containsPoint(point: Vector2): boolean; +declare module es { + class PostProcessor { + enabled: boolean; + effect: egret.Filter; + scene: Scene; + shape: egret.Shape; + static default_vert: string; + constructor(effect?: egret.Filter); + onAddedToScene(scene: Scene): void; + process(): void; + onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; + protected drawFullscreenQuad(): void; + unload(): void; + } } -declare class Circle extends Shape { - radius: number; - _originalRadius: number; - center: Vector2; - readonly position: Vector2; - readonly bounds: Rectangle; - constructor(radius: number); - pointCollidesWithShape(point: Vector2): CollisionResult; - collidesWithShape(other: Shape): CollisionResult; - overlaps(other: Shape): any; +declare module es { + class GaussianBlurPostProcessor extends PostProcessor { + onAddedToScene(scene: Scene): void; + } } -declare class CollisionResult { - collider: Collider; - minimumTranslationVector: Vector2; - normal: Vector2; - point: Vector2; - invertResult(): void; +declare module es { + abstract class Renderer { + camera: Camera; + onAddedToScene(scene: Scene): void; + protected beginRender(cam: Camera): void; + abstract render(scene: Scene): any; + unload(): void; + protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void; + } } -declare class ShapeCollisions { - static polygonToPolygon(first: Polygon, second: Polygon): CollisionResult; - static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number; - static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): { - min: number; - max: number; - }; - static circleToPolygon(circle: Circle, polygon: Polygon): CollisionResult; - static circleToBox(circle: Circle, box: Box): CollisionResult; - static pointToCircle(point: Vector2, circle: Circle): CollisionResult; - static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; - static pointToPoly(point: Vector2, poly: Polygon): CollisionResult; - static circleToCircle(first: Circle, second: Circle): CollisionResult; - static boxToBox(first: Box, second: Box): CollisionResult; - private static minkowskiDifference; +declare module es { + class DefaultRenderer extends Renderer { + render(scene: Scene): void; + } } -declare class SpatialHash { - gridBounds: Rectangle; - private _raycastParser; - private _cellSize; - private _inverseCellSize; - private _overlapTestCircle; - private _tempHashSet; - private _cellDict; - constructor(cellSize?: number); - remove(collider: Collider): void; - register(collider: Collider): void; - clear(): void; - overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; - aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): { - tempHashSet: Collider[]; +declare module es { + class ScreenSpaceRenderer extends Renderer { + render(scene: Scene): void; + } +} +declare module es { + class PolyLight extends RenderableComponent { + power: number; + protected _radius: number; + private _lightEffect; + private _indices; + radius: number; + constructor(radius: number, color: number, power: number); + private computeTriangleIndices; + setRadius(radius: number): void; + render(camera: Camera): void; + reset(): void; + } +} +declare module es { + abstract class SceneTransition { + private _hasPreviousSceneRender; + loadsNewScene: boolean; + isNewSceneLoaded: boolean; + protected sceneLoadAction: Function; + onScreenObscured: Function; + onTransitionCompleted: Function; + readonly hasPreviousSceneRender: boolean; + constructor(sceneLoadAction: Function); + preRender(): void; + render(): void; + onBeginTransition(): Promise; + protected transitionComplete(): void; + protected loadNextScene(): Promise; + tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise; + } +} +declare module es { + class FadeTransition extends SceneTransition { + fadeToColor: number; + fadeOutDuration: number; + fadeEaseType: Function; + delayBeforeFadeInDuration: number; + private _mask; + private _alpha; + constructor(sceneLoadAction: Function); + onBeginTransition(): Promise; + render(): void; + } +} +declare module es { + class WindTransition extends SceneTransition { + private _mask; + private _windEffect; + duration: number; + windSegments: number; + size: number; + easeType: (t: number) => number; + constructor(sceneLoadAction: Function); + onBeginTransition(): Promise; + } +} +declare module es { + class Bezier { + static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; + static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; + static getFirstDerivativeThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; + static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; + static getOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, end: Vector2, distanceTolerance?: number): Vector2[]; + private static recursiveGetOptimizedDrawingPoints; + } +} +declare module es { + class Flags { + static isFlagSet(self: number, flag: number): boolean; + static isUnshiftedFlagSet(self: number, flag: number): boolean; + static setFlagExclusive(self: number, flag: number): number; + static setFlag(self: number, flag: number): number; + static unsetFlag(self: number, flag: number): number; + static invertFlags(self: number): number; + } +} +declare module es { + class MathHelper { + static readonly Epsilon: number; + static readonly Rad2Deg: number; + static readonly Deg2Rad: number; + static toDegrees(radians: number): number; + static toRadians(degrees: number): number; + static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number; + static lerp(value1: number, value2: number, amount: number): number; + static clamp(value: number, min: number, max: number): number; + static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2; + static isEven(value: number): boolean; + static clamp01(value: number): number; + static angleBetweenVectors(from: Vector2, to: Vector2): number; + } +} +declare module es { + class Matrix2D { + m11: number; + m12: number; + m21: number; + m22: number; + m31: number; + m32: number; + private static _identity; + static readonly identity: Matrix2D; + constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number); + translation: Vector2; + rotation: number; + rotationDegrees: number; + scale: Vector2; + static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; + static divide(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; + static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; + static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D; + determinant(): number; + static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D; + static createTranslation(xPosition: number, yPosition: number): Matrix2D; + static createTranslationVector(position: Vector2): Matrix2D; + static createRotation(radians: number, result?: Matrix2D): Matrix2D; + static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; + toEgretMatrix(): egret.Matrix; + } +} +declare module es { + class Rectangle extends egret.Rectangle { + readonly max: Vector2; + readonly center: Vector2; + location: Vector2; + size: Vector2; + intersects(value: egret.Rectangle): boolean; + containsRect(value: Rectangle): boolean; + getHalfSize(): Vector2; + static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; + getClosestPointOnRectangleBorderToPoint(point: Vector2): { + res: Vector2; + edgeNormal: Vector2; + }; + getClosestPointOnBoundsToOrigin(): Vector2; + calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void; + setEgretRect(rect: egret.Rectangle): Rectangle; + static rectEncompassingPoints(points: Vector2[]): Rectangle; + } +} +declare module es { + class Vector3 { + x: number; + y: number; + z: number; + constructor(x: number, y: number, z: number); + } +} +declare module es { + class ColliderTriggerHelper { + private _entity; + private _activeTriggerIntersections; + private _previousTriggerIntersections; + private _tempTriggerList; + constructor(entity: Entity); + update(): void; + private checkForExitedColliders; + private notifyTriggerListeners; + } +} +declare module es { + enum PointSectors { + center = 0, + top = 1, + bottom = 2, + topLeft = 9, + topRight = 5, + left = 8, + right = 4, + bottomLeft = 10, + bottomRight = 6 + } + class Collisions { + static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean; + static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2; + static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; + static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean; + static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean; + static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean; + static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean; + static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean; + static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean; + static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors; + } +} +declare module es { + class Physics { + private static _spatialHash; + static spatialHashCellSize: number; + static readonly allLayers: number; + static reset(): void; + static clear(): void; + static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; + static boxcastBroadphase(rect: Rectangle, layerMask?: number): { + colliders: Collider[]; + rect: Rectangle; + }; + static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): { + tempHashSet: Collider[]; + bounds: Rectangle; + }; + static addCollider(collider: Collider): void; + static removeCollider(collider: Collider): void; + static updateCollider(collider: Collider): void; + static debugDraw(secondsToDisplay: any): void; + } +} +declare module es { + abstract class Shape { + position: Vector2; + center: Vector2; bounds: Rectangle; - }; - private cellAtPosition; - private cellCoords; - debugDraw(secondsToDisplay: number, textScale?: number): void; - private debugDrawCellDetails; + abstract recalculateBounds(collider: Collider): any; + abstract pointCollidesWithShape(point: Vector2): CollisionResult; + abstract overlaps(other: Shape): any; + abstract collidesWithShape(other: Shape): CollisionResult; + } } -declare class RaycastResultParser { +declare module es { + class Polygon extends Shape { + points: Vector2[]; + readonly edgeNormals: Vector2[]; + _areEdgeNormalsDirty: boolean; + _edgeNormals: Vector2[]; + _originalPoints: Vector2[]; + _polygonCenter: Vector2; + isBox: boolean; + isUnrotated: boolean; + constructor(points: Vector2[], isBox?: boolean); + setPoints(points: Vector2[]): void; + recalculateCenterAndEdgeNormals(): void; + buildEdgeNormals(): void; + static buildSymmetricalPolygon(vertCount: number, radius: number): any[]; + static recenterPolygonVerts(points: Vector2[]): void; + static findPolygonCenter(points: Vector2[]): Vector2; + static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { + closestPoint: any; + distanceSquared: any; + edgeNormal: any; + }; + recalculateBounds(collider: Collider): void; + overlaps(other: Shape): any; + collidesWithShape(other: Shape): any; + containsPoint(point: Vector2): boolean; + pointCollidesWithShape(point: Vector2): CollisionResult; + } } -declare class NumberDictionary { - private _store; - private getKey; - add(x: number, y: number, list: Collider[]): void; - remove(obj: Collider): void; - tryGetValue(x: number, y: number): Collider[]; - clear(): void; +declare module es { + class Box extends Polygon { + width: number; + height: number; + constructor(width: number, height: number); + private static buildBox; + updateBox(width: number, height: number): void; + overlaps(other: Shape): any; + collidesWithShape(other: Shape): any; + containsPoint(point: Vector2): boolean; + } +} +declare module es { + class Circle extends Shape { + radius: number; + _originalRadius: number; + constructor(radius: number); + recalculateBounds(collider: es.Collider): void; + overlaps(other: Shape): any; + collidesWithShape(other: Shape): CollisionResult; + pointCollidesWithShape(point: Vector2): CollisionResult; + } +} +declare module es { + class CollisionResult { + collider: Collider; + minimumTranslationVector: Vector2; + normal: Vector2; + point: Vector2; + invertResult(): void; + } +} +declare module es { + class ShapeCollisions { + static polygonToPolygon(first: Polygon, second: Polygon): CollisionResult; + static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number; + static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): { + min: number; + max: number; + }; + static circleToPolygon(circle: Circle, polygon: Polygon): CollisionResult; + static circleToBox(circle: Circle, box: Box): CollisionResult; + static pointToCircle(point: Vector2, circle: Circle): CollisionResult; + static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; + static pointToPoly(point: Vector2, poly: Polygon): CollisionResult; + static circleToCircle(first: Circle, second: Circle): CollisionResult; + static boxToBox(first: Box, second: Box): CollisionResult; + private static minkowskiDifference; + } +} +declare module es { + class SpatialHash { + gridBounds: Rectangle; + _raycastParser: RaycastResultParser; + _cellSize: number; + _inverseCellSize: number; + _overlapTestCircle: Circle; + _cellDict: NumberDictionary; + _tempHashSet: Collider[]; + constructor(cellSize?: number); + private cellCoords; + private cellAtPosition; + register(collider: Collider): void; + remove(collider: Collider): void; + removeWithBruteForce(obj: Collider): void; + clear(): void; + debugDraw(secondsToDisplay: number, textScale?: number): void; + private debugDrawCellDetails; + aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): { + tempHashSet: Collider[]; + bounds: Rectangle; + }; + overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; + } + class NumberDictionary { + _store: Map; + private getKey; + add(x: number, y: number, list: Collider[]): void; + remove(obj: Collider): void; + tryGetValue(x: number, y: number): Collider[]; + clear(): void; + } + class RaycastResultParser { + } } declare class ArrayUtils { static bubbleSort(ary: number[]): void; @@ -1090,72 +1343,83 @@ declare class Base64Utils { private static _utf8_decode; private static getConfKey; } -declare class ContentManager { - protected loadedAssets: Map; - loadRes(name: string, local?: boolean): Promise; - dispose(): void; +declare module es { + class ContentManager { + protected loadedAssets: Map; + loadRes(name: string, local?: boolean): Promise; + dispose(): void; + } } -declare class DrawUtils { - static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void; - static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void; - static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void; - static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void; - static drawPixel(shape: egret.Shape, position: Vector2, color: number, size?: number): void; +declare module es { + class DrawUtils { + static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void; + static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void; + static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void; + static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void; + static drawPixel(shape: egret.Shape, position: Vector2, color: number, size?: number): void; + static getColorMatrix(color: number): egret.ColorMatrixFilter; + } } -declare class Emitter { - private _messageTable; - constructor(); - addObserver(eventType: T, handler: Function, context: any): void; - removeObserver(eventType: T, handler: Function): void; - emit(eventType: T, data?: any): void; +declare module es { + class FuncPack { + func: Function; + context: any; + constructor(func: Function, context: any); + } + class Emitter { + private _messageTable; + constructor(); + addObserver(eventType: T, handler: Function, context: any): void; + removeObserver(eventType: T, handler: Function): void; + emit(eventType: T, data?: any): void; + } } -declare class FuncPack { - func: Function; - context: any; - constructor(func: Function, context: any); +declare module es { + class GlobalManager { + static globalManagers: GlobalManager[]; + private _enabled; + enabled: boolean; + setEnabled(isEnabled: boolean): void; + onEnabled(): void; + onDisabled(): void; + update(): void; + static registerGlobalManager(manager: GlobalManager): void; + static unregisterGlobalManager(manager: GlobalManager): void; + static getGlobalManager(type: any): T; + } } -declare class GlobalManager { - static globalManagers: GlobalManager[]; - private _enabled; - enabled: boolean; - setEnabled(isEnabled: boolean): void; - onEnabled(): void; - onDisabled(): void; - update(): void; - static registerGlobalManager(manager: GlobalManager): void; - static unregisterGlobalManager(manager: GlobalManager): void; - static getGlobalManager(type: any): T; -} -declare class TouchState { - x: number; - y: number; - touchPoint: number; - touchDown: boolean; - readonly position: Vector2; - reset(): void; -} -declare class Input { - private static _init; - private static _stage; - private static _previousTouchState; - private static _gameTouchs; - private static _resolutionOffset; - private static _resolutionScale; - private static _touchIndex; - private static _totalTouchCount; - static readonly touchPosition: Vector2; - static maxSupportedTouch: number; - static readonly resolutionScale: Vector2; - static readonly totalTouchCount: number; - static readonly gameTouchs: TouchState[]; - static readonly touchPositionDelta: Vector2; - static initialize(stage: egret.Stage): void; - private static initTouchCache; - private static touchBegin; - private static touchMove; - private static touchEnd; - private static setpreviousTouchState; - static scaledPosition(position: Vector2): Vector2; +declare module es { + class TouchState { + x: number; + y: number; + touchPoint: number; + touchDown: boolean; + readonly position: Vector2; + reset(): void; + } + class Input { + private static _init; + private static _stage; + private static _previousTouchState; + private static _gameTouchs; + private static _resolutionOffset; + private static _resolutionScale; + private static _touchIndex; + private static _totalTouchCount; + static readonly touchPosition: Vector2; + static maxSupportedTouch: number; + static readonly resolutionScale: Vector2; + static readonly totalTouchCount: number; + static readonly gameTouchs: TouchState[]; + static readonly touchPositionDelta: Vector2; + static initialize(stage: egret.Stage): void; + private static initTouchCache; + private static touchBegin; + private static touchMove; + private static touchEnd; + private static setpreviousTouchState; + static scaledPosition(position: Vector2): Vector2; + } } declare class KeyboardUtils { static TYPE_KEY_DOWN: number; @@ -1241,13 +1505,15 @@ declare class KeyboardUtils { private static keyCodeToString; static destroy(): void; } -declare class ListPool { - private static readonly _objectQueue; - static warmCache(cacheCount: number): void; - static trimCache(cacheCount: any): void; - static clearCache(): void; - static obtain(): Array; - static free(obj: Array): void; +declare module es { + class ListPool { + private static readonly _objectQueue; + static warmCache(cacheCount: number): void; + static trimCache(cacheCount: any): void; + static clearCache(): void; + static obtain(): T[]; + static free(obj: Array): void; + } } declare const THREAD_ID: string; declare const setItem: any; @@ -1260,12 +1526,14 @@ declare class LockUtils { constructor(key: any); lock(): Promise<{}>; } -declare class Pair { - first: T; - second: T; - constructor(first: T, second: T); - clear(): void; - equals(other: Pair): boolean; +declare module es { + class Pair { + first: T; + second: T; + constructor(first: T, second: T); + clear(): void; + equals(other: Pair): boolean; + } } declare class RandomUtils { static randrange(start: number, stop: number, step?: number): number; @@ -1278,53 +1546,61 @@ declare class RandomUtils { static random(): number; static boolean(chance?: number): boolean; } -declare class RectangleExt { - static union(first: Rectangle, point: Vector2): Rectangle; +declare module es { + class RectangleExt { + static union(first: Rectangle, point: Vector2): Rectangle; + } } -declare class Triangulator { - triangleIndices: number[]; - private _triPrev; - private _triNext; - triangulate(points: Vector2[], arePointsCCW?: boolean): void; - private initialize; - static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean; +declare module es { + class Triangulator { + triangleIndices: number[]; + private _triPrev; + private _triNext; + triangulate(points: Vector2[], arePointsCCW?: boolean): void; + private initialize; + static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean; + } } -declare class Vector2Ext { - static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean; - static cross(u: Vector2, v: Vector2): number; - static perpendicular(first: Vector2, second: Vector2): Vector2; - static normalize(vec: Vector2): Vector2; - static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void; - static transformR(position: Vector2, matrix: Matrix2D): Vector2; - static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void; - static round(vec: Vector2): Vector2; +declare module es { + class Vector2Ext { + static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean; + static cross(u: Vector2, v: Vector2): number; + static perpendicular(first: Vector2, second: Vector2): Vector2; + static normalize(vec: Vector2): Vector2; + static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void; + static transformR(position: Vector2, matrix: Matrix2D): Vector2; + static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void; + static round(vec: Vector2): Vector2; + } } declare class WebGLUtils { static getContext(): CanvasRenderingContext2D; } -declare class Layout { - clientArea: Rectangle; - safeArea: Rectangle; - constructor(); - place(size: Vector2, horizontalMargin: number, verticalMargine: number, alignment: Alignment): Rectangle; -} -declare enum Alignment { - none = 0, - left = 1, - right = 2, - horizontalCenter = 4, - top = 8, - bottom = 16, - verticalCenter = 32, - topLeft = 9, - topRight = 10, - topCenter = 12, - bottomLeft = 17, - bottomRight = 18, - bottomCenter = 20, - centerLeft = 33, - centerRight = 34, - center = 36 +declare module es { + class Layout { + clientArea: Rectangle; + safeArea: Rectangle; + constructor(); + place(size: Vector2, horizontalMargin: number, verticalMargine: number, alignment: Alignment): Rectangle; + } + enum Alignment { + none = 0, + left = 1, + right = 2, + horizontalCenter = 4, + top = 8, + bottom = 16, + verticalCenter = 32, + topLeft = 9, + topRight = 10, + topCenter = 12, + bottomLeft = 17, + bottomRight = 18, + bottomCenter = 20, + centerLeft = 33, + centerRight = 34, + center = 36 + } } declare namespace stopwatch { class Stopwatch { @@ -1365,72 +1641,74 @@ declare namespace stopwatch { readonly duration: number; } } -declare class TimeRuler { - static readonly maxBars: number; - static readonly maxSamples: number; - static readonly maxNestCall: number; - static readonly barHeight: number; - static readonly maxSampleFrames: number; - static readonly logSnapDuration: number; - static readonly barPadding: number; - static readonly autoAdjustDelay: number; - static Instance: TimeRuler; - private _frameKey; - private _logKey; - private _logs; - private sampleFrames; - targetSampleFrames: number; - width: number; - enabled: true; - private _position; - private _prevLog; - private _curLog; - private frameCount; - private markers; - private stopwacth; - private _markerNameToIdMap; - private _updateCount; - showLog: boolean; - private _frameAdjust; - constructor(); - private onGraphicsDeviceReset; - startFrame(): void; - beginMark(markerName: string, color: number, barIndex?: number): void; - endMark(markerName: string, barIndex?: number): void; - getAverageTime(barIndex: number, markerName: string): number; - resetLog(): void; - render(position?: Vector2, width?: number): void; -} -declare class FrameLog { - bars: MarkerCollection[]; - constructor(); -} -declare class MarkerCollection { - markers: Marker[]; - markCount: number; - markerNests: number[]; - nestCount: number; - constructor(); -} -declare class Marker { - markerId: number; - beginTime: number; - endTime: number; - color: number; -} -declare class MarkerInfo { - name: string; - logs: MarkerLog[]; - constructor(name: any); -} -declare class MarkerLog { - snapMin: number; - snapMax: number; - snapAvg: number; - min: number; - max: number; - avg: number; - samples: number; - color: number; - initialized: boolean; +declare module es { + class TimeRuler { + static readonly maxBars: number; + static readonly maxSamples: number; + static readonly maxNestCall: number; + static readonly barHeight: number; + static readonly maxSampleFrames: number; + static readonly logSnapDuration: number; + static readonly barPadding: number; + static readonly autoAdjustDelay: number; + static Instance: TimeRuler; + private _frameKey; + private _logKey; + private _logs; + private sampleFrames; + targetSampleFrames: number; + width: number; + enabled: true; + private _position; + private _prevLog; + private _curLog; + private frameCount; + private markers; + private stopwacth; + private _markerNameToIdMap; + private _updateCount; + showLog: boolean; + private _frameAdjust; + constructor(); + private onGraphicsDeviceReset; + startFrame(): void; + beginMark(markerName: string, color: number, barIndex?: number): void; + endMark(markerName: string, barIndex?: number): void; + getAverageTime(barIndex: number, markerName: string): number; + resetLog(): void; + render(position?: Vector2, width?: number): void; + } + class FrameLog { + bars: MarkerCollection[]; + constructor(); + } + class MarkerCollection { + markers: Marker[]; + markCount: number; + markerNests: number[]; + nestCount: number; + constructor(); + } + class Marker { + markerId: number; + beginTime: number; + endTime: number; + color: number; + } + class MarkerInfo { + name: string; + logs: MarkerLog[]; + constructor(name: any); + } + class MarkerLog { + snapMin: number; + snapMax: number; + snapAvg: number; + min: number; + max: number; + avg: number; + samples: number; + color: number; + initialized: boolean; + } } diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index c729622d..c83321cc 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -273,2772 +273,3282 @@ Array.prototype.sum = function (selector) { } return sum(this, selector); }; -var PriorityQueueNode = (function () { - function PriorityQueueNode() { - this.priority = 0; - this.insertionIndex = 0; - this.queueIndex = 0; - } - return PriorityQueueNode; -}()); -var AStarPathfinder = (function () { - function AStarPathfinder() { - } - AStarPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new AStarNode(start), 0); - costSoFar.set(start, 0); - var _loop_2 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priority = newCost + graph.heuristic(next, goal); - frontier.enqueue(new AStarNode(next), priority); - cameFrom.set(next, current.data); +var es; +(function (es) { + var PriorityQueueNode = (function () { + function PriorityQueueNode() { + this.priority = 0; + this.insertionIndex = 0; + this.queueIndex = 0; + } + return PriorityQueueNode; + }()); + es.PriorityQueueNode = PriorityQueueNode; +})(es || (es = {})); +var es; +(function (es) { + var AStarPathfinder = (function () { + function AStarPathfinder() { + } + AStarPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new es.PriorityQueue(1000); + frontier.enqueue(new AStarNode(start), 0); + costSoFar.set(start, 0); + var _loop_2 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; } - }); + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priority = newCost + graph.heuristic(next, goal); + frontier.enqueue(new AStarNode(next), priority); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_1 = _loop_2(); + if (state_1 === "break") + break; + } + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; }; - while (frontier.count > 0) { - var state_1 = _loop_2(); - if (state_1 === "break") - break; + AStarPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + AStarPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + AStarPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return AStarPathfinder; + }()); + es.AStarPathfinder = AStarPathfinder; + var AStarNode = (function (_super) { + __extends(AStarNode, _super); + function AStarNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - AStarPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; + return AStarNode; + }(es.PriorityQueueNode)); + es.AStarNode = AStarNode; +})(es || (es = {})); +var es; +(function (es) { + var AstarGridGraph = (function () { + function AstarGridGraph(width, height) { + this.dirs = [ + new es.Vector2(1, 0), + new es.Vector2(0, -1), + new es.Vector2(-1, 0), + new es.Vector2(0, 1) + ]; + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; } - return false; - }; - AStarPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; + AstarGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + AstarGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + AstarGridGraph.prototype.search = function (start, goal) { + return es.AStarPathfinder.search(this, start, goal); + }; + AstarGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this.dirs.forEach(function (dir) { + var next = new es.Vector2(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + AstarGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + AstarGridGraph.prototype.heuristic = function (node, goal) { + return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); + }; + return AstarGridGraph; + }()); + es.AstarGridGraph = AstarGridGraph; +})(es || (es = {})); +var es; +(function (es) { + var PriorityQueue = (function () { + function PriorityQueue(maxNodes) { + this._numNodes = 0; + this._nodes = new Array(maxNodes + 1); + this._numNodesEverEnqueued = 0; } - return null; - }; - AStarPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return AStarPathfinder; -}()); -var AStarNode = (function (_super) { - __extends(AStarNode, _super); - function AStarNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return AStarNode; -}(PriorityQueueNode)); -var AstarGridGraph = (function () { - function AstarGridGraph(width, height) { - this.dirs = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - } - AstarGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - }; - AstarGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - AstarGridGraph.prototype.search = function (start, goal) { - return AStarPathfinder.search(this, start, goal); - }; - AstarGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this.dirs.forEach(function (dir) { - var next = new Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); + PriorityQueue.prototype.clear = function () { + this._nodes.splice(1, this._numNodes); + this._numNodes = 0; + }; + Object.defineProperty(PriorityQueue.prototype, "count", { + get: function () { + return this._numNodes; + }, + enumerable: true, + configurable: true }); - return this._neighbors; - }; - AstarGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; - }; - AstarGridGraph.prototype.heuristic = function (node, goal) { - return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); - }; - return AstarGridGraph; -}()); -var PriorityQueue = (function () { - function PriorityQueue(maxNodes) { - this._numNodes = 0; - this._nodes = new Array(maxNodes + 1); - this._numNodesEverEnqueued = 0; - } - PriorityQueue.prototype.clear = function () { - this._nodes.splice(1, this._numNodes); - this._numNodes = 0; - }; - Object.defineProperty(PriorityQueue.prototype, "count", { - get: function () { - return this._numNodes; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(PriorityQueue.prototype, "maxSize", { - get: function () { - return this._nodes.length - 1; - }, - enumerable: true, - configurable: true - }); - PriorityQueue.prototype.contains = function (node) { - if (!node) { - console.error("node cannot be null"); - return false; - } - if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length) { - console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); - return false; - } - return (this._nodes[node.queueIndex] == node); - }; - PriorityQueue.prototype.enqueue = function (node, priority) { - node.priority = priority; - this._numNodes++; - this._nodes[this._numNodes] = node; - node.queueIndex = this._numNodes; - node.insertionIndex = this._numNodesEverEnqueued++; - this.cascadeUp(this._nodes[this._numNodes]); - }; - PriorityQueue.prototype.dequeue = function () { - var returnMe = this._nodes[1]; - this.remove(returnMe); - return returnMe; - }; - PriorityQueue.prototype.remove = function (node) { - if (node.queueIndex == this._numNodes) { - this._nodes[this._numNodes] = null; + Object.defineProperty(PriorityQueue.prototype, "maxSize", { + get: function () { + return this._nodes.length - 1; + }, + enumerable: true, + configurable: true + }); + PriorityQueue.prototype.contains = function (node) { + if (!node) { + console.error("node cannot be null"); + return false; + } + if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length) { + console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); + return false; + } + return (this._nodes[node.queueIndex] == node); + }; + PriorityQueue.prototype.enqueue = function (node, priority) { + node.priority = priority; + this._numNodes++; + this._nodes[this._numNodes] = node; + node.queueIndex = this._numNodes; + node.insertionIndex = this._numNodesEverEnqueued++; + this.cascadeUp(this._nodes[this._numNodes]); + }; + PriorityQueue.prototype.dequeue = function () { + var returnMe = this._nodes[1]; + this.remove(returnMe); + return returnMe; + }; + PriorityQueue.prototype.remove = function (node) { + if (node.queueIndex == this._numNodes) { + this._nodes[this._numNodes] = null; + this._numNodes--; + return; + } + var formerLastNode = this._nodes[this._numNodes]; + this.swap(node, formerLastNode); + delete this._nodes[this._numNodes]; this._numNodes--; - return; - } - var formerLastNode = this._nodes[this._numNodes]; - this.swap(node, formerLastNode); - delete this._nodes[this._numNodes]; - this._numNodes--; - this.onNodeUpdated(formerLastNode); - }; - PriorityQueue.prototype.isValidQueue = function () { - for (var i = 1; i < this._nodes.length; i++) { - if (this._nodes[i]) { - var childLeftIndex = 2 * i; - if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && - this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) - return false; + this.onNodeUpdated(formerLastNode); + }; + PriorityQueue.prototype.isValidQueue = function () { + for (var i = 1; i < this._nodes.length; i++) { + if (this._nodes[i]) { + var childLeftIndex = 2 * i; + if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && + this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) + return false; + var childRightIndex = childLeftIndex + 1; + if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && + this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) + return false; + } + } + return true; + }; + PriorityQueue.prototype.onNodeUpdated = function (node) { + var parentIndex = Math.floor(node.queueIndex / 2); + var parentNode = this._nodes[parentIndex]; + if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { + this.cascadeUp(node); + } + else { + this.cascadeDown(node); + } + }; + PriorityQueue.prototype.cascadeDown = function (node) { + var newParent; + var finalQueueIndex = node.queueIndex; + while (true) { + newParent = node; + var childLeftIndex = 2 * finalQueueIndex; + if (childLeftIndex > this._numNodes) { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } + var childLeft = this._nodes[childLeftIndex]; + if (this.hasHigherPriority(childLeft, newParent)) { + newParent = childLeft; + } var childRightIndex = childLeftIndex + 1; - if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && - this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) - return false; - } - } - return true; - }; - PriorityQueue.prototype.onNodeUpdated = function (node) { - var parentIndex = Math.floor(node.queueIndex / 2); - var parentNode = this._nodes[parentIndex]; - if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { - this.cascadeUp(node); - } - else { - this.cascadeDown(node); - } - }; - PriorityQueue.prototype.cascadeDown = function (node) { - var newParent; - var finalQueueIndex = node.queueIndex; - while (true) { - newParent = node; - var childLeftIndex = 2 * finalQueueIndex; - if (childLeftIndex > this._numNodes) { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - var childLeft = this._nodes[childLeftIndex]; - if (this.hasHigherPriority(childLeft, newParent)) { - newParent = childLeft; - } - var childRightIndex = childLeftIndex + 1; - if (childRightIndex <= this._numNodes) { - var childRight = this._nodes[childRightIndex]; - if (this.hasHigherPriority(childRight, newParent)) { - newParent = childRight; + if (childRightIndex <= this._numNodes) { + var childRight = this._nodes[childRightIndex]; + if (this.hasHigherPriority(childRight, newParent)) { + newParent = childRight; + } + } + if (newParent != node) { + this._nodes[finalQueueIndex] = newParent; + var temp = newParent.queueIndex; + newParent.queueIndex = finalQueueIndex; + finalQueueIndex = temp; + } + else { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; } } - if (newParent != node) { - this._nodes[finalQueueIndex] = newParent; - var temp = newParent.queueIndex; - newParent.queueIndex = finalQueueIndex; - finalQueueIndex = temp; - } - else { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - } - }; - PriorityQueue.prototype.cascadeUp = function (node) { - var parent = Math.floor(node.queueIndex / 2); - while (parent >= 1) { - var parentNode = this._nodes[parent]; - if (this.hasHigherPriority(parentNode, node)) - break; - this.swap(node, parentNode); - parent = Math.floor(node.queueIndex / 2); - } - }; - PriorityQueue.prototype.swap = function (node1, node2) { - this._nodes[node1.queueIndex] = node2; - this._nodes[node2.queueIndex] = node1; - var temp = node1.queueIndex; - node1.queueIndex = node2.queueIndex; - node2.queueIndex = temp; - }; - PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { - return (higher.priority < lower.priority || - (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); - }; - return PriorityQueue; -}()); -var BreadthFirstPathfinder = (function () { - function BreadthFirstPathfinder() { - } - BreadthFirstPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var frontier = []; - frontier.unshift(start); - var cameFrom = new Map(); - cameFrom.set(start, start); - var _loop_3 = function () { - var current = frontier.shift(); - if (JSON.stringify(current) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current).forEach(function (next) { - if (!_this.hasKey(cameFrom, next)) { - frontier.unshift(next); - cameFrom.set(next, current); - } - }); }; - while (frontier.length > 0) { - var state_2 = _loop_3(); - if (state_2 === "break") - break; - } - return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null; - }; - BreadthFirstPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - return false; - }; - return BreadthFirstPathfinder; -}()); -var UnweightedGraph = (function () { - function UnweightedGraph() { - this.edges = new Map(); - } - UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { - this.edges.set(node, edges); - return this; - }; - UnweightedGraph.prototype.getNeighbors = function (node) { - return this.edges.get(node); - }; - return UnweightedGraph; -}()); -var Vector2 = (function () { - function Vector2(x, y) { - this.x = 0; - this.y = 0; - this.x = x ? x : 0; - this.y = y ? y : this.x; - } - Object.defineProperty(Vector2, "zero", { - get: function () { - return Vector2.zeroVector2; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "one", { - get: function () { - return Vector2.unitVector2; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "unitX", { - get: function () { - return Vector2.unitXVector; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "unitY", { - get: function () { - return Vector2.unitYVector; - }, - enumerable: true, - configurable: true - }); - Vector2.add = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x + value2.x; - result.y = value1.y + value2.y; - return result; - }; - Vector2.divide = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x / value2.x; - result.y = value1.y / value2.y; - return result; - }; - Vector2.multiply = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - }; - Vector2.subtract = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - }; - Vector2.prototype.normalize = function () { - var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); - this.x *= val; - this.y *= val; - }; - Vector2.prototype.length = function () { - return Math.sqrt((this.x * this.x) + (this.y * this.y)); - }; - Vector2.prototype.round = function () { - return new Vector2(Math.round(this.x), Math.round(this.y)); - }; - Vector2.normalize = function (value) { - var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); - value.x *= val; - value.y *= val; - return value; - }; - Vector2.dot = function (value1, value2) { - return (value1.x * value2.x) + (value1.y * value2.y); - }; - Vector2.distanceSquared = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return (v1 * v1) + (v2 * v2); - }; - Vector2.clamp = function (value1, min, max) { - return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y)); - }; - Vector2.lerp = function (value1, value2, amount) { - return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount)); - }; - Vector2.transform = function (position, matrix) { - return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); - }; - Vector2.distance = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return Math.sqrt((v1 * v1) + (v2 * v2)); - }; - Vector2.negate = function (value) { - var result = new Vector2(); - result.x = -value.x; - result.y = -value.y; - return result; - }; - Vector2.unitYVector = new Vector2(0, 1); - Vector2.unitXVector = new Vector2(1, 0); - Vector2.unitVector2 = new Vector2(1, 1); - Vector2.zeroVector2 = new Vector2(0, 0); - return Vector2; -}()); -var UnweightedGridGraph = (function () { - function UnweightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } - this.walls = []; - this._neighbors = new Array(4); - this._width = width; - this._hegiht = height; - this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; - } - UnweightedGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; - }; - UnweightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - UnweightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - UnweightedGridGraph.prototype.search = function (start, goal) { - return BreadthFirstPathfinder.search(this, start, goal); - }; - UnweightedGridGraph.CARDINAL_DIRS = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, -1) - ]; - UnweightedGridGraph.COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; - return UnweightedGridGraph; -}()); -var WeightedGridGraph = (function () { - function WeightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; - } - WeightedGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - }; - WeightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - WeightedGridGraph.prototype.search = function (start, goal) { - return WeightedPathfinder.search(this, start, goal); - }; - WeightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - WeightedGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; - }; - WeightedGridGraph.CARDINAL_DIRS = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; - WeightedGridGraph.COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; - return WeightedGridGraph; -}()); -var WeightedNode = (function (_super) { - __extends(WeightedNode, _super); - function WeightedNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return WeightedNode; -}(PriorityQueueNode)); -var WeightedPathfinder = (function () { - function WeightedPathfinder() { - } - WeightedPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new WeightedNode(start), 0); - costSoFar.set(start, 0); - var _loop_4 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; + PriorityQueue.prototype.cascadeUp = function (node) { + var parent = Math.floor(node.queueIndex / 2); + while (parent >= 1) { + var parentNode = this._nodes[parent]; + if (this.hasHigherPriority(parentNode, node)) + break; + this.swap(node, parentNode); + parent = Math.floor(node.queueIndex / 2); } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priprity = newCost; - frontier.enqueue(new WeightedNode(next), priprity); - cameFrom.set(next, current.data); - } - }); }; - while (frontier.count > 0) { - var state_3 = _loop_4(); - if (state_3 === "break") - break; + PriorityQueue.prototype.swap = function (node1, node2) { + this._nodes[node1.queueIndex] = node2; + this._nodes[node2.queueIndex] = node1; + var temp = node1.queueIndex; + node1.queueIndex = node2.queueIndex; + node2.queueIndex = temp; + }; + PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { + return (higher.priority < lower.priority || + (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); + }; + return PriorityQueue; + }()); + es.PriorityQueue = PriorityQueue; +})(es || (es = {})); +var es; +(function (es) { + var BreadthFirstPathfinder = (function () { + function BreadthFirstPathfinder() { } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - WeightedPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - return false; - }; - WeightedPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; - } - return null; - }; - WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return WeightedPathfinder; -}()); -var Debug = (function () { - function Debug() { - } - Debug.drawHollowRect = function (rectanle, color, duration) { - if (duration === void 0) { duration = 0; } - this._debugDrawItems.push(new DebugDrawItem(rectanle, color, duration)); - }; - Debug.render = function () { - if (this._debugDrawItems.length > 0) { - var debugShape = new egret.Shape(); - if (SceneManager.scene) { - SceneManager.scene.addChild(debugShape); + BreadthFirstPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var frontier = []; + frontier.unshift(start); + var cameFrom = new Map(); + cameFrom.set(start, start); + var _loop_3 = function () { + var current = frontier.shift(); + if (JSON.stringify(current) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current).forEach(function (next) { + if (!_this.hasKey(cameFrom, next)) { + frontier.unshift(next); + cameFrom.set(next, current); + } + }); + }; + while (frontier.length > 0) { + var state_2 = _loop_3(); + if (state_2 === "break") + break; } - for (var i = this._debugDrawItems.length - 1; i >= 0; i--) { - var item = this._debugDrawItems[i]; - if (item.draw(debugShape)) - this._debugDrawItems.removeAt(i); + return foundPath ? es.AStarPathfinder.recontructPath(cameFrom, start, goal) : null; + }; + BreadthFirstPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; } + return false; + }; + return BreadthFirstPathfinder; + }()); + es.BreadthFirstPathfinder = BreadthFirstPathfinder; +})(es || (es = {})); +var es; +(function (es) { + var UnweightedGraph = (function () { + function UnweightedGraph() { + this.edges = new Map(); } - }; - Debug._debugDrawItems = []; - return Debug; -}()); -var DebugDefaults = (function () { - function DebugDefaults() { - } - DebugDefaults.verletParticle = 0xDC345E; - DebugDefaults.verletConstraintEdge = 0x433E36; - return DebugDefaults; -}()); -var DebugDrawType; -(function (DebugDrawType) { - DebugDrawType[DebugDrawType["line"] = 0] = "line"; - DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle"; - DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel"; - DebugDrawType[DebugDrawType["text"] = 3] = "text"; -})(DebugDrawType || (DebugDrawType = {})); -var DebugDrawItem = (function () { - function DebugDrawItem(rectangle, color, duration) { - this.rectangle = rectangle; - this.color = color; - this.duration = duration; - this.drawType = DebugDrawType.hollowRectangle; - } - DebugDrawItem.prototype.draw = function (shape) { - switch (this.drawType) { - case DebugDrawType.line: - DrawUtils.drawLine(shape, this.start, this.end, this.color); - break; - case DebugDrawType.hollowRectangle: - DrawUtils.drawHollowRect(shape, this.rectangle, this.color); - break; - case DebugDrawType.pixel: - DrawUtils.drawPixel(shape, new Vector2(this.x, this.y), this.color, this.size); - break; - case DebugDrawType.text: - break; + UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { + this.edges.set(node, edges); + return this; + }; + UnweightedGraph.prototype.getNeighbors = function (node) { + return this.edges.get(node); + }; + return UnweightedGraph; + }()); + es.UnweightedGraph = UnweightedGraph; +})(es || (es = {})); +var es; +(function (es) { + var Vector2 = (function () { + function Vector2(x, y) { + this.x = 0; + this.y = 0; + this.x = x ? x : 0; + this.y = y ? y : this.x; } - this.duration -= Time.deltaTime; - return this.duration < 0; - }; - return DebugDrawItem; -}()); -var Component = (function (_super) { - __extends(Component, _super); - function Component() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._enabled = true; - _this.updateInterval = 1; - _this._updateOrder = 0; - return _this; - } - Object.defineProperty(Component.prototype, "enabled", { - get: function () { - return this.entity ? this.entity.enabled && this._enabled : this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Component.prototype, "localPosition", { - get: function () { - return new Vector2(this.entity.x + this.x, this.entity.y + this.y); - }, - enumerable: true, - configurable: true - }); - Component.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); + Object.defineProperty(Vector2, "zero", { + get: function () { + return Vector2.zeroVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "one", { + get: function () { + return Vector2.unitVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitX", { + get: function () { + return Vector2.unitXVector; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitY", { + get: function () { + return Vector2.unitYVector; + }, + enumerable: true, + configurable: true + }); + Vector2.add = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x + value2.x; + result.y = value1.y + value2.y; + return result; + }; + Vector2.divide = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x / value2.x; + result.y = value1.y / value2.y; + return result; + }; + Vector2.multiply = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x * value2.x; + result.y = value1.y * value2.y; + return result; + }; + Vector2.subtract = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x - value2.x; + result.y = value1.y - value2.y; + return result; + }; + Vector2.prototype.normalize = function () { + var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); + this.x *= val; + this.y *= val; + }; + Vector2.prototype.length = function () { + return Math.sqrt((this.x * this.x) + (this.y * this.y)); + }; + Vector2.prototype.round = function () { + return new Vector2(Math.round(this.x), Math.round(this.y)); + }; + Vector2.normalize = function (value) { + var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); + value.x *= val; + value.y *= val; + return value; + }; + Vector2.dot = function (value1, value2) { + return (value1.x * value2.x) + (value1.y * value2.y); + }; + Vector2.distanceSquared = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return (v1 * v1) + (v2 * v2); + }; + Vector2.clamp = function (value1, min, max) { + return new Vector2(es.MathHelper.clamp(value1.x, min.x, max.x), es.MathHelper.clamp(value1.y, min.y, max.y)); + }; + Vector2.lerp = function (value1, value2, amount) { + return new Vector2(es.MathHelper.lerp(value1.x, value2.x, amount), es.MathHelper.lerp(value1.y, value2.y, amount)); + }; + Vector2.transform = function (position, matrix) { + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + }; + Vector2.distance = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return Math.sqrt((v1 * v1) + (v2 * v2)); + }; + Vector2.negate = function (value) { + var result = new Vector2(); + result.x = -value.x; + result.y = -value.y; + return result; + }; + Vector2.unitYVector = new Vector2(0, 1); + Vector2.unitXVector = new Vector2(1, 0); + Vector2.unitVector2 = new Vector2(1, 1); + Vector2.zeroVector2 = new Vector2(0, 0); + return Vector2; + }()); + es.Vector2 = Vector2; +})(es || (es = {})); +var es; +(function (es) { + var UnweightedGridGraph = (function () { + function UnweightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this._neighbors = new Array(4); + this._width = width; + this._hegiht = height; + this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; + } + UnweightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; + }; + UnweightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + UnweightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new es.Vector2(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + UnweightedGridGraph.prototype.search = function (start, goal) { + return es.BreadthFirstPathfinder.search(this, start, goal); + }; + UnweightedGridGraph.CARDINAL_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(0, -1), + new es.Vector2(-1, 0), + new es.Vector2(0, -1) + ]; + UnweightedGridGraph.COMPASS_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(1, -1), + new es.Vector2(0, -1), + new es.Vector2(-1, -1), + new es.Vector2(-1, 0), + new es.Vector2(-1, 1), + new es.Vector2(0, 1), + new es.Vector2(1, 1), + ]; + return UnweightedGridGraph; + }()); + es.UnweightedGridGraph = UnweightedGridGraph; +})(es || (es = {})); +var es; +(function (es) { + var WeightedGridGraph = (function () { + function WeightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; + this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; + } + WeightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + WeightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + WeightedGridGraph.prototype.search = function (start, goal) { + return es.WeightedPathfinder.search(this, start, goal); + }; + WeightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new es.Vector2(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + WeightedGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + WeightedGridGraph.CARDINAL_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(0, -1), + new es.Vector2(-1, 0), + new es.Vector2(0, 1) + ]; + WeightedGridGraph.COMPASS_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(1, -1), + new es.Vector2(0, -1), + new es.Vector2(-1, -1), + new es.Vector2(-1, 0), + new es.Vector2(-1, 1), + new es.Vector2(0, 1), + new es.Vector2(1, 1), + ]; + return WeightedGridGraph; + }()); + es.WeightedGridGraph = WeightedGridGraph; +})(es || (es = {})); +var es; +(function (es) { + var WeightedNode = (function (_super) { + __extends(WeightedNode, _super); + function WeightedNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return WeightedNode; + }(es.PriorityQueueNode)); + es.WeightedNode = WeightedNode; + var WeightedPathfinder = (function () { + function WeightedPathfinder() { + } + WeightedPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new es.PriorityQueue(1000); + frontier.enqueue(new WeightedNode(start), 0); + costSoFar.set(start, 0); + var _loop_4 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priprity = newCost; + frontier.enqueue(new WeightedNode(next), priprity); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_3 = _loop_4(); + if (state_3 === "break") + break; } - else { - this.onDisabled(); + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; + }; + WeightedPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; } + return false; + }; + WeightedPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return WeightedPathfinder; + }()); + es.WeightedPathfinder = WeightedPathfinder; +})(es || (es = {})); +var es; +(function (es) { + var Debug = (function () { + function Debug() { } - return this; - }; - Object.defineProperty(Component.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (value) { - this.setUpdateOrder(value); - }, - enumerable: true, - configurable: true - }); - Component.prototype.setUpdateOrder = function (updateOrder) { - if (this._updateOrder != updateOrder) { - this._updateOrder = updateOrder; + Debug.drawHollowRect = function (rectanle, color, duration) { + if (duration === void 0) { duration = 0; } + this._debugDrawItems.push(new es.DebugDrawItem(rectanle, color, duration)); + }; + Debug.render = function () { + if (this._debugDrawItems.length > 0) { + var debugShape = new egret.Shape(); + if (es.SceneManager.scene) { + es.SceneManager.scene.addChild(debugShape); + } + for (var i = this._debugDrawItems.length - 1; i >= 0; i--) { + var item = this._debugDrawItems[i]; + if (item.draw(debugShape)) + this._debugDrawItems.removeAt(i); + } + } + }; + Debug._debugDrawItems = []; + return Debug; + }()); + es.Debug = Debug; +})(es || (es = {})); +var es; +(function (es) { + var DebugDefaults = (function () { + function DebugDefaults() { } - return this; - }; - Component.prototype.initialize = function () { - }; - Component.prototype.onAddedToEntity = function () { - }; - Component.prototype.onRemovedFromEntity = function () { - }; - Component.prototype.onEnabled = function () { - }; - Component.prototype.onDisabled = function () { - }; - Component.prototype.debugRender = function () { - }; - Component.prototype.update = function () { - }; - Component.prototype.onEntityTransformChanged = function (comp) { - }; - Component.prototype.registerComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false); - this.entity.scene.entityProcessors.onComponentAdded(this.entity); - }; - Component.prototype.deregisterComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)); - this.entity.scene.entityProcessors.onComponentRemoved(this.entity); - }; - return Component; -}(egret.DisplayObjectContainer)); -var CoreEvents; -(function (CoreEvents) { - CoreEvents[CoreEvents["SceneChanged"] = 0] = "SceneChanged"; -})(CoreEvents || (CoreEvents = {})); -var Entity = (function (_super) { - __extends(Entity, _super); - function Entity(name) { - var _this = _super.call(this) || this; - _this._updateOrder = 0; - _this._enabled = true; - _this._tag = 0; - _this.name = name; - _this.components = new ComponentList(_this); - _this.id = Entity._idGenerator++; - _this.componentBits = new BitSet(); - _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this); - return _this; - } - Object.defineProperty(Entity.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (value) { - this.$setX(value.x); - this.$setY(value.y); - this.onEntityTransformChanged(TransformComponent.position); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "scale", { - get: function () { - return new Vector2(this.scaleX, this.scaleY); - }, - set: function (value) { - this.$setScaleX(value.x); - this.$setScaleY(value.y); - this.onEntityTransformChanged(TransformComponent.scale); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "rotation", { - get: function () { - return this.$getRotation(); - }, - set: function (value) { - this.$setRotation(value); - this.onEntityTransformChanged(TransformComponent.rotation); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true - }); - Entity.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; + DebugDefaults.verletParticle = 0xDC345E; + DebugDefaults.verletConstraintEdge = 0x433E36; + return DebugDefaults; + }()); + es.DebugDefaults = DebugDefaults; +})(es || (es = {})); +var es; +(function (es) { + var DebugDrawType; + (function (DebugDrawType) { + DebugDrawType[DebugDrawType["line"] = 0] = "line"; + DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle"; + DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel"; + DebugDrawType[DebugDrawType["text"] = 3] = "text"; + })(DebugDrawType = es.DebugDrawType || (es.DebugDrawType = {})); + var DebugDrawItem = (function () { + function DebugDrawItem(rectangle, color, duration) { + this.rectangle = rectangle; + this.color = color; + this.duration = duration; + this.drawType = DebugDrawType.hollowRectangle; } - return this; - }; - Object.defineProperty(Entity.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (value) { - this.setTag(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "stage", { - get: function () { - if (!this.scene) - return null; - return this.scene.stage; - }, - enumerable: true, - configurable: true - }); - Entity.prototype.onAddToStage = function () { - this.onEntityTransformChanged(TransformComponent.position); - }; - Object.defineProperty(Entity.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (value) { - this.setUpdateOrder(value); - }, - enumerable: true, - configurable: true - }); - Entity.prototype.roundPosition = function () { - this.position = Vector2Ext.round(this.position); - }; - Entity.prototype.setUpdateOrder = function (updateOrder) { - if (this._updateOrder != updateOrder) { - this._updateOrder = updateOrder; - if (this.scene) { + DebugDrawItem.prototype.draw = function (shape) { + switch (this.drawType) { + case DebugDrawType.line: + es.DrawUtils.drawLine(shape, this.start, this.end, this.color); + break; + case DebugDrawType.hollowRectangle: + es.DrawUtils.drawHollowRect(shape, this.rectangle, this.color); + break; + case DebugDrawType.pixel: + es.DrawUtils.drawPixel(shape, new es.Vector2(this.x, this.y), this.color, this.size); + break; + case DebugDrawType.text: + break; + } + this.duration -= es.Time.deltaTime; + return this.duration < 0; + }; + return DebugDrawItem; + }()); + es.DebugDrawItem = DebugDrawItem; +})(es || (es = {})); +var es; +(function (es) { + var Component = (function () { + function Component() { + this.updateInterval = 1; + this._enabled = true; + this._updateOrder = 0; + } + Object.defineProperty(Component.prototype, "transform", { + get: function () { + return this.entity.transform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Component.prototype, "enabled", { + get: function () { + return this.entity ? this.entity.enabled && this._enabled : this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Component.prototype, "updateOrder", { + get: function () { + return this._updateOrder; + }, + set: function (value) { + this.setUpdateOrder(value); + }, + enumerable: true, + configurable: true + }); + Component.prototype.initialize = function () { + }; + Component.prototype.onAddedToEntity = function () { + }; + Component.prototype.onRemovedFromEntity = function () { + }; + Component.prototype.onEntityTransformChanged = function (comp) { + }; + Component.prototype.debugRender = function () { + }; + Component.prototype.onEnabled = function () { + }; + Component.prototype.onDisabled = function () { + }; + Component.prototype.update = function () { + }; + Component.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } } return this; - } - }; - Entity.prototype.setTag = function (tag) { - if (this._tag != tag) { - if (this.scene) { - this.scene.entities.removeFromTagList(this); - } - this._tag = tag; - if (this.scene) { - this.scene.entities.addToTagList(this); + }; + Component.prototype.setUpdateOrder = function (updateOrder) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; } + return this; + }; + Component.prototype.clone = function () { + var component = ObjectUtils.clone(this); + component.entity = null; + return component; + }; + return Component; + }()); + es.Component = Component; +})(es || (es = {})); +var es; +(function (es) { + var CoreEvents; + (function (CoreEvents) { + CoreEvents[CoreEvents["SceneChanged"] = 0] = "SceneChanged"; + })(CoreEvents = es.CoreEvents || (es.CoreEvents = {})); +})(es || (es = {})); +var es; +(function (es) { + var Entity = (function () { + function Entity(name) { + this.updateInterval = 1; + this._tag = 0; + this._enabled = true; + this._updateOrder = 0; + this.components = new es.ComponentList(this); + this.transform = new es.Transform(this); + this.name = name; + this.id = Entity._idGenerator++; + this.componentBits = new es.BitSet(); } - return this; - }; - Entity.prototype.attachToScene = function (newScene) { - this.scene = newScene; - newScene.entities.add(this); - this.components.registerAllComponents(); - for (var i = 0; i < this.numChildren; i++) { - this.getChildAt(i).entity.attachToScene(newScene); - } - }; - Entity.prototype.detachFromScene = function () { - this.scene.entities.remove(this); - this.components.deregisterAllComponents(); - for (var i = 0; i < this.numChildren; i++) - this.getChildAt(i).entity.detachFromScene(); - }; - Entity.prototype.addComponent = function (component) { - component.entity = this; - this.components.add(component); - this.addChild(component); - component.initialize(); - return component; - }; - Entity.prototype.hasComponent = function (type) { - return this.components.getComponent(type, false) != null; - }; - Entity.prototype.getOrCreateComponent = function (type) { - var comp = this.components.getComponent(type, true); - if (!comp) { - comp = this.addComponent(type); - } - return comp; - }; - Entity.prototype.getComponent = function (type) { - return this.components.getComponent(type, false); - }; - Entity.prototype.getComponents = function (typeName, componentList) { - return this.components.getComponents(typeName, componentList); - }; - Entity.prototype.onEntityTransformChanged = function (comp) { - this.components.onEntityTransformChanged(comp); - }; - Entity.prototype.removeComponentForType = function (type) { - var comp = this.getComponent(type); - if (comp) { - this.removeComponent(comp); - return true; - } - return false; - }; - Entity.prototype.removeComponent = function (component) { - this.components.remove(component); - }; - Entity.prototype.removeAllComponents = function () { - for (var i = 0; i < this.components.count; i++) { - this.removeComponent(this.components.buffer[i]); - } - }; - Entity.prototype.update = function () { - this.components.update(); - }; - Entity.prototype.onAddedToScene = function () { - }; - Entity.prototype.onRemovedFromScene = function () { - if (this._isDestoryed) - this.components.removeAllComponents(); - }; - Entity.prototype.destroy = function () { - this._isDestoryed = true; - this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); - this.scene.entities.remove(this); - this.removeChildren(); - if (this.parent) - this.parent.removeChild(this); - for (var i = this.numChildren - 1; i >= 0; i--) { - var child = this.getChildAt(i); - child.entity.destroy(); - } - }; - return Entity; -}(egret.DisplayObjectContainer)); -var TransformComponent; -(function (TransformComponent) { - TransformComponent[TransformComponent["rotation"] = 0] = "rotation"; - TransformComponent[TransformComponent["scale"] = 1] = "scale"; - TransformComponent[TransformComponent["position"] = 2] = "position"; -})(TransformComponent || (TransformComponent = {})); -var Scene = (function (_super) { - __extends(Scene, _super); - function Scene() { - var _this = _super.call(this) || this; - _this.enablePostProcessing = true; - _this._renderers = []; - _this._postProcessors = []; - _this.entityProcessors = new EntityProcessorList(); - _this.renderableComponents = new RenderableComponentList(); - _this.entities = new EntityList(_this); - _this.content = new ContentManager(); - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); - _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); - return _this; - } - Scene.prototype.createEntity = function (name) { - var entity = new Entity(name); - entity.position = new Vector2(0, 0); - return this.addEntity(entity); - }; - Scene.prototype.addEntity = function (entity) { - this.entities.add(entity); - entity.scene = this; - this.addChild(entity); - for (var i = 0; i < entity.numChildren; i++) - this.addEntity(entity.getChildAt(i).entity); - return entity; - }; - Scene.prototype.destroyAllEntities = function () { - for (var i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destroy(); - } - }; - Scene.prototype.findEntity = function (name) { - return this.entities.findEntity(name); - }; - Scene.prototype.addEntityProcessor = function (processor) { - processor.scene = this; - this.entityProcessors.add(processor); - return processor; - }; - Scene.prototype.removeEntityProcessor = function (processor) { - this.entityProcessors.remove(processor); - }; - Scene.prototype.getEntityProcessor = function () { - return this.entityProcessors.getProcessor(); - }; - Scene.prototype.addRenderer = function (renderer) { - this._renderers.push(renderer); - this._renderers.sort(); - renderer.onAddedToScene(this); - return renderer; - }; - Scene.prototype.getRenderer = function (type) { - for (var i = 0; i < this._renderers.length; i++) { - if (this._renderers[i] instanceof type) - return this._renderers[i]; - } - return null; - }; - Scene.prototype.removeRenderer = function (renderer) { - this._renderers.remove(renderer); - renderer.unload(); - }; - Scene.prototype.begin = function () { - if (SceneManager.sceneTransition) { - SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); - } - else { - SceneManager.stage.addChild(this); - } - if (this._renderers.length == 0) { - this.addRenderer(new DefaultRenderer()); - console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); - } - this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); - Physics.reset(); - if (this.entityProcessors) - this.entityProcessors.begin(); - this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); - this._didSceneBegin = true; - this.onStart(); - }; - Scene.prototype.end = function () { - this._didSceneBegin = false; - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].unload(); - } - for (var i = 0; i < this._postProcessors.length; i++) { - this._postProcessors[i].unload(); - } - this.entities.removeAllEntities(); - this.removeChildren(); - Physics.clear(); - this.camera = null; - this.content.dispose(); - if (this.entityProcessors) - this.entityProcessors.end(); - this.unload(); - if (this.parent) - this.parent.removeChild(this); - }; - Scene.prototype.onStart = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2]; - }); + Object.defineProperty(Entity.prototype, "tag", { + get: function () { + return this._tag; + }, + set: function (value) { + this.setTag(value); + }, + enumerable: true, + configurable: true }); - }; - Scene.prototype.onActive = function () { - }; - Scene.prototype.onDeactive = function () { - }; - Scene.prototype.unload = function () { }; - Scene.prototype.update = function () { - this.entities.updateLists(); - if (this.entityProcessors) - this.entityProcessors.update(); - this.entities.update(); - if (this.entityProcessors) - this.entityProcessors.lateUpdate(); - this.renderableComponents.updateList(); - }; - Scene.prototype.postRender = function () { - var enabledCounter = 0; - if (this.enablePostProcessing) { + Object.defineProperty(Entity.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "updateOrder", { + get: function () { + return this._updateOrder; + }, + set: function (value) { + this.setUpdateOrder(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "isDestroyed", { + get: function () { + return this._isDestroyed; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "parent", { + get: function () { + return this.transform.parent; + }, + set: function (value) { + this.transform.setParent(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "childCount", { + get: function () { + return this.transform.childCount; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "position", { + get: function () { + return this.transform.position; + }, + set: function (value) { + this.transform.setPosition(value.x, value.y); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "rotation", { + get: function () { + return this.transform.rotation; + }, + set: function (value) { + this.transform.setRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "scale", { + get: function () { + return this.transform.scale; + }, + set: function (value) { + this.transform.setScale(value); + }, + enumerable: true, + configurable: true + }); + Entity.prototype.onTransformChanged = function (comp) { + this.components.onEntityTransformChanged(comp); + }; + Entity.prototype.setTag = function (tag) { + if (this._tag != tag) { + if (this.scene) + this.scene.entities.removeFromTagList(this); + this._tag = tag; + if (this.scene) + this.scene.entities.addToTagList(this); + } + return this; + }; + Entity.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) + this.components.onEntityEnabled(); + else + this.components.onEntityDisabled(); + } + return this; + }; + Entity.prototype.setUpdateOrder = function (updateOrder) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; + if (this.scene) { + } + return this; + } + }; + Entity.prototype.destroy = function () { + this._isDestroyed = true; + this.scene.entities.remove(this); + this.transform.parent = null; + for (var i = this.transform.childCount - 1; i >= 0; i--) { + var child = this.transform.getChild(i); + child.entity.destroy(); + } + }; + Entity.prototype.detachFromScene = function () { + this.scene.entities.remove(this); + this.components.deregisterAllComponents(); + for (var i = 0; i < this.transform.childCount; i++) + this.transform.getChild(i).entity.detachFromScene(); + }; + Entity.prototype.attachToScene = function (newScene) { + this.scene = newScene; + newScene.entities.add(this); + this.components.registerAllComponents(); + for (var i = 0; i < this.transform.childCount; i++) { + this.transform.getChild(i).entity.attachToScene(newScene); + } + }; + Entity.prototype.clone = function (position) { + if (position === void 0) { position = new es.Vector2(); } + var entity = new Entity(this.name + "(clone)"); + entity.copyFrom(this); + entity.transform.position = position; + return entity; + }; + Entity.prototype.copyFrom = function (entity) { + this.tag = entity.tag; + this.updateInterval = entity.updateInterval; + this.updateOrder = entity.updateOrder; + this.enabled = entity.enabled; + this.transform.scale = entity.transform.scale; + this.transform.rotation = entity.transform.rotation; + for (var i = 0; i < entity.components.count; i++) + this.addComponent(entity.components.buffer[i].clone()); + for (var i = 0; i < entity.components._componentsToAdd.length; i++) + this.addComponent(entity.components._componentsToAdd[i].clone()); + for (var i = 0; i < entity.transform.childCount; i++) { + var child = entity.transform.getChild(i).entity; + var childClone = child.clone(); + childClone.transform.copyFrom(child.transform); + childClone.transform.parent = this.transform; + } + }; + Entity.prototype.onAddedToScene = function () { + }; + Entity.prototype.onRemovedFromScene = function () { + if (this._isDestroyed) + this.components.removeAllComponents(); + }; + Entity.prototype.update = function () { + this.components.update(); + }; + Entity.prototype.addComponent = function (component) { + component.entity = this; + this.components.add(component); + component.initialize(); + return component; + }; + Entity.prototype.getComponent = function (type) { + return this.components.getComponent(type, false); + }; + Entity.prototype.hasComponent = function (type) { + return this.components.getComponent(type, false) != null; + }; + Entity.prototype.getOrCreateComponent = function (type) { + var comp = this.components.getComponent(type, true); + if (!comp) { + comp = this.addComponent(type); + } + return comp; + }; + Entity.prototype.getComponents = function (typeName, componentList) { + return this.components.getComponents(typeName, componentList); + }; + Entity.prototype.removeComponent = function (component) { + this.components.remove(component); + }; + Entity.prototype.removeComponentForType = function (type) { + var comp = this.getComponent(type); + if (comp) { + this.removeComponent(comp); + return true; + } + return false; + }; + Entity.prototype.removeAllComponents = function () { + for (var i = 0; i < this.components.count; i++) { + this.removeComponent(this.components.buffer[i]); + } + }; + Entity.prototype.toString = function () { + return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]"; + }; + return Entity; + }()); + es.Entity = Entity; +})(es || (es = {})); +var es; +(function (es) { + var Scene = (function (_super) { + __extends(Scene, _super); + function Scene() { + var _this = _super.call(this) || this; + _this.enablePostProcessing = true; + _this._renderers = []; + _this._postProcessors = []; + _this.entities = new es.EntityList(_this); + _this.renderableComponents = new es.RenderableComponentList(); + _this.content = new es.ContentManager(); + _this.entityProcessors = new es.EntityProcessorList(); + _this.width = es.SceneManager.stage.stageWidth; + _this.height = es.SceneManager.stage.stageHeight; + _this.initialize(); + return _this; + } + Scene.createWithDefaultRenderer = function () { + var scene = new Scene(); + scene.addRenderer(new es.DefaultRenderer()); + return scene; + }; + Scene.prototype.initialize = function () { }; + Scene.prototype.onStart = function () { + return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { + return [2]; + }); }); + }; + Scene.prototype.unload = function () { }; + Scene.prototype.onActive = function () { }; + Scene.prototype.onDeactive = function () { }; + Scene.prototype.begin = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + if (es.SceneManager.sceneTransition) { + es.SceneManager.stage.addChildAt(this, es.SceneManager.stage.numChildren - 1); + } + else { + es.SceneManager.stage.addChild(this); + } + if (this._renderers.length == 0) { + this.addRenderer(new es.DefaultRenderer()); + console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); + } + this.camera = this.createEntity("camera").getOrCreateComponent(new es.Camera()); + es.Physics.reset(); + if (this.entityProcessors) + this.entityProcessors.begin(); + this.addEventListener(egret.Event.ACTIVATE, this.onActive, this); + this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + this._didSceneBegin = true; + this.onStart(); + return [2]; + }); + }); + }; + Scene.prototype.end = function () { + this._didSceneBegin = false; + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].unload(); + } for (var i = 0; i < this._postProcessors.length; i++) { - if (this._postProcessors[i].enable) { - var isEven = MathHelper.isEven(enabledCounter); - enabledCounter++; - this._postProcessors[i].process(); - } + this._postProcessors[i].unload(); } - } - }; - Scene.prototype.render = function () { - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].render(this); - } - }; - Scene.prototype.addPostProcessor = function (postProcessor) { - this._postProcessors.push(postProcessor); - this._postProcessors.sort(); - postProcessor.onAddedToScene(this); - if (this._didSceneBegin) { - postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); - } - return postProcessor; - }; - return Scene; -}(egret.DisplayObjectContainer)); -var SceneManager = (function () { - function SceneManager(stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - SceneManager._instnace = this; - SceneManager.emitter = new Emitter(); - SceneManager.content = new ContentManager(); - SceneManager.stage = stage; - SceneManager.initialize(stage); - SceneManager.timerRuler = new TimeRuler(); - } - Object.defineProperty(SceneManager, "Instance", { - get: function () { - return this._instnace; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SceneManager, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - if (!value) - throw new Error("场景不能为空"); - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - SceneManager.Instance.onSceneChanged(); + this.entities.removeAllEntities(); + this.removeChildren(); + this.camera = null; + this.content.dispose(); + if (this.entityProcessors) + this.entityProcessors.end(); + if (this.parent) + this.parent.removeChild(this); + this.unload(); + }; + Scene.prototype.update = function () { + this.entities.updateLists(); + if (this.entityProcessors) + this.entityProcessors.update(); + this.entities.update(); + if (this.entityProcessors) + this.entityProcessors.lateUpdate(); + this.renderableComponents.updateList(); + }; + Scene.prototype.render = function () { + if (this._renderers.length == 0) { + console.error("there are no renderers in the scene!"); + return; } - else { - this._nextScene = value; + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].render(this); } - this.registerActiveSceneChanged(this._scene, this._nextScene); - }, - enumerable: true, - configurable: true - }); - SceneManager.initialize = function (stage) { - Input.initialize(stage); - }; - SceneManager.update = function () { - SceneManager.startDebugUpdate(); - Time.update(egret.getTimer()); - if (SceneManager._scene) { - for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } - if (!SceneManager.sceneTransition || - (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { - SceneManager._scene.update(); - } - if (SceneManager._nextScene) { - SceneManager._scene.end(); - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._instnace.onSceneChanged(); - SceneManager._scene.begin(); - } - } - SceneManager.endDebugUpdate(); - SceneManager.render(); - }; - SceneManager.render = function () { - if (this.sceneTransition) { - this.sceneTransition.preRender(); - if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } - else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { - this._scene.render(); - this._scene.postRender(); - } - this.sceneTransition.render(); - } - } - else if (this._scene) { - this._scene.render(); - Debug.render(); - this._scene.postRender(); - } - }; - SceneManager.startSceneTransition = function (sceneTransition) { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; - } - this.sceneTransition = sceneTransition; - return sceneTransition; - }; - SceneManager.registerActiveSceneChanged = function (current, next) { - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - }; - SceneManager.prototype.onSceneChanged = function () { - SceneManager.emitter.emit(CoreEvents.SceneChanged); - Time.sceneChanged(); - }; - SceneManager.startDebugUpdate = function () { - TimeRuler.Instance.startFrame(); - TimeRuler.Instance.beginMark("update", 0x00FF00); - }; - SceneManager.endDebugUpdate = function () { - TimeRuler.Instance.endMark("update"); - }; - return SceneManager; -}()); -var Camera = (function (_super) { - __extends(Camera, _super); - function Camera() { - var _this = _super.call(this) || this; - _this._origin = Vector2.zero; - _this._minimumZoom = 0.3; - _this._maximumZoom = 3; - _this._position = Vector2.zero; - _this.followLerp = 0.1; - _this.deadzone = new Rectangle(); - _this.focusOffset = new Vector2(); - _this.mapLockEnabled = false; - _this.mapSize = new Vector2(); - _this._worldSpaceDeadZone = new Rectangle(); - _this._desiredPositionDelta = new Vector2(); - _this.cameraStyle = CameraStyle.lockOn; - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.setZoom(0); - return _this; - } - Object.defineProperty(Camera.prototype, "zoom", { - get: function () { - if (this._zoom == 0) - return 1; - if (this._zoom < 1) - return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); - return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); - }, - set: function (value) { - this.setZoom(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "minimumZoom", { - get: function () { - return this._minimumZoom; - }, - set: function (value) { - this.setMinimumZoom(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "maximumZoom", { - get: function () { - return this._maximumZoom; - }, - set: function (value) { - this.setMaximumZoom(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (value) { - if (this._origin != value) { - this._origin = value; - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "position", { - get: function () { - return this._position; - }, - set: function (value) { - this._position = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "x", { - get: function () { - return this._position.x; - }, - set: function (value) { - this._position.x = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "y", { - get: function () { - return this._position.y; - }, - set: function (value) { - this._position.y = value; - }, - enumerable: true, - configurable: true - }); - Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { - var oldOrigin = this._origin; - this.origin = new Vector2(newWidth / 2, newHeight / 2); - this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); - }; - Camera.prototype.setMinimumZoom = function (minZoom) { - if (this._zoom < minZoom) - this._zoom = this.minimumZoom; - this._minimumZoom = minZoom; - return this; - }; - Camera.prototype.setMaximumZoom = function (maxZoom) { - if (this._zoom > maxZoom) - this._zoom = maxZoom; - this._maximumZoom = maxZoom; - return this; - }; - Camera.prototype.setZoom = function (zoom) { - var newZoom = MathHelper.clamp(zoom, -1, 1); - if (newZoom == 0) { - this._zoom = 1; - } - else if (newZoom < 0) { - this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); - } - else { - this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); - } - SceneManager.scene.scaleX = this._zoom; - SceneManager.scene.scaleY = this._zoom; - return this; - }; - Camera.prototype.setRotation = function (rotation) { - SceneManager.scene.rotation = rotation; - return this; - }; - Camera.prototype.setPosition = function (position) { - this.entity.position = position; - return this; - }; - Camera.prototype.follow = function (targetEntity, cameraStyle) { - if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; } - this.targetEntity = targetEntity; - this.cameraStyle = cameraStyle; - var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - switch (this.cameraStyle) { - case CameraStyle.cameraWindow: - var w = cameraBounds.width / 6; - var h = cameraBounds.height / 3; - this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10); - break; - } - }; - Camera.prototype.update = function () { - var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); - this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; - this._worldSpaceDeadZone.width = this.deadzone.width; - this._worldSpaceDeadZone.height = this.deadzone.height; - if (this.targetEntity) - this.updateFollow(); - this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); - this.entity.roundPosition(); - if (this.mapLockEnabled) { - this.position = this.clampToMapSize(this.position); - this.entity.roundPosition(); - } - }; - Camera.prototype.clampToMapSize = function (position) { - var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); - var cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); - return Vector2.clamp(position, halfScreen, cameraMax); - }; - Camera.prototype.updateFollow = function () { - this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; - if (this.cameraStyle == CameraStyle.lockOn) { - var targetX = this.targetEntity.position.x; - var targetY = this.targetEntity.position.y; - if (this._worldSpaceDeadZone.x > targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - else if (this._worldSpaceDeadZone.x < targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - if (this._worldSpaceDeadZone.y < targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - else if (this._worldSpaceDeadZone.y > targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - } - else { - if (!this._targetCollider) { - this._targetCollider = this.targetEntity.getComponent(Collider); - if (!this._targetCollider) - return; - } - var targetBounds = this.targetEntity.getComponent(Collider).bounds; - if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { - if (this._worldSpaceDeadZone.left > targetBounds.left) - this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; - else if (this._worldSpaceDeadZone.right < targetBounds.right) - this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; - if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) - this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; - else if (this._worldSpaceDeadZone.top > targetBounds.top) - this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; - } - } - }; - return Camera; -}(Component)); -var CameraStyle; -(function (CameraStyle) { - CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; - CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; -})(CameraStyle || (CameraStyle = {})); -var ComponentPool = (function () { - function ComponentPool(typeClass) { - this._type = typeClass; - this._cache = []; - } - ComponentPool.prototype.obtain = function () { - try { - return this._cache.length > 0 ? this._cache.shift() : new this._type(); - } - catch (err) { - throw new Error(this._type + err); - } - }; - ComponentPool.prototype.free = function (component) { - component.reset(); - this._cache.push(component); - }; - return ComponentPool; -}()); -var PooledComponent = (function (_super) { - __extends(PooledComponent, _super); - function PooledComponent() { - return _super !== null && _super.apply(this, arguments) || this; - } - return PooledComponent; -}(Component)); -var RenderableComponent = (function (_super) { - __extends(RenderableComponent, _super); - function RenderableComponent() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._areBoundsDirty = true; - _this._bounds = new Rectangle(); - _this._localOffset = Vector2.zero; - _this.color = 0x000000; - return _this; - } - Object.defineProperty(RenderableComponent.prototype, "width", { - get: function () { - return this.getWidth(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "height", { - get: function () { - return this.getHeight(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "isVisible", { - get: function () { - return this._isVisible; - }, - set: function (value) { - this._isVisible = value; - if (this._isVisible) - this.onBecameVisible(); - else - this.onBecameInvisible(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "bounds", { - get: function () { - return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); - }, - enumerable: true, - configurable: true - }); - RenderableComponent.prototype.getWidth = function () { - return this.bounds.width; - }; - RenderableComponent.prototype.getHeight = function () { - return this.bounds.height; - }; - RenderableComponent.prototype.onBecameVisible = function () { }; - RenderableComponent.prototype.onBecameInvisible = function () { }; - RenderableComponent.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = camera.getBounds().intersects(this.getBounds()); - return this.isVisible; - }; - return RenderableComponent; -}(PooledComponent)); -var Mesh = (function (_super) { - __extends(Mesh, _super); - function Mesh() { - var _this = _super.call(this) || this; - _this._mesh = new egret.Mesh(); - return _this; - } - Mesh.prototype.setTexture = function (texture) { - this._mesh.texture = texture; - return this; - }; - Mesh.prototype.onAddedToEntity = function () { - this.addChild(this._mesh); - }; - Mesh.prototype.onRemovedFromEntity = function () { - this.removeChild(this._mesh); - }; - Mesh.prototype.render = function (camera) { - this.x = this.entity.position.x - camera.position.x + camera.origin.x; - this.y = this.entity.position.y - camera.position.y + camera.origin.y; - }; - Mesh.prototype.reset = function () { - }; - return Mesh; -}(RenderableComponent)); -var SpriteRenderer = (function (_super) { - __extends(SpriteRenderer, _super); - function SpriteRenderer() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(SpriteRenderer.prototype, "sprite", { - get: function () { - return this._sprite; - }, - set: function (value) { - this.setSprite(value); - }, - enumerable: true, - configurable: true - }); - SpriteRenderer.prototype.setSprite = function (sprite) { - this.removeChildren(); - this._sprite = sprite; - if (this._sprite) { - this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width; - this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height; - } - this.bitmap = new egret.Bitmap(sprite.texture2D); - this.addChild(this.bitmap); - return this; - }; - SpriteRenderer.prototype.setColor = function (color) { - var colorMatrix = [ - 1, 0, 0, 0, 0, - 0, 1, 0, 0, 0, - 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0 - ]; - colorMatrix[0] = Math.floor(color / 256 / 256) / 255; - colorMatrix[6] = Math.floor(color / 256 % 256) / 255; - colorMatrix[12] = color % 256 / 255; - var colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this.filters = [colorFilter]; - return this; - }; - SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); - this.visible = this.isVisible; - return this.isVisible; - }; - SpriteRenderer.prototype.render = function (camera) { - if (this.x != -camera.position.x + camera.origin.x || - this.y != -camera.position.y + camera.origin.y) { - this.x = -camera.position.x + camera.origin.x; - this.y = -camera.position.y + camera.origin.y; - this.entity.onEntityTransformChanged(TransformComponent.position); - } - }; - SpriteRenderer.prototype.onRemovedFromEntity = function () { - if (this.parent) - this.parent.removeChild(this); - }; - SpriteRenderer.prototype.reset = function () { - }; - return SpriteRenderer; -}(RenderableComponent)); -var TiledSpriteRenderer = (function (_super) { - __extends(TiledSpriteRenderer, _super); - function TiledSpriteRenderer(sprite) { - var _this = _super.call(this) || this; - _this.leftTexture = new egret.Bitmap(); - _this.rightTexture = new egret.Bitmap(); - _this.leftTexture.texture = sprite.texture2D; - _this.rightTexture.texture = sprite.texture2D; - _this.setSprite(sprite); - _this.sourceRect = sprite.sourceRect; - return _this; - } - Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", { - get: function () { - return this.sourceRect.x; - }, - set: function (value) { - this.sourceRect.x = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", { - get: function () { - return this.sourceRect.y; - }, - set: function (value) { - this.sourceRect.y = value; - }, - enumerable: true, - configurable: true - }); - TiledSpriteRenderer.prototype.render = function (camera) { - if (!this.sprite) - return; - _super.prototype.render.call(this, camera); - var renderTexture = new egret.RenderTexture(); - var cacheBitmap = new egret.DisplayObjectContainer(); - cacheBitmap.removeChildren(); - cacheBitmap.addChild(this.leftTexture); - cacheBitmap.addChild(this.rightTexture); - this.leftTexture.x = this.sourceRect.x; - this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; - this.leftTexture.y = this.sourceRect.y; - this.rightTexture.y = this.sourceRect.y; - cacheBitmap.cacheAsBitmap = true; - renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); - this.bitmap.texture = renderTexture; - }; - return TiledSpriteRenderer; -}(SpriteRenderer)); -var ScrollingSpriteRenderer = (function (_super) { - __extends(ScrollingSpriteRenderer, _super); - function ScrollingSpriteRenderer() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.scrollSpeedX = 15; - _this.scroolSpeedY = 0; - _this._scrollX = 0; - _this._scrollY = 0; - return _this; - } - ScrollingSpriteRenderer.prototype.update = function () { - this._scrollX += this.scrollSpeedX * Time.deltaTime; - this._scrollY += this.scroolSpeedY * Time.deltaTime; - this.sourceRect.x = this._scrollX; - this.sourceRect.y = this._scrollY; - }; - ScrollingSpriteRenderer.prototype.render = function (camera) { - if (!this.sprite) - return; - _super.prototype.render.call(this, camera); - var renderTexture = new egret.RenderTexture(); - var cacheBitmap = new egret.DisplayObjectContainer(); - cacheBitmap.removeChildren(); - cacheBitmap.addChild(this.leftTexture); - cacheBitmap.addChild(this.rightTexture); - this.leftTexture.x = this.sourceRect.x; - this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; - this.leftTexture.y = this.sourceRect.y; - this.rightTexture.y = this.sourceRect.y; - cacheBitmap.cacheAsBitmap = true; - renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); - this.bitmap.texture = renderTexture; - }; - return ScrollingSpriteRenderer; -}(TiledSpriteRenderer)); -var Sprite = (function () { - function Sprite(texture, sourceRect, origin) { - if (sourceRect === void 0) { sourceRect = new Rectangle(0, 0, texture.textureWidth, texture.textureHeight); } - if (origin === void 0) { origin = sourceRect.getHalfSize(); } - this.uvs = new Rectangle(); - this.texture2D = texture; - this.sourceRect = sourceRect; - this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); - this.origin = origin; - var inverseTexW = 1 / texture.textureWidth; - var inverseTexH = 1 / texture.textureHeight; - this.uvs.x = sourceRect.x * inverseTexW; - this.uvs.y = sourceRect.y * inverseTexH; - this.uvs.width = sourceRect.width * inverseTexW; - this.uvs.height = sourceRect.height * inverseTexH; - } - return Sprite; -}()); -var SpriteAnimation = (function () { - function SpriteAnimation(sprites, frameRate) { - this.sprites = sprites; - this.frameRate = frameRate; - } - return SpriteAnimation; -}()); -var SpriteAnimator = (function (_super) { - __extends(SpriteAnimator, _super); - function SpriteAnimator(sprite) { - var _this = _super.call(this) || this; - _this.speed = 1; - _this.animationState = State.none; - _this._animations = new Map(); - _this._elapsedTime = 0; - if (sprite) - _this.setSprite(sprite); - return _this; - } - Object.defineProperty(SpriteAnimator.prototype, "isRunning", { - get: function () { - return this.animationState == State.running; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SpriteAnimator.prototype, "animations", { - get: function () { - return this._animations; - }, - enumerable: true, - configurable: true - }); - SpriteAnimator.prototype.addAnimation = function (name, animation) { - if (!this.sprite && animation.sprites.length > 0) - this.setSprite(animation.sprites[0]); - this._animations[name] = animation; - return this; - }; - SpriteAnimator.prototype.play = function (name, loopMode) { - if (loopMode === void 0) { loopMode = null; } - this.currentAnimation = this._animations[name]; - this.currentAnimationName = name; - this.currentFrame = 0; - this.animationState = State.running; - this.sprite = this.currentAnimation.sprites[0]; - this._elapsedTime = 0; - this._loopMode = loopMode ? loopMode : LoopMode.loop; - }; - SpriteAnimator.prototype.isAnimationActive = function (name) { - return this.currentAnimation && this.currentAnimationName == name; - }; - SpriteAnimator.prototype.pause = function () { - this.animationState = State.paused; - }; - SpriteAnimator.prototype.unPause = function () { - this.animationState = State.running; - }; - SpriteAnimator.prototype.stop = function () { - this.currentAnimation = null; - this.currentAnimationName = null; - this.currentFrame = 0; - this.animationState = State.none; - }; - SpriteAnimator.prototype.update = function () { - if (this.animationState != State.running || !this.currentAnimation) - return; - var animation = this.currentAnimation; - var secondsPerFrame = 1 / (animation.frameRate * this.speed); - var iterationDuration = secondsPerFrame * animation.sprites.length; - this._elapsedTime += Time.deltaTime; - var time = Math.abs(this._elapsedTime); - if (this._loopMode == LoopMode.once && time > iterationDuration || - this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) { - this.animationState = State.completed; - this._elapsedTime = 0; - this.currentFrame = 0; - this.sprite = animation.sprites[this.currentFrame]; - return; - } - var i = Math.floor(time / secondsPerFrame); - var n = animation.sprites.length; - if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) { - var maxIndex = n - 1; - this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2)); - } - else { - this.currentFrame = i % n; - } - this.sprite = animation.sprites[this.currentFrame]; - }; - return SpriteAnimator; -}(SpriteRenderer)); -var LoopMode; -(function (LoopMode) { - LoopMode[LoopMode["loop"] = 0] = "loop"; - LoopMode[LoopMode["once"] = 1] = "once"; - LoopMode[LoopMode["clampForever"] = 2] = "clampForever"; - LoopMode[LoopMode["pingPong"] = 3] = "pingPong"; - LoopMode[LoopMode["pingPongOnce"] = 4] = "pingPongOnce"; -})(LoopMode || (LoopMode = {})); -var State; -(function (State) { - State[State["none"] = 0] = "none"; - State[State["running"] = 1] = "running"; - State[State["paused"] = 2] = "paused"; - State[State["completed"] = 3] = "completed"; -})(State || (State = {})); -var Mover = (function (_super) { - __extends(Mover, _super); - function Mover() { - return _super !== null && _super.apply(this, arguments) || this; - } - Mover.prototype.onAddedToEntity = function () { - this._triggerHelper = new ColliderTriggerHelper(this.entity); - }; - Mover.prototype.calculateMovement = function (motion) { - var collisionResult = new CollisionResult(); - if (!this.entity.getComponent(Collider) || !this._triggerHelper) { - return null; - } - var colliders = this.entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - if (collider.isTrigger) - continue; - var bounds = collider.bounds; - bounds.x += motion.x; - bounds.y += motion.y; - var boxcastResult = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); - bounds = boxcastResult.bounds; - var neighbors = boxcastResult.tempHashSet; - for (var j = 0; j < neighbors.length; j++) { - var neighbor = neighbors[j]; - if (neighbor.isTrigger) - continue; - var _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult) { - motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); - if (_internalcollisionResult.collider) { - collisionResult = _internalcollisionResult; + }; + Scene.prototype.postRender = function () { + if (this.enablePostProcessing) { + for (var i = 0; i < this._postProcessors.length; i++) { + if (this._postProcessors[i].enabled) { + this._postProcessors[i].process(); } } } - } - ListPool.free(colliders); - return { collisionResult: collisionResult, motion: motion }; - }; - Mover.prototype.applyMovement = function (motion) { - this.entity.position = Vector2.add(this.entity.position, motion); - if (this._triggerHelper) - this._triggerHelper.update(); - }; - Mover.prototype.move = function (motion) { - var movementResult = this.calculateMovement(motion); - var collisionResult = movementResult.collisionResult; - motion = movementResult.motion; - this.applyMovement(motion); - return collisionResult; - }; - return Mover; -}(Component)); -var ProjectileMover = (function (_super) { - __extends(ProjectileMover, _super); - function ProjectileMover() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._tempTriggerList = []; - return _this; - } - ProjectileMover.prototype.onAddedToEntity = function () { - this._collider = this.entity.getComponent(Collider); - if (!this._collider) - console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!"); - }; - ProjectileMover.prototype.move = function (motion) { - if (!this._collider) - return false; - var didCollide = false; - this.entity.position = Vector2.add(this.entity.position, motion); - var neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); - for (var i = 0; i < neighbors.colliders.length; i++) { - var neighbor = neighbors.colliders[i]; - if (this._collider.overlaps(neighbor) && neighbor.enabled) { - didCollide = true; - this.notifyTriggerListeners(this._collider, neighbor); + }; + Scene.prototype.addRenderer = function (renderer) { + this._renderers.push(renderer); + this._renderers.sort(); + renderer.onAddedToScene(this); + return renderer; + }; + Scene.prototype.getRenderer = function (type) { + for (var i = 0; i < this._renderers.length; i++) { + if (this._renderers[i] instanceof type) + return this._renderers[i]; } - } - return didCollide; - }; - ProjectileMover.prototype.notifyTriggerListeners = function (self, other) { - other.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i = 0; i < this._tempTriggerList.length; i++) { - this._tempTriggerList[i].onTriggerEnter(self, other); - } - this._tempTriggerList.length = 0; - this.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i = 0; i < this._tempTriggerList.length; i++) { - this._tempTriggerList[i].onTriggerEnter(other, self); - } - this._tempTriggerList.length = 0; - }; - return ProjectileMover; -}(Component)); -var Collider = (function (_super) { - __extends(Collider, _super); - function Collider() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.physicsLayer = 1 << 0; - _this.registeredPhysicsBounds = new Rectangle(); - _this.shouldColliderScaleAndRotateWithTransform = true; - _this.collidesWithLayers = Physics.allLayers; - return _this; - } - Object.defineProperty(Collider.prototype, "bounds", { - get: function () { - var shapeBounds = this.shape.bounds; - var colliderBuonds = new Rectangle(this.entity.x, this.entity.y, shapeBounds.width, shapeBounds.height); - return colliderBuonds; - }, - enumerable: true, - configurable: true - }); - Collider.prototype.registerColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { - Physics.addCollider(this); - this._isColliderRegistered = true; - } - }; - Collider.prototype.unregisterColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && this._isColliderRegistered) { - Physics.removeCollider(this); - } - this._isColliderRegistered = false; - }; - Collider.prototype.overlaps = function (other) { - return this.shape.overlaps(other.shape); - }; - Collider.prototype.collidesWith = function (collider, motion) { - var oldPosition = this.entity.position; - this.entity.position = Vector2.add(this.entity.position, motion); - var result = this.shape.collidesWithShape(collider.shape); - if (result) - result.collider = collider; - this.entity.position = oldPosition; - return result; - }; - Collider.prototype.onAddedToEntity = function () { - if (this._colliderRequiresAutoSizing) { - if (!(this instanceof BoxCollider || this instanceof CircleCollider)) { - console.error("Only box and circle colliders can be created automatically"); + return null; + }; + Scene.prototype.removeRenderer = function (renderer) { + if (!this._renderers.contains(renderer)) + return; + this._renderers.remove(renderer); + renderer.unload(); + }; + Scene.prototype.addPostProcessor = function (postProcessor) { + this._postProcessors.push(postProcessor); + this._postProcessors.sort(); + postProcessor.onAddedToScene(this); + if (this._didSceneBegin) { + postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); } - var renderable = this.entity.getComponent(RenderableComponent); - if (renderable) { - var bounds = renderable.bounds; - var width = bounds.width / this.entity.scale.x; - var height = bounds.height / this.entity.scale.y; - if (this instanceof CircleCollider) { - var circleCollider = this; - circleCollider.radius = Math.max(width, height) * 0.5; + return postProcessor; + }; + Scene.prototype.getPostProcessor = function (type) { + for (var i = 0; i < this._postProcessors.length; i++) { + if (this._postProcessors[i] instanceof type) + return this._postProcessors[i]; + } + return null; + }; + Scene.prototype.removePostProcessor = function (postProcessor) { + if (!this._postProcessors.contains(postProcessor)) + return; + this._postProcessors.remove(postProcessor); + postProcessor.unload(); + }; + Scene.prototype.createEntity = function (name) { + var entity = new es.Entity(name); + return this.addEntity(entity); + }; + Scene.prototype.addEntity = function (entity) { + if (this.entities.buffer.contains(entity)) + console.warn("You are attempting to add the same entity to a scene twice: " + entity); + this.entities.add(entity); + entity.scene = this; + for (var i = 0; i < entity.transform.childCount; i++) + this.addEntity(entity.transform.getChild(i).entity); + return entity; + }; + Scene.prototype.destroyAllEntities = function () { + for (var i = 0; i < this.entities.count; i++) { + this.entities.buffer[i].destroy(); + } + }; + Scene.prototype.findEntity = function (name) { + return this.entities.findEntity(name); + }; + Scene.prototype.findEntitiesWithTag = function (tag) { + return this.entities.entitiesWithTag(tag); + }; + Scene.prototype.entitiesOfType = function (type) { + return this.entities.entitiesOfType(type); + }; + Scene.prototype.findComponentOfType = function (type) { + return this.entities.findComponentOfType(type); + }; + Scene.prototype.findComponentsOfType = function (type) { + return this.entities.findComponentsOfType(type); + }; + Scene.prototype.addEntityProcessor = function (processor) { + processor.scene = this; + this.entityProcessors.add(processor); + return processor; + }; + Scene.prototype.removeEntityProcessor = function (processor) { + this.entityProcessors.remove(processor); + }; + Scene.prototype.getEntityProcessor = function () { + return this.entityProcessors.getProcessor(); + }; + return Scene; + }(egret.DisplayObjectContainer)); + es.Scene = Scene; +})(es || (es = {})); +var es; +(function (es) { + var SceneManager = (function () { + function SceneManager(stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); + SceneManager._instnace = this; + SceneManager.emitter = new es.Emitter(); + SceneManager.content = new es.ContentManager(); + SceneManager.stage = stage; + SceneManager.initialize(stage); + SceneManager.timerRuler = new es.TimeRuler(); + } + Object.defineProperty(SceneManager, "Instance", { + get: function () { + return this._instnace; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SceneManager, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + if (!value) + throw new Error("场景不能为空"); + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + SceneManager.Instance.onSceneChanged(); } else { - this.width = width; - this.height = height; + this._nextScene = value; } - this.addChild(this.shape); + this.registerActiveSceneChanged(this._scene, this._nextScene); + }, + enumerable: true, + configurable: true + }); + SceneManager.initialize = function (stage) { + es.Input.initialize(stage); + }; + SceneManager.update = function () { + SceneManager.startDebugUpdate(); + es.Time.update(egret.getTimer()); + if (SceneManager._scene) { + for (var i = es.GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (es.GlobalManager.globalManagers[i].enabled) + es.GlobalManager.globalManagers[i].update(); + } + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + SceneManager._scene.update(); + } + if (SceneManager._nextScene) { + SceneManager._scene.end(); + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + SceneManager._instnace.onSceneChanged(); + SceneManager._scene.begin(); + } + } + SceneManager.endDebugUpdate(); + SceneManager.render(); + }; + SceneManager.render = function () { + if (this.sceneTransition) { + this.sceneTransition.preRender(); + if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { + this._scene.render(); + this._scene.postRender(); + this.sceneTransition.onBeginTransition(); + } + else if (this.sceneTransition) { + if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + this.sceneTransition.render(); + } + } + else if (this._scene) { + this._scene.render(); + es.Debug.render(); + this._scene.postRender(); + } + }; + SceneManager.startSceneTransition = function (sceneTransition) { + if (this.sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } + this.sceneTransition = sceneTransition; + return sceneTransition; + }; + SceneManager.registerActiveSceneChanged = function (current, next) { + if (this.activeSceneChanged) + this.activeSceneChanged(current, next); + }; + SceneManager.prototype.onSceneChanged = function () { + SceneManager.emitter.emit(es.CoreEvents.SceneChanged); + es.Time.sceneChanged(); + }; + SceneManager.startDebugUpdate = function () { + es.TimeRuler.Instance.startFrame(); + es.TimeRuler.Instance.beginMark("update", 0x00FF00); + }; + SceneManager.endDebugUpdate = function () { + es.TimeRuler.Instance.endMark("update"); + }; + return SceneManager; + }()); + es.SceneManager = SceneManager; +})(es || (es = {})); +var transform; +(function (transform) { + var Component; + (function (Component) { + Component[Component["position"] = 0] = "position"; + Component[Component["scale"] = 1] = "scale"; + Component[Component["rotation"] = 2] = "rotation"; + })(Component = transform.Component || (transform.Component = {})); +})(transform || (transform = {})); +var es; +(function (es) { + var DirtyType; + (function (DirtyType) { + DirtyType[DirtyType["clean"] = 0] = "clean"; + DirtyType[DirtyType["positionDirty"] = 1] = "positionDirty"; + DirtyType[DirtyType["scaleDirty"] = 2] = "scaleDirty"; + DirtyType[DirtyType["rotationDirty"] = 3] = "rotationDirty"; + })(DirtyType = es.DirtyType || (es.DirtyType = {})); + var Transform = (function () { + function Transform(entity) { + this.entity = entity; + this.scale = es.Vector2.one; + this._children = []; + } + Object.defineProperty(Transform.prototype, "parent", { + get: function () { + return this._parent; + }, + set: function (value) { + this.setParent(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "childCount", { + get: function () { + return this._children.length; + }, + enumerable: true, + configurable: true + }); + Transform.prototype.getChild = function (index) { + return this._children[index]; + }; + Transform.prototype.setParent = function (parent) { + if (this._parent == parent) + return this; + if (!this._parent) { + this._parent._children.remove(this); + this._parent._children.push(this); + } + this._parent = parent; + this.setDirty(DirtyType.positionDirty); + return this; + }; + Transform.prototype.setPosition = function (x, y) { + this.position = new es.Vector2(x, y); + this.setDirty(DirtyType.positionDirty); + return this; + }; + Transform.prototype.setRotation = function (degrees) { + this.rotation = degrees; + this.setDirty(DirtyType.rotationDirty); + return this; + }; + Transform.prototype.setScale = function (scale) { + this.scale = scale; + this.setDirty(DirtyType.scaleDirty); + return this; + }; + Transform.prototype.lookAt = function (pos) { + var sign = this.position.x > pos.x ? -1 : 1; + var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos)); + this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY)); + }; + Transform.prototype.roundPosition = function () { + this.position = this.position.round(); + }; + Transform.prototype.setDirty = function (dirtyFlagType) { + if ((this.hierarchyDirty & dirtyFlagType) == 0) { + this.hierarchyDirty |= dirtyFlagType; + switch (dirtyFlagType) { + case es.DirtyType.positionDirty: + this.entity.onTransformChanged(transform.Component.position); + break; + case es.DirtyType.rotationDirty: + this.entity.onTransformChanged(transform.Component.rotation); + break; + case es.DirtyType.scaleDirty: + this.entity.onTransformChanged(transform.Component.scale); + break; + } + if (!this._children) + this._children = []; + for (var i = 0; i < this._children.length; i++) + this._children[i].setDirty(dirtyFlagType); + } + }; + Transform.prototype.copyFrom = function (transform) { + this.position = transform.position; + this.rotation = transform.rotation; + this.scale = transform.scale; + this.setDirty(DirtyType.positionDirty); + this.setDirty(DirtyType.rotationDirty); + this.setDirty(DirtyType.scaleDirty); + }; + return Transform; + }()); + es.Transform = Transform; +})(es || (es = {})); +var es; +(function (es) { + var CameraStyle; + (function (CameraStyle) { + CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; + CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; + })(CameraStyle = es.CameraStyle || (es.CameraStyle = {})); + var Camera = (function (_super) { + __extends(Camera, _super); + function Camera(targetEntity, cameraStyle) { + if (targetEntity === void 0) { targetEntity = null; } + if (cameraStyle === void 0) { cameraStyle = CameraStyle.lockOn; } + var _this = _super.call(this) || this; + _this._minimumZoom = 0.3; + _this._maximumZoom = 3; + _this._origin = es.Vector2.zero; + _this.followLerp = 0.1; + _this.deadzone = new es.Rectangle(); + _this.focusOffset = new es.Vector2(); + _this.mapLockEnabled = false; + _this.mapSize = new es.Vector2(); + _this._desiredPositionDelta = new es.Vector2(); + _this._worldSpaceDeadZone = new es.Rectangle(); + _this._targetEntity = targetEntity; + _this._cameraStyle = cameraStyle; + _this.setZoom(0); + return _this; + } + Object.defineProperty(Camera.prototype, "position", { + get: function () { + return this.entity.transform.position; + }, + set: function (value) { + this.entity.transform.position = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "rotation", { + get: function () { + return this.entity.transform.rotation; + }, + set: function (value) { + this.entity.transform.rotation = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "zoom", { + get: function () { + if (this._zoom == 0) + return 1; + if (this._zoom < 1) + return es.MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); + return es.MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); + }, + set: function (value) { + this.setZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "minimumZoom", { + get: function () { + return this._minimumZoom; + }, + set: function (value) { + this.setMinimumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "maximumZoom", { + get: function () { + return this._maximumZoom; + }, + set: function (value) { + this.setMaximumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "bounds", { + get: function () { + return new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + if (this._origin != value) { + this._origin = value; + } + }, + enumerable: true, + configurable: true + }); + Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { + var oldOrigin = this._origin; + this.origin = new es.Vector2(newWidth / 2, newHeight / 2); + this.entity.transform.position = es.Vector2.add(this.entity.transform.position, es.Vector2.subtract(this._origin, oldOrigin)); + }; + Camera.prototype.setPosition = function (position) { + this.entity.transform.setPosition(position.x, position.y); + return this; + }; + Camera.prototype.setRotation = function (rotation) { + this.entity.transform.setRotation(rotation); + return this; + }; + Camera.prototype.setZoom = function (zoom) { + var newZoom = es.MathHelper.clamp(zoom, -1, 1); + if (newZoom == 0) { + this._zoom = 1; + } + else if (newZoom < 0) { + this._zoom = es.MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); } else { - console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); + this._zoom = es.MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); } - } - this._isParentEntityAddedToScene = true; - this.registerColliderWithPhysicsSystem(); - }; - Collider.prototype.onRemovedFromEntity = function () { - this.unregisterColliderWithPhysicsSystem(); - this._isParentEntityAddedToScene = false; - this.removeChild(this.shape); - }; - Collider.prototype.onEnabled = function () { - this.registerColliderWithPhysicsSystem(); - }; - Collider.prototype.onDisabled = function () { - this.unregisterColliderWithPhysicsSystem(); - }; - Collider.prototype.onEntityTransformChanged = function (comp) { - if (this._isColliderRegistered) - Physics.updateCollider(this); - }; - Collider.prototype.update = function () { - var renderable = this.entity.getComponent(RenderableComponent); - if (renderable) { - this.$setX(renderable.x); - this.$setY(renderable.y); - } - }; - return Collider; -}(Component)); -var BoxCollider = (function (_super) { - __extends(BoxCollider, _super); - function BoxCollider() { - var _this = _super.call(this) || this; - _this.shape = new Box(1, 1); - _this._colliderRequiresAutoSizing = true; - return _this; - } - Object.defineProperty(BoxCollider.prototype, "width", { - get: function () { - return this.shape.width; - }, - set: function (value) { - this.setWidth(value); - }, - enumerable: true, - configurable: true - }); - BoxCollider.prototype.setWidth = function (width) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width) { - box.updateBox(width, box.height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - Object.defineProperty(BoxCollider.prototype, "height", { - get: function () { - return this.shape.height; - }, - set: function (value) { - this.setHeight(value); - }, - enumerable: true, - configurable: true - }); - BoxCollider.prototype.setHeight = function (height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (height != box.height) { - box.updateBox(box.width, height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - }; - BoxCollider.prototype.setSize = function (width, height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width || height != box.height) { - box.updateBox(width, height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - return BoxCollider; -}(Collider)); -var CircleCollider = (function (_super) { - __extends(CircleCollider, _super); - function CircleCollider(radius) { - var _this = _super.call(this) || this; - if (radius) - _this._colliderRequiresAutoSizing = true; - _this.shape = new Circle(radius ? radius : 1); - return _this; - } - Object.defineProperty(CircleCollider.prototype, "radius", { - get: function () { - return this.shape.radius; - }, - set: function (value) { - this.setRadius(value); - }, - enumerable: true, - configurable: true - }); - CircleCollider.prototype.setRadius = function (radius) { - this._colliderRequiresAutoSizing = false; - var circle = this.shape; - if (radius != circle.radius) { - circle.radius = radius; - circle._originalRadius = radius; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - return CircleCollider; -}(Collider)); -var PolygonCollider = (function (_super) { - __extends(PolygonCollider, _super); - function PolygonCollider(points) { - var _this = _super.call(this) || this; - var isPolygonClosed = points[0] == points[points.length - 1]; - if (isPolygonClosed) - points.splice(points.length - 1, 1); - Polygon.recenterPolygonVerts(points); - _this.shape = new Polygon(points); - return _this; - } - return PolygonCollider; -}(Collider)); -var EntitySystem = (function () { - function EntitySystem(matcher) { - this._entities = []; - this._matcher = matcher ? matcher : Matcher.empty(); - } - Object.defineProperty(EntitySystem.prototype, "matcher", { - get: function () { - return this._matcher; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(EntitySystem.prototype, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - this._scene = value; - this._entities = []; - }, - enumerable: true, - configurable: true - }); - EntitySystem.prototype.initialize = function () { - }; - EntitySystem.prototype.onChanged = function (entity) { - var contains = this._entities.contains(entity); - var interest = this._matcher.IsIntersted(entity); - if (interest && !contains) - this.add(entity); - else if (!interest && contains) - this.remove(entity); - }; - EntitySystem.prototype.add = function (entity) { - this._entities.push(entity); - this.onAdded(entity); - }; - EntitySystem.prototype.onAdded = function (entity) { - }; - EntitySystem.prototype.remove = function (entity) { - this._entities.remove(entity); - this.onRemoved(entity); - }; - EntitySystem.prototype.onRemoved = function (entity) { - }; - EntitySystem.prototype.update = function () { - this.begin(); - this.process(this._entities); - }; - EntitySystem.prototype.lateUpdate = function () { - this.lateProcess(this._entities); - this.end(); - }; - EntitySystem.prototype.begin = function () { - }; - EntitySystem.prototype.process = function (entities) { - }; - EntitySystem.prototype.lateProcess = function (entities) { - }; - EntitySystem.prototype.end = function () { - }; - return EntitySystem; -}()); -var EntityProcessingSystem = (function (_super) { - __extends(EntityProcessingSystem, _super); - function EntityProcessingSystem(matcher) { - return _super.call(this, matcher) || this; - } - EntityProcessingSystem.prototype.lateProcessEntity = function (entity) { - }; - EntityProcessingSystem.prototype.process = function (entities) { - var _this = this; - entities.forEach(function (entity) { return _this.processEntity(entity); }); - }; - EntityProcessingSystem.prototype.lateProcess = function (entities) { - var _this = this; - entities.forEach(function (entity) { return _this.lateProcessEntity(entity); }); - }; - return EntityProcessingSystem; -}(EntitySystem)); -var PassiveSystem = (function (_super) { - __extends(PassiveSystem, _super); - function PassiveSystem() { - return _super !== null && _super.apply(this, arguments) || this; - } - PassiveSystem.prototype.onChanged = function (entity) { - }; - PassiveSystem.prototype.process = function (entities) { - this.begin(); - this.end(); - }; - return PassiveSystem; -}(EntitySystem)); -var ProcessingSystem = (function (_super) { - __extends(ProcessingSystem, _super); - function ProcessingSystem() { - return _super !== null && _super.apply(this, arguments) || this; - } - ProcessingSystem.prototype.onChanged = function (entity) { - }; - ProcessingSystem.prototype.process = function (entities) { - this.begin(); - this.processSystem(); - this.end(); - }; - return ProcessingSystem; -}(EntitySystem)); -var BitSet = (function () { - function BitSet(nbits) { - if (nbits === void 0) { nbits = 64; } - var length = nbits >> 6; - if ((nbits & BitSet.LONG_MASK) != 0) - length++; - this._bits = new Array(length); - } - BitSet.prototype.and = function (bs) { - var max = Math.min(this._bits.length, bs._bits.length); - var i; - for (var i_1 = 0; i_1 < max; ++i_1) - this._bits[i_1] &= bs._bits[i_1]; - while (i < this._bits.length) - this._bits[i++] = 0; - }; - BitSet.prototype.andNot = function (bs) { - var i = Math.min(this._bits.length, bs._bits.length); - while (--i >= 0) - this._bits[i] &= ~bs._bits[i]; - }; - BitSet.prototype.cardinality = function () { - var card = 0; - for (var i = this._bits.length - 1; i >= 0; i--) { - var a = this._bits[i]; - if (a == 0) - continue; - if (a == -1) { - card += 64; - continue; + es.SceneManager.scene.scaleX = this._zoom; + es.SceneManager.scene.scaleY = this._zoom; + return this; + }; + Camera.prototype.setMinimumZoom = function (minZoom) { + if (this._zoom < minZoom) + this._zoom = this.minimumZoom; + this._minimumZoom = minZoom; + return this; + }; + Camera.prototype.setMaximumZoom = function (maxZoom) { + if (maxZoom <= 0) { + console.error("maximumZoom must be greater than zero"); + return; } - a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); - a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); - var b = ((a >> 32) + a); - b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); - b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); - card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); - } - return card; - }; - BitSet.prototype.clear = function (pos) { - if (pos != undefined) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] &= ~(1 << pos); - } - else { - for (var i = 0; i < this._bits.length; i++) - this._bits[i] = 0; - } - }; - BitSet.prototype.ensure = function (lastElt) { - if (lastElt >= this._bits.length) { - var nd = new Number[lastElt + 1]; - nd = this._bits.copyWithin(0, 0, this._bits.length); - this._bits = nd; - } - }; - BitSet.prototype.get = function (pos) { - var offset = pos >> 6; - if (offset >= this._bits.length) - return false; - return (this._bits[offset] & (1 << pos)) != 0; - }; - BitSet.prototype.intersects = function (set) { - var i = Math.min(this._bits.length, set._bits.length); - while (--i >= 0) { - if ((this._bits[i] & set._bits[i]) != 0) - return true; - } - return false; - }; - BitSet.prototype.isEmpty = function () { - for (var i = this._bits.length - 1; i >= 0; i--) { - if (this._bits[i]) - return false; - } - return true; - }; - BitSet.prototype.nextSetBit = function (from) { - var offset = from >> 6; - var mask = 1 << from; - while (offset < this._bits.length) { - var h = this._bits[offset]; - do { - if ((h & mask) != 0) - return from; - mask <<= 1; - from++; - } while (mask != 0); - mask = 1; - offset++; - } - return -1; - }; - BitSet.prototype.set = function (pos, value) { - if (value === void 0) { value = true; } - if (value) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] |= 1 << pos; - } - else { - this.clear(pos); - } - }; - BitSet.LONG_MASK = 0x3f; - return BitSet; -}()); -var ComponentList = (function () { - function ComponentList(entity) { - this._components = []; - this._componentsToAdd = []; - this._componentsToRemove = []; - this._tempBufferList = []; - this._entity = entity; - } - Object.defineProperty(ComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true - }); - ComponentList.prototype.add = function (component) { - this._componentsToAdd.push(component); - }; - ComponentList.prototype.remove = function (component) { - if (this._componentsToRemove.contains(component)) - console.warn("You are trying to remove a Component (" + component + ") that you already removed"); - if (this._componentsToAdd.contains(component)) { - this._componentsToAdd.remove(component); - return; - } - this._componentsToRemove.push(component); - }; - ComponentList.prototype.removeAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - this.handleRemove(this._components[i]); - } - this._components.length = 0; - this._componentsToAdd.length = 0; - this._componentsToRemove.length = 0; - }; - ComponentList.prototype.deregisterAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - } - }; - ComponentList.prototype.registerAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - } - }; - ComponentList.prototype.updateLists = function () { - if (this._componentsToRemove.length > 0) { - for (var i = 0; i < this._componentsToRemove.length; i++) { - this.handleRemove(this._componentsToRemove[i]); - this._components.remove(this._componentsToRemove[i]); + if (this._zoom > maxZoom) + this._zoom = maxZoom; + this._maximumZoom = maxZoom; + return this; + }; + Camera.prototype.zoomIn = function (deltaZoom) { + this.zoom += deltaZoom; + }; + Camera.prototype.zoomOut = function (deltaZoom) { + this.zoom -= deltaZoom; + }; + Camera.prototype.onAddedToEntity = function () { + this.follow(this._targetEntity, this._cameraStyle); + }; + Camera.prototype.update = function () { + var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)); + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.width = this.deadzone.width; + this._worldSpaceDeadZone.height = this.deadzone.height; + if (this._targetEntity) + this.updateFollow(); + this.position = es.Vector2.lerp(this.position, es.Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); + this.entity.transform.roundPosition(); + if (this.mapLockEnabled) { + this.position = this.clampToMapSize(this.position); + this.entity.transform.roundPosition(); } - this._componentsToRemove.length = 0; - } - if (this._componentsToAdd.length > 0) { - for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { - var component = this._componentsToAdd[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - this._components.push(component); - this._tempBufferList.push(component); + }; + Camera.prototype.clampToMapSize = function (position) { + var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)); + var cameraMax = new es.Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); + return es.Vector2.clamp(position, halfScreen, cameraMax); + }; + Camera.prototype.updateFollow = function () { + this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; + if (this._cameraStyle == CameraStyle.lockOn) { + var targetX = this._targetEntity.transform.position.x; + var targetY = this._targetEntity.transform.position.y; + if (this._worldSpaceDeadZone.x > targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + else if (this._worldSpaceDeadZone.x < targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + if (this._worldSpaceDeadZone.y < targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + else if (this._worldSpaceDeadZone.y > targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; } - this._componentsToAdd.length = 0; - for (var i = 0; i < this._tempBufferList.length; i++) { - var component = this._tempBufferList[i]; - component.onAddedToEntity(); - if (component.enabled) { - component.onEnabled(); + else { + if (!this._targetCollider) { + this._targetCollider = this._targetEntity.getComponent(es.Collider); + if (!this._targetCollider) + return; + } + var targetBounds = this._targetEntity.getComponent(es.Collider).bounds; + if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { + if (this._worldSpaceDeadZone.left > targetBounds.left) + this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; + else if (this._worldSpaceDeadZone.right < targetBounds.right) + this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; + if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) + this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; + else if (this._worldSpaceDeadZone.top > targetBounds.top) + this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; } } - this._tempBufferList.length = 0; + }; + Camera.prototype.follow = function (targetEntity, cameraStyle) { + if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; } + this._targetEntity = targetEntity; + this._cameraStyle = cameraStyle; + switch (this._cameraStyle) { + case CameraStyle.cameraWindow: + var w = this.bounds.width / 6; + var h = this.bounds.height / 3; + this.deadzone = new es.Rectangle((this.bounds.width - w) / 2, (this.bounds.height - h) / 2, w, h); + break; + case CameraStyle.lockOn: + this.deadzone = new es.Rectangle(this.bounds.width / 2, this.bounds.height / 2, 10, 10); + break; + } + }; + Camera.prototype.setCenteredDeadzone = function (width, height) { + this.deadzone = new es.Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height); + }; + return Camera; + }(es.Component)); + es.Camera = Camera; +})(es || (es = {})); +var es; +(function (es) { + var ComponentPool = (function () { + function ComponentPool(typeClass) { + this._type = typeClass; + this._cache = []; } - }; - ComponentList.prototype.onEntityTransformChanged = function (comp) { - for (var i = 0; i < this._components.length; i++) { - if (this._components[i].enabled) - this._components[i].onEntityTransformChanged(comp); + ComponentPool.prototype.obtain = function () { + try { + return this._cache.length > 0 ? this._cache.shift() : new this._type(); + } + catch (err) { + throw new Error(this._type + err); + } + }; + ComponentPool.prototype.free = function (component) { + component.reset(); + this._cache.push(component); + }; + return ComponentPool; + }()); + es.ComponentPool = ComponentPool; +})(es || (es = {})); +var es; +(function (es) { + var IUpdatableComparer = (function () { + function IUpdatableComparer() { } - for (var i = 0; i < this._componentsToAdd.length; i++) { - if (this._componentsToAdd[i].enabled) - this._componentsToAdd[i].onEntityTransformChanged(comp); + IUpdatableComparer.prototype.compare = function (a, b) { + return a.updateOrder - b.updateOrder; + }; + return IUpdatableComparer; + }()); + es.IUpdatableComparer = IUpdatableComparer; +})(es || (es = {})); +var es; +(function (es) { + var PooledComponent = (function (_super) { + __extends(PooledComponent, _super); + function PooledComponent() { + return _super !== null && _super.apply(this, arguments) || this; } - }; - ComponentList.prototype.handleRemove = function (component) { - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - component.onRemovedFromEntity(); - component.entity = null; - }; - ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof type) - return component; + return PooledComponent; + }(es.Component)); + es.PooledComponent = PooledComponent; +})(es || (es = {})); +var es; +(function (es) { + var RenderableComponent = (function (_super) { + __extends(RenderableComponent, _super); + function RenderableComponent() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.color = 0x000000; + _this._localOffset = es.Vector2.zero; + _this._renderLayer = 0; + _this._bounds = new es.Rectangle(); + _this._areBoundsDirty = true; + return _this; } - if (!onlyReturnInitializedComponents) { - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; + Object.defineProperty(RenderableComponent.prototype, "width", { + get: function () { + return this.bounds.width; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "height", { + get: function () { + return this.bounds.height; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "bounds", { + get: function () { + if (this._areBoundsDirty) { + this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, es.Vector2.zero, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height); + this._areBoundsDirty = false; + } + return this._bounds; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "renderLayer", { + get: function () { + return this._renderLayer; + }, + set: function (value) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "localOffset", { + get: function () { + return this._localOffset; + }, + set: function (value) { + this.setLocalOffset(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "isVisible", { + get: function () { + return this._isVisible; + }, + set: function (value) { + if (this._isVisible != value) { + this._isVisible = value; + if (this._isVisible) + this.onBecameVisible(); + else + this.onBecameInvisible(); + } + }, + enumerable: true, + configurable: true + }); + RenderableComponent.prototype.onEntityTransformChanged = function (comp) { + this._areBoundsDirty = true; + }; + RenderableComponent.prototype.onBecameVisible = function () { + }; + RenderableComponent.prototype.onBecameInvisible = function () { + }; + RenderableComponent.prototype.isVisibleFromCamera = function (camera) { + this.isVisible = camera.bounds.intersects(this.bounds); + return this.isVisible; + }; + RenderableComponent.prototype.setRenderLayer = function (renderLayer) { + if (renderLayer != this._renderLayer) { + var oldRenderLayer = this._renderLayer; + this._renderLayer = renderLayer; + if (this.entity && this.entity.scene) + this.entity.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer); + } + return this; + }; + RenderableComponent.prototype.setColor = function (color) { + this.color = color; + return this; + }; + RenderableComponent.prototype.setLocalOffset = function (offset) { + if (this._localOffset != offset) { + this._localOffset = offset; + } + return this; + }; + RenderableComponent.prototype.toString = function () { + return "[RenderableComponent] " + this + ", renderLayer: " + this.renderLayer; + }; + return RenderableComponent; + }(es.Component)); + es.RenderableComponent = RenderableComponent; +})(es || (es = {})); +var es; +(function (es) { + var Mesh = (function (_super) { + __extends(Mesh, _super); + function Mesh() { + var _this = _super.call(this) || this; + _this._mesh = new egret.Mesh(); + return _this; + } + Mesh.prototype.setTexture = function (texture) { + this._mesh.texture = texture; + return this; + }; + Mesh.prototype.reset = function () { + }; + Mesh.prototype.render = function (camera) { + }; + return Mesh; + }(es.RenderableComponent)); + es.Mesh = Mesh; +})(es || (es = {})); +var es; +(function (es) { + var SpriteRenderer = (function (_super) { + __extends(SpriteRenderer, _super); + function SpriteRenderer(sprite) { + if (sprite === void 0) { sprite = null; } + var _this = _super.call(this) || this; + if (sprite instanceof es.Sprite) + _this.setSprite(sprite); + else if (sprite instanceof egret.Texture) + _this.setSprite(new es.Sprite(sprite)); + return _this; + } + Object.defineProperty(SpriteRenderer.prototype, "bounds", { + get: function () { + if (this._areBoundsDirty) { + if (this._sprite) { + this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.sourceRect.width, this._sprite.sourceRect.height); + this._areBoundsDirty = false; + } + return this._bounds; + } + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteRenderer.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + this.setOrigin(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteRenderer.prototype, "originNormalized", { + get: function () { + return new es.Vector2(this._origin.x / this.width * this.entity.transform.scale.x, this._origin.y / this.height * this.entity.transform.scale.y); + }, + set: function (value) { + this.setOrigin(new es.Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteRenderer.prototype, "sprite", { + get: function () { + return this._sprite; + }, + set: function (value) { + this.setSprite(value); + }, + enumerable: true, + configurable: true + }); + SpriteRenderer.prototype.setSprite = function (sprite) { + this._sprite = sprite; + if (this._sprite) { + this._origin = this._sprite.origin; + } + return this; + }; + SpriteRenderer.prototype.setOrigin = function (origin) { + if (this._origin != origin) { + this._origin = origin; + this._areBoundsDirty = true; + } + return this; + }; + SpriteRenderer.prototype.setOriginNormalized = function (value) { + this.setOrigin(new es.Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y)); + return this; + }; + SpriteRenderer.prototype.render = function (camera) { + }; + return SpriteRenderer; + }(es.RenderableComponent)); + es.SpriteRenderer = SpriteRenderer; +})(es || (es = {})); +var es; +(function (es) { + var TiledSpriteRenderer = (function (_super) { + __extends(TiledSpriteRenderer, _super); + function TiledSpriteRenderer(sprite) { + var _this = _super.call(this, sprite) || this; + _this.leftTexture = new egret.Bitmap(); + _this.rightTexture = new egret.Bitmap(); + _this.leftTexture.texture = sprite.texture2D; + _this.rightTexture.texture = sprite.texture2D; + _this.setSprite(sprite); + _this.sourceRect = sprite.sourceRect; + return _this; + } + Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", { + get: function () { + return this.sourceRect.x; + }, + set: function (value) { + this.sourceRect.x = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", { + get: function () { + return this.sourceRect.y; + }, + set: function (value) { + this.sourceRect.y = value; + }, + enumerable: true, + configurable: true + }); + TiledSpriteRenderer.prototype.render = function (camera) { + if (!this.sprite) + return; + _super.prototype.render.call(this, camera); + var renderTexture = new egret.RenderTexture(); + var cacheBitmap = new egret.DisplayObjectContainer(); + cacheBitmap.removeChildren(); + cacheBitmap.addChild(this.leftTexture); + cacheBitmap.addChild(this.rightTexture); + this.leftTexture.x = this.sourceRect.x; + this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; + this.leftTexture.y = this.sourceRect.y; + this.rightTexture.y = this.sourceRect.y; + cacheBitmap.cacheAsBitmap = true; + renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); + }; + return TiledSpriteRenderer; + }(es.SpriteRenderer)); + es.TiledSpriteRenderer = TiledSpriteRenderer; +})(es || (es = {})); +var es; +(function (es) { + var ScrollingSpriteRenderer = (function (_super) { + __extends(ScrollingSpriteRenderer, _super); + function ScrollingSpriteRenderer() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.scrollSpeedX = 15; + _this.scroolSpeedY = 0; + _this._scrollX = 0; + _this._scrollY = 0; + return _this; + } + ScrollingSpriteRenderer.prototype.update = function () { + this._scrollX += this.scrollSpeedX * es.Time.deltaTime; + this._scrollY += this.scroolSpeedY * es.Time.deltaTime; + this.sourceRect.x = this._scrollX; + this.sourceRect.y = this._scrollY; + }; + ScrollingSpriteRenderer.prototype.render = function (camera) { + if (!this.sprite) + return; + _super.prototype.render.call(this, camera); + var renderTexture = new egret.RenderTexture(); + var cacheBitmap = new egret.DisplayObjectContainer(); + cacheBitmap.removeChildren(); + cacheBitmap.addChild(this.leftTexture); + cacheBitmap.addChild(this.rightTexture); + this.leftTexture.x = this.sourceRect.x; + this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; + this.leftTexture.y = this.sourceRect.y; + this.rightTexture.y = this.sourceRect.y; + cacheBitmap.cacheAsBitmap = true; + renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); + }; + return ScrollingSpriteRenderer; + }(es.TiledSpriteRenderer)); + es.ScrollingSpriteRenderer = ScrollingSpriteRenderer; +})(es || (es = {})); +var es; +(function (es) { + var Sprite = (function () { + function Sprite(texture, sourceRect, origin) { + if (sourceRect === void 0) { sourceRect = new es.Rectangle(0, 0, texture.textureWidth, texture.textureHeight); } + if (origin === void 0) { origin = sourceRect.getHalfSize(); } + this.uvs = new es.Rectangle(); + this.texture2D = texture; + this.sourceRect = sourceRect; + this.center = new es.Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); + this.origin = origin; + var inverseTexW = 1 / texture.textureWidth; + var inverseTexH = 1 / texture.textureHeight; + this.uvs.x = sourceRect.x * inverseTexW; + this.uvs.y = sourceRect.y * inverseTexH; + this.uvs.width = sourceRect.width * inverseTexW; + this.uvs.height = sourceRect.height * inverseTexH; + } + return Sprite; + }()); + es.Sprite = Sprite; +})(es || (es = {})); +var es; +(function (es) { + var SpriteAnimation = (function () { + function SpriteAnimation(sprites, frameRate) { + this.sprites = sprites; + this.frameRate = frameRate; + } + return SpriteAnimation; + }()); + es.SpriteAnimation = SpriteAnimation; +})(es || (es = {})); +var es; +(function (es) { + var LoopMode; + (function (LoopMode) { + LoopMode[LoopMode["loop"] = 0] = "loop"; + LoopMode[LoopMode["once"] = 1] = "once"; + LoopMode[LoopMode["clampForever"] = 2] = "clampForever"; + LoopMode[LoopMode["pingPong"] = 3] = "pingPong"; + LoopMode[LoopMode["pingPongOnce"] = 4] = "pingPongOnce"; + })(LoopMode = es.LoopMode || (es.LoopMode = {})); + var State; + (function (State) { + State[State["none"] = 0] = "none"; + State[State["running"] = 1] = "running"; + State[State["paused"] = 2] = "paused"; + State[State["completed"] = 3] = "completed"; + })(State = es.State || (es.State = {})); + var SpriteAnimator = (function (_super) { + __extends(SpriteAnimator, _super); + function SpriteAnimator(sprite) { + var _this = _super.call(this, sprite) || this; + _this.speed = 1; + _this.animationState = State.none; + _this._animations = new Map(); + _this._elapsedTime = 0; + return _this; + } + Object.defineProperty(SpriteAnimator.prototype, "isRunning", { + get: function () { + return this.animationState == State.running; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteAnimator.prototype, "animations", { + get: function () { + return this._animations; + }, + enumerable: true, + configurable: true + }); + SpriteAnimator.prototype.update = function () { + if (this.animationState != State.running || !this.currentAnimation) + return; + var animation = this.currentAnimation; + var secondsPerFrame = 1 / (animation.frameRate * this.speed); + var iterationDuration = secondsPerFrame * animation.sprites.length; + this._elapsedTime += es.Time.deltaTime; + var time = Math.abs(this._elapsedTime); + if (this._loopMode == LoopMode.once && time > iterationDuration || + this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) { + this.animationState = State.completed; + this._elapsedTime = 0; + this.currentFrame = 0; + this.sprite = animation.sprites[this.currentFrame]; + return; + } + var i = Math.floor(time / secondsPerFrame); + var n = animation.sprites.length; + if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) { + var maxIndex = n - 1; + this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2)); + } + else { + this.currentFrame = i % n; + } + this.sprite = animation.sprites[this.currentFrame]; + }; + SpriteAnimator.prototype.addAnimation = function (name, animation) { + if (!this.sprite && animation.sprites.length > 0) + this.setSprite(animation.sprites[0]); + this._animations[name] = animation; + return this; + }; + SpriteAnimator.prototype.play = function (name, loopMode) { + if (loopMode === void 0) { loopMode = null; } + this.currentAnimation = this._animations[name]; + this.currentAnimationName = name; + this.currentFrame = 0; + this.animationState = State.running; + this.sprite = this.currentAnimation.sprites[0]; + this._elapsedTime = 0; + this._loopMode = loopMode ? loopMode : LoopMode.loop; + }; + SpriteAnimator.prototype.isAnimationActive = function (name) { + return this.currentAnimation && this.currentAnimationName == name; + }; + SpriteAnimator.prototype.pause = function () { + this.animationState = State.paused; + }; + SpriteAnimator.prototype.unPause = function () { + this.animationState = State.running; + }; + SpriteAnimator.prototype.stop = function () { + this.currentAnimation = null; + this.currentAnimationName = null; + this.currentFrame = 0; + this.animationState = State.none; + }; + return SpriteAnimator; + }(es.SpriteRenderer)); + es.SpriteAnimator = SpriteAnimator; +})(es || (es = {})); +var es; +(function (es) { + var Mover = (function (_super) { + __extends(Mover, _super); + function Mover() { + return _super !== null && _super.apply(this, arguments) || this; + } + Mover.prototype.onAddedToEntity = function () { + this._triggerHelper = new es.ColliderTriggerHelper(this.entity); + }; + Mover.prototype.calculateMovement = function (motion) { + var collisionResult = new es.CollisionResult(); + if (!this.entity.getComponent(es.Collider) || !this._triggerHelper) { + return null; + } + var colliders = this.entity.getComponents(es.Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + if (collider.isTrigger) + continue; + var bounds = collider.bounds; + bounds.x += motion.x; + bounds.y += motion.y; + var boxcastResult = es.Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); + bounds = boxcastResult.bounds; + var neighbors = boxcastResult.tempHashSet; + for (var j = 0; j < neighbors.length; j++) { + var neighbor = neighbors[j]; + if (neighbor.isTrigger) + continue; + var _internalcollisionResult = collider.collidesWith(neighbor, motion); + if (_internalcollisionResult) { + motion = es.Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); + if (_internalcollisionResult.collider) { + collisionResult = _internalcollisionResult; + } + } + } + } + es.ListPool.free(colliders); + return { collisionResult: collisionResult, motion: motion }; + }; + Mover.prototype.applyMovement = function (motion) { + this.entity.position = es.Vector2.add(this.entity.position, motion); + if (this._triggerHelper) + this._triggerHelper.update(); + }; + Mover.prototype.move = function (motion) { + var movementResult = this.calculateMovement(motion); + var collisionResult = movementResult.collisionResult; + motion = movementResult.motion; + this.applyMovement(motion); + return collisionResult; + }; + return Mover; + }(es.Component)); + es.Mover = Mover; +})(es || (es = {})); +var es; +(function (es) { + var ProjectileMover = (function (_super) { + __extends(ProjectileMover, _super); + function ProjectileMover() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._tempTriggerList = []; + return _this; + } + ProjectileMover.prototype.onAddedToEntity = function () { + this._collider = this.entity.getComponent(es.Collider); + if (!this._collider) + console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!"); + }; + ProjectileMover.prototype.move = function (motion) { + if (!this._collider) + return false; + var didCollide = false; + this.entity.position = es.Vector2.add(this.entity.position, motion); + var neighbors = es.Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); + for (var i = 0; i < neighbors.colliders.length; i++) { + var neighbor = neighbors.colliders[i]; + if (this._collider.overlaps(neighbor) && neighbor.enabled) { + didCollide = true; + this.notifyTriggerListeners(this._collider, neighbor); + } + } + return didCollide; + }; + ProjectileMover.prototype.notifyTriggerListeners = function (self, other) { + other.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + this._tempTriggerList[i].onTriggerEnter(self, other); + } + this._tempTriggerList.length = 0; + this.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + this._tempTriggerList[i].onTriggerEnter(other, self); + } + this._tempTriggerList.length = 0; + }; + return ProjectileMover; + }(es.Component)); + es.ProjectileMover = ProjectileMover; +})(es || (es = {})); +var es; +(function (es) { + var Collider = (function (_super) { + __extends(Collider, _super); + function Collider() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.physicsLayer = 1 << 0; + _this.collidesWithLayers = es.Physics.allLayers; + _this.shouldColliderScaleAndRotateWithTransform = true; + _this.registeredPhysicsBounds = new es.Rectangle(); + _this._localOffset = es.Vector2.zero; + return _this; + } + Object.defineProperty(Collider.prototype, "localOffset", { + get: function () { + return this._localOffset; + }, + set: function (value) { + this.setLocalOffset(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "absolutePosition", { + get: function () { + return es.Vector2.add(this.entity.transform.position, this._localOffset); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "rotation", { + get: function () { + if (this.shouldColliderScaleAndRotateWithTransform && this.entity) + return this.entity.transform.rotation; + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "bounds", { + get: function () { + this.shape.recalculateBounds(this); + return this.shape.bounds; + }, + enumerable: true, + configurable: true + }); + Collider.prototype.setLocalOffset = function (offset) { + if (this._localOffset != offset) { + this.unregisterColliderWithPhysicsSystem(); + this._localOffset = offset; + this._localOffsetLength = this._localOffset.length(); + this.registerColliderWithPhysicsSystem(); + } + return this; + }; + Collider.prototype.setShouldColliderScaleAndRotateWithTransform = function (shouldColliderScaleAndRotationWithTransform) { + this.shouldColliderScaleAndRotateWithTransform = shouldColliderScaleAndRotationWithTransform; + return this; + }; + Collider.prototype.onAddedToEntity = function () { + if (this._colliderRequiresAutoSizing) { + if (!(this instanceof es.BoxCollider || this instanceof es.CircleCollider)) { + console.error("Only box and circle colliders can be created automatically"); + return; + } + var renderable = this.entity.getComponent(es.RenderableComponent); + if (renderable) { + var bounds = renderable.bounds; + var width = bounds.width / this.entity.scale.x; + var height = bounds.height / this.entity.scale.y; + if (this instanceof es.CircleCollider) { + var circleCollider = this; + circleCollider.radius = Math.max(width, height) * 0.5; + } + else { + this.width = width; + this.height = height; + } + this.localOffset = es.Vector2.subtract(bounds.center, this.entity.transform.position); + } + else { + console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); + } + } + this._isParentEntityAddedToScene = true; + this.registerColliderWithPhysicsSystem(); + }; + Collider.prototype.onRemovedFromEntity = function () { + this.unregisterColliderWithPhysicsSystem(); + this._isParentEntityAddedToScene = false; + }; + Collider.prototype.onEntityTransformChanged = function (comp) { + if (this._isColliderRegistered) + es.Physics.updateCollider(this); + }; + Collider.prototype.onEnabled = function () { + this.registerColliderWithPhysicsSystem(); + }; + Collider.prototype.onDisabled = function () { + this.unregisterColliderWithPhysicsSystem(); + }; + Collider.prototype.registerColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { + es.Physics.addCollider(this); + this._isColliderRegistered = true; + } + }; + Collider.prototype.unregisterColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && this._isColliderRegistered) { + es.Physics.removeCollider(this); + } + this._isColliderRegistered = false; + }; + Collider.prototype.overlaps = function (other) { + return this.shape.overlaps(other.shape); + }; + Collider.prototype.collidesWith = function (collider, motion) { + var oldPosition = this.entity.position; + this.entity.position = es.Vector2.add(this.entity.position, motion); + var result = this.shape.collidesWithShape(collider.shape); + if (result) + result.collider = collider; + this.entity.position = oldPosition; + return result; + }; + return Collider; + }(es.Component)); + es.Collider = Collider; +})(es || (es = {})); +var es; +(function (es) { + var BoxCollider = (function (_super) { + __extends(BoxCollider, _super); + function BoxCollider() { + var _this = _super.call(this) || this; + _this.shape = new es.Box(1, 1); + _this._colliderRequiresAutoSizing = true; + return _this; + } + Object.defineProperty(BoxCollider.prototype, "width", { + get: function () { + return this.shape.width; + }, + set: function (value) { + this.setWidth(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BoxCollider.prototype, "height", { + get: function () { + return this.shape.height; + }, + set: function (value) { + this.setHeight(value); + }, + enumerable: true, + configurable: true + }); + BoxCollider.prototype.setSize = function (width, height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width || height != box.height) { + box.updateBox(width, height); + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + return this; + }; + BoxCollider.prototype.setWidth = function (width) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width) { + box.updateBox(width, box.height); + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + return this; + }; + BoxCollider.prototype.setHeight = function (height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (height != box.height) { + box.updateBox(box.width, height); + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + }; + BoxCollider.prototype.toString = function () { + return "[BoxCollider: bounds: " + this.bounds + "]"; + }; + return BoxCollider; + }(es.Collider)); + es.BoxCollider = BoxCollider; +})(es || (es = {})); +var es; +(function (es) { + var CircleCollider = (function (_super) { + __extends(CircleCollider, _super); + function CircleCollider(radius) { + var _this = _super.call(this) || this; + if (radius) + _this._colliderRequiresAutoSizing = true; + _this.shape = new es.Circle(radius ? radius : 1); + return _this; + } + Object.defineProperty(CircleCollider.prototype, "radius", { + get: function () { + return this.shape.radius; + }, + set: function (value) { + this.setRadius(value); + }, + enumerable: true, + configurable: true + }); + CircleCollider.prototype.setRadius = function (radius) { + this._colliderRequiresAutoSizing = false; + var circle = this.shape; + if (radius != circle.radius) { + circle.radius = radius; + circle._originalRadius = radius; + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + return this; + }; + CircleCollider.prototype.toString = function () { + return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]"; + }; + return CircleCollider; + }(es.Collider)); + es.CircleCollider = CircleCollider; +})(es || (es = {})); +var es; +(function (es) { + var PolygonCollider = (function (_super) { + __extends(PolygonCollider, _super); + function PolygonCollider(points) { + var _this = _super.call(this) || this; + var isPolygonClosed = points[0] == points[points.length - 1]; + if (isPolygonClosed) + points.splice(points.length - 1, 1); + var center = es.Polygon.findPolygonCenter(points); + _this.setLocalOffset(center); + es.Polygon.recenterPolygonVerts(points); + _this.shape = new es.Polygon(points); + return _this; + } + return PolygonCollider; + }(es.Collider)); + es.PolygonCollider = PolygonCollider; +})(es || (es = {})); +var es; +(function (es) { + var EntitySystem = (function () { + function EntitySystem(matcher) { + this._entities = []; + this._matcher = matcher ? matcher : es.Matcher.empty(); + } + Object.defineProperty(EntitySystem.prototype, "matcher", { + get: function () { + return this._matcher; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(EntitySystem.prototype, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + this._scene = value; + this._entities = []; + }, + enumerable: true, + configurable: true + }); + EntitySystem.prototype.initialize = function () { + }; + EntitySystem.prototype.onChanged = function (entity) { + var contains = this._entities.contains(entity); + var interest = this._matcher.IsIntersted(entity); + if (interest && !contains) + this.add(entity); + else if (!interest && contains) + this.remove(entity); + }; + EntitySystem.prototype.add = function (entity) { + this._entities.push(entity); + this.onAdded(entity); + }; + EntitySystem.prototype.onAdded = function (entity) { + }; + EntitySystem.prototype.remove = function (entity) { + this._entities.remove(entity); + this.onRemoved(entity); + }; + EntitySystem.prototype.onRemoved = function (entity) { + }; + EntitySystem.prototype.update = function () { + this.begin(); + this.process(this._entities); + }; + EntitySystem.prototype.lateUpdate = function () { + this.lateProcess(this._entities); + this.end(); + }; + EntitySystem.prototype.begin = function () { + }; + EntitySystem.prototype.process = function (entities) { + }; + EntitySystem.prototype.lateProcess = function (entities) { + }; + EntitySystem.prototype.end = function () { + }; + return EntitySystem; + }()); + es.EntitySystem = EntitySystem; +})(es || (es = {})); +var es; +(function (es) { + var EntityProcessingSystem = (function (_super) { + __extends(EntityProcessingSystem, _super); + function EntityProcessingSystem(matcher) { + return _super.call(this, matcher) || this; + } + EntityProcessingSystem.prototype.lateProcessEntity = function (entity) { + }; + EntityProcessingSystem.prototype.process = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.processEntity(entity); }); + }; + EntityProcessingSystem.prototype.lateProcess = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.lateProcessEntity(entity); }); + }; + return EntityProcessingSystem; + }(es.EntitySystem)); + es.EntityProcessingSystem = EntityProcessingSystem; +})(es || (es = {})); +var es; +(function (es) { + var PassiveSystem = (function (_super) { + __extends(PassiveSystem, _super); + function PassiveSystem() { + return _super !== null && _super.apply(this, arguments) || this; + } + PassiveSystem.prototype.onChanged = function (entity) { + }; + PassiveSystem.prototype.process = function (entities) { + this.begin(); + this.end(); + }; + return PassiveSystem; + }(es.EntitySystem)); + es.PassiveSystem = PassiveSystem; +})(es || (es = {})); +var es; +(function (es) { + var ProcessingSystem = (function (_super) { + __extends(ProcessingSystem, _super); + function ProcessingSystem() { + return _super !== null && _super.apply(this, arguments) || this; + } + ProcessingSystem.prototype.onChanged = function (entity) { + }; + ProcessingSystem.prototype.process = function (entities) { + this.begin(); + this.processSystem(); + this.end(); + }; + return ProcessingSystem; + }(es.EntitySystem)); + es.ProcessingSystem = ProcessingSystem; +})(es || (es = {})); +var es; +(function (es) { + var BitSet = (function () { + function BitSet(nbits) { + if (nbits === void 0) { nbits = 64; } + var length = nbits >> 6; + if ((nbits & BitSet.LONG_MASK) != 0) + length++; + this._bits = new Array(length); + } + BitSet.prototype.and = function (bs) { + var max = Math.min(this._bits.length, bs._bits.length); + var i; + for (var i_1 = 0; i_1 < max; ++i_1) + this._bits[i_1] &= bs._bits[i_1]; + while (i < this._bits.length) + this._bits[i++] = 0; + }; + BitSet.prototype.andNot = function (bs) { + var i = Math.min(this._bits.length, bs._bits.length); + while (--i >= 0) + this._bits[i] &= ~bs._bits[i]; + }; + BitSet.prototype.cardinality = function () { + var card = 0; + for (var i = this._bits.length - 1; i >= 0; i--) { + var a = this._bits[i]; + if (a == 0) + continue; + if (a == -1) { + card += 64; + continue; + } + a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); + a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); + var b = ((a >> 32) + a); + b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); + b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); + card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); + } + return card; + }; + BitSet.prototype.clear = function (pos) { + if (pos != undefined) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] &= ~(1 << pos); + } + else { + for (var i = 0; i < this._bits.length; i++) + this._bits[i] = 0; + } + }; + BitSet.prototype.ensure = function (lastElt) { + if (lastElt >= this._bits.length) { + var nd = new Number[lastElt + 1]; + nd = this._bits.copyWithin(0, 0, this._bits.length); + this._bits = nd; + } + }; + BitSet.prototype.get = function (pos) { + var offset = pos >> 6; + if (offset >= this._bits.length) + return false; + return (this._bits[offset] & (1 << pos)) != 0; + }; + BitSet.prototype.intersects = function (set) { + var i = Math.min(this._bits.length, set._bits.length); + while (--i >= 0) { + if ((this._bits[i] & set._bits[i]) != 0) + return true; + } + return false; + }; + BitSet.prototype.isEmpty = function () { + for (var i = this._bits.length - 1; i >= 0; i--) { + if (this._bits[i]) + return false; + } + return true; + }; + BitSet.prototype.nextSetBit = function (from) { + var offset = from >> 6; + var mask = 1 << from; + while (offset < this._bits.length) { + var h = this._bits[offset]; + do { + if ((h & mask) != 0) + return from; + mask <<= 1; + from++; + } while (mask != 0); + mask = 1; + offset++; + } + return -1; + }; + BitSet.prototype.set = function (pos, value) { + if (value === void 0) { value = true; } + if (value) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] |= 1 << pos; + } + else { + this.clear(pos); + } + }; + BitSet.LONG_MASK = 0x3f; + return BitSet; + }()); + es.BitSet = BitSet; +})(es || (es = {})); +var es; +(function (es) { + var ComponentList = (function () { + function ComponentList(entity) { + this._components = []; + this._componentsToAdd = []; + this._componentsToRemove = []; + this._tempBufferList = []; + this._entity = entity; + } + Object.defineProperty(ComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(ComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true + }); + ComponentList.prototype.markEntityListUnsorted = function () { + this._isComponentListUnsorted = true; + }; + ComponentList.prototype.add = function (component) { + this._componentsToAdd.push(component); + }; + ComponentList.prototype.remove = function (component) { + if (this._componentsToRemove.contains(component)) + console.warn("You are trying to remove a Component (" + component + ") that you already removed"); + if (this._componentsToAdd.contains(component)) { + this._componentsToAdd.remove(component); + return; + } + this._componentsToRemove.push(component); + }; + ComponentList.prototype.removeAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + this.handleRemove(this._components[i]); + } + this._components.length = 0; + this._componentsToAdd.length = 0; + this._componentsToRemove.length = 0; + }; + ComponentList.prototype.deregisterAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + } + }; + ComponentList.prototype.registerAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + } + }; + ComponentList.prototype.updateLists = function () { + if (this._componentsToRemove.length > 0) { + for (var i = 0; i < this._componentsToRemove.length; i++) { + this.handleRemove(this._componentsToRemove[i]); + this._components.remove(this._componentsToRemove[i]); + } + this._componentsToRemove.length = 0; + } + if (this._componentsToAdd.length > 0) { + for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + this._components.push(component); + this._tempBufferList.push(component); + } + this._componentsToAdd.length = 0; + this._isComponentListUnsorted = true; + for (var i = 0; i < this._tempBufferList.length; i++) { + var component = this._tempBufferList[i]; + component.onAddedToEntity(); + if (component.enabled) { + component.onEnabled(); + } + } + this._tempBufferList.length = 0; + } + if (this._isComponentListUnsorted) { + this._components.sort(ComponentList.compareUpdatableOrder.compare); + this._isComponentListUnsorted = false; + } + }; + ComponentList.prototype.handleRemove = function (component) { + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + component.onRemovedFromEntity(); + component.entity = null; + }; + ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; if (component instanceof type) return component; } - } - return null; - }; - ComponentList.prototype.getComponents = function (typeName, components) { - if (!components) - components = []; - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (typeof (typeName) == "string") { - if (egret.is(component, typeName)) { - components.push(component); + if (!onlyReturnInitializedComponents) { + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof type) + return component; } } - else { - if (component instanceof typeName) { - components.push(component); + return null; + }; + ComponentList.prototype.getComponents = function (typeName, components) { + if (!components) + components = []; + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } } } - } - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; - if (typeof (typeName) == "string") { - if (egret.is(component, typeName)) { - components.push(component); + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } } } - else { - if (component instanceof typeName) { - components.push(component); - } + return components; + }; + ComponentList.prototype.update = function () { + this.updateLists(); + for (var i = 0; i < this._components.length; i++) { + var updatableComponent = this._components[i]; + if (updatableComponent.enabled && + (updatableComponent.updateInterval == 1 || + es.Time.frameCount % updatableComponent.updateInterval == 0)) + updatableComponent.update(); } - } - return components; - }; - ComponentList.prototype.update = function () { - this.updateLists(); - for (var i = 0; i < this._components.length; i++) { - var updatable = this._components[i]; - var updateableComponent = void 0; - if (updatable instanceof Component) - updateableComponent = updatable; - if (updatable.enabled && - updateableComponent.enabled && - (updateableComponent.updateInterval == 1 || - Time.frameCount % updateableComponent.updateInterval == 0)) - updatable.update(); - } - }; - return ComponentList; -}()); -var ComponentTypeManager = (function () { - function ComponentTypeManager() { - } - ComponentTypeManager.add = function (type) { - if (!this._componentTypesMask.has(type)) - this._componentTypesMask[type] = this._componentTypesMask.size; - }; - ComponentTypeManager.getIndexFor = function (type) { - var v = -1; - if (!this._componentTypesMask.has(type)) { - this.add(type); - v = this._componentTypesMask.get(type); - } - return v; - }; - ComponentTypeManager._componentTypesMask = new Map(); - return ComponentTypeManager; -}()); -var EntityList = (function () { - function EntityList(scene) { - this._entitiesToRemove = []; - this._entitiesToAdded = []; - this._tempEntityList = []; - this._entities = []; - this._entityDict = new Map(); - this._unsortedTags = []; - this.scene = scene; - } - Object.defineProperty(EntityList.prototype, "count", { - get: function () { - return this._entities.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(EntityList.prototype, "buffer", { - get: function () { - return this._entities; - }, - enumerable: true, - configurable: true - }); - EntityList.prototype.add = function (entity) { - if (this._entitiesToAdded.indexOf(entity) == -1) - this._entitiesToAdded.push(entity); - }; - EntityList.prototype.remove = function (entity) { - if (this._entitiesToAdded.contains(entity)) { - this._entitiesToAdded.remove(entity); - return; - } - if (!this._entitiesToRemove.contains(entity)) - this._entitiesToRemove.push(entity); - }; - EntityList.prototype.findEntity = function (name) { - for (var i = 0; i < this._entities.length; i++) { - if (this._entities[i].name == name) - return this._entities[i]; - } - return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; }); - }; - EntityList.prototype.getTagList = function (tag) { - var list = this._entityDict.get(tag); - if (!list) { - list = []; - this._entityDict.set(tag, list); - } - return this._entityDict.get(tag); - }; - EntityList.prototype.addToTagList = function (entity) { - var list = this.getTagList(entity.tag); - if (!list.contains(entity)) { - list.push(entity); - this._unsortedTags.push(entity.tag); - } - }; - EntityList.prototype.removeFromTagList = function (entity) { - var list = this._entityDict.get(entity.tag); - if (list) { - list.remove(entity); - } - }; - EntityList.prototype.update = function () { - for (var i = 0; i < this._entities.length; i++) { - var entity = this._entities[i]; - if (entity.enabled) - entity.update(); - } - }; - EntityList.prototype.removeAllEntities = function () { - this._entitiesToAdded.length = 0; - this.updateLists(); - for (var i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestoryed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; - } - this._entities.length = 0; - this._entityDict.clear(); - }; - EntityList.prototype.updateLists = function () { - var _this = this; - if (this._entitiesToRemove.length > 0) { - var temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - _this._entities.remove(entity); - entity.scene = null; - _this.scene.entityProcessors.onEntityRemoved(entity); - }); - this._tempEntityList.length = 0; - } - if (this._entitiesToAdded.length > 0) { - var temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - if (!_this._entities.contains(entity)) { - _this._entities.push(entity); - entity.scene = _this.scene; - _this.scene.entityProcessors.onEntityAdded(entity); - } - }); - this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); - this._tempEntityList.length = 0; - } - if (this._unsortedTags.length > 0) { - this._unsortedTags.forEach(function (tag) { - _this._entityDict.get(tag).sort(); - }); - this._unsortedTags.length = 0; - } - }; - return EntityList; -}()); -var EntityProcessorList = (function () { - function EntityProcessorList() { - this._processors = []; - } - EntityProcessorList.prototype.add = function (processor) { - this._processors.push(processor); - }; - EntityProcessorList.prototype.remove = function (processor) { - this._processors.remove(processor); - }; - EntityProcessorList.prototype.onComponentAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onComponentRemoved = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityRemoved = function (entity) { - this.removeFromProcessors(entity); - }; - EntityProcessorList.prototype.notifyEntityChanged = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].onChanged(entity); - } - }; - EntityProcessorList.prototype.removeFromProcessors = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].remove(entity); - } - }; - EntityProcessorList.prototype.begin = function () { - }; - EntityProcessorList.prototype.update = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].update(); - } - }; - EntityProcessorList.prototype.lateUpdate = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].lateUpdate(); - } - }; - EntityProcessorList.prototype.end = function () { - }; - EntityProcessorList.prototype.getProcessor = function () { - for (var i = 0; i < this._processors.length; i++) { - var processor = this._processors[i]; - if (processor instanceof EntitySystem) - return processor; - } - return null; - }; - return EntityProcessorList; -}()); -var Matcher = (function () { - function Matcher() { - this.allSet = new BitSet(); - this.exclusionSet = new BitSet(); - this.oneSet = new BitSet(); - } - Matcher.empty = function () { - return new Matcher(); - }; - Matcher.prototype.getAllSet = function () { - return this.allSet; - }; - Matcher.prototype.getExclusionSet = function () { - return this.exclusionSet; - }; - Matcher.prototype.getOneSet = function () { - return this.oneSet; - }; - Matcher.prototype.IsIntersted = function (e) { - if (!this.allSet.isEmpty()) { - for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { - if (!e.componentBits.get(i)) - return false; + }; + ComponentList.prototype.onEntityTransformChanged = function (comp) { + for (var i = 0; i < this._components.length; i++) { + if (this._components[i].enabled) + this._components[i].onEntityTransformChanged(comp); } + for (var i = 0; i < this._componentsToAdd.length; i++) { + if (this._componentsToAdd[i].enabled) + this._componentsToAdd[i].onEntityTransformChanged(comp); + } + }; + ComponentList.prototype.onEntityEnabled = function () { + for (var i = 0; i < this._components.length; i++) + this._components[i].onEnabled(); + }; + ComponentList.prototype.onEntityDisabled = function () { + for (var i = 0; i < this._components.length; i++) + this._components[i].onDisabled(); + }; + ComponentList.compareUpdatableOrder = new es.IUpdatableComparer(); + return ComponentList; + }()); + es.ComponentList = ComponentList; +})(es || (es = {})); +var es; +(function (es) { + var ComponentTypeManager = (function () { + function ComponentTypeManager() { } - if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) - return false; - if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) - return false; - return true; - }; - Matcher.prototype.all = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + ComponentTypeManager.add = function (type) { + if (!this._componentTypesMask.has(type)) + this._componentTypesMask[type] = this._componentTypesMask.size; + }; + ComponentTypeManager.getIndexFor = function (type) { + var v = -1; + if (!this._componentTypesMask.has(type)) { + this.add(type); + v = this._componentTypesMask.get(type); + } + return v; + }; + ComponentTypeManager._componentTypesMask = new Map(); + return ComponentTypeManager; + }()); + es.ComponentTypeManager = ComponentTypeManager; +})(es || (es = {})); +var es; +(function (es) { + var EntityList = (function () { + function EntityList(scene) { + this._entitiesToRemove = []; + this._entitiesToAdded = []; + this._tempEntityList = []; + this._entities = []; + this._entityDict = new Map(); + this._unsortedTags = []; + this.scene = scene; } - types.forEach(function (type) { - _this.allSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(EntityList.prototype, "count", { + get: function () { + return this._entities.length; + }, + enumerable: true, + configurable: true }); - return this; - }; - Matcher.prototype.exclude = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; - } - types.forEach(function (type) { - _this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(EntityList.prototype, "buffer", { + get: function () { + return this._entities; + }, + enumerable: true, + configurable: true }); - return this; - }; - Matcher.prototype.one = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + EntityList.prototype.add = function (entity) { + if (this._entitiesToAdded.indexOf(entity) == -1) + this._entitiesToAdded.push(entity); + }; + EntityList.prototype.remove = function (entity) { + if (this._entitiesToAdded.contains(entity)) { + this._entitiesToAdded.remove(entity); + return; + } + if (!this._entitiesToRemove.contains(entity)) + this._entitiesToRemove.push(entity); + }; + EntityList.prototype.findEntity = function (name) { + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].name == name) + return this._entities[i]; + } + return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; }); + }; + EntityList.prototype.entitiesWithTag = function (tag) { + var list = this.getTagList(tag); + var returnList = es.ListPool.obtain(); + for (var i = 0; i < list.length; i++) + returnList.push(list[i]); + return returnList; + }; + EntityList.prototype.entitiesOfType = function (type) { + var list = es.ListPool.obtain(); + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i] instanceof type) + list.push(this._entities[i]); + } + this._entitiesToAdded.forEach(function (entity) { + if (entity instanceof type) + list.push(entity); + }); + return list; + }; + EntityList.prototype.findComponentOfType = function (type) { + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].enabled) { + var comp = this._entities[i].getComponent(type); + if (comp) + return comp; + } + } + for (var i = 0; i < this._entitiesToAdded.length; i++) { + var entity = this._entitiesToAdded[i]; + if (entity.enabled) { + var comp = entity.getComponent(type); + if (comp) + return comp; + } + } + return null; + }; + EntityList.prototype.findComponentsOfType = function (type) { + var comps = es.ListPool.obtain(); + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].enabled) + this._entities[i].getComponents(type, comps); + } + for (var i = 0; i < this._entitiesToAdded.length; i++) { + var entity = this._entitiesToAdded[i]; + if (entity.enabled) + entity.getComponents(type, comps); + } + return comps; + }; + EntityList.prototype.getTagList = function (tag) { + var list = this._entityDict.get(tag); + if (!list) { + list = []; + this._entityDict.set(tag, list); + } + return this._entityDict.get(tag); + }; + EntityList.prototype.addToTagList = function (entity) { + var list = this.getTagList(entity.tag); + if (!list.contains(entity)) { + list.push(entity); + this._unsortedTags.push(entity.tag); + } + }; + EntityList.prototype.removeFromTagList = function (entity) { + var list = this._entityDict.get(entity.tag); + if (list) { + list.remove(entity); + } + }; + EntityList.prototype.update = function () { + for (var i = 0; i < this._entities.length; i++) { + var entity = this._entities[i]; + if (entity.enabled) + entity.update(); + } + }; + EntityList.prototype.removeAllEntities = function () { + this._entitiesToAdded.length = 0; + this.updateLists(); + for (var i = 0; i < this._entities.length; i++) { + this._entities[i]._isDestroyed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + this._entities.length = 0; + this._entityDict.clear(); + }; + EntityList.prototype.updateLists = function () { + var _this = this; + if (this._entitiesToRemove.length > 0) { + var temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + _this._entities.remove(entity); + entity.scene = null; + _this.scene.entityProcessors.onEntityRemoved(entity); + }); + this._tempEntityList.length = 0; + } + if (this._entitiesToAdded.length > 0) { + var temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + if (!_this._entities.contains(entity)) { + _this._entities.push(entity); + entity.scene = _this.scene; + _this.scene.entityProcessors.onEntityAdded(entity); + } + }); + this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); + this._tempEntityList.length = 0; + } + if (this._unsortedTags.length > 0) { + this._unsortedTags.forEach(function (tag) { + _this._entityDict.get(tag).sort(); + }); + this._unsortedTags.length = 0; + } + }; + return EntityList; + }()); + es.EntityList = EntityList; +})(es || (es = {})); +var es; +(function (es) { + var EntityProcessorList = (function () { + function EntityProcessorList() { + this._processors = []; } - types.forEach(function (type) { - _this.oneSet.set(ComponentTypeManager.getIndexFor(type)); - }); - return this; - }; - return Matcher; -}()); + EntityProcessorList.prototype.add = function (processor) { + this._processors.push(processor); + }; + EntityProcessorList.prototype.remove = function (processor) { + this._processors.remove(processor); + }; + EntityProcessorList.prototype.onComponentAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onComponentRemoved = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityRemoved = function (entity) { + this.removeFromProcessors(entity); + }; + EntityProcessorList.prototype.notifyEntityChanged = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].onChanged(entity); + } + }; + EntityProcessorList.prototype.removeFromProcessors = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].remove(entity); + } + }; + EntityProcessorList.prototype.begin = function () { + }; + EntityProcessorList.prototype.update = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].update(); + } + }; + EntityProcessorList.prototype.lateUpdate = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].lateUpdate(); + } + }; + EntityProcessorList.prototype.end = function () { + }; + EntityProcessorList.prototype.getProcessor = function () { + for (var i = 0; i < this._processors.length; i++) { + var processor = this._processors[i]; + if (processor instanceof es.EntitySystem) + return processor; + } + return null; + }; + return EntityProcessorList; + }()); + es.EntityProcessorList = EntityProcessorList; +})(es || (es = {})); +var es; +(function (es) { + var Matcher = (function () { + function Matcher() { + this.allSet = new es.BitSet(); + this.exclusionSet = new es.BitSet(); + this.oneSet = new es.BitSet(); + } + Matcher.empty = function () { + return new Matcher(); + }; + Matcher.prototype.getAllSet = function () { + return this.allSet; + }; + Matcher.prototype.getExclusionSet = function () { + return this.exclusionSet; + }; + Matcher.prototype.getOneSet = function () { + return this.oneSet; + }; + Matcher.prototype.IsIntersted = function (e) { + if (!this.allSet.isEmpty()) { + for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { + if (!e.componentBits.get(i)) + return false; + } + } + if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) + return false; + if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) + return false; + return true; + }; + Matcher.prototype.all = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.allSet.set(es.ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.exclude = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.exclusionSet.set(es.ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.one = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.oneSet.set(es.ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + return Matcher; + }()); + es.Matcher = Matcher; +})(es || (es = {})); var ObjectUtils = (function () { function ObjectUtils() { } @@ -3058,34 +3568,100 @@ var ObjectUtils = (function () { }; return ObjectUtils; }()); -var RenderableComponentList = (function () { - function RenderableComponentList() { - this._components = []; - } - Object.defineProperty(RenderableComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true - }); - RenderableComponentList.prototype.add = function (component) { - this._components.push(component); - }; - RenderableComponentList.prototype.remove = function (component) { - this._components.remove(component); - }; - RenderableComponentList.prototype.updateList = function () { - }; - return RenderableComponentList; -}()); +var es; +(function (es) { + var RenderableComparer = (function () { + function RenderableComparer() { + } + RenderableComparer.prototype.compare = function (self, other) { + return other.renderLayer - self.renderLayer; + }; + return RenderableComparer; + }()); + es.RenderableComparer = RenderableComparer; +})(es || (es = {})); +var es; +(function (es) { + var RenderableComponentList = (function () { + function RenderableComponentList() { + this._components = []; + this._componentsByRenderLayer = new Map(); + this._unsortedRenderLayers = []; + this._componentsNeedSort = true; + } + Object.defineProperty(RenderableComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true + }); + RenderableComponentList.prototype.add = function (component) { + this._components.push(component); + this.addToRenderLayerList(component, component.renderLayer); + }; + RenderableComponentList.prototype.remove = function (component) { + this._components.remove(component); + this._componentsByRenderLayer.get(component.renderLayer).remove(component); + }; + RenderableComponentList.prototype.updateRenderableRenderLayer = function (component, oldRenderLayer, newRenderLayer) { + if (this._componentsByRenderLayer.has(oldRenderLayer) && this._componentsByRenderLayer.get(oldRenderLayer).contains(component)) { + this._componentsByRenderLayer.get(oldRenderLayer).remove(component); + this.addToRenderLayerList(component, newRenderLayer); + } + }; + RenderableComponentList.prototype.setRenderLayerNeedsComponentSort = function (renderLayer) { + if (!this._unsortedRenderLayers.contains(renderLayer)) + this._unsortedRenderLayers.push(renderLayer); + this._componentsNeedSort = true; + }; + RenderableComponentList.prototype.setNeedsComponentSort = function () { + this._componentsNeedSort = true; + }; + RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) { + var list = this.componentsWithRenderLayer(renderLayer); + if (!list.contains(component)) { + console.warn("Component renderLayer list already contains this component"); + return; + } + list.push(component); + if (!this._unsortedRenderLayers.contains(renderLayer)) + this._unsortedRenderLayers.push(renderLayer); + this._componentsNeedSort = true; + }; + RenderableComponentList.prototype.componentsWithRenderLayer = function (renderLayer) { + if (!this._componentsByRenderLayer.get(renderLayer)) { + this._componentsByRenderLayer.set(renderLayer, []); + } + return this._componentsByRenderLayer.get(renderLayer); + }; + RenderableComponentList.prototype.updateList = function () { + if (this._componentsNeedSort) { + this._components.sort(RenderableComponentList.compareUpdatableOrder.compare); + this._componentsNeedSort = false; + } + if (this._unsortedRenderLayers.length > 0) { + for (var i = 0, count = this._unsortedRenderLayers.length; i < count; i++) { + var renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]); + if (renderLayerComponents) { + renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare); + } + } + this._unsortedRenderLayers.length = 0; + } + }; + RenderableComponentList.compareUpdatableOrder = new es.RenderableComparer(); + return RenderableComponentList; + }()); + es.RenderableComponentList = RenderableComponentList; +})(es || (es = {})); var StringUtils = (function () { function StringUtils() { } @@ -3230,155 +3806,163 @@ var StringUtils = (function () { ]; return StringUtils; }()); -var TextureUtils = (function () { - function TextureUtils() { - } - TextureUtils.convertImageToCanvas = function (texture, rect) { - if (!this.sharedCanvas) { - this.sharedCanvas = egret.sys.createCanvas(); - this.sharedContext = this.sharedCanvas.getContext("2d"); +var es; +(function (es) { + var TextureUtils = (function () { + function TextureUtils() { } - var w = texture.$getTextureWidth(); - var h = texture.$getTextureHeight(); - if (!rect) { - rect = egret.$TempRectangle; - rect.x = 0; - rect.y = 0; - rect.width = w; - rect.height = h; - } - rect.x = Math.min(rect.x, w - 1); - rect.y = Math.min(rect.y, h - 1); - rect.width = Math.min(rect.width, w - rect.x); - rect.height = Math.min(rect.height, h - rect.y); - var iWidth = Math.floor(rect.width); - var iHeight = Math.floor(rect.height); - var surface = this.sharedCanvas; - surface["style"]["width"] = iWidth + "px"; - surface["style"]["height"] = iHeight + "px"; - this.sharedCanvas.width = iWidth; - this.sharedCanvas.height = iHeight; - if (egret.Capabilities.renderMode == "webgl") { - var renderTexture = void 0; - if (!texture.$renderBuffer) { - if (egret.sys.systemRenderer["renderClear"]) { - egret.sys.systemRenderer["renderClear"](); + TextureUtils.convertImageToCanvas = function (texture, rect) { + if (!this.sharedCanvas) { + this.sharedCanvas = egret.sys.createCanvas(); + this.sharedContext = this.sharedCanvas.getContext("2d"); + } + var w = texture.$getTextureWidth(); + var h = texture.$getTextureHeight(); + if (!rect) { + rect = egret.$TempRectangle; + rect.x = 0; + rect.y = 0; + rect.width = w; + rect.height = h; + } + rect.x = Math.min(rect.x, w - 1); + rect.y = Math.min(rect.y, h - 1); + rect.width = Math.min(rect.width, w - rect.x); + rect.height = Math.min(rect.height, h - rect.y); + var iWidth = Math.floor(rect.width); + var iHeight = Math.floor(rect.height); + var surface = this.sharedCanvas; + surface["style"]["width"] = iWidth + "px"; + surface["style"]["height"] = iHeight + "px"; + this.sharedCanvas.width = iWidth; + this.sharedCanvas.height = iHeight; + if (egret.Capabilities.renderMode == "webgl") { + var renderTexture = void 0; + if (!texture.$renderBuffer) { + if (egret.sys.systemRenderer["renderClear"]) { + egret.sys.systemRenderer["renderClear"](); + } + renderTexture = new egret.RenderTexture(); + renderTexture.drawToTexture(new egret.Bitmap(texture)); } - renderTexture = new egret.RenderTexture(); - renderTexture.drawToTexture(new egret.Bitmap(texture)); + else { + renderTexture = texture; + } + var pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight); + var x = 0; + var y = 0; + for (var i = 0; i < pixels.length; i += 4) { + this.sharedContext.fillStyle = + 'rgba(' + pixels[i] + + ',' + pixels[i + 1] + + ',' + pixels[i + 2] + + ',' + (pixels[i + 3] / 255) + ')'; + this.sharedContext.fillRect(x, y, 1, 1); + x++; + if (x == iWidth) { + x = 0; + y++; + } + } + if (!texture.$renderBuffer) { + renderTexture.dispose(); + } + return surface; } else { - renderTexture = texture; + var bitmapData = texture; + var offsetX = Math.round(bitmapData.$offsetX); + var offsetY = Math.round(bitmapData.$offsetY); + var bitmapWidth = bitmapData.$bitmapWidth; + var bitmapHeight = bitmapData.$bitmapHeight; + var $TextureScaleFactor = es.SceneManager.stage.textureScaleFactor; + this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); + return surface; } - var pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight); - var x = 0; - var y = 0; - for (var i = 0; i < pixels.length; i += 4) { - this.sharedContext.fillStyle = - 'rgba(' + pixels[i] - + ',' + pixels[i + 1] - + ',' + pixels[i + 2] - + ',' + (pixels[i + 3] / 255) + ')'; - this.sharedContext.fillRect(x, y, 1, 1); - x++; - if (x == iWidth) { - x = 0; - y++; - } + }; + TextureUtils.toDataURL = function (type, texture, rect, encoderOptions) { + try { + var surface = this.convertImageToCanvas(texture, rect); + var result = surface.toDataURL(type, encoderOptions); + return result; } - if (!texture.$renderBuffer) { - renderTexture.dispose(); + catch (e) { + egret.$error(1033); } - return surface; - } - else { - var bitmapData = texture; - var offsetX = Math.round(bitmapData.$offsetX); - var offsetY = Math.round(bitmapData.$offsetY); - var bitmapWidth = bitmapData.$bitmapWidth; - var bitmapHeight = bitmapData.$bitmapHeight; - var $TextureScaleFactor = SceneManager.stage.textureScaleFactor; - this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); - return surface; - } - }; - TextureUtils.toDataURL = function (type, texture, rect, encoderOptions) { - try { + return null; + }; + TextureUtils.eliFoTevas = function (type, texture, filePath, rect, encoderOptions) { var surface = this.convertImageToCanvas(texture, rect); - var result = surface.toDataURL(type, encoderOptions); + var result = surface.toTempFilePathSync({ + fileType: type.indexOf("png") >= 0 ? "png" : "jpg" + }); + wx.getFileSystemManager().saveFile({ + tempFilePath: result, + filePath: wx.env.USER_DATA_PATH + "/" + filePath, + success: function (res) { + } + }); return result; - } - catch (e) { - egret.$error(1033); - } - return null; - }; - TextureUtils.eliFoTevas = function (type, texture, filePath, rect, encoderOptions) { - var surface = this.convertImageToCanvas(texture, rect); - var result = surface.toTempFilePathSync({ - fileType: type.indexOf("png") >= 0 ? "png" : "jpg" - }); - wx.getFileSystemManager().saveFile({ - tempFilePath: result, - filePath: wx.env.USER_DATA_PATH + "/" + filePath, - success: function (res) { + }; + TextureUtils.getPixel32 = function (texture, x, y) { + egret.$warn(1041, "getPixel32", "getPixels"); + return texture.getPixels(x, y); + }; + TextureUtils.getPixels = function (texture, x, y, width, height) { + if (width === void 0) { width = 1; } + if (height === void 0) { height = 1; } + if (egret.Capabilities.renderMode == "webgl") { + var renderTexture = void 0; + if (!texture.$renderBuffer) { + renderTexture = new egret.RenderTexture(); + renderTexture.drawToTexture(new egret.Bitmap(texture)); + } + else { + renderTexture = texture; + } + var pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height); + return pixels; } - }); - return result; - }; - TextureUtils.getPixel32 = function (texture, x, y) { - egret.$warn(1041, "getPixel32", "getPixels"); - return texture.getPixels(x, y); - }; - TextureUtils.getPixels = function (texture, x, y, width, height) { - if (width === void 0) { width = 1; } - if (height === void 0) { height = 1; } - if (egret.Capabilities.renderMode == "webgl") { - var renderTexture = void 0; - if (!texture.$renderBuffer) { - renderTexture = new egret.RenderTexture(); - renderTexture.drawToTexture(new egret.Bitmap(texture)); + try { + var surface = this.convertImageToCanvas(texture); + var result = this.sharedContext.getImageData(x, y, width, height).data; + return result; } - else { - renderTexture = texture; + catch (e) { + egret.$error(1039); } - var pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height); - return pixels; + }; + return TextureUtils; + }()); + es.TextureUtils = TextureUtils; +})(es || (es = {})); +var es; +(function (es) { + var Time = (function () { + function Time() { } - try { - var surface = this.convertImageToCanvas(texture); - var result = this.sharedContext.getImageData(x, y, width, height).data; - return result; - } - catch (e) { - egret.$error(1039); - } - }; - return TextureUtils; -}()); -var Time = (function () { - function Time() { - } - Time.update = function (currentTime) { - var dt = (currentTime - this._lastTime) / 1000; - this.deltaTime = dt * this.timeScale; - this.unscaledDeltaTime = dt; - this._timeSinceSceneLoad += dt; - this.frameCount++; - this._lastTime = currentTime; - }; - Time.sceneChanged = function () { - this._timeSinceSceneLoad = 0; - }; - Time.checkEvery = function (interval) { - return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval); - }; - Time.deltaTime = 0; - Time.timeScale = 1; - Time.frameCount = 0; - Time._lastTime = 0; - return Time; -}()); + Time.update = function (currentTime) { + var dt = (currentTime - this._lastTime) / 1000; + this.deltaTime = dt * this.timeScale; + this.unscaledDeltaTime = dt; + this._timeSinceSceneLoad += dt; + this.frameCount++; + this._lastTime = currentTime; + }; + Time.sceneChanged = function () { + this._timeSinceSceneLoad = 0; + }; + Time.checkEvery = function (interval) { + return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval); + }; + Time.deltaTime = 0; + Time.timeScale = 1; + Time.frameCount = 0; + Time._lastTime = 0; + return Time; + }()); + es.Time = Time; +})(es || (es = {})); var TimeUtils = (function () { function TimeUtils() { } @@ -3532,405 +4116,143 @@ var TimeUtils = (function () { }; return TimeUtils; }()); -var GraphicsCapabilities = (function (_super) { - __extends(GraphicsCapabilities, _super); - function GraphicsCapabilities() { - return _super !== null && _super.apply(this, arguments) || this; - } - GraphicsCapabilities.prototype.initialize = function (device) { - this.platformInitialize(device); - }; - GraphicsCapabilities.prototype.platformInitialize = function (device) { - var capabilities = this; - capabilities["isMobile"] = true; - var systemInfo = wx.getSystemInfoSync(); - var systemStr = systemInfo.system.toLowerCase(); - if (systemStr.indexOf("ios") > -1) { - capabilities["os"] = "iOS"; +var es; +(function (es) { + var GraphicsCapabilities = (function (_super) { + __extends(GraphicsCapabilities, _super); + function GraphicsCapabilities() { + return _super !== null && _super.apply(this, arguments) || this; } - else if (systemStr.indexOf("android") > -1) { - capabilities["os"] = "Android"; - } - var language = systemInfo.language; - if (language.indexOf('zh') > -1) { - language = "zh-CN"; - } - else { - language = "en-US"; - } - capabilities["language"] = language; - }; - return GraphicsCapabilities; -}(egret.Capabilities)); -var GraphicsDevice = (function () { - function GraphicsDevice() { - this.graphicsCapabilities = new GraphicsCapabilities(); - this.graphicsCapabilities.initialize(this); - } - return GraphicsDevice; -}()); -var Viewport = (function () { - function Viewport(x, y, width, height) { - this._x = x; - this._y = y; - this._width = width; - this._height = height; - this._minDepth = 0; - this._maxDepth = 1; - } - Object.defineProperty(Viewport.prototype, "aspectRatio", { - get: function () { - if ((this._height != 0) && (this._width != 0)) - return (this._width / this._height); - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Viewport.prototype, "bounds", { - get: function () { - return new Rectangle(this._x, this._y, this._width, this._height); - }, - set: function (value) { - this._x = value.x; - this._y = value.y; - this._width = value.width; - this._height = value.height; - }, - enumerable: true, - configurable: true - }); - return Viewport; -}()); -var GaussianBlurEffect = (function (_super) { - __extends(GaussianBlurEffect, _super); - function GaussianBlurEffect() { - return _super.call(this, PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight - }) || this; - } - GaussianBlurEffect.blur_frag = "precision mediump float;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float screenWidth;\n" + - "uniform float screenHeight;\n" + - "float normpdf(in float x, in float sigma)\n" + - "{\n" + - "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + - "}\n" + - "void main()\n" + - "{\n" + - "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "const int mSize = 11;\n" + - "const int kSize = (mSize - 1)/2;\n" + - "float kernel[mSize];\n" + - "vec3 final_colour = vec3(0.0);\n" + - "float sigma = 7.0;\n" + - "float z = 0.0;\n" + - "for (int j = 0; j <= kSize; ++j)\n" + - "{\n" + - "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + - "}\n" + - "for (int j = 0; j < mSize; ++j)\n" + - "{\n" + - "z += kernel[j];\n" + - "}\n" + - "for (int i = -kSize; i <= kSize; ++i)\n" + - "{\n" + - "for (int j = -kSize; j <= kSize; ++j)\n" + - "{\n" + - "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "}\n}\n" + - "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + - "}"; - return GaussianBlurEffect; -}(egret.CustomFilter)); -var PolygonLightEffect = (function (_super) { - __extends(PolygonLightEffect, _super); - function PolygonLightEffect() { - return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this; - } - PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - PolygonLightEffect.fragmentSrc = "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + - "#define SAMPLE_COUNT 15\n" + - "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + - "uniform float _sampleWeights[SAMPLE_COUNT];\n" + - "void main(void) {\n" + - "vec4 c = vec4(0, 0, 0, 0);\n" + - "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + - " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + - "gl_FragColor = c;\n" + - "}"; - return PolygonLightEffect; -}(egret.CustomFilter)); -var PostProcessor = (function () { - function PostProcessor(effect) { - if (effect === void 0) { effect = null; } - this.enable = true; - this.effect = effect; - } - PostProcessor.prototype.onAddedToScene = function (scene) { - this.scene = scene; - this.shape = new egret.Shape(); - this.shape.graphics.beginFill(0xFFFFFF, 1); - this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this.shape.graphics.endFill(); - scene.addChild(this.shape); - }; - PostProcessor.prototype.process = function () { - this.drawFullscreenQuad(); - }; - PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { }; - PostProcessor.prototype.drawFullscreenQuad = function () { - this.scene.filters = [this.effect]; - }; - PostProcessor.prototype.unload = function () { - if (this.effect) { - this.effect = null; - } - this.scene.removeChild(this.shape); - this.scene = null; - }; - PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "attribute vec2 aColor;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "varying vec4 vColor;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - "vTextureCoord = aTextureCoord;\n" + - "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + - "}"; - return PostProcessor; -}()); -var GaussianBlurPostProcessor = (function (_super) { - __extends(GaussianBlurPostProcessor, _super); - function GaussianBlurPostProcessor() { - return _super !== null && _super.apply(this, arguments) || this; - } - GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { - _super.prototype.onAddedToScene.call(this, scene); - this.effect = new GaussianBlurEffect(); - }; - return GaussianBlurPostProcessor; -}(PostProcessor)); -var Renderer = (function () { - function Renderer() { - } - Renderer.prototype.onAddedToScene = function (scene) { }; - Renderer.prototype.beginRender = function (cam) { - }; - Renderer.prototype.unload = function () { }; - Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { - renderable.render(cam); - }; - return Renderer; -}()); -var DefaultRenderer = (function (_super) { - __extends(DefaultRenderer, _super); - function DefaultRenderer() { - return _super !== null && _super.apply(this, arguments) || this; - } - DefaultRenderer.prototype.render = function (scene) { - var cam = this.camera ? this.camera : scene.camera; - this.beginRender(cam); - for (var i = 0; i < scene.renderableComponents.count; i++) { - var renderable = scene.renderableComponents.buffer[i]; - if (renderable.enabled && renderable.isVisibleFromCamera(cam)) - this.renderAfterStateCheck(renderable, cam); - } - }; - return DefaultRenderer; -}(Renderer)); -var ScreenSpaceRenderer = (function (_super) { - __extends(ScreenSpaceRenderer, _super); - function ScreenSpaceRenderer() { - return _super !== null && _super.apply(this, arguments) || this; - } - ScreenSpaceRenderer.prototype.render = function (scene) { - }; - return ScreenSpaceRenderer; -}(Renderer)); -var PolyLight = (function (_super) { - __extends(PolyLight, _super); - function PolyLight(radius, color, power) { - var _this = _super.call(this) || this; - _this._indices = []; - _this.radius = radius; - _this.power = power; - _this.color = color; - _this.computeTriangleIndices(); - return _this; - } - Object.defineProperty(PolyLight.prototype, "radius", { - get: function () { - return this._radius; - }, - set: function (value) { - this.setRadius(value); - }, - enumerable: true, - configurable: true - }); - PolyLight.prototype.computeTriangleIndices = function (totalTris) { - if (totalTris === void 0) { totalTris = 20; } - this._indices.length = 0; - for (var i = 0; i < totalTris; i += 2) { - this._indices.push(0); - this._indices.push(i + 2); - this._indices.push(i + 1); - } - }; - PolyLight.prototype.setRadius = function (radius) { - if (radius != this._radius) { - this._radius = radius; - this._areBoundsDirty = true; - } - }; - PolyLight.prototype.render = function (camera) { - }; - PolyLight.prototype.reset = function () { - }; - return PolyLight; -}(RenderableComponent)); -var SceneTransition = (function () { - function SceneTransition(sceneLoadAction) { - this.sceneLoadAction = sceneLoadAction; - this.loadsNewScene = sceneLoadAction != null; - } - Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { - get: function () { - if (!this._hasPreviousSceneRender) { - this._hasPreviousSceneRender = true; - return false; + GraphicsCapabilities.prototype.initialize = function (device) { + this.platformInitialize(device); + }; + GraphicsCapabilities.prototype.platformInitialize = function (device) { + var capabilities = this; + capabilities["isMobile"] = true; + var systemInfo = wx.getSystemInfoSync(); + var systemStr = systemInfo.system.toLowerCase(); + if (systemStr.indexOf("ios") > -1) { + capabilities["os"] = "iOS"; } - return true; - }, - enumerable: true, - configurable: true - }); - SceneTransition.prototype.preRender = function () { }; - SceneTransition.prototype.render = function () { - }; - SceneTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.loadNextScene()]; - case 1: - _a.sent(); - this.transitionComplete(); - return [2]; - } - }); - }); - }; - SceneTransition.prototype.transitionComplete = function () { - SceneManager.sceneTransition = null; - if (this.onTransitionCompleted) { - this.onTransitionCompleted(); + else if (systemStr.indexOf("android") > -1) { + capabilities["os"] = "Android"; + } + var language = systemInfo.language; + if (language.indexOf('zh') > -1) { + language = "zh-CN"; + } + else { + language = "en-US"; + } + capabilities["language"] = language; + }; + return GraphicsCapabilities; + }(egret.Capabilities)); + es.GraphicsCapabilities = GraphicsCapabilities; +})(es || (es = {})); +var es; +(function (es) { + var GraphicsDevice = (function () { + function GraphicsDevice() { + this.graphicsCapabilities = new es.GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); } - }; - SceneTransition.prototype.loadNextScene = function () { - return __awaiter(this, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (this.onScreenObscured) - this.onScreenObscured(); - if (!this.loadsNewScene) { - this.isNewSceneLoaded = true; - } - _a = SceneManager; - return [4, this.sceneLoadAction()]; - case 1: - _a.scene = _b.sent(); - this.isNewSceneLoaded = true; - return [2]; - } - }); + return GraphicsDevice; + }()); + es.GraphicsDevice = GraphicsDevice; +})(es || (es = {})); +var es; +(function (es) { + var Viewport = (function () { + function Viewport(x, y, width, height) { + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } + Object.defineProperty(Viewport.prototype, "aspectRatio", { + get: function () { + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + }, + enumerable: true, + configurable: true }); - }; - SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) { - if (reverseDirection === void 0) { reverseDirection = false; } - return new Promise(function (resolve) { - var start = reverseDirection ? 1 : 0; - var end = reverseDirection ? 0 : 1; - egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () { - resolve(); - }); + Object.defineProperty(Viewport.prototype, "bounds", { + get: function () { + return new es.Rectangle(this._x, this._y, this._width, this._height); + }, + set: function (value) { + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + }, + enumerable: true, + configurable: true }); - }; - return SceneTransition; -}()); -var FadeTransition = (function (_super) { - __extends(FadeTransition, _super); - function FadeTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.fadeToColor = 0x000000; - _this.fadeOutDuration = 0.4; - _this.fadeEaseType = egret.Ease.quadInOut; - _this.delayBeforeFadeInDuration = 0.1; - _this._alpha = 0; - _this._mask = new egret.Shape(); - return _this; - } - FadeTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this._mask.graphics.endFill(); - SceneManager.stage.addChild(this._mask); - egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) - .call(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.loadNextScene()]; - case 1: - _a.sent(); - return [2]; - } - }); - }); }).wait(this.delayBeforeFadeInDuration).call(function () { - egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { - _this.transitionComplete(); - SceneManager.stage.removeChild(_this._mask); - }); - }); - return [2]; - }); - }); - }; - FadeTransition.prototype.render = function () { - this._mask.graphics.clear(); - this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this._mask.graphics.endFill(); - }; - return FadeTransition; -}(SceneTransition)); -var WindTransition = (function (_super) { - __extends(WindTransition, _super); - function WindTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.duration = 1; - _this.easeType = egret.Ease.quadOut; - var vertexSrc = "attribute vec2 aVertexPosition;\n" + + return Viewport; + }()); + es.Viewport = Viewport; +})(es || (es = {})); +var es; +(function (es) { + var GaussianBlurEffect = (function (_super) { + __extends(GaussianBlurEffect, _super); + function GaussianBlurEffect() { + return _super.call(this, es.PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { + screenWidth: es.SceneManager.stage.stageWidth, + screenHeight: es.SceneManager.stage.stageHeight + }) || this; + } + GaussianBlurEffect.blur_frag = "precision mediump float;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float screenWidth;\n" + + "uniform float screenHeight;\n" + + "float normpdf(in float x, in float sigma)\n" + + "{\n" + + "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + + "}\n" + + "void main()\n" + + "{\n" + + "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "const int mSize = 11;\n" + + "const int kSize = (mSize - 1)/2;\n" + + "float kernel[mSize];\n" + + "vec3 final_colour = vec3(0.0);\n" + + "float sigma = 7.0;\n" + + "float z = 0.0;\n" + + "for (int j = 0; j <= kSize; ++j)\n" + + "{\n" + + "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + + "}\n" + + "for (int j = 0; j < mSize; ++j)\n" + + "{\n" + + "z += kernel[j];\n" + + "}\n" + + "for (int i = -kSize; i <= kSize; ++i)\n" + + "{\n" + + "for (int j = -kSize; j <= kSize; ++j)\n" + + "{\n" + + "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "}\n}\n" + + "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + + "}"; + return GaussianBlurEffect; + }(egret.CustomFilter)); + es.GaussianBlurEffect = GaussianBlurEffect; +})(es || (es = {})); +var es; +(function (es) { + var PolygonLightEffect = (function (_super) { + __extends(PolygonLightEffect, _super); + function PolygonLightEffect() { + return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this; + } + PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" + "attribute vec2 aTextureCoord;\n" + "uniform vec2 projectionVector;\n" + "varying vec2 vTextureCoord;\n" + @@ -3939,1369 +4261,1761 @@ var WindTransition = (function (_super) { " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + " vTextureCoord = aTextureCoord;\n" + "}"; - var fragmentSrc = "precision lowp float;\n" + + PolygonLightEffect.fragmentSrc = "precision lowp float;\n" + "varying vec2 vTextureCoord;\n" + "uniform sampler2D uSampler;\n" + - "uniform float _progress;\n" + - "uniform float _size;\n" + - "uniform float _windSegments;\n" + + "#define SAMPLE_COUNT 15\n" + + "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + + "uniform float _sampleWeights[SAMPLE_COUNT];\n" + "void main(void) {\n" + - "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + - "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + - "float r = x - floor(x);\n" + - "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + - "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + - "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + + "vec4 c = vec4(0, 0, 0, 0);\n" + + "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + + " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + + "gl_FragColor = c;\n" + "}"; - _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { - _progress: 0, - _size: 0.3, - _windSegments: 100 - }); - _this._mask = new egret.Shape(); - _this._mask.graphics.beginFill(0xFFFFFF, 1); - _this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - _this._mask.graphics.endFill(); - _this._mask.filters = [_this._windEffect]; - SceneManager.stage.addChild(_this._mask); - return _this; - } - Object.defineProperty(WindTransition.prototype, "windSegments", { - set: function (value) { - this._windEffect.uniforms._windSegments = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(WindTransition.prototype, "size", { - set: function (value) { - this._windEffect.uniforms._size = value; - }, - enumerable: true, - configurable: true - }); - WindTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.loadNextScene(); - return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)]; - case 1: - _a.sent(); - this.transitionComplete(); - SceneManager.stage.removeChild(this._mask); - return [2]; - } - }); - }); - }; - return WindTransition; -}(SceneTransition)); -var Bezier = (function () { - function Bezier() { - } - Bezier.getPoint = function (p0, p1, p2, t) { - t = MathHelper.clamp01(t); - var oneMinusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMinusT * oneMinusT), p0), Vector2.multiply(new Vector2(2 * oneMinusT * t), p1)), Vector2.multiply(new Vector2(t * t), p2)); - }; - Bezier.getFirstDerivative = function (p0, p1, p2, t) { - return Vector2.add(Vector2.multiply(new Vector2(2 * (1 - t)), Vector2.subtract(p1, p0)), Vector2.multiply(new Vector2(2 * t), Vector2.subtract(p2, p1))); - }; - Bezier.getFirstDerivativeThree = function (start, firstControlPoint, secondControlPoint, end, t) { - t = MathHelper.clamp01(t); - var oneMunusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT), Vector2.subtract(firstControlPoint, start)), Vector2.multiply(new Vector2(6 * oneMunusT * t), Vector2.subtract(secondControlPoint, firstControlPoint))), Vector2.multiply(new Vector2(3 * t * t), Vector2.subtract(end, secondControlPoint))); - }; - Bezier.getPointThree = function (start, firstControlPoint, secondControlPoint, end, t) { - t = MathHelper.clamp01(t); - var oneMunusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMunusT * oneMunusT * oneMunusT), start), Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT * t), firstControlPoint)), Vector2.multiply(new Vector2(3 * oneMunusT * t * t), secondControlPoint)), Vector2.multiply(new Vector2(t * t * t), end)); - }; - Bezier.getOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, distanceTolerance) { - if (distanceTolerance === void 0) { distanceTolerance = 1; } - var points = ListPool.obtain(); - points.push(start); - this.recursiveGetOptimizedDrawingPoints(start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance); - points.push(end); - return points; - }; - Bezier.recursiveGetOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance) { - var pt12 = Vector2.divide(Vector2.add(start, firstCtrlPoint), new Vector2(2)); - var pt23 = Vector2.divide(Vector2.add(firstCtrlPoint, secondCtrlPoint), new Vector2(2)); - var pt34 = Vector2.divide(Vector2.add(secondCtrlPoint, end), new Vector2(2)); - var pt123 = Vector2.divide(Vector2.add(pt12, pt23), new Vector2(2)); - var pt234 = Vector2.divide(Vector2.add(pt23, pt34), new Vector2(2)); - var pt1234 = Vector2.divide(Vector2.add(pt123, pt234), new Vector2(2)); - var deltaLine = Vector2.subtract(end, start); - var d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); - var d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); - if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) { - points.push(pt1234); - return; + return PolygonLightEffect; + }(egret.CustomFilter)); + es.PolygonLightEffect = PolygonLightEffect; +})(es || (es = {})); +var es; +(function (es) { + var PostProcessor = (function () { + function PostProcessor(effect) { + if (effect === void 0) { effect = null; } + this.enabled = true; + this.effect = effect; } - this.recursiveGetOptimizedDrawingPoints(start, pt12, pt123, pt1234, points, distanceTolerance); - this.recursiveGetOptimizedDrawingPoints(pt1234, pt234, pt34, end, points, distanceTolerance); - }; - return Bezier; -}()); -var Flags = (function () { - function Flags() { - } - Flags.isFlagSet = function (self, flag) { - return (self & flag) != 0; - }; - Flags.isUnshiftedFlagSet = function (self, flag) { - flag = 1 << flag; - return (self & flag) != 0; - }; - Flags.setFlagExclusive = function (self, flag) { - return 1 << flag; - }; - Flags.setFlag = function (self, flag) { - return (self | 1 << flag); - }; - Flags.unsetFlag = function (self, flag) { - flag = 1 << flag; - return (self & (~flag)); - }; - Flags.invertFlags = function (self) { - return ~self; - }; - return Flags; -}()); -var MathHelper = (function () { - function MathHelper() { - } - MathHelper.toDegrees = function (radians) { - return radians * 57.295779513082320876798154814105; - }; - MathHelper.toRadians = function (degrees) { - return degrees * 0.017453292519943295769236907684886; - }; - MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { - return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); - }; - MathHelper.lerp = function (value1, value2, amount) { - return value1 + (value2 - value1) * amount; - }; - MathHelper.clamp = function (value, min, max) { - if (value < min) - return min; - if (value > max) - return max; - return value; - }; - MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { - var radians = MathHelper.toRadians(angleInDegrees); - return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); - }; - MathHelper.isEven = function (value) { - return value % 2 == 0; - }; - MathHelper.clamp01 = function (value) { - if (value < 0) - return 0; - if (value > 1) - return 1; - return value; - }; - MathHelper.angleBetweenVectors = function (from, to) { - return Math.atan2(to.y - from.y, to.x - from.x); - }; - MathHelper.Epsilon = 0.00001; - MathHelper.Rad2Deg = 57.29578; - MathHelper.Deg2Rad = 0.0174532924; - return MathHelper; -}()); -var Matrix2D = (function () { - function Matrix2D(m11, m12, m21, m22, m31, m32) { - this.m11 = 0; - this.m12 = 0; - this.m21 = 0; - this.m22 = 0; - this.m31 = 0; - this.m32 = 0; - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; - } - Object.defineProperty(Matrix2D, "identity", { - get: function () { - return Matrix2D._identity; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "translation", { - get: function () { - return new Vector2(this.m31, this.m32); - }, - set: function (value) { - this.m31 = value.x; - this.m32 = value.y; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "rotation", { - get: function () { - return Math.atan2(this.m21, this.m11); - }, - set: function (value) { - var val1 = Math.cos(value); - var val2 = Math.sin(value); - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this.rotation); - }, - set: function (value) { - this.rotation = MathHelper.toRadians(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "scale", { - get: function () { - return new Vector2(this.m11, this.m22); - }, - set: function (value) { - this.m11 = value.x; - this.m12 = value.y; - }, - enumerable: true, - configurable: true - }); - Matrix2D.add = function (matrix1, matrix2) { - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; - return matrix1; - }; - Matrix2D.divide = function (matrix1, matrix2) { - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; - return matrix1; - }; - Matrix2D.multiply = function (matrix1, matrix2) { - var result = new Matrix2D(); - var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); - var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); - var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); - var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); - var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; - var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; - result.m11 = m11; - result.m12 = m12; - result.m21 = m21; - result.m22 = m22; - result.m31 = m31; - result.m32 = m32; - return result; - }; - Matrix2D.multiplyTranslation = function (matrix, x, y) { - var trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); - }; - Matrix2D.prototype.determinant = function () { - return this.m11 * this.m22 - this.m12 * this.m21; - }; - Matrix2D.invert = function (matrix, result) { - if (result === void 0) { result = new Matrix2D(); } - var det = 1 / matrix.determinant(); - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - return result; - }; - Matrix2D.createTranslation = function (xPosition, yPosition) { - var result = new Matrix2D(); - result.m11 = 1; - result.m12 = 0; - result.m21 = 0; - result.m22 = 1; - result.m31 = xPosition; - result.m32 = yPosition; - return result; - }; - Matrix2D.createTranslationVector = function (position) { - return this.createTranslation(position.x, position.y); - }; - Matrix2D.createRotation = function (radians, result) { - result = new Matrix2D(); - var val1 = Math.cos(radians); - var val2 = Math.sin(radians); - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - return result; - }; - Matrix2D.createScale = function (xScale, yScale, result) { - if (result === void 0) { result = new Matrix2D(); } - result.m11 = xScale; - result.m12 = 0; - result.m21 = 0; - result.m22 = yScale; - result.m31 = 0; - result.m32 = 0; - return result; - }; - Matrix2D.prototype.toEgretMatrix = function () { - var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); - return matrix; - }; - Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); - return Matrix2D; -}()); -var Rectangle = (function (_super) { - __extends(Rectangle, _super); - function Rectangle() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(Rectangle.prototype, "max", { - get: function () { - return new Vector2(this.right, this.bottom); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Rectangle.prototype, "center", { - get: function () { - return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Rectangle.prototype, "location", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (value) { - this.x = value.x; - this.y = value.y; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Rectangle.prototype, "size", { - get: function () { - return new Vector2(this.width, this.height); - }, - set: function (value) { - this.width = value.x; - this.height = value.y; - }, - enumerable: true, - configurable: true - }); - Rectangle.prototype.intersects = function (value) { - return value.left < this.right && - this.left < value.right && - value.top < this.bottom && - this.top < value.bottom; - }; - Rectangle.prototype.containsRect = function (value) { - return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && - (this.y <= value.y)) && - (value.y < (this.y + this.height))); - }; - Rectangle.prototype.getHalfSize = function () { - return new Vector2(this.width * 0.5, this.height * 0.5); - }; - Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { - return new Rectangle(minX, minY, maxX - minX, maxY - minY); - }; - Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { - var edgeNormal = Vector2.zero; - var res = new Vector2(); - res.x = MathHelper.clamp(point.x, this.left, this.right); - res.y = MathHelper.clamp(point.y, this.top, this.bottom); - if (this.contains(res.x, res.y)) { - var dl = res.x - this.left; - var dr = this.right - res.x; - var dt = res.y - this.top; - var db = this.bottom - res.y; - var min = Math.min(dl, dr, dt, db); - if (min == dt) { - res.y = this.top; - edgeNormal.y = -1; - } - else if (min == db) { - res.y = this.bottom; - edgeNormal.y = 1; - } - else if (min == dl) { - res.x = this.left; - edgeNormal.x = -1; - } - else { - res.x = this.right; - edgeNormal.x = 1; - } - } - else { - if (res.x == this.left) - edgeNormal.x = -1; - if (res.x == this.right) - edgeNormal.x = 1; - if (res.y == this.top) - edgeNormal.y = -1; - if (res.y == this.bottom) - edgeNormal.y = 1; - } - return { res: res, edgeNormal: edgeNormal }; - }; - Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () { - var max = this.max; - var minDist = Math.abs(this.location.x); - var boundsPoint = new Vector2(this.location.x, 0); - if (Math.abs(max.x) < minDist) { - minDist = Math.abs(max.x); - boundsPoint.x = max.x; - boundsPoint.y = 0; - } - if (Math.abs(max.y) < minDist) { - minDist = Math.abs(max.y); - boundsPoint.x = 0; - boundsPoint.y = max.y; - } - if (Math.abs(this.location.y) < minDist) { - minDist = Math.abs(this.location.y); - boundsPoint.x = 0; - boundsPoint.y = this.location.y; - } - return boundsPoint; - }; - Rectangle.prototype.setEgretRect = function (rect) { - this.x = rect.x; - this.y = rect.y; - this.width = rect.width; - this.height = rect.height; - return this; - }; - Rectangle.rectEncompassingPoints = function (points) { - var minX = Number.POSITIVE_INFINITY; - var minY = Number.POSITIVE_INFINITY; - var maxX = Number.NEGATIVE_INFINITY; - var maxY = Number.NEGATIVE_INFINITY; - for (var i = 0; i < points.length; i++) { - var pt = points[i]; - if (pt.x < minX) - minX = pt.x; - if (pt.x > maxX) - maxX = pt.x; - if (pt.y < minY) - minY = pt.y; - if (pt.y > maxY) - maxY = pt.y; - } - return this.fromMinMax(minX, minY, maxX, maxY); - }; - return Rectangle; -}(egret.Rectangle)); -var Vector3 = (function () { - function Vector3(x, y, z) { - this.x = x; - this.y = y; - this.z = z; - } - return Vector3; -}()); -var ColliderTriggerHelper = (function () { - function ColliderTriggerHelper(entity) { - this._activeTriggerIntersections = []; - this._previousTriggerIntersections = []; - this._tempTriggerList = []; - this._entity = entity; - } - ColliderTriggerHelper.prototype.update = function () { - var colliders = this._entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - var boxcastResult = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); - collider.bounds = boxcastResult.rect; - var neighbors = boxcastResult.colliders; - var _loop_5 = function (j) { - var neighbor = neighbors[j]; - if (!collider.isTrigger && !neighbor.isTrigger) - return "continue"; - if (collider.overlaps(neighbor)) { - var pair_1 = new Pair(collider, neighbor); - var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) { - return value.first == pair_1.first && value.second == pair_1.second; - }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) { - return value.first == pair_1.first && value.second == pair_1.second; - }) == -1; - if (shouldReportTriggerEvent) - this_1.notifyTriggerListeners(pair_1, true); - if (!this_1._activeTriggerIntersections.contains(pair_1)) - this_1._activeTriggerIntersections.push(pair_1); - } - }; - var this_1 = this; - for (var j = 0; j < neighbors.length; j++) { - _loop_5(j); - } - } - ListPool.free(colliders); - this.checkForExitedColliders(); - }; - ColliderTriggerHelper.prototype.checkForExitedColliders = function () { - var _this = this; - var _loop_6 = function (i) { - var index = this_2._previousTriggerIntersections.findIndex(function (value) { - if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second) - return true; - return false; - }); - if (index != -1) - this_2._previousTriggerIntersections.removeAt(index); + PostProcessor.prototype.onAddedToScene = function (scene) { + this.scene = scene; + this.shape = new egret.Shape(); + this.shape.graphics.beginFill(0xFFFFFF, 1); + this.shape.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.shape.graphics.endFill(); + scene.addChild(this.shape); }; - var this_2 = this; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - _loop_6(i); - } - for (var i = 0; i < this._previousTriggerIntersections.length; i++) { - this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); - } - this._previousTriggerIntersections.length = 0; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) { - this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); + PostProcessor.prototype.process = function () { + this.drawFullscreenQuad(); + }; + PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { }; + PostProcessor.prototype.drawFullscreenQuad = function () { + this.scene.filters = [this.effect]; + }; + PostProcessor.prototype.unload = function () { + if (this.effect) { + this.effect = null; } + this.scene.removeChild(this.shape); + this.scene = null; + }; + PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "attribute vec2 aColor;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "varying vec4 vColor;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + "vTextureCoord = aTextureCoord;\n" + + "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + + "}"; + return PostProcessor; + }()); + es.PostProcessor = PostProcessor; +})(es || (es = {})); +var es; +(function (es) { + var GaussianBlurPostProcessor = (function (_super) { + __extends(GaussianBlurPostProcessor, _super); + function GaussianBlurPostProcessor() { + return _super !== null && _super.apply(this, arguments) || this; } - this._activeTriggerIntersections.length = 0; - }; - ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) { - collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i = 0; i < this._tempTriggerList.length; i++) { - if (isEntering) { - this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); + GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { + _super.prototype.onAddedToScene.call(this, scene); + this.effect = new es.GaussianBlurEffect(); + }; + return GaussianBlurPostProcessor; + }(es.PostProcessor)); + es.GaussianBlurPostProcessor = GaussianBlurPostProcessor; +})(es || (es = {})); +var es; +(function (es) { + var Renderer = (function () { + function Renderer() { + } + Renderer.prototype.onAddedToScene = function (scene) { }; + Renderer.prototype.beginRender = function (cam) { + }; + Renderer.prototype.unload = function () { }; + Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { + renderable.render(cam); + }; + return Renderer; + }()); + es.Renderer = Renderer; +})(es || (es = {})); +var es; +(function (es) { + var DefaultRenderer = (function (_super) { + __extends(DefaultRenderer, _super); + function DefaultRenderer() { + return _super !== null && _super.apply(this, arguments) || this; + } + DefaultRenderer.prototype.render = function (scene) { + var cam = this.camera ? this.camera : scene.camera; + this.beginRender(cam); + for (var i = 0; i < scene.renderableComponents.count; i++) { + var renderable = scene.renderableComponents.buffer[i]; + if (renderable.enabled && renderable.isVisibleFromCamera(cam)) + this.renderAfterStateCheck(renderable, cam); + } + }; + return DefaultRenderer; + }(es.Renderer)); + es.DefaultRenderer = DefaultRenderer; +})(es || (es = {})); +var es; +(function (es) { + var ScreenSpaceRenderer = (function (_super) { + __extends(ScreenSpaceRenderer, _super); + function ScreenSpaceRenderer() { + return _super !== null && _super.apply(this, arguments) || this; + } + ScreenSpaceRenderer.prototype.render = function (scene) { + }; + return ScreenSpaceRenderer; + }(es.Renderer)); + es.ScreenSpaceRenderer = ScreenSpaceRenderer; +})(es || (es = {})); +var es; +(function (es) { + var PolyLight = (function (_super) { + __extends(PolyLight, _super); + function PolyLight(radius, color, power) { + var _this = _super.call(this) || this; + _this._indices = []; + _this.radius = radius; + _this.power = power; + _this.color = color; + _this.computeTriangleIndices(); + return _this; + } + Object.defineProperty(PolyLight.prototype, "radius", { + get: function () { + return this._radius; + }, + set: function (value) { + this.setRadius(value); + }, + enumerable: true, + configurable: true + }); + PolyLight.prototype.computeTriangleIndices = function (totalTris) { + if (totalTris === void 0) { totalTris = 20; } + this._indices.length = 0; + for (var i = 0; i < totalTris; i += 2) { + this._indices.push(0); + this._indices.push(i + 2); + this._indices.push(i + 1); + } + }; + PolyLight.prototype.setRadius = function (radius) { + if (radius != this._radius) { + this._radius = radius; + this._areBoundsDirty = true; + } + }; + PolyLight.prototype.render = function (camera) { + }; + PolyLight.prototype.reset = function () { + }; + return PolyLight; + }(es.RenderableComponent)); + es.PolyLight = PolyLight; +})(es || (es = {})); +var es; +(function (es) { + var SceneTransition = (function () { + function SceneTransition(sceneLoadAction) { + this.sceneLoadAction = sceneLoadAction; + this.loadsNewScene = sceneLoadAction != null; + } + Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { + get: function () { + if (!this._hasPreviousSceneRender) { + this._hasPreviousSceneRender = true; + return false; + } + return true; + }, + enumerable: true, + configurable: true + }); + SceneTransition.prototype.preRender = function () { }; + SceneTransition.prototype.render = function () { + }; + SceneTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + this.transitionComplete(); + return [2]; + } + }); + }); + }; + SceneTransition.prototype.transitionComplete = function () { + es.SceneManager.sceneTransition = null; + if (this.onTransitionCompleted) { + this.onTransitionCompleted(); + } + }; + SceneTransition.prototype.loadNextScene = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (this.onScreenObscured) + this.onScreenObscured(); + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + } + _a = es.SceneManager; + return [4, this.sceneLoadAction()]; + case 1: + _a.scene = _b.sent(); + this.isNewSceneLoaded = true; + return [2]; + } + }); + }); + }; + SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) { + if (reverseDirection === void 0) { reverseDirection = false; } + return new Promise(function (resolve) { + var start = reverseDirection ? 1 : 0; + var end = reverseDirection ? 0 : 1; + egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () { + resolve(); + }); + }); + }; + return SceneTransition; + }()); + es.SceneTransition = SceneTransition; +})(es || (es = {})); +var es; +(function (es) { + var FadeTransition = (function (_super) { + __extends(FadeTransition, _super); + function FadeTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.fadeToColor = 0x000000; + _this.fadeOutDuration = 0.4; + _this.fadeEaseType = egret.Ease.quadInOut; + _this.delayBeforeFadeInDuration = 0.1; + _this._alpha = 0; + _this._mask = new egret.Shape(); + return _this; + } + FadeTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + this._mask.graphics.beginFill(this.fadeToColor, 1); + this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + es.SceneManager.stage.addChild(this._mask); + egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) + .call(function () { return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + return [2]; + } + }); + }); }).wait(this.delayBeforeFadeInDuration).call(function () { + egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { + _this.transitionComplete(); + es.SceneManager.stage.removeChild(_this._mask); + }); + }); + return [2]; + }); + }); + }; + FadeTransition.prototype.render = function () { + this._mask.graphics.clear(); + this._mask.graphics.beginFill(this.fadeToColor, this._alpha); + this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + }; + return FadeTransition; + }(es.SceneTransition)); + es.FadeTransition = FadeTransition; +})(es || (es = {})); +var es; +(function (es) { + var WindTransition = (function (_super) { + __extends(WindTransition, _super); + function WindTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.duration = 1; + _this.easeType = egret.Ease.quadOut; + var vertexSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + var fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float _progress;\n" + + "uniform float _size;\n" + + "uniform float _windSegments;\n" + + "void main(void) {\n" + + "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + + "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + + "float r = x - floor(x);\n" + + "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + + "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + + "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + + "}"; + _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { + _progress: 0, + _size: 0.3, + _windSegments: 100 + }); + _this._mask = new egret.Shape(); + _this._mask.graphics.beginFill(0xFFFFFF, 1); + _this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + _this._mask.graphics.endFill(); + _this._mask.filters = [_this._windEffect]; + es.SceneManager.stage.addChild(_this._mask); + return _this; + } + Object.defineProperty(WindTransition.prototype, "windSegments", { + set: function (value) { + this._windEffect.uniforms._windSegments = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WindTransition.prototype, "size", { + set: function (value) { + this._windEffect.uniforms._size = value; + }, + enumerable: true, + configurable: true + }); + WindTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.loadNextScene(); + return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)]; + case 1: + _a.sent(); + this.transitionComplete(); + es.SceneManager.stage.removeChild(this._mask); + return [2]; + } + }); + }); + }; + return WindTransition; + }(es.SceneTransition)); + es.WindTransition = WindTransition; +})(es || (es = {})); +var es; +(function (es) { + var Bezier = (function () { + function Bezier() { + } + Bezier.getPoint = function (p0, p1, p2, t) { + t = es.MathHelper.clamp01(t); + var oneMinusT = 1 - t; + return es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(oneMinusT * oneMinusT), p0), es.Vector2.multiply(new es.Vector2(2 * oneMinusT * t), p1)), es.Vector2.multiply(new es.Vector2(t * t), p2)); + }; + Bezier.getFirstDerivative = function (p0, p1, p2, t) { + return es.Vector2.add(es.Vector2.multiply(new es.Vector2(2 * (1 - t)), es.Vector2.subtract(p1, p0)), es.Vector2.multiply(new es.Vector2(2 * t), es.Vector2.subtract(p2, p1))); + }; + Bezier.getFirstDerivativeThree = function (start, firstControlPoint, secondControlPoint, end, t) { + t = es.MathHelper.clamp01(t); + var oneMunusT = 1 - t; + return es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(3 * oneMunusT * oneMunusT), es.Vector2.subtract(firstControlPoint, start)), es.Vector2.multiply(new es.Vector2(6 * oneMunusT * t), es.Vector2.subtract(secondControlPoint, firstControlPoint))), es.Vector2.multiply(new es.Vector2(3 * t * t), es.Vector2.subtract(end, secondControlPoint))); + }; + Bezier.getPointThree = function (start, firstControlPoint, secondControlPoint, end, t) { + t = es.MathHelper.clamp01(t); + var oneMunusT = 1 - t; + return es.Vector2.add(es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(oneMunusT * oneMunusT * oneMunusT), start), es.Vector2.multiply(new es.Vector2(3 * oneMunusT * oneMunusT * t), firstControlPoint)), es.Vector2.multiply(new es.Vector2(3 * oneMunusT * t * t), secondControlPoint)), es.Vector2.multiply(new es.Vector2(t * t * t), end)); + }; + Bezier.getOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, distanceTolerance) { + if (distanceTolerance === void 0) { distanceTolerance = 1; } + var points = es.ListPool.obtain(); + points.push(start); + this.recursiveGetOptimizedDrawingPoints(start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance); + points.push(end); + return points; + }; + Bezier.recursiveGetOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance) { + var pt12 = es.Vector2.divide(es.Vector2.add(start, firstCtrlPoint), new es.Vector2(2)); + var pt23 = es.Vector2.divide(es.Vector2.add(firstCtrlPoint, secondCtrlPoint), new es.Vector2(2)); + var pt34 = es.Vector2.divide(es.Vector2.add(secondCtrlPoint, end), new es.Vector2(2)); + var pt123 = es.Vector2.divide(es.Vector2.add(pt12, pt23), new es.Vector2(2)); + var pt234 = es.Vector2.divide(es.Vector2.add(pt23, pt34), new es.Vector2(2)); + var pt1234 = es.Vector2.divide(es.Vector2.add(pt123, pt234), new es.Vector2(2)); + var deltaLine = es.Vector2.subtract(end, start); + var d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); + var d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); + if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) { + points.push(pt1234); + return; + } + this.recursiveGetOptimizedDrawingPoints(start, pt12, pt123, pt1234, points, distanceTolerance); + this.recursiveGetOptimizedDrawingPoints(pt1234, pt234, pt34, end, points, distanceTolerance); + }; + return Bezier; + }()); + es.Bezier = Bezier; +})(es || (es = {})); +var es; +(function (es) { + var Flags = (function () { + function Flags() { + } + Flags.isFlagSet = function (self, flag) { + return (self & flag) != 0; + }; + Flags.isUnshiftedFlagSet = function (self, flag) { + flag = 1 << flag; + return (self & flag) != 0; + }; + Flags.setFlagExclusive = function (self, flag) { + return 1 << flag; + }; + Flags.setFlag = function (self, flag) { + return (self | 1 << flag); + }; + Flags.unsetFlag = function (self, flag) { + flag = 1 << flag; + return (self & (~flag)); + }; + Flags.invertFlags = function (self) { + return ~self; + }; + return Flags; + }()); + es.Flags = Flags; +})(es || (es = {})); +var es; +(function (es) { + var MathHelper = (function () { + function MathHelper() { + } + MathHelper.toDegrees = function (radians) { + return radians * 57.295779513082320876798154814105; + }; + MathHelper.toRadians = function (degrees) { + return degrees * 0.017453292519943295769236907684886; + }; + MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { + return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); + }; + MathHelper.lerp = function (value1, value2, amount) { + return value1 + (value2 - value1) * amount; + }; + MathHelper.clamp = function (value, min, max) { + if (value < min) + return min; + if (value > max) + return max; + return value; + }; + MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { + var radians = MathHelper.toRadians(angleInDegrees); + return new es.Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); + }; + MathHelper.isEven = function (value) { + return value % 2 == 0; + }; + MathHelper.clamp01 = function (value) { + if (value < 0) + return 0; + if (value > 1) + return 1; + return value; + }; + MathHelper.angleBetweenVectors = function (from, to) { + return Math.atan2(to.y - from.y, to.x - from.x); + }; + MathHelper.Epsilon = 0.00001; + MathHelper.Rad2Deg = 57.29578; + MathHelper.Deg2Rad = 0.0174532924; + return MathHelper; + }()); + es.MathHelper = MathHelper; +})(es || (es = {})); +var es; +(function (es) { + var Matrix2D = (function () { + function Matrix2D(m11, m12, m21, m22, m31, m32) { + this.m11 = 0; + this.m12 = 0; + this.m21 = 0; + this.m22 = 0; + this.m31 = 0; + this.m32 = 0; + this.m11 = m11 ? m11 : 1; + this.m12 = m12 ? m12 : 0; + this.m21 = m21 ? m21 : 0; + this.m22 = m22 ? m22 : 1; + this.m31 = m31 ? m31 : 0; + this.m32 = m32 ? m32 : 0; + } + Object.defineProperty(Matrix2D, "identity", { + get: function () { + return Matrix2D._identity; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "translation", { + get: function () { + return new es.Vector2(this.m31, this.m32); + }, + set: function (value) { + this.m31 = value.x; + this.m32 = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotation", { + get: function () { + return Math.atan2(this.m21, this.m11); + }, + set: function (value) { + var val1 = Math.cos(value); + var val2 = Math.sin(value); + this.m11 = val1; + this.m12 = val2; + this.m21 = -val2; + this.m22 = val1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { + get: function () { + return es.MathHelper.toDegrees(this.rotation); + }, + set: function (value) { + this.rotation = es.MathHelper.toRadians(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "scale", { + get: function () { + return new es.Vector2(this.m11, this.m22); + }, + set: function (value) { + this.m11 = value.x; + this.m12 = value.y; + }, + enumerable: true, + configurable: true + }); + Matrix2D.add = function (matrix1, matrix2) { + matrix1.m11 += matrix2.m11; + matrix1.m12 += matrix2.m12; + matrix1.m21 += matrix2.m21; + matrix1.m22 += matrix2.m22; + matrix1.m31 += matrix2.m31; + matrix1.m32 += matrix2.m32; + return matrix1; + }; + Matrix2D.divide = function (matrix1, matrix2) { + matrix1.m11 /= matrix2.m11; + matrix1.m12 /= matrix2.m12; + matrix1.m21 /= matrix2.m21; + matrix1.m22 /= matrix2.m22; + matrix1.m31 /= matrix2.m31; + matrix1.m32 /= matrix2.m32; + return matrix1; + }; + Matrix2D.multiply = function (matrix1, matrix2) { + var result = new Matrix2D(); + var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); + var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); + var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); + var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); + var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; + var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; + result.m11 = m11; + result.m12 = m12; + result.m21 = m21; + result.m22 = m22; + result.m31 = m31; + result.m32 = m32; + return result; + }; + Matrix2D.multiplyTranslation = function (matrix, x, y) { + var trans = Matrix2D.createTranslation(x, y); + return Matrix2D.multiply(matrix, trans); + }; + Matrix2D.prototype.determinant = function () { + return this.m11 * this.m22 - this.m12 * this.m21; + }; + Matrix2D.invert = function (matrix, result) { + if (result === void 0) { result = new Matrix2D(); } + var det = 1 / matrix.determinant(); + result.m11 = matrix.m22 * det; + result.m12 = -matrix.m12 * det; + result.m21 = -matrix.m21 * det; + result.m22 = matrix.m11 * det; + result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; + result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; + return result; + }; + Matrix2D.createTranslation = function (xPosition, yPosition) { + var result = new Matrix2D(); + result.m11 = 1; + result.m12 = 0; + result.m21 = 0; + result.m22 = 1; + result.m31 = xPosition; + result.m32 = yPosition; + return result; + }; + Matrix2D.createTranslationVector = function (position) { + return this.createTranslation(position.x, position.y); + }; + Matrix2D.createRotation = function (radians, result) { + result = new Matrix2D(); + var val1 = Math.cos(radians); + var val2 = Math.sin(radians); + result.m11 = val1; + result.m12 = val2; + result.m21 = -val2; + result.m22 = val1; + return result; + }; + Matrix2D.createScale = function (xScale, yScale, result) { + if (result === void 0) { result = new Matrix2D(); } + result.m11 = xScale; + result.m12 = 0; + result.m21 = 0; + result.m22 = yScale; + result.m31 = 0; + result.m32 = 0; + return result; + }; + Matrix2D.prototype.toEgretMatrix = function () { + var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + }; + Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); + return Matrix2D; + }()); + es.Matrix2D = Matrix2D; +})(es || (es = {})); +var es; +(function (es) { + var Rectangle = (function (_super) { + __extends(Rectangle, _super); + function Rectangle() { + return _super !== null && _super.apply(this, arguments) || this; + } + Object.defineProperty(Rectangle.prototype, "max", { + get: function () { + return new es.Vector2(this.right, this.bottom); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "center", { + get: function () { + return new es.Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "location", { + get: function () { + return new es.Vector2(this.x, this.y); + }, + set: function (value) { + this.x = value.x; + this.y = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "size", { + get: function () { + return new es.Vector2(this.width, this.height); + }, + set: function (value) { + this.width = value.x; + this.height = value.y; + }, + enumerable: true, + configurable: true + }); + Rectangle.prototype.intersects = function (value) { + return value.left < this.right && + this.left < value.right && + value.top < this.bottom && + this.top < value.bottom; + }; + Rectangle.prototype.containsRect = function (value) { + return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && + (this.y <= value.y)) && + (value.y < (this.y + this.height))); + }; + Rectangle.prototype.getHalfSize = function () { + return new es.Vector2(this.width * 0.5, this.height * 0.5); + }; + Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { + return new Rectangle(minX, minY, maxX - minX, maxY - minY); + }; + Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { + var edgeNormal = es.Vector2.zero; + var res = new es.Vector2(); + res.x = es.MathHelper.clamp(point.x, this.left, this.right); + res.y = es.MathHelper.clamp(point.y, this.top, this.bottom); + if (this.contains(res.x, res.y)) { + var dl = res.x - this.left; + var dr = this.right - res.x; + var dt = res.y - this.top; + var db = this.bottom - res.y; + var min = Math.min(dl, dr, dt, db); + if (min == dt) { + res.y = this.top; + edgeNormal.y = -1; + } + else if (min == db) { + res.y = this.bottom; + edgeNormal.y = 1; + } + else if (min == dl) { + res.x = this.left; + edgeNormal.x = -1; + } + else { + res.x = this.right; + edgeNormal.x = 1; + } } else { - this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); + if (res.x == this.left) + edgeNormal.x = -1; + if (res.x == this.right) + edgeNormal.x = 1; + if (res.y == this.top) + edgeNormal.y = -1; + if (res.y == this.bottom) + edgeNormal.y = 1; } - this._tempTriggerList.length = 0; - if (collisionPair.second.entity) { - collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { - if (isEntering) { - this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second); - } - else { - this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second); + return { res: res, edgeNormal: edgeNormal }; + }; + Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () { + var max = this.max; + var minDist = Math.abs(this.location.x); + var boundsPoint = new es.Vector2(this.location.x, 0); + if (Math.abs(max.x) < minDist) { + minDist = Math.abs(max.x); + boundsPoint.x = max.x; + boundsPoint.y = 0; + } + if (Math.abs(max.y) < minDist) { + minDist = Math.abs(max.y); + boundsPoint.x = 0; + boundsPoint.y = max.y; + } + if (Math.abs(this.location.y) < minDist) { + minDist = Math.abs(this.location.y); + boundsPoint.x = 0; + boundsPoint.y = this.location.y; + } + return boundsPoint; + }; + Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) { + this.x = parentPosition.x + position.x - origin.x * scale.x; + this.y = parentPosition.y + position.y - origin.y * scale.y; + this.width = width * scale.x; + this.height = height * scale.y; + }; + Rectangle.prototype.setEgretRect = function (rect) { + this.x = rect.x; + this.y = rect.y; + this.width = rect.width; + this.height = rect.height; + return this; + }; + Rectangle.rectEncompassingPoints = function (points) { + var minX = Number.POSITIVE_INFINITY; + var minY = Number.POSITIVE_INFINITY; + var maxX = Number.NEGATIVE_INFINITY; + var maxY = Number.NEGATIVE_INFINITY; + for (var i = 0; i < points.length; i++) { + var pt = points[i]; + if (pt.x < minX) + minX = pt.x; + if (pt.x > maxX) + maxX = pt.x; + if (pt.y < minY) + minY = pt.y; + if (pt.y > maxY) + maxY = pt.y; + } + return this.fromMinMax(minX, minY, maxX, maxY); + }; + return Rectangle; + }(egret.Rectangle)); + es.Rectangle = Rectangle; +})(es || (es = {})); +var es; +(function (es) { + var Vector3 = (function () { + function Vector3(x, y, z) { + this.x = x; + this.y = y; + this.z = z; + } + return Vector3; + }()); + es.Vector3 = Vector3; +})(es || (es = {})); +var es; +(function (es) { + var ColliderTriggerHelper = (function () { + function ColliderTriggerHelper(entity) { + this._activeTriggerIntersections = []; + this._previousTriggerIntersections = []; + this._tempTriggerList = []; + this._entity = entity; + } + ColliderTriggerHelper.prototype.update = function () { + var colliders = this._entity.getComponents(es.Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + var boxcastResult = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); + collider.bounds = boxcastResult.rect; + var neighbors = boxcastResult.colliders; + var _loop_5 = function (j) { + var neighbor = neighbors[j]; + if (!collider.isTrigger && !neighbor.isTrigger) + return "continue"; + if (collider.overlaps(neighbor)) { + var pair_1 = new es.Pair(collider, neighbor); + var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1; + if (shouldReportTriggerEvent) + this_1.notifyTriggerListeners(pair_1, true); + if (!this_1._activeTriggerIntersections.contains(pair_1)) + this_1._activeTriggerIntersections.push(pair_1); } + }; + var this_1 = this; + for (var j = 0; j < neighbors.length; j++) { + _loop_5(j); + } + } + es.ListPool.free(colliders); + this.checkForExitedColliders(); + }; + ColliderTriggerHelper.prototype.checkForExitedColliders = function () { + var _this = this; + var _loop_6 = function (i) { + var index = this_2._previousTriggerIntersections.findIndex(function (value) { + if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second) + return true; + return false; + }); + if (index != -1) + this_2._previousTriggerIntersections.removeAt(index); + }; + var this_2 = this; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + _loop_6(i); + } + for (var i = 0; i < this._previousTriggerIntersections.length; i++) { + this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); + } + this._previousTriggerIntersections.length = 0; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) { + this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); + } + } + this._activeTriggerIntersections.length = 0; + }; + ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) { + collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + if (isEntering) { + this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); + } + else { + this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); } this._tempTriggerList.length = 0; + if (collisionPair.second.entity) { + collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { + if (isEntering) { + this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second); + } + else { + this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second); + } + } + this._tempTriggerList.length = 0; + } } + }; + return ColliderTriggerHelper; + }()); + es.ColliderTriggerHelper = ColliderTriggerHelper; +})(es || (es = {})); +var es; +(function (es) { + var PointSectors; + (function (PointSectors) { + PointSectors[PointSectors["center"] = 0] = "center"; + PointSectors[PointSectors["top"] = 1] = "top"; + PointSectors[PointSectors["bottom"] = 2] = "bottom"; + PointSectors[PointSectors["topLeft"] = 9] = "topLeft"; + PointSectors[PointSectors["topRight"] = 5] = "topRight"; + PointSectors[PointSectors["left"] = 8] = "left"; + PointSectors[PointSectors["right"] = 4] = "right"; + PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft"; + PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight"; + })(PointSectors = es.PointSectors || (es.PointSectors = {})); + var Collisions = (function () { + function Collisions() { } - }; - return ColliderTriggerHelper; -}()); -var PointSectors; -(function (PointSectors) { - PointSectors[PointSectors["center"] = 0] = "center"; - PointSectors[PointSectors["top"] = 1] = "top"; - PointSectors[PointSectors["bottom"] = 2] = "bottom"; - PointSectors[PointSectors["topLeft"] = 9] = "topLeft"; - PointSectors[PointSectors["topRight"] = 5] = "topRight"; - PointSectors[PointSectors["left"] = 8] = "left"; - PointSectors[PointSectors["right"] = 4] = "right"; - PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft"; - PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight"; -})(PointSectors || (PointSectors = {})); -var Collisions = (function () { - function Collisions() { - } - Collisions.isLineToLine = function (a1, a2, b1, b2) { - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) - return false; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) - return false; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) - return false; - return true; - }; - Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { - var intersection = new Vector2(0, 0); - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) - return intersection; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) - return intersection; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) - return intersection; - intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); - return intersection; - }; - Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); - }; - Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) { - return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); - }; - Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) { - return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; - }; - Collisions.isCircleToPoint = function (circleCenter, radius, point) { - return Vector2.distanceSquared(circleCenter, point) < radius * radius; - }; - Collisions.isRectToCircle = function (rect, cPosition, cRadius) { - var ew = rect.width * 0.5; - var eh = rect.height * 0.5; - var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); - var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); - return vx * vx + vy * vy < cRadius * cRadius; - }; - Collisions.isRectToLine = function (rect, lineFrom, lineTo) { - var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); - var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); - if (fromSector == PointSectors.center || toSector == PointSectors.center) { + Collisions.isLineToLine = function (a1, a2, b1, b2) { + var b = es.Vector2.subtract(a2, a1); + var d = es.Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return false; + var c = es.Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return false; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return false; return true; - } - else if ((fromSector & toSector) != 0) { + }; + Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { + var intersection = new es.Vector2(0, 0); + var b = es.Vector2.subtract(a2, a1); + var d = es.Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return intersection; + var c = es.Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return intersection; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return intersection; + intersection = es.Vector2.add(a1, new es.Vector2(t * b.x, t * b.y)); + return intersection; + }; + Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = es.Vector2.subtract(lineB, lineA); + var w = es.Vector2.subtract(closestTo, lineA); + var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v); + t = es.MathHelper.clamp(t, 0, 1); + return es.Vector2.add(lineA, new es.Vector2(v.x * t, v.y * t)); + }; + Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) { + return es.Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); + }; + Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) { + return es.Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; + }; + Collisions.isCircleToPoint = function (circleCenter, radius, point) { + return es.Vector2.distanceSquared(circleCenter, point) < radius * radius; + }; + Collisions.isRectToCircle = function (rect, cPosition, cRadius) { + var ew = rect.width * 0.5; + var eh = rect.height * 0.5; + var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); + var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); + return vx * vx + vy * vy < cRadius * cRadius; + }; + Collisions.isRectToLine = function (rect, lineFrom, lineTo) { + var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); + var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); + if (fromSector == PointSectors.center || toSector == PointSectors.center) { + return true; + } + else if ((fromSector & toSector) != 0) { + return false; + } + else { + var both = fromSector | toSector; + var edgeFrom = void 0; + var edgeTo = void 0; + if ((both & PointSectors.top) != 0) { + edgeFrom = new es.Vector2(rect.x, rect.y); + edgeTo = new es.Vector2(rect.x + rect.width, rect.y); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.bottom) != 0) { + edgeFrom = new es.Vector2(rect.x, rect.y + rect.height); + edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.left) != 0) { + edgeFrom = new es.Vector2(rect.x, rect.y); + edgeTo = new es.Vector2(rect.x, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.right) != 0) { + edgeFrom = new es.Vector2(rect.x + rect.width, rect.y); + edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + } return false; + }; + Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { + return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; + }; + Collisions.getSector = function (rX, rY, rW, rH, point) { + var sector = PointSectors.center; + if (point.x < rX) + sector |= PointSectors.left; + else if (point.x >= rX + rW) + sector |= PointSectors.right; + if (point.y < rY) + sector |= PointSectors.top; + else if (point.y >= rY + rH) + sector |= PointSectors.bottom; + return sector; + }; + return Collisions; + }()); + es.Collisions = Collisions; +})(es || (es = {})); +var es; +(function (es) { + var Physics = (function () { + function Physics() { } - else { - var both = fromSector | toSector; - var edgeFrom = void 0; - var edgeTo = void 0; - if ((both & PointSectors.top) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + Physics.reset = function () { + this._spatialHash = new es.SpatialHash(this.spatialHashCellSize); + }; + Physics.clear = function () { + this._spatialHash.clear(); + }; + Physics.overlapCircleAll = function (center, randius, results, layerMask) { + if (layerMask === void 0) { layerMask = -1; } + return this._spatialHash.overlapCircle(center, randius, results, layerMask); + }; + Physics.boxcastBroadphase = function (rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + var boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); + return { colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds }; + }; + Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + return this._spatialHash.aabbBroadphase(rect, collider, layerMask); + }; + Physics.addCollider = function (collider) { + Physics._spatialHash.register(collider); + }; + Physics.removeCollider = function (collider) { + Physics._spatialHash.remove(collider); + }; + Physics.updateCollider = function (collider) { + this._spatialHash.remove(collider); + this._spatialHash.register(collider); + }; + Physics.debugDraw = function (secondsToDisplay) { + this._spatialHash.debugDraw(secondsToDisplay, 2); + }; + Physics.spatialHashCellSize = 100; + Physics.allLayers = -1; + return Physics; + }()); + es.Physics = Physics; +})(es || (es = {})); +var es; +(function (es) { + var Shape = (function () { + function Shape() { + } + return Shape; + }()); + es.Shape = Shape; +})(es || (es = {})); +var es; +(function (es) { + var Polygon = (function (_super) { + __extends(Polygon, _super); + function Polygon(points, isBox) { + var _this = _super.call(this) || this; + _this._areEdgeNormalsDirty = true; + _this.isUnrotated = true; + _this.setPoints(points); + _this.isBox = isBox; + return _this; + } + Object.defineProperty(Polygon.prototype, "edgeNormals", { + get: function () { + if (this._areEdgeNormalsDirty) + this.buildEdgeNormals(); + return this._edgeNormals; + }, + enumerable: true, + configurable: true + }); + Polygon.prototype.setPoints = function (points) { + this.points = points; + this.recalculateCenterAndEdgeNormals(); + this._originalPoints = []; + for (var i = 0; i < this.points.length; i++) { + this._originalPoints.push(this.points[i]); } - if ((both & PointSectors.bottom) != 0) { - edgeFrom = new Vector2(rect.x, rect.y + rect.height); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + }; + Polygon.prototype.recalculateCenterAndEdgeNormals = function () { + this._polygonCenter = Polygon.findPolygonCenter(this.points); + this._areEdgeNormalsDirty = true; + }; + Polygon.prototype.buildEdgeNormals = function () { + var totalEdges = this.isBox ? 2 : this.points.length; + if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) + this._edgeNormals = new Array(totalEdges); + var p2; + for (var i = 0; i < totalEdges; i++) { + var p1 = this.points[i]; + if (i + 1 >= this.points.length) + p2 = this.points[0]; + else + p2 = this.points[i + 1]; + var perp = es.Vector2Ext.perpendicular(p1, p2); + perp = es.Vector2.normalize(perp); + this._edgeNormals[i] = perp; } - if ((both & PointSectors.left) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + }; + Polygon.buildSymmetricalPolygon = function (vertCount, radius) { + var verts = new Array(vertCount); + for (var i = 0; i < vertCount; i++) { + var a = 2 * Math.PI * (i / vertCount); + verts[i] = new es.Vector2(Math.cos(a), Math.sin(a) * radius); } - if ((both & PointSectors.right) != 0) { - edgeFrom = new Vector2(rect.x + rect.width, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + return verts; + }; + Polygon.recenterPolygonVerts = function (points) { + var center = this.findPolygonCenter(points); + for (var i = 0; i < points.length; i++) + points[i] = es.Vector2.subtract(points[i], center); + }; + Polygon.findPolygonCenter = function (points) { + var x = 0, y = 0; + for (var i = 0; i < points.length; i++) { + x += points[i].x; + y += points[i].y; } + return new es.Vector2(x / points.length, y / points.length); + }; + Polygon.getClosestPointOnPolygonToPoint = function (points, point) { + var distanceSquared = Number.MAX_VALUE; + var edgeNormal = new es.Vector2(0, 0); + var closestPoint = new es.Vector2(0, 0); + var tempDistanceSquared; + for (var i = 0; i < points.length; i++) { + var j = i + 1; + if (j == points.length) + j = 0; + var closest = es.ShapeCollisions.closestPointOnLine(points[i], points[j], point); + tempDistanceSquared = es.Vector2.distanceSquared(point, closest); + if (tempDistanceSquared < distanceSquared) { + distanceSquared = tempDistanceSquared; + closestPoint = closest; + var line = es.Vector2.subtract(points[j], points[i]); + edgeNormal.x = -line.y; + edgeNormal.y = line.x; + } + } + edgeNormal = es.Vector2.normalize(edgeNormal); + return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + }; + Polygon.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotateWithTransform) { + this.isUnrotated = collider.entity.transform.rotation == 0; + } + this.position = es.Vector2.add(collider.entity.transform.position, this.center); + this.bounds = es.Rectangle.rectEncompassingPoints(this.points); + this.bounds.location = es.Vector2.add(this.bounds.location, this.position); + }; + Polygon.prototype.overlaps = function (other) { + var result; + if (other instanceof Polygon) + return es.ShapeCollisions.polygonToPolygon(this, other); + if (other instanceof es.Circle) { + result = es.ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return true; + } + return false; + } + throw new Error("overlaps of Pologon to " + other + " are not supported"); + }; + Polygon.prototype.collidesWithShape = function (other) { + var result = new es.CollisionResult(); + if (other instanceof Polygon) { + return es.ShapeCollisions.polygonToPolygon(this, other); + } + if (other instanceof es.Circle) { + result = es.ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return result; + } + return null; + } + throw new Error("overlaps of Polygon to " + other + " are not supported"); + }; + Polygon.prototype.containsPoint = function (point) { + point = es.Vector2.subtract(point, this.position); + var isInside = false; + for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { + if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && + (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + + this.points[i].x)) { + isInside = !isInside; + } + } + return isInside; + }; + Polygon.prototype.pointCollidesWithShape = function (point) { + return es.ShapeCollisions.pointToPoly(point, this); + }; + return Polygon; + }(es.Shape)); + es.Polygon = Polygon; +})(es || (es = {})); +var es; +(function (es) { + var Box = (function (_super) { + __extends(Box, _super); + function Box(width, height) { + var _this = _super.call(this, Box.buildBox(width, height), true) || this; + _this.width = width; + _this.height = height; + return _this; } - return false; - }; - Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { - return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; - }; - Collisions.getSector = function (rX, rY, rW, rH, point) { - var sector = PointSectors.center; - if (point.x < rX) - sector |= PointSectors.left; - else if (point.x >= rX + rW) - sector |= PointSectors.right; - if (point.y < rY) - sector |= PointSectors.top; - else if (point.y >= rY + rH) - sector |= PointSectors.bottom; - return sector; - }; - return Collisions; -}()); -var Physics = (function () { - function Physics() { - } - Physics.reset = function () { - this._spatialHash = new SpatialHash(this.spatialHashCellSize); - }; - Physics.clear = function () { - this._spatialHash.clear(); - }; - Physics.overlapCircleAll = function (center, randius, results, layerMask) { - if (layerMask === void 0) { layerMask = -1; } - return this._spatialHash.overlapCircle(center, randius, results, layerMask); - }; - Physics.boxcastBroadphase = function (rect, layerMask) { - if (layerMask === void 0) { layerMask = this.allLayers; } - var boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); - return { colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds }; - }; - Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { - if (layerMask === void 0) { layerMask = this.allLayers; } - return this._spatialHash.aabbBroadphase(rect, collider, layerMask); - }; - Physics.addCollider = function (collider) { - Physics._spatialHash.register(collider); - }; - Physics.removeCollider = function (collider) { - Physics._spatialHash.remove(collider); - }; - Physics.updateCollider = function (collider) { - this._spatialHash.remove(collider); - this._spatialHash.register(collider); - }; - Physics.debugDraw = function (secondsToDisplay) { - this._spatialHash.debugDraw(secondsToDisplay, 2); - }; - Physics.spatialHashCellSize = 100; - Physics.allLayers = -1; - return Physics; -}()); -var Shape = (function (_super) { - __extends(Shape, _super); - function Shape() { - return _super !== null && _super.apply(this, arguments) || this; - } - return Shape; -}(egret.DisplayObject)); -var Polygon = (function (_super) { - __extends(Polygon, _super); - function Polygon(points, isBox) { - var _this = _super.call(this) || this; - _this._areEdgeNormalsDirty = true; - _this.center = new Vector2(); - _this.setPoints(points); - _this.isBox = isBox; - return _this; - } - Object.defineProperty(Polygon.prototype, "position", { - get: function () { - return new Vector2(this.parent.x, this.parent.y); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Polygon.prototype, "bounds", { - get: function () { - return new Rectangle(this.x, this.y, this.width, this.height); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Polygon.prototype, "edgeNormals", { - get: function () { - if (this._areEdgeNormalsDirty) - this.buildEdgeNormals(); - return this._edgeNormals; - }, - enumerable: true, - configurable: true - }); - Polygon.prototype.buildEdgeNormals = function () { - var totalEdges = this.isBox ? 2 : this.points.length; - if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) - this._edgeNormals = new Array(totalEdges); - var p2; - for (var i = 0; i < totalEdges; i++) { - var p1 = this.points[i]; - if (i + 1 >= this.points.length) - p2 = this.points[0]; - else - p2 = this.points[i + 1]; - var perp = Vector2Ext.perpendicular(p1, p2); - perp = Vector2.normalize(perp); - this._edgeNormals[i] = perp; + Box.buildBox = function (width, height) { + var halfWidth = width / 2; + var halfHeight = height / 2; + var verts = new Array(4); + verts[0] = new es.Vector2(-halfWidth, -halfHeight); + verts[1] = new es.Vector2(halfWidth, -halfHeight); + verts[2] = new es.Vector2(halfWidth, halfHeight); + verts[3] = new es.Vector2(-halfWidth, halfHeight); + return verts; + }; + Box.prototype.updateBox = function (width, height) { + this.width = width; + this.height = height; + var halfWidth = width / 2; + var halfHeight = height / 2; + this.points[0] = new es.Vector2(-halfWidth, -halfHeight); + this.points[1] = new es.Vector2(halfWidth, -halfHeight); + this.points[2] = new es.Vector2(halfWidth, halfHeight); + this.points[3] = new es.Vector2(-halfWidth, halfHeight); + for (var i = 0; i < this.points.length; i++) + this._originalPoints[i] = this.points[i]; + }; + Box.prototype.overlaps = function (other) { + if (this.isUnrotated) { + if (other instanceof Box) + return this.bounds.intersects(other.bounds); + if (other instanceof es.Circle) + return es.Collisions.isRectToCircle(this.bounds, other.position, other.radius); + } + return _super.prototype.overlaps.call(this, other); + }; + Box.prototype.collidesWithShape = function (other) { + if (other instanceof Box && other.isUnrotated) { + return es.ShapeCollisions.boxToBox(this, other); + } + return _super.prototype.collidesWithShape.call(this, other); + }; + Box.prototype.containsPoint = function (point) { + if (this.isUnrotated) + return this.bounds.contains(point.x, point.y); + return _super.prototype.containsPoint.call(this, point); + }; + return Box; + }(es.Polygon)); + es.Box = Box; +})(es || (es = {})); +var es; +(function (es) { + var Circle = (function (_super) { + __extends(Circle, _super); + function Circle(radius) { + var _this = _super.call(this) || this; + _this.radius = radius; + _this._originalRadius = radius; + return _this; } - }; - Polygon.prototype.setPoints = function (points) { - this.points = points; - this.recalculateCenterAndEdgeNormals(); - this._originalPoints = []; - for (var i = 0; i < this.points.length; i++) { - this._originalPoints.push(this.points[i]); + Circle.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotateWithTransform) { + var scale = collider.entity.transform.scale; + var hasUnitScale = scale.x == 1 && scale.y == 1; + var maxScale = Math.max(scale.x, scale.y); + this.radius = this._originalRadius * maxScale; + if (collider.entity.transform.rotation != 0) { + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg; + var offsetLength = hasUnitScale ? collider._localOffsetLength : es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); + } + } + this.position = es.Vector2.add(collider.transform.position, this.center); + this.bounds = new es.Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); + }; + Circle.prototype.overlaps = function (other) { + if (other instanceof es.Box && other.isUnrotated) + return es.Collisions.isRectToCircle(other.bounds, this.position, this.radius); + if (other instanceof Circle) + return es.Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); + if (other instanceof es.Polygon) + return es.ShapeCollisions.circleToPolygon(this, other); + throw new Error("overlaps of circle to " + other + " are not supported"); + }; + Circle.prototype.collidesWithShape = function (other) { + if (other instanceof es.Box && other.isUnrotated) { + return es.ShapeCollisions.circleToBox(this, other); + } + if (other instanceof Circle) { + return es.ShapeCollisions.circleToCircle(this, other); + } + if (other instanceof es.Polygon) { + return es.ShapeCollisions.circleToPolygon(this, other); + } + throw new Error("Collisions of Circle to " + other + " are not supported"); + }; + Circle.prototype.pointCollidesWithShape = function (point) { + return es.ShapeCollisions.pointToCircle(point, this); + }; + return Circle; + }(es.Shape)); + es.Circle = Circle; +})(es || (es = {})); +var es; +(function (es) { + var CollisionResult = (function () { + function CollisionResult() { + this.minimumTranslationVector = es.Vector2.zero; + this.normal = es.Vector2.zero; + this.point = es.Vector2.zero; } - }; - Polygon.prototype.collidesWithShape = function (other) { - var result = new CollisionResult(); - if (other instanceof Polygon) { - return ShapeCollisions.polygonToPolygon(this, other); + CollisionResult.prototype.invertResult = function () { + this.minimumTranslationVector = es.Vector2.negate(this.minimumTranslationVector); + this.normal = es.Vector2.negate(this.normal); + }; + return CollisionResult; + }()); + es.CollisionResult = CollisionResult; +})(es || (es = {})); +var es; +(function (es) { + var ShapeCollisions = (function () { + function ShapeCollisions() { } - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); + ShapeCollisions.polygonToPolygon = function (first, second) { + var result = new es.CollisionResult(); + var isIntersecting = true; + var firstEdges = first.edgeNormals; + var secondEdges = second.edgeNormals; + var minIntervalDistance = Number.POSITIVE_INFINITY; + var translationAxis = new es.Vector2(); + var polygonOffset = es.Vector2.subtract(first.position, second.position); + var axis; + for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { + if (edgeIndex < firstEdges.length) { + axis = firstEdges[edgeIndex]; + } + else { + axis = secondEdges[edgeIndex - firstEdges.length]; + } + var minA = 0; + var minB = 0; + var maxA = 0; + var maxB = 0; + var intervalDist = 0; + var ta = this.getInterval(axis, first, minA, maxA); + minA = ta.min; + minB = ta.max; + var tb = this.getInterval(axis, second, minB, maxB); + minB = tb.min; + maxB = tb.max; + var relativeIntervalOffset = es.Vector2.dot(polygonOffset, axis); + minA += relativeIntervalOffset; + maxA += relativeIntervalOffset; + intervalDist = this.intervalDistance(minA, maxA, minB, maxB); + if (intervalDist > 0) + isIntersecting = false; + if (!isIntersecting) + return null; + intervalDist = Math.abs(intervalDist); + if (intervalDist < minIntervalDistance) { + minIntervalDistance = intervalDist; + translationAxis = axis; + if (es.Vector2.dot(translationAxis, polygonOffset) < 0) + translationAxis = new es.Vector2(-translationAxis); + } + } + result.normal = translationAxis; + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-translationAxis.x, -translationAxis.y), new es.Vector2(minIntervalDistance)); + return result; + }; + ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { + if (minA < minB) + return minB - maxA; + return minA - minB; + }; + ShapeCollisions.getInterval = function (axis, polygon, min, max) { + var dot = es.Vector2.dot(polygon.points[0], axis); + min = max = dot; + for (var i = 1; i < polygon.points.length; i++) { + dot = es.Vector2.dot(polygon.points[i], axis); + if (dot < min) { + min = dot; + } + else if (dot > max) { + max = dot; + } + } + return { min: min, max: max }; + }; + ShapeCollisions.circleToPolygon = function (circle, polygon) { + var result = new es.CollisionResult(); + var poly2Circle = es.Vector2.subtract(circle.position, polygon.position); + var gpp = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); + var closestPoint = gpp.closestPoint; + var distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + var circleCenterInsidePoly = polygon.containsPoint(circle.position); + if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) + return null; + var mtv; + if (circleCenterInsidePoly) { + mtv = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared) - circle.radius)); + } + else { + if (distanceSquared == 0) { + mtv = es.Vector2.multiply(result.normal, new es.Vector2(circle.radius)); + } + else { + var distance = Math.sqrt(distanceSquared); + mtv = es.Vector2.multiply(new es.Vector2(-es.Vector2.subtract(poly2Circle, closestPoint)), new es.Vector2((circle.radius - distanceSquared) / distance)); + } + } + result.minimumTranslationVector = mtv; + result.point = es.Vector2.add(closestPoint, polygon.position); + return result; + }; + ShapeCollisions.circleToBox = function (circle, box) { + var result = new es.CollisionResult(); + var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; + if (box.containsPoint(circle.position)) { + result.point = closestPointOnBounds; + var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.subtract(result.normal, new es.Vector2(circle.radius))); + result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace); + return result; + } + var sqrDistance = es.Vector2.distanceSquared(closestPointOnBounds, circle.position); + if (sqrDistance == 0) { + result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(circle.radius)); + } + else if (sqrDistance <= circle.radius * circle.radius) { + result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds); + var depth = result.normal.length() - circle.radius; + result.normal = es.Vector2Ext.normalize(result.normal); + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal); return result; } return null; - } - throw new Error("overlaps of Polygon to " + other + " are not supported"); - }; - Polygon.prototype.recalculateCenterAndEdgeNormals = function () { - this._polygonCenter = Polygon.findPolygonCenter(this.points); - this._areEdgeNormalsDirty = true; - }; - Polygon.prototype.overlaps = function (other) { - var result; - if (other instanceof Polygon) - return ShapeCollisions.polygonToPolygon(this, other); - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); - return true; + }; + ShapeCollisions.pointToCircle = function (point, circle) { + var result = new es.CollisionResult(); + var distanceSquared = es.Vector2.distanceSquared(point, circle.position); + var sumOfRadii = 1 + circle.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = es.Vector2.normalize(es.Vector2.subtract(point, circle.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth, -depth), result.normal); + result.point = es.Vector2.add(circle.position, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius, circle.radius))); + return result; } - return false; - } - throw new Error("overlaps of Pologon to " + other + " are not supported"); - }; - Polygon.findPolygonCenter = function (points) { - var x = 0, y = 0; - for (var i = 0; i < points.length; i++) { - x += points[i].x; - y += points[i].y; - } - return new Vector2(x / points.length, y / points.length); - }; - Polygon.recenterPolygonVerts = function (points) { - var center = this.findPolygonCenter(points); - for (var i = 0; i < points.length; i++) - points[i] = Vector2.subtract(points[i], center); - }; - Polygon.getClosestPointOnPolygonToPoint = function (points, point) { - var distanceSquared = Number.MAX_VALUE; - var edgeNormal = new Vector2(0, 0); - var closestPoint = new Vector2(0, 0); - var tempDistanceSquared; - for (var i = 0; i < points.length; i++) { - var j = i + 1; - if (j == points.length) - j = 0; - var closest = ShapeCollisions.closestPointOnLine(points[i], points[j], point); - tempDistanceSquared = Vector2.distanceSquared(point, closest); - if (tempDistanceSquared < distanceSquared) { - distanceSquared = tempDistanceSquared; - closestPoint = closest; - var line = Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; - } - } - edgeNormal = Vector2.normalize(edgeNormal); - return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; - }; - Polygon.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToPoly(point, this); - }; - Polygon.prototype.containsPoint = function (point) { - point = Vector2.subtract(point, this.position); - var isInside = false; - for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { - if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && - (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + - this.points[i].x)) { - isInside = !isInside; - } - } - return isInside; - }; - Polygon.buildSymmertricalPolygon = function (vertCount, radius) { - var verts = new Array(vertCount); - for (var i = 0; i < vertCount; i++) { - var a = 2 * Math.PI * (i / vertCount); - verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); - } - return verts; - }; - return Polygon; -}(Shape)); -var Box = (function (_super) { - __extends(Box, _super); - function Box(width, height) { - var _this = _super.call(this, Box.buildBox(width, height), true) || this; - _this.width = width; - _this.height = height; - return _this; - } - Box.buildBox = function (width, height) { - var halfWidth = width / 2; - var halfHeight = height / 2; - var verts = new Array(4); - verts[0] = new Vector2(-halfWidth, -halfHeight); - verts[1] = new Vector2(halfWidth, -halfHeight); - verts[2] = new Vector2(halfWidth, halfHeight); - verts[3] = new Vector2(-halfWidth, halfHeight); - return verts; - }; - Box.prototype.overlaps = function (other) { - if (other instanceof Box) - return this.bounds.intersects(other.bounds); - if (other instanceof Circle) - return Collisions.isRectToCircle(this.bounds, other.position, other.radius); - return _super.prototype.overlaps.call(this, other); - }; - Box.prototype.collidesWithShape = function (other) { - if (other instanceof Box) { - return ShapeCollisions.boxToBox(this, other); - } - return _super.prototype.collidesWithShape.call(this, other); - }; - Box.prototype.updateBox = function (width, height) { - this.width = width; - this.height = height; - var halfWidth = width / 2; - var halfHeight = height / 2; - this.points[0] = new Vector2(-halfWidth, -halfHeight); - this.points[1] = new Vector2(halfWidth, -halfHeight); - this.points[2] = new Vector2(halfWidth, halfHeight); - this.points[3] = new Vector2(-halfWidth, halfHeight); - for (var i = 0; i < this.points.length; i++) - this._originalPoints[i] = this.points[i]; - }; - Box.prototype.containsPoint = function (point) { - return this.bounds.contains(point.x, point.y); - }; - return Box; -}(Polygon)); -var Circle = (function (_super) { - __extends(Circle, _super); - function Circle(radius) { - var _this = _super.call(this) || this; - _this.center = new Vector2(); - _this.radius = radius; - _this._originalRadius = radius; - return _this; - } - Object.defineProperty(Circle.prototype, "position", { - get: function () { - return new Vector2(this.parent.x, this.parent.y); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Circle.prototype, "bounds", { - get: function () { - return new Rectangle().setEgretRect(this.getBounds()); - }, - enumerable: true, - configurable: true - }); - Circle.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToCircle(point, this); - }; - Circle.prototype.collidesWithShape = function (other) { - if (other instanceof Box) { - return ShapeCollisions.circleToBox(this, other); - } - if (other instanceof Circle) { - return ShapeCollisions.circleToCircle(this, other); - } - if (other instanceof Polygon) { - return ShapeCollisions.circleToPolygon(this, other); - } - throw new Error("Collisions of Circle to " + other + " are not supported"); - }; - Circle.prototype.overlaps = function (other) { - if (other instanceof Box) - return Collisions.isRectToCircle(other.bounds, this.position, this.radius); - if (other instanceof Circle) - return Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); - if (other instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, other); - throw new Error("overlaps of circle to " + other + " are not supported"); - }; - return Circle; -}(Shape)); -var CollisionResult = (function () { - function CollisionResult() { - this.minimumTranslationVector = Vector2.zero; - this.normal = Vector2.zero; - this.point = Vector2.zero; - } - CollisionResult.prototype.invertResult = function () { - this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector); - this.normal = Vector2.negate(this.normal); - }; - return CollisionResult; -}()); -var ShapeCollisions = (function () { - function ShapeCollisions() { - } - ShapeCollisions.polygonToPolygon = function (first, second) { - var result = new CollisionResult(); - var isIntersecting = true; - var firstEdges = first.edgeNormals; - var secondEdges = second.edgeNormals; - var minIntervalDistance = Number.POSITIVE_INFINITY; - var translationAxis = new Vector2(); - var polygonOffset = Vector2.subtract(first.position, second.position); - var axis; - for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { - if (edgeIndex < firstEdges.length) { - axis = firstEdges[edgeIndex]; - } - else { - axis = secondEdges[edgeIndex - firstEdges.length]; - } - var minA = 0; - var minB = 0; - var maxA = 0; - var maxB = 0; - var intervalDist = 0; - var ta = this.getInterval(axis, first, minA, maxA); - minA = ta.min; - minB = ta.max; - var tb = this.getInterval(axis, second, minB, maxB); - minB = tb.min; - maxB = tb.max; - var relativeIntervalOffset = Vector2.dot(polygonOffset, axis); - minA += relativeIntervalOffset; - maxA += relativeIntervalOffset; - intervalDist = this.intervalDistance(minA, maxA, minB, maxB); - if (intervalDist > 0) - isIntersecting = false; - if (!isIntersecting) - return null; - intervalDist = Math.abs(intervalDist); - if (intervalDist < minIntervalDistance) { - minIntervalDistance = intervalDist; - translationAxis = axis; - if (Vector2.dot(translationAxis, polygonOffset) < 0) - translationAxis = new Vector2(-translationAxis); - } - } - result.normal = translationAxis; - result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance)); - return result; - }; - ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { - if (minA < minB) - return minB - maxA; - return minA - minB; - }; - ShapeCollisions.getInterval = function (axis, polygon, min, max) { - var dot = Vector2.dot(polygon.points[0], axis); - min = max = dot; - for (var i = 1; i < polygon.points.length; i++) { - dot = Vector2.dot(polygon.points[i], axis); - if (dot < min) { - min = dot; - } - else if (dot > max) { - max = dot; - } - } - return { min: min, max: max }; - }; - ShapeCollisions.circleToPolygon = function (circle, polygon) { - var result = new CollisionResult(); - var poly2Circle = Vector2.subtract(circle.position, polygon.position); - var gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); - var closestPoint = gpp.closestPoint; - var distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - var circleCenterInsidePoly = polygon.containsPoint(circle.position); - if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) return null; - var mtv; - if (circleCenterInsidePoly) { - mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared) - circle.radius)); - } - else { - if (distanceSquared == 0) { - mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); + }; + ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = es.Vector2.subtract(lineB, lineA); + var w = es.Vector2.subtract(closestTo, lineA); + var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v); + t = es.MathHelper.clamp(t, 0, 1); + return es.Vector2.add(lineA, es.Vector2.multiply(v, new es.Vector2(t, t))); + }; + ShapeCollisions.pointToPoly = function (point, poly) { + var result = new es.CollisionResult(); + if (poly.containsPoint(point)) { + var distanceSquared = void 0; + var gpp = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position)); + var closestPoint = gpp.closestPoint; + distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); + result.point = es.Vector2.add(closestPoint, poly.position); + return result; } - else { - var distance = Math.sqrt(distanceSquared); - mtv = Vector2.multiply(new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), new Vector2((circle.radius - distanceSquared) / distance)); + return null; + }; + ShapeCollisions.circleToCircle = function (first, second) { + var result = new es.CollisionResult(); + var distanceSquared = es.Vector2.distanceSquared(first.position, second.position); + var sumOfRadii = first.radius + second.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = es.Vector2.normalize(es.Vector2.subtract(first.position, second.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth), result.normal); + result.point = es.Vector2.add(second.position, es.Vector2.multiply(result.normal, new es.Vector2(second.radius))); + return result; } - } - result.minimumTranslationVector = mtv; - result.point = Vector2.add(closestPoint, polygon.position); - return result; - }; - ShapeCollisions.circleToBox = function (circle, box) { - var result = new CollisionResult(); - var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; - if (box.containsPoint(circle.position)) { - result.point = closestPointOnBounds; - var safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); - result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); - return result; - } - var sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); - if (sqrDistance == 0) { - result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius)); - } - else if (sqrDistance <= circle.radius * circle.radius) { - result.normal = Vector2.subtract(circle.position, closestPointOnBounds); - var depth = result.normal.length() - circle.radius; - result.normal = Vector2Ext.normalize(result.normal); - result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); - return result; - } - return null; - }; - ShapeCollisions.pointToCircle = function (point, circle) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared(point, circle.position); - var sumOfRadii = 1 + circle.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize(Vector2.subtract(point, circle.position)); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal); - result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius))); - return result; - } - return null; - }; - ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); - }; - ShapeCollisions.pointToPoly = function (point, poly) { - var result = new CollisionResult(); - if (poly.containsPoint(point)) { - var distanceSquared = void 0; - var gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position)); - var closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); - result.point = Vector2.add(closestPoint, poly.position); - return result; - } - return null; - }; - ShapeCollisions.circleToCircle = function (first, second) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared(first.position, second.position); - var sumOfRadii = first.radius + second.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position)); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal); - result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius))); - return result; - } - return null; - }; - ShapeCollisions.boxToBox = function (first, second) { - var result = new CollisionResult(); - var minkowskiDiff = this.minkowskiDifference(first, second); - if (minkowskiDiff.contains(0, 0)) { - result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); - if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) - return null; - result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); - result.normal.normalize(); - return result; - } - return null; - }; - ShapeCollisions.minkowskiDifference = function (first, second) { - var positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, Vector2.divide(first.bounds.size, new Vector2(2)))); - var topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max); - var fullSize = Vector2.add(first.bounds.size, second.bounds.size); - return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y); - }; - return ShapeCollisions; -}()); -var SpatialHash = (function () { - function SpatialHash(cellSize) { - if (cellSize === void 0) { cellSize = 100; } - this.gridBounds = new Rectangle(); - this._overlapTestCircle = new Circle(0); - this._tempHashSet = []; - this._cellDict = new NumberDictionary(); - this._cellSize = cellSize; - this._inverseCellSize = 1 / this._cellSize; - this._raycastParser = new RaycastResultParser(); - } - SpatialHash.prototype.remove = function (collider) { - var bounds = collider.registeredPhysicsBounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) - console.error("removing Collider [" + collider + "] from a cell that it is not present in"); - else - cell.remove(collider); + return null; + }; + ShapeCollisions.boxToBox = function (first, second) { + var result = new es.CollisionResult(); + var minkowskiDiff = this.minkowskiDifference(first, second); + if (minkowskiDiff.contains(0, 0)) { + result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); + if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) + return null; + result.normal = new es.Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); + result.normal.normalize(); + return result; } + return null; + }; + ShapeCollisions.minkowskiDifference = function (first, second) { + var positionOffset = es.Vector2.subtract(first.position, es.Vector2.add(first.bounds.location, es.Vector2.divide(first.bounds.size, new es.Vector2(2)))); + var topLeft = es.Vector2.subtract(es.Vector2.add(first.bounds.location, positionOffset), second.bounds.max); + var fullSize = es.Vector2.add(first.bounds.size, second.bounds.size); + return new es.Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y); + }; + return ShapeCollisions; + }()); + es.ShapeCollisions = ShapeCollisions; +})(es || (es = {})); +var es; +(function (es) { + var SpatialHash = (function () { + function SpatialHash(cellSize) { + if (cellSize === void 0) { cellSize = 100; } + this.gridBounds = new es.Rectangle(); + this._overlapTestCircle = new es.Circle(0); + this._cellDict = new NumberDictionary(); + this._tempHashSet = []; + this._cellSize = cellSize; + this._inverseCellSize = 1 / this._cellSize; + this._raycastParser = new RaycastResultParser(); } - }; - SpatialHash.prototype.register = function (collider) { - var bounds = collider.bounds; - collider.registeredPhysicsBounds = bounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - if (!this.gridBounds.contains(p1.x, p1.y)) { - this.gridBounds = RectangleExt.union(this.gridBounds, p1); - } - if (!this.gridBounds.contains(p2.x, p2.y)) { - this.gridBounds = RectangleExt.union(this.gridBounds, p2); - } - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var c = this.cellAtPosition(x, y, true); - if (c.indexOf(collider) == -1) - c.push(collider); - } - } - }; - SpatialHash.prototype.clear = function () { - this._cellDict.clear(); - }; - SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { - var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); - this._overlapTestCircle.radius = radius; - var resultCounter = 0; - var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); - bounds = aabbBroadphaseResult.bounds; - var potentials = aabbBroadphaseResult.tempHashSet; - for (var i = 0; i < potentials.length; i++) { - var collider = potentials[i]; - if (collider instanceof BoxCollider) { - results[resultCounter] = collider; - resultCounter++; - } - else if (collider instanceof CircleCollider) { - if (collider.shape.overlaps(this._overlapTestCircle)) { - results[resultCounter] = collider; - resultCounter++; + SpatialHash.prototype.cellCoords = function (x, y) { + return new es.Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); + }; + SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { + if (createCellIfEmpty === void 0) { createCellIfEmpty = false; } + var cell = this._cellDict.tryGetValue(x, y); + if (!cell) { + if (createCellIfEmpty) { + cell = []; + this._cellDict.add(x, y, cell); } } - else if (collider instanceof PolygonCollider) { - if (collider.shape.overlaps(this._overlapTestCircle)) { - results[resultCounter] = collider; - resultCounter++; + return cell; + }; + SpatialHash.prototype.register = function (collider) { + var bounds = collider.bounds; + collider.registeredPhysicsBounds = bounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + if (!this.gridBounds.contains(p1.x, p1.y)) { + this.gridBounds = es.RectangleExt.union(this.gridBounds, p1); + } + if (!this.gridBounds.contains(p2.x, p2.y)) { + this.gridBounds = es.RectangleExt.union(this.gridBounds, p2); + } + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var c = this.cellAtPosition(x, y, true); + if (c.indexOf(collider) == -1) + c.push(collider); } } - else { - throw new Error("overlapCircle against this collider type is not implemented!"); + }; + SpatialHash.prototype.remove = function (collider) { + var bounds = collider.registeredPhysicsBounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) + console.error("removing Collider [" + collider + "] from a cell that it is not present in"); + else + cell.remove(collider); + } } - if (resultCounter == results.length) - return resultCounter; - } - return resultCounter; - }; - SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) { - this._tempHashSet.length = 0; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) - continue; - for (var i = 0; i < cell.length; i++) { - var collider = cell[i]; - if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer)) + }; + SpatialHash.prototype.removeWithBruteForce = function (obj) { + this._cellDict.remove(obj); + }; + SpatialHash.prototype.clear = function () { + this._cellDict.clear(); + }; + SpatialHash.prototype.debugDraw = function (secondsToDisplay, textScale) { + if (textScale === void 0) { textScale = 1; } + for (var x = this.gridBounds.x; x <= this.gridBounds.right; x++) { + for (var y = this.gridBounds.y; y <= this.gridBounds.bottom; y++) { + var cell = this.cellAtPosition(x, y); + if (cell && cell.length > 0) + this.debugDrawCellDetails(x, y, cell.length, secondsToDisplay, textScale); + } + } + }; + SpatialHash.prototype.debugDrawCellDetails = function (x, y, cellCount, secondsToDisplay, textScale) { + if (secondsToDisplay === void 0) { secondsToDisplay = 0.5; } + if (textScale === void 0) { textScale = 1; } + }; + SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) { + this._tempHashSet.length = 0; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) continue; - if (bounds.intersects(collider.bounds)) { - if (this._tempHashSet.indexOf(collider) == -1) - this._tempHashSet.push(collider); + for (var i = 0; i < cell.length; i++) { + var collider = cell[i]; + if (collider == excludeCollider || !es.Flags.isFlagSet(layerMask, collider.physicsLayer)) + continue; + if (bounds.intersects(collider.bounds)) { + if (this._tempHashSet.indexOf(collider) == -1) + this._tempHashSet.push(collider); + } } } } - } - return { tempHashSet: this._tempHashSet, bounds: bounds }; - }; - SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { - if (createCellIfEmpty === void 0) { createCellIfEmpty = false; } - var cell = this._cellDict.tryGetValue(x, y); - if (!cell) { - if (createCellIfEmpty) { - cell = []; - this._cellDict.add(x, y, cell); + return { tempHashSet: this._tempHashSet, bounds: bounds }; + }; + SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { + var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); + this._overlapTestCircle.radius = radius; + this._overlapTestCircle.position = circleCenter; + var resultCounter = 0; + var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); + bounds = aabbBroadphaseResult.bounds; + var potentials = aabbBroadphaseResult.tempHashSet; + for (var i = 0; i < potentials.length; i++) { + var collider = potentials[i]; + if (collider instanceof es.BoxCollider) { + results[resultCounter] = collider; + resultCounter++; + } + else if (collider instanceof es.CircleCollider) { + if (collider.shape.overlaps(this._overlapTestCircle)) { + results[resultCounter] = collider; + resultCounter++; + } + } + else if (collider instanceof es.PolygonCollider) { + if (collider.shape.overlaps(this._overlapTestCircle)) { + results[resultCounter] = collider; + resultCounter++; + } + } + else { + throw new Error("overlapCircle against this collider type is not implemented!"); + } + if (resultCounter == results.length) + return resultCounter; } + return resultCounter; + }; + return SpatialHash; + }()); + es.SpatialHash = SpatialHash; + var NumberDictionary = (function () { + function NumberDictionary() { + this._store = new Map(); } - return cell; - }; - SpatialHash.prototype.cellCoords = function (x, y) { - return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); - }; - SpatialHash.prototype.debugDraw = function (secondsToDisplay, textScale) { - if (textScale === void 0) { textScale = 1; } - for (var x = this.gridBounds.x; x <= this.gridBounds.right; x++) { - for (var y = this.gridBounds.y; y <= this.gridBounds.bottom; y++) { - var cell = this.cellAtPosition(x, y); - if (cell && cell.length > 0) - this.debugDrawCellDetails(x, y, cell.length, secondsToDisplay, textScale); - } + NumberDictionary.prototype.getKey = function (x, y) { + return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); + }; + NumberDictionary.prototype.add = function (x, y, list) { + this._store.set(this.getKey(x, y), list); + }; + NumberDictionary.prototype.remove = function (obj) { + this._store.forEach(function (list) { + if (list.contains(obj)) + list.remove(obj); + }); + }; + NumberDictionary.prototype.tryGetValue = function (x, y) { + return this._store.get(this.getKey(x, y)); + }; + NumberDictionary.prototype.clear = function () { + this._store.clear(); + }; + return NumberDictionary; + }()); + es.NumberDictionary = NumberDictionary; + var RaycastResultParser = (function () { + function RaycastResultParser() { } - }; - SpatialHash.prototype.debugDrawCellDetails = function (x, y, cellCount, secondsToDisplay, textScale) { - if (secondsToDisplay === void 0) { secondsToDisplay = 0.5; } - if (textScale === void 0) { textScale = 1; } - }; - return SpatialHash; -}()); -var RaycastResultParser = (function () { - function RaycastResultParser() { - } - return RaycastResultParser; -}()); -var NumberDictionary = (function () { - function NumberDictionary() { - this._store = new Map(); - } - NumberDictionary.prototype.getKey = function (x, y) { - return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); - }; - NumberDictionary.prototype.add = function (x, y, list) { - this._store.set(this.getKey(x, y), list); - }; - NumberDictionary.prototype.remove = function (obj) { - this._store.forEach(function (list) { - if (list.contains(obj)) - list.remove(obj); - }); - }; - NumberDictionary.prototype.tryGetValue = function (x, y) { - return this._store.get(this.getKey(x, y)); - }; - NumberDictionary.prototype.clear = function () { - this._store.clear(); - }; - return NumberDictionary; -}()); + return RaycastResultParser; + }()); + es.RaycastResultParser = RaycastResultParser; +})(es || (es = {})); var ArrayUtils = (function () { function ArrayUtils() { } @@ -5588,329 +6302,363 @@ var Base64Utils = (function () { }; return Base64Utils; }()); -var ContentManager = (function () { - function ContentManager() { - this.loadedAssets = new Map(); - } - ContentManager.prototype.loadRes = function (name, local) { - var _this = this; - if (local === void 0) { local = true; } - return new Promise(function (resolve, reject) { - var res = _this.loadedAssets.get(name); - if (res) { - resolve(res); +var es; +(function (es) { + var ContentManager = (function () { + function ContentManager() { + this.loadedAssets = new Map(); + } + ContentManager.prototype.loadRes = function (name, local) { + var _this = this; + if (local === void 0) { local = true; } + return new Promise(function (resolve, reject) { + var res = _this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } + if (local) { + RES.getResAsync(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + else { + RES.getResByUrl(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }); + }; + ContentManager.prototype.dispose = function () { + this.loadedAssets.forEach(function (value) { + var assetsToRemove = value; + assetsToRemove.dispose(); + }); + this.loadedAssets.clear(); + }; + return ContentManager; + }()); + es.ContentManager = ContentManager; +})(es || (es = {})); +var es; +(function (es) { + var DrawUtils = (function () { + function DrawUtils() { + } + DrawUtils.drawLine = function (shape, start, end, color, thickness) { + if (thickness === void 0) { thickness = 1; } + this.drawLineAngle(shape, start, es.MathHelper.angleBetweenVectors(start, end), es.Vector2.distance(start, end), color, thickness); + }; + DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) { + if (thickness === void 0) { thickness = 1; } + shape.graphics.beginFill(color); + shape.graphics.drawRect(start.x, start.y, 1, 1); + shape.graphics.endFill(); + shape.scaleX = length; + shape.scaleY = thickness; + shape.$anchorOffsetX = 0; + shape.$anchorOffsetY = 0; + shape.rotation = radians; + }; + DrawUtils.drawHollowRect = function (shape, rect, color, thickness) { + if (thickness === void 0) { thickness = 1; } + this.drawHollowRectR(shape, rect.x, rect.y, rect.width, rect.height, color, thickness); + }; + DrawUtils.drawHollowRectR = function (shape, x, y, width, height, color, thickness) { + if (thickness === void 0) { thickness = 1; } + var tl = new es.Vector2(x, y).round(); + var tr = new es.Vector2(x + width, y).round(); + var br = new es.Vector2(x + width, y + height).round(); + var bl = new es.Vector2(x, y + height).round(); + this.drawLine(shape, tl, tr, color, thickness); + this.drawLine(shape, tr, br, color, thickness); + this.drawLine(shape, br, bl, color, thickness); + this.drawLine(shape, bl, tl, color, thickness); + }; + DrawUtils.drawPixel = function (shape, position, color, size) { + if (size === void 0) { size = 1; } + var destRect = new es.Rectangle(position.x, position.y, size, size); + if (size != 1) { + destRect.x -= size * 0.5; + destRect.y -= size * 0.5; + } + shape.graphics.beginFill(color); + shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height); + shape.graphics.endFill(); + }; + DrawUtils.getColorMatrix = function (color) { + var colorMatrix = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 + ]; + colorMatrix[0] = Math.floor(color / 256 / 256) / 255; + colorMatrix[6] = Math.floor(color / 256 % 256) / 255; + colorMatrix[12] = color % 256 / 255; + return new egret.ColorMatrixFilter(colorMatrix); + }; + return DrawUtils; + }()); + es.DrawUtils = DrawUtils; +})(es || (es = {})); +var es; +(function (es) { + var FuncPack = (function () { + function FuncPack(func, context) { + this.func = func; + this.context = context; + } + return FuncPack; + }()); + es.FuncPack = FuncPack; + var Emitter = (function () { + function Emitter() { + this._messageTable = new Map(); + } + Emitter.prototype.addObserver = function (eventType, handler, context) { + var list = this._messageTable.get(eventType); + if (!list) { + list = []; + this._messageTable.set(eventType, list); + } + if (list.contains(handler)) + console.warn("您试图添加相同的观察者两次"); + list.push(new FuncPack(handler, context)); + }; + Emitter.prototype.removeObserver = function (eventType, handler) { + var messageData = this._messageTable.get(eventType); + var index = messageData.findIndex(function (data) { return data.func == handler; }); + if (index != -1) + messageData.removeAt(index); + }; + Emitter.prototype.emit = function (eventType, data) { + var list = this._messageTable.get(eventType); + if (list) { + for (var i = list.length - 1; i >= 0; i--) + list[i].func.call(list[i].context, data); + } + }; + return Emitter; + }()); + es.Emitter = Emitter; +})(es || (es = {})); +var es; +(function (es) { + var GlobalManager = (function () { + function GlobalManager() { + } + Object.defineProperty(GlobalManager.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + GlobalManager.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } + } + }; + GlobalManager.prototype.onEnabled = function () { }; + GlobalManager.prototype.onDisabled = function () { }; + GlobalManager.prototype.update = function () { }; + GlobalManager.registerGlobalManager = function (manager) { + this.globalManagers.push(manager); + manager.enabled = true; + }; + GlobalManager.unregisterGlobalManager = function (manager) { + this.globalManagers.remove(manager); + manager.enabled = false; + }; + GlobalManager.getGlobalManager = function (type) { + for (var i = 0; i < this.globalManagers.length; i++) { + if (this.globalManagers[i] instanceof type) + return this.globalManagers[i]; + } + return null; + }; + GlobalManager.globalManagers = []; + return GlobalManager; + }()); + es.GlobalManager = GlobalManager; +})(es || (es = {})); +var es; +(function (es) { + var TouchState = (function () { + function TouchState() { + this.x = 0; + this.y = 0; + this.touchPoint = -1; + this.touchDown = false; + } + Object.defineProperty(TouchState.prototype, "position", { + get: function () { + return new es.Vector2(this.x, this.y); + }, + enumerable: true, + configurable: true + }); + TouchState.prototype.reset = function () { + this.x = 0; + this.y = 0; + this.touchDown = false; + this.touchPoint = -1; + }; + return TouchState; + }()); + es.TouchState = TouchState; + var Input = (function () { + function Input() { + } + Object.defineProperty(Input, "touchPosition", { + get: function () { + if (!this._gameTouchs[0]) + return es.Vector2.zero; + return this._gameTouchs[0].position; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "maxSupportedTouch", { + get: function () { + return this._stage.maxTouches; + }, + set: function (value) { + this._stage.maxTouches = value; + this.initTouchCache(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "resolutionScale", { + get: function () { + return this._resolutionScale; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "totalTouchCount", { + get: function () { + return this._totalTouchCount; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "gameTouchs", { + get: function () { + return this._gameTouchs; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "touchPositionDelta", { + get: function () { + var delta = es.Vector2.subtract(this.touchPosition, this._previousTouchState.position); + if (delta.length() > 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + return delta; + }, + enumerable: true, + configurable: true + }); + Input.initialize = function (stage) { + if (this._init) return; - } - if (local) { - RES.getResAsync(name).then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }).catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } - else { - RES.getResByUrl(name).then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }).catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } - }); - }; - ContentManager.prototype.dispose = function () { - this.loadedAssets.forEach(function (value) { - var assetsToRemove = value; - assetsToRemove.dispose(); - }); - this.loadedAssets.clear(); - }; - return ContentManager; -}()); -var DrawUtils = (function () { - function DrawUtils() { - } - DrawUtils.drawLine = function (shape, start, end, color, thickness) { - if (thickness === void 0) { thickness = 1; } - this.drawLineAngle(shape, start, MathHelper.angleBetweenVectors(start, end), Vector2.distance(start, end), color, thickness); - }; - DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) { - if (thickness === void 0) { thickness = 1; } - shape.graphics.beginFill(color); - shape.graphics.drawRect(start.x, start.y, 1, 1); - shape.graphics.endFill(); - shape.scaleX = length; - shape.scaleY = thickness; - shape.$anchorOffsetX = 0; - shape.$anchorOffsetY = 0; - shape.rotation = radians; - }; - DrawUtils.drawHollowRect = function (shape, rect, color, thickness) { - if (thickness === void 0) { thickness = 1; } - this.drawHollowRectR(shape, rect.x, rect.y, rect.width, rect.height, color, thickness); - }; - DrawUtils.drawHollowRectR = function (shape, x, y, width, height, color, thickness) { - if (thickness === void 0) { thickness = 1; } - var tl = new Vector2(x, y).round(); - var tr = new Vector2(x + width, y).round(); - var br = new Vector2(x + width, y + height).round(); - var bl = new Vector2(x, y + height).round(); - this.drawLine(shape, tl, tr, color, thickness); - this.drawLine(shape, tr, br, color, thickness); - this.drawLine(shape, br, bl, color, thickness); - this.drawLine(shape, bl, tl, color, thickness); - }; - DrawUtils.drawPixel = function (shape, position, color, size) { - if (size === void 0) { size = 1; } - var destRect = new Rectangle(position.x, position.y, size, size); - if (size != 1) { - destRect.x -= size * 0.5; - destRect.y -= size * 0.5; - } - shape.graphics.beginFill(color); - shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height); - shape.graphics.endFill(); - }; - return DrawUtils; -}()); -var Emitter = (function () { - function Emitter() { - this._messageTable = new Map(); - } - Emitter.prototype.addObserver = function (eventType, handler, context) { - var list = this._messageTable.get(eventType); - if (!list) { - list = []; - this._messageTable.set(eventType, list); - } - if (list.contains(handler)) - console.warn("您试图添加相同的观察者两次"); - list.push(new FuncPack(handler, context)); - }; - Emitter.prototype.removeObserver = function (eventType, handler) { - var messageData = this._messageTable.get(eventType); - var index = messageData.findIndex(function (data) { return data.func == handler; }); - if (index != -1) - messageData.removeAt(index); - }; - Emitter.prototype.emit = function (eventType, data) { - var list = this._messageTable.get(eventType); - if (list) { - for (var i = list.length - 1; i >= 0; i--) - list[i].func.call(list[i].context, data); - } - }; - return Emitter; -}()); -var FuncPack = (function () { - function FuncPack(func, context) { - this.func = func; - this.context = context; - } - return FuncPack; -}()); -var GlobalManager = (function () { - function GlobalManager() { - } - Object.defineProperty(GlobalManager.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true - }); - GlobalManager.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); - } - else { - this.onDisabled(); - } - } - }; - GlobalManager.prototype.onEnabled = function () { }; - GlobalManager.prototype.onDisabled = function () { }; - GlobalManager.prototype.update = function () { }; - GlobalManager.registerGlobalManager = function (manager) { - this.globalManagers.push(manager); - manager.enabled = true; - }; - GlobalManager.unregisterGlobalManager = function (manager) { - this.globalManagers.remove(manager); - manager.enabled = false; - }; - GlobalManager.getGlobalManager = function (type) { - for (var i = 0; i < this.globalManagers.length; i++) { - if (this.globalManagers[i] instanceof type) - return this.globalManagers[i]; - } - return null; - }; - GlobalManager.globalManagers = []; - return GlobalManager; -}()); -var TouchState = (function () { - function TouchState() { - this.x = 0; - this.y = 0; - this.touchPoint = -1; - this.touchDown = false; - } - Object.defineProperty(TouchState.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - enumerable: true, - configurable: true - }); - TouchState.prototype.reset = function () { - this.x = 0; - this.y = 0; - this.touchDown = false; - this.touchPoint = -1; - }; - return TouchState; -}()); -var Input = (function () { - function Input() { - } - Object.defineProperty(Input, "touchPosition", { - get: function () { - if (!this._gameTouchs[0]) - return Vector2.zero; - return this._gameTouchs[0].position; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "maxSupportedTouch", { - get: function () { - return this._stage.maxTouches; - }, - set: function (value) { - this._stage.maxTouches = value; + this._init = true; + this._stage = stage; + this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); this.initTouchCache(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "resolutionScale", { - get: function () { - return this._resolutionScale; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "totalTouchCount", { - get: function () { - return this._totalTouchCount; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "gameTouchs", { - get: function () { - return this._gameTouchs; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "touchPositionDelta", { - get: function () { - var delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position); - if (delta.length() > 0) { + }; + Input.initTouchCache = function () { + this._totalTouchCount = 0; + this._touchIndex = 0; + this._gameTouchs.length = 0; + for (var i = 0; i < this.maxSupportedTouch; i++) { + this._gameTouchs.push(new TouchState()); + } + }; + Input.touchBegin = function (evt) { + if (this._touchIndex < this.maxSupportedTouch) { + this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; + this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; + this._gameTouchs[this._touchIndex].x = evt.stageX; + this._gameTouchs[this._touchIndex].y = evt.stageY; + if (this._touchIndex == 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + this._touchIndex++; + this._totalTouchCount++; + } + }; + Input.touchMove = function (evt) { + if (evt.touchPointID == this._gameTouchs[0].touchPoint) { this.setpreviousTouchState(this._gameTouchs[0]); } - return delta; - }, - enumerable: true, - configurable: true - }); - Input.initialize = function (stage) { - if (this._init) - return; - this._init = true; - this._stage = stage; - this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); - this.initTouchCache(); - }; - Input.initTouchCache = function () { - this._totalTouchCount = 0; - this._touchIndex = 0; - this._gameTouchs.length = 0; - for (var i = 0; i < this.maxSupportedTouch; i++) { - this._gameTouchs.push(new TouchState()); - } - }; - Input.touchBegin = function (evt) { - if (this._touchIndex < this.maxSupportedTouch) { - this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; - this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; - this._gameTouchs[this._touchIndex].x = evt.stageX; - this._gameTouchs[this._touchIndex].y = evt.stageY; - if (this._touchIndex == 0) { - this.setpreviousTouchState(this._gameTouchs[0]); + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.x = evt.stageX; + touchData.y = evt.stageY; } - this._touchIndex++; - this._totalTouchCount++; - } - }; - Input.touchMove = function (evt) { - if (evt.touchPointID == this._gameTouchs[0].touchPoint) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.x = evt.stageX; - touchData.y = evt.stageY; - } - }; - Input.touchEnd = function (evt) { - var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.reset(); - if (touchIndex == 0) - this._previousTouchState.reset(); - this._totalTouchCount--; - if (this.totalTouchCount == 0) { - this._touchIndex = 0; + }; + Input.touchEnd = function (evt) { + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.reset(); + if (touchIndex == 0) + this._previousTouchState.reset(); + this._totalTouchCount--; + if (this.totalTouchCount == 0) { + this._touchIndex = 0; + } } - } - }; - Input.setpreviousTouchState = function (touchState) { - this._previousTouchState = new TouchState(); - this._previousTouchState.x = touchState.position.x; - this._previousTouchState.y = touchState.position.y; - this._previousTouchState.touchPoint = touchState.touchPoint; - this._previousTouchState.touchDown = touchState.touchDown; - }; - Input.scaledPosition = function (position) { - var scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); - return Vector2.multiply(scaledPos, this.resolutionScale); - }; - Input._init = false; - Input._previousTouchState = new TouchState(); - Input._gameTouchs = []; - Input._resolutionOffset = new Vector2(); - Input._resolutionScale = Vector2.one; - Input._touchIndex = 0; - Input._totalTouchCount = 0; - return Input; -}()); + }; + Input.setpreviousTouchState = function (touchState) { + this._previousTouchState = new TouchState(); + this._previousTouchState.x = touchState.position.x; + this._previousTouchState.y = touchState.position.y; + this._previousTouchState.touchPoint = touchState.touchPoint; + this._previousTouchState.touchDown = touchState.touchDown; + }; + Input.scaledPosition = function (position) { + var scaledPos = new es.Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); + return es.Vector2.multiply(scaledPos, this.resolutionScale); + }; + Input._init = false; + Input._previousTouchState = new TouchState(); + Input._gameTouchs = []; + Input._resolutionOffset = new es.Vector2(); + Input._resolutionScale = es.Vector2.one; + Input._touchIndex = 0; + Input._totalTouchCount = 0; + return Input; + }()); + es.Input = Input; +})(es || (es = {})); var KeyboardUtils = (function () { function KeyboardUtils() { } @@ -6111,36 +6859,40 @@ var KeyboardUtils = (function () { KeyboardUtils.WINDOWS = "Windows"; return KeyboardUtils; }()); -var ListPool = (function () { - function ListPool() { - } - ListPool.warmCache = function (cacheCount) { - cacheCount -= this._objectQueue.length; - if (cacheCount > 0) { - for (var i = 0; i < cacheCount; i++) { - this._objectQueue.unshift([]); - } +var es; +(function (es) { + var ListPool = (function () { + function ListPool() { } - }; - ListPool.trimCache = function (cacheCount) { - while (cacheCount > this._objectQueue.length) - this._objectQueue.shift(); - }; - ListPool.clearCache = function () { - this._objectQueue.length = 0; - }; - ListPool.obtain = function () { - if (this._objectQueue.length > 0) - return this._objectQueue.shift(); - return []; - }; - ListPool.free = function (obj) { - this._objectQueue.unshift(obj); - obj.length = 0; - }; - ListPool._objectQueue = []; - return ListPool; -}()); + ListPool.warmCache = function (cacheCount) { + cacheCount -= this._objectQueue.length; + if (cacheCount > 0) { + for (var i = 0; i < cacheCount; i++) { + this._objectQueue.unshift([]); + } + } + }; + ListPool.trimCache = function (cacheCount) { + while (cacheCount > this._objectQueue.length) + this._objectQueue.shift(); + }; + ListPool.clearCache = function () { + this._objectQueue.length = 0; + }; + ListPool.obtain = function () { + if (this._objectQueue.length > 0) + return this._objectQueue.shift(); + return []; + }; + ListPool.free = function (obj) { + this._objectQueue.unshift(obj); + obj.length = 0; + }; + ListPool._objectQueue = []; + return ListPool; + }()); + es.ListPool = ListPool; +})(es || (es = {})); var THREAD_ID = Math.floor(Math.random() * 1000) + "-" + Date.now(); var setItem = egret.localStorage.setItem.bind(localStorage); var getItem = egret.localStorage.getItem.bind(localStorage); @@ -6182,19 +6934,23 @@ var LockUtils = (function () { }; return LockUtils; }()); -var Pair = (function () { - function Pair(first, second) { - this.first = first; - this.second = second; - } - Pair.prototype.clear = function () { - this.first = this.second = null; - }; - Pair.prototype.equals = function (other) { - return this.first == other.first && this.second == other.second; - }; - return Pair; -}()); +var es; +(function (es) { + var Pair = (function () { + function Pair(first, second) { + this.first = first; + this.second = second; + } + Pair.prototype.clear = function () { + this.first = this.second = null; + }; + Pair.prototype.equals = function (other) { + return this.first == other.first && this.second == other.second; + }; + return Pair; + }()); + es.Pair = Pair; +})(es || (es = {})); var RandomUtils = (function () { function RandomUtils() { } @@ -6262,142 +7018,154 @@ var RandomUtils = (function () { }; return RandomUtils; }()); -var RectangleExt = (function () { - function RectangleExt() { - } - RectangleExt.union = function (first, point) { - var rect = new Rectangle(point.x, point.y, 0, 0); - var result = new Rectangle(); - result.x = Math.min(first.x, rect.x); - result.y = Math.min(first.y, rect.y); - result.width = Math.max(first.right, rect.right) - result.x; - result.height = Math.max(first.bottom, result.bottom) - result.y; - return result; - }; - return RectangleExt; -}()); -var Triangulator = (function () { - function Triangulator() { - this.triangleIndices = []; - this._triPrev = new Array(12); - this._triNext = new Array(12); - } - Triangulator.prototype.triangulate = function (points, arePointsCCW) { - if (arePointsCCW === void 0) { arePointsCCW = true; } - var count = points.length; - this.initialize(count); - var iterations = 0; - var index = 0; - while (count > 3 && iterations < 500) { - iterations++; - var isEar = true; - var a = points[this._triPrev[index]]; - var b = points[index]; - var c = points[this._triNext[index]]; - if (Vector2Ext.isTriangleCCW(a, b, c)) { - var k = this._triNext[this._triNext[index]]; - do { - if (Triangulator.testPointTriangle(points[k], a, b, c)) { - isEar = false; - break; - } - k = this._triNext[k]; - } while (k != this._triPrev[index]); +var es; +(function (es) { + var RectangleExt = (function () { + function RectangleExt() { + } + RectangleExt.union = function (first, point) { + var rect = new es.Rectangle(point.x, point.y, 0, 0); + var result = new es.Rectangle(); + result.x = Math.min(first.x, rect.x); + result.y = Math.min(first.y, rect.y); + result.width = Math.max(first.right, rect.right) - result.x; + result.height = Math.max(first.bottom, result.bottom) - result.y; + return result; + }; + return RectangleExt; + }()); + es.RectangleExt = RectangleExt; +})(es || (es = {})); +var es; +(function (es) { + var Triangulator = (function () { + function Triangulator() { + this.triangleIndices = []; + this._triPrev = new Array(12); + this._triNext = new Array(12); + } + Triangulator.prototype.triangulate = function (points, arePointsCCW) { + if (arePointsCCW === void 0) { arePointsCCW = true; } + var count = points.length; + this.initialize(count); + var iterations = 0; + var index = 0; + while (count > 3 && iterations < 500) { + iterations++; + var isEar = true; + var a = points[this._triPrev[index]]; + var b = points[index]; + var c = points[this._triNext[index]]; + if (es.Vector2Ext.isTriangleCCW(a, b, c)) { + var k = this._triNext[this._triNext[index]]; + do { + if (Triangulator.testPointTriangle(points[k], a, b, c)) { + isEar = false; + break; + } + k = this._triNext[k]; + } while (k != this._triPrev[index]); + } + else { + isEar = false; + } + if (isEar) { + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); + this._triNext[this._triPrev[index]] = this._triNext[index]; + this._triPrev[this._triNext[index]] = this._triPrev[index]; + count--; + index = this._triPrev[index]; + } + else { + index = this._triNext[index]; + } + } + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); + if (!arePointsCCW) + this.triangleIndices.reverse(); + }; + Triangulator.prototype.initialize = function (count) { + this.triangleIndices.length = 0; + if (this._triNext.length < count) { + this._triNext.reverse(); + this._triNext = new Array(Math.max(this._triNext.length * 2, count)); + } + if (this._triPrev.length < count) { + this._triPrev.reverse(); + this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); + } + for (var i = 0; i < count; i++) { + this._triPrev[i] = i - 1; + this._triNext[i] = i + 1; + } + this._triPrev[0] = count - 1; + this._triNext[count - 1] = 0; + }; + Triangulator.testPointTriangle = function (point, a, b, c) { + if (es.Vector2Ext.cross(es.Vector2.subtract(point, a), es.Vector2.subtract(b, a)) < 0) + return false; + if (es.Vector2Ext.cross(es.Vector2.subtract(point, b), es.Vector2.subtract(c, b)) < 0) + return false; + if (es.Vector2Ext.cross(es.Vector2.subtract(point, c), es.Vector2.subtract(a, c)) < 0) + return false; + return true; + }; + return Triangulator; + }()); + es.Triangulator = Triangulator; +})(es || (es = {})); +var es; +(function (es) { + var Vector2Ext = (function () { + function Vector2Ext() { + } + Vector2Ext.isTriangleCCW = function (a, center, c) { + return this.cross(es.Vector2.subtract(center, a), es.Vector2.subtract(c, center)) < 0; + }; + Vector2Ext.cross = function (u, v) { + return u.y * v.x - u.x * v.y; + }; + Vector2Ext.perpendicular = function (first, second) { + return new es.Vector2(-1 * (second.y - first.y), second.x - first.x); + }; + Vector2Ext.normalize = function (vec) { + var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); + if (magnitude > es.MathHelper.Epsilon) { + vec = es.Vector2.divide(vec, new es.Vector2(magnitude)); } else { - isEar = false; + vec.x = vec.y = 0; } - if (isEar) { - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); - this._triNext[this._triPrev[index]] = this._triNext[index]; - this._triPrev[this._triNext[index]] = this._triPrev[index]; - count--; - index = this._triPrev[index]; + return vec; + }; + Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) { + for (var i = 0; i < length; i++) { + var position = sourceArray[sourceIndex + i]; + var destination = destinationArray[destinationIndex + i]; + destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + destinationArray[destinationIndex + i] = destination; } - else { - index = this._triNext[index]; - } - } - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); - if (!arePointsCCW) - this.triangleIndices.reverse(); - }; - Triangulator.prototype.initialize = function (count) { - this.triangleIndices.length = 0; - if (this._triNext.length < count) { - this._triNext.reverse(); - this._triNext = new Array(Math.max(this._triNext.length * 2, count)); - } - if (this._triPrev.length < count) { - this._triPrev.reverse(); - this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); - } - for (var i = 0; i < count; i++) { - this._triPrev[i] = i - 1; - this._triNext[i] = i + 1; - } - this._triPrev[0] = count - 1; - this._triNext[count - 1] = 0; - }; - Triangulator.testPointTriangle = function (point, a, b, c) { - if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0) - return false; - if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0) - return false; - if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0) - return false; - return true; - }; - return Triangulator; -}()); -var Vector2Ext = (function () { - function Vector2Ext() { - } - Vector2Ext.isTriangleCCW = function (a, center, c) { - return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; - }; - Vector2Ext.cross = function (u, v) { - return u.y * v.x - u.x * v.y; - }; - Vector2Ext.perpendicular = function (first, second) { - return new Vector2(-1 * (second.y - first.y), second.x - first.x); - }; - Vector2Ext.normalize = function (vec) { - var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); - if (magnitude > MathHelper.Epsilon) { - vec = Vector2.divide(vec, new Vector2(magnitude)); - } - else { - vec.x = vec.y = 0; - } - return vec; - }; - Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) { - for (var i = 0; i < length; i++) { - var position = sourceArray[sourceIndex + i]; - var destination = destinationArray[destinationIndex + i]; - destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; - destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; - destinationArray[destinationIndex + i] = destination; - } - }; - Vector2Ext.transformR = function (position, matrix) { - var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; - var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; - return new Vector2(x, y); - }; - Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { - this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); - }; - Vector2Ext.round = function (vec) { - return new Vector2(Math.round(vec.x), Math.round(vec.y)); - }; - return Vector2Ext; -}()); + }; + Vector2Ext.transformR = function (position, matrix) { + var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + return new es.Vector2(x, y); + }; + Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { + this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); + }; + Vector2Ext.round = function (vec) { + return new es.Vector2(Math.round(vec.x), Math.round(vec.y)); + }; + return Vector2Ext; + }()); + es.Vector2Ext = Vector2Ext; +})(es || (es = {})); var WebGLUtils = (function () { function WebGLUtils() { } @@ -6407,66 +7175,70 @@ var WebGLUtils = (function () { }; return WebGLUtils; }()); -var Layout = (function () { - function Layout() { - this.clientArea = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this.safeArea = this.clientArea; - } - Layout.prototype.place = function (size, horizontalMargin, verticalMargine, alignment) { - var rc = new Rectangle(0, 0, size.x, size.y); - if ((alignment & Alignment.left) != 0) { - rc.x = this.clientArea.x + (this.clientArea.width * horizontalMargin); +var es; +(function (es) { + var Layout = (function () { + function Layout() { + this.clientArea = new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.safeArea = this.clientArea; } - else if ((alignment & Alignment.right) != 0) { - rc.x = this.clientArea.x + (this.clientArea.width * (1 - horizontalMargin)) - rc.width; - } - else if ((alignment & Alignment.horizontalCenter) != 0) { - rc.x = this.clientArea.x + (this.clientArea.width - rc.width) / 2 + (horizontalMargin * this.clientArea.width); - } - else { - } - if ((alignment & Alignment.top) != 0) { - rc.y = this.clientArea.y + (this.clientArea.height * verticalMargine); - } - else if ((alignment & Alignment.bottom) != 0) { - rc.y = this.clientArea.y + (this.clientArea.height * (1 - verticalMargine)) - rc.height; - } - else if ((alignment & Alignment.verticalCenter) != 0) { - rc.y = this.clientArea.y + (this.clientArea.height - rc.height) / 2 + (verticalMargine * this.clientArea.height); - } - else { - } - if (rc.left < this.safeArea.left) - rc.x = this.safeArea.left; - if (rc.right > this.safeArea.right) - rc.x = this.safeArea.right - rc.width; - if (rc.top < this.safeArea.top) - rc.y = this.safeArea.top; - if (rc.bottom > this.safeArea.bottom) - rc.y = this.safeArea.bottom - rc.height; - return rc; - }; - return Layout; -}()); -var Alignment; -(function (Alignment) { - Alignment[Alignment["none"] = 0] = "none"; - Alignment[Alignment["left"] = 1] = "left"; - Alignment[Alignment["right"] = 2] = "right"; - Alignment[Alignment["horizontalCenter"] = 4] = "horizontalCenter"; - Alignment[Alignment["top"] = 8] = "top"; - Alignment[Alignment["bottom"] = 16] = "bottom"; - Alignment[Alignment["verticalCenter"] = 32] = "verticalCenter"; - Alignment[Alignment["topLeft"] = 9] = "topLeft"; - Alignment[Alignment["topRight"] = 10] = "topRight"; - Alignment[Alignment["topCenter"] = 12] = "topCenter"; - Alignment[Alignment["bottomLeft"] = 17] = "bottomLeft"; - Alignment[Alignment["bottomRight"] = 18] = "bottomRight"; - Alignment[Alignment["bottomCenter"] = 20] = "bottomCenter"; - Alignment[Alignment["centerLeft"] = 33] = "centerLeft"; - Alignment[Alignment["centerRight"] = 34] = "centerRight"; - Alignment[Alignment["center"] = 36] = "center"; -})(Alignment || (Alignment = {})); + Layout.prototype.place = function (size, horizontalMargin, verticalMargine, alignment) { + var rc = new es.Rectangle(0, 0, size.x, size.y); + if ((alignment & Alignment.left) != 0) { + rc.x = this.clientArea.x + (this.clientArea.width * horizontalMargin); + } + else if ((alignment & Alignment.right) != 0) { + rc.x = this.clientArea.x + (this.clientArea.width * (1 - horizontalMargin)) - rc.width; + } + else if ((alignment & Alignment.horizontalCenter) != 0) { + rc.x = this.clientArea.x + (this.clientArea.width - rc.width) / 2 + (horizontalMargin * this.clientArea.width); + } + else { + } + if ((alignment & Alignment.top) != 0) { + rc.y = this.clientArea.y + (this.clientArea.height * verticalMargine); + } + else if ((alignment & Alignment.bottom) != 0) { + rc.y = this.clientArea.y + (this.clientArea.height * (1 - verticalMargine)) - rc.height; + } + else if ((alignment & Alignment.verticalCenter) != 0) { + rc.y = this.clientArea.y + (this.clientArea.height - rc.height) / 2 + (verticalMargine * this.clientArea.height); + } + else { + } + if (rc.left < this.safeArea.left) + rc.x = this.safeArea.left; + if (rc.right > this.safeArea.right) + rc.x = this.safeArea.right - rc.width; + if (rc.top < this.safeArea.top) + rc.y = this.safeArea.top; + if (rc.bottom > this.safeArea.bottom) + rc.y = this.safeArea.bottom - rc.height; + return rc; + }; + return Layout; + }()); + es.Layout = Layout; + var Alignment; + (function (Alignment) { + Alignment[Alignment["none"] = 0] = "none"; + Alignment[Alignment["left"] = 1] = "left"; + Alignment[Alignment["right"] = 2] = "right"; + Alignment[Alignment["horizontalCenter"] = 4] = "horizontalCenter"; + Alignment[Alignment["top"] = 8] = "top"; + Alignment[Alignment["bottom"] = 16] = "bottom"; + Alignment[Alignment["verticalCenter"] = 32] = "verticalCenter"; + Alignment[Alignment["topLeft"] = 9] = "topLeft"; + Alignment[Alignment["topRight"] = 10] = "topRight"; + Alignment[Alignment["topCenter"] = 12] = "topCenter"; + Alignment[Alignment["bottomLeft"] = 17] = "bottomLeft"; + Alignment[Alignment["bottomRight"] = 18] = "bottomRight"; + Alignment[Alignment["bottomCenter"] = 20] = "bottomCenter"; + Alignment[Alignment["centerLeft"] = 33] = "centerLeft"; + Alignment[Alignment["centerRight"] = 34] = "centerRight"; + Alignment[Alignment["center"] = 36] = "center"; + })(Alignment = es.Alignment || (es.Alignment = {})); +})(es || (es = {})); var stopwatch; (function (stopwatch) { var Stopwatch = (function () { @@ -6598,251 +7370,260 @@ var stopwatch; stopwatch.setDefaultSystemTimeGetter = setDefaultSystemTimeGetter; var _defaultSystemTimeGetter = Date.now; })(stopwatch || (stopwatch = {})); -var TimeRuler = (function () { - function TimeRuler() { - this._frameKey = 'frame'; - this._logKey = 'log'; - this.markers = []; - this.stopwacth = new stopwatch.Stopwatch(); - this._markerNameToIdMap = new Map(); - this.showLog = false; - TimeRuler.Instance = this; - this._logs = new Array(2); - for (var i = 0; i < this._logs.length; ++i) - this._logs[i] = new FrameLog(); - this.sampleFrames = this.targetSampleFrames = 1; - this.width = SceneManager.stage.stageWidth * 0.8; - this.onGraphicsDeviceReset(); - } - TimeRuler.prototype.onGraphicsDeviceReset = function () { - var layout = new Layout(); - this._position = layout.place(new Vector2(this.width, TimeRuler.barHeight), 0, 0.01, Alignment.bottomCenter).location; - }; - TimeRuler.prototype.startFrame = function () { - var _this = this; - var lock = new LockUtils(this._frameKey); - lock.lock().then(function () { - _this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10); - if (isNaN(_this._updateCount)) - _this._updateCount = 0; - var count = _this._updateCount; - count += 1; - egret.localStorage.setItem(_this._frameKey, count.toString()); - if (_this.enabled && (1 < count && count < TimeRuler.maxSampleFrames)) - return; - _this._prevLog = _this._logs[_this.frameCount++ & 0x1]; - _this._curLog = _this._logs[_this.frameCount & 0x1]; - var endFrameTime = _this.stopwacth.getTime(); - for (var barIndex = 0; barIndex < _this._prevLog.bars.length; ++barIndex) { - var prevBar = _this._prevLog.bars[barIndex]; - var nextBar = _this._curLog.bars[barIndex]; - for (var nest = 0; nest < prevBar.nestCount; ++nest) { - var markerIdx = prevBar.markerNests[nest]; - prevBar.markers[markerIdx].endTime = endFrameTime; - nextBar.markerNests[nest] = nest; - nextBar.markers[nest].markerId = prevBar.markers[markerIdx].markerId; - nextBar.markers[nest].beginTime = 0; - nextBar.markers[nest].endTime = -1; - nextBar.markers[nest].color = prevBar.markers[markerIdx].color; - } - for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) { - var duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime; - var markerId = prevBar.markers[markerIdx].markerId; - var m = _this.markers[markerId]; - m.logs[barIndex].color = prevBar.markers[markerIdx].color; - if (!m.logs[barIndex].initialized) { - m.logs[barIndex].min = duration; - m.logs[barIndex].max = duration; - m.logs[barIndex].avg = duration; - m.logs[barIndex].initialized = true; +var es; +(function (es) { + var TimeRuler = (function () { + function TimeRuler() { + this._frameKey = 'frame'; + this._logKey = 'log'; + this.markers = []; + this.stopwacth = new stopwatch.Stopwatch(); + this._markerNameToIdMap = new Map(); + this.showLog = false; + TimeRuler.Instance = this; + this._logs = new Array(2); + for (var i = 0; i < this._logs.length; ++i) + this._logs[i] = new FrameLog(); + this.sampleFrames = this.targetSampleFrames = 1; + this.width = es.SceneManager.stage.stageWidth * 0.8; + this.onGraphicsDeviceReset(); + } + TimeRuler.prototype.onGraphicsDeviceReset = function () { + var layout = new es.Layout(); + this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location; + }; + TimeRuler.prototype.startFrame = function () { + var _this = this; + var lock = new LockUtils(this._frameKey); + lock.lock().then(function () { + _this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10); + if (isNaN(_this._updateCount)) + _this._updateCount = 0; + var count = _this._updateCount; + count += 1; + egret.localStorage.setItem(_this._frameKey, count.toString()); + if (_this.enabled && (1 < count && count < TimeRuler.maxSampleFrames)) + return; + _this._prevLog = _this._logs[_this.frameCount++ & 0x1]; + _this._curLog = _this._logs[_this.frameCount & 0x1]; + var endFrameTime = _this.stopwacth.getTime(); + for (var barIndex = 0; barIndex < _this._prevLog.bars.length; ++barIndex) { + var prevBar = _this._prevLog.bars[barIndex]; + var nextBar = _this._curLog.bars[barIndex]; + for (var nest = 0; nest < prevBar.nestCount; ++nest) { + var markerIdx = prevBar.markerNests[nest]; + prevBar.markers[markerIdx].endTime = endFrameTime; + nextBar.markerNests[nest] = nest; + nextBar.markers[nest].markerId = prevBar.markers[markerIdx].markerId; + nextBar.markers[nest].beginTime = 0; + nextBar.markers[nest].endTime = -1; + nextBar.markers[nest].color = prevBar.markers[markerIdx].color; } - else { - m.logs[barIndex].min = Math.min(m.logs[barIndex].min, duration); - m.logs[barIndex].max = Math.min(m.logs[barIndex].max, duration); - m.logs[barIndex].avg += duration; - m.logs[barIndex].avg *= 0.5; - if (m.logs[barIndex].samples++ >= TimeRuler.logSnapDuration) { - m.logs[barIndex].snapMin = m.logs[barIndex].min; - m.logs[barIndex].snapMax = m.logs[barIndex].max; - m.logs[barIndex].snapAvg = m.logs[barIndex].avg; - m.logs[barIndex].samples = 0; + for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) { + var duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime; + var markerId = prevBar.markers[markerIdx].markerId; + var m = _this.markers[markerId]; + m.logs[barIndex].color = prevBar.markers[markerIdx].color; + if (!m.logs[barIndex].initialized) { + m.logs[barIndex].min = duration; + m.logs[barIndex].max = duration; + m.logs[barIndex].avg = duration; + m.logs[barIndex].initialized = true; + } + else { + m.logs[barIndex].min = Math.min(m.logs[barIndex].min, duration); + m.logs[barIndex].max = Math.min(m.logs[barIndex].max, duration); + m.logs[barIndex].avg += duration; + m.logs[barIndex].avg *= 0.5; + if (m.logs[barIndex].samples++ >= TimeRuler.logSnapDuration) { + m.logs[barIndex].snapMin = m.logs[barIndex].min; + m.logs[barIndex].snapMax = m.logs[barIndex].max; + m.logs[barIndex].snapAvg = m.logs[barIndex].avg; + m.logs[barIndex].samples = 0; + } } } + nextBar.markCount = prevBar.nestCount; + nextBar.nestCount = prevBar.nestCount; } - nextBar.markCount = prevBar.nestCount; - nextBar.nestCount = prevBar.nestCount; - } - _this.stopwacth.reset(); - _this.stopwacth.start(); - }); - }; - TimeRuler.prototype.beginMark = function (markerName, color, barIndex) { - var _this = this; - if (barIndex === void 0) { barIndex = 0; } - var lock = new LockUtils(this._frameKey); - lock.lock().then(function () { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + _this.stopwacth.reset(); + _this.stopwacth.start(); + }); + }; + TimeRuler.prototype.beginMark = function (markerName, color, barIndex) { + var _this = this; + if (barIndex === void 0) { barIndex = 0; } + var lock = new LockUtils(this._frameKey); + lock.lock().then(function () { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + throw new Error("barIndex argument out of range"); + var bar = _this._curLog.bars[barIndex]; + if (bar.markCount >= TimeRuler.maxSamples) { + throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count"); + } + if (bar.nestCount >= TimeRuler.maxNestCall) { + throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); + } + var markerId = _this._markerNameToIdMap.get(markerName); + if (isNaN(markerId)) { + markerId = _this.markers.length; + _this._markerNameToIdMap.set(markerName, markerId); + } + bar.markerNests[bar.nestCount++] = bar.markCount; + bar.markers[bar.markCount].markerId = markerId; + bar.markers[bar.markCount].color = color; + bar.markers[bar.markCount].beginTime = _this.stopwacth.getTime(); + bar.markers[bar.markCount].endTime = -1; + }); + }; + TimeRuler.prototype.endMark = function (markerName, barIndex) { + var _this = this; + if (barIndex === void 0) { barIndex = 0; } + var lock = new LockUtils(this._frameKey); + lock.lock().then(function () { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + throw new Error("barIndex argument out of range"); + var bar = _this._curLog.bars[barIndex]; + if (bar.nestCount <= 0) { + throw new Error("call beginMark method before calling endMark method"); + } + var markerId = _this._markerNameToIdMap.get(markerName); + if (isNaN(markerId)) { + throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method"); + } + var markerIdx = bar.markerNests[--bar.nestCount]; + if (bar.markers[markerIdx].markerId != markerId) { + throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B)."); + } + bar.markers[markerIdx].endTime = _this.stopwacth.getTime(); + }); + }; + TimeRuler.prototype.getAverageTime = function (barIndex, markerName) { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) { throw new Error("barIndex argument out of range"); - var bar = _this._curLog.bars[barIndex]; - if (bar.markCount >= TimeRuler.maxSamples) { - throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count"); } - if (bar.nestCount >= TimeRuler.maxNestCall) { - throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); + var result = 0; + var markerId = this._markerNameToIdMap.get(markerName); + if (markerId) { + result = this.markers[markerId].logs[barIndex].avg; } - var markerId = _this._markerNameToIdMap.get(markerName); - if (isNaN(markerId)) { - markerId = _this.markers.length; - _this._markerNameToIdMap.set(markerName, markerId); - } - bar.markerNests[bar.nestCount++] = bar.markCount; - bar.markers[bar.markCount].markerId = markerId; - bar.markers[bar.markCount].color = color; - bar.markers[bar.markCount].beginTime = _this.stopwacth.getTime(); - bar.markers[bar.markCount].endTime = -1; - }); - }; - TimeRuler.prototype.endMark = function (markerName, barIndex) { - var _this = this; - if (barIndex === void 0) { barIndex = 0; } - var lock = new LockUtils(this._frameKey); - lock.lock().then(function () { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) - throw new Error("barIndex argument out of range"); - var bar = _this._curLog.bars[barIndex]; - if (bar.nestCount <= 0) { - throw new Error("call beginMark method before calling endMark method"); - } - var markerId = _this._markerNameToIdMap.get(markerName); - if (isNaN(markerId)) { - throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method"); - } - var markerIdx = bar.markerNests[--bar.nestCount]; - if (bar.markers[markerIdx].markerId != markerId) { - throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B)."); - } - bar.markers[markerIdx].endTime = _this.stopwacth.getTime(); - }); - }; - TimeRuler.prototype.getAverageTime = function (barIndex, markerName) { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) { - throw new Error("barIndex argument out of range"); - } - var result = 0; - var markerId = this._markerNameToIdMap.get(markerName); - if (markerId) { - result = this.markers[markerId].logs[barIndex].avg; - } - return result; - }; - TimeRuler.prototype.resetLog = function () { - var _this = this; - var lock = new LockUtils(this._logKey); - lock.lock().then(function () { - var count = parseInt(egret.localStorage.getItem(_this._logKey), 10); - count += 1; - egret.localStorage.setItem(_this._logKey, count.toString()); - _this.markers.forEach(function (markerInfo) { - for (var i = 0; i < markerInfo.logs.length; ++i) { - markerInfo.logs[i].initialized = false; - markerInfo.logs[i].snapMin = 0; - markerInfo.logs[i].snapMax = 0; - markerInfo.logs[i].snapAvg = 0; - markerInfo.logs[i].min = 0; - markerInfo.logs[i].max = 0; - markerInfo.logs[i].avg = 0; - markerInfo.logs[i].samples = 0; + return result; + }; + TimeRuler.prototype.resetLog = function () { + var _this = this; + var lock = new LockUtils(this._logKey); + lock.lock().then(function () { + var count = parseInt(egret.localStorage.getItem(_this._logKey), 10); + count += 1; + egret.localStorage.setItem(_this._logKey, count.toString()); + _this.markers.forEach(function (markerInfo) { + for (var i = 0; i < markerInfo.logs.length; ++i) { + markerInfo.logs[i].initialized = false; + markerInfo.logs[i].snapMin = 0; + markerInfo.logs[i].snapMax = 0; + markerInfo.logs[i].snapAvg = 0; + markerInfo.logs[i].min = 0; + markerInfo.logs[i].max = 0; + markerInfo.logs[i].avg = 0; + markerInfo.logs[i].samples = 0; + } + }); + }); + }; + TimeRuler.prototype.render = function (position, width) { + if (position === void 0) { position = this._position; } + if (width === void 0) { width = this.width; } + egret.localStorage.setItem(this._frameKey, "0"); + if (!this.showLog) + return; + var height = 0; + var maxTime = 0; + this._prevLog.bars.forEach(function (bar) { + if (bar.markCount > 0) { + height += TimeRuler.barHeight + TimeRuler.barPadding * 2; + maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime); } }); - }); - }; - TimeRuler.prototype.render = function (position, width) { - if (position === void 0) { position = this._position; } - if (width === void 0) { width = this.width; } - egret.localStorage.setItem(this._frameKey, "0"); - if (!this.showLog) - return; - var height = 0; - var maxTime = 0; - this._prevLog.bars.forEach(function (bar) { - if (bar.markCount > 0) { - height += TimeRuler.barHeight + TimeRuler.barPadding * 2; - maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime); + var frameSpan = 1 / 60 * 1000; + var sampleSpan = this.sampleFrames * frameSpan; + if (maxTime > sampleSpan) { + this._frameAdjust = Math.max(0, this._frameAdjust) + 1; } - }); - var frameSpan = 1 / 60 * 1000; - var sampleSpan = this.sampleFrames * frameSpan; - if (maxTime > sampleSpan) { - this._frameAdjust = Math.max(0, this._frameAdjust) + 1; + else { + this._frameAdjust = Math.min(0, this._frameAdjust) - 1; + } + if (Math.max(this._frameAdjust) > TimeRuler.autoAdjustDelay) { + this.sampleFrames = Math.min(TimeRuler.maxSampleFrames, this.sampleFrames); + this.sampleFrames = Math.max(this.targetSampleFrames, (maxTime / frameSpan) + 1); + this._frameAdjust = 0; + } + var msToPs = width / sampleSpan; + var startY = position.y - (height - TimeRuler.barHeight); + var y = startY; + }; + TimeRuler.maxBars = 8; + TimeRuler.maxSamples = 256; + TimeRuler.maxNestCall = 32; + TimeRuler.barHeight = 8; + TimeRuler.maxSampleFrames = 4; + TimeRuler.logSnapDuration = 120; + TimeRuler.barPadding = 2; + TimeRuler.autoAdjustDelay = 30; + return TimeRuler; + }()); + es.TimeRuler = TimeRuler; + var FrameLog = (function () { + function FrameLog() { + this.bars = new Array(TimeRuler.maxBars); + this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); } - else { - this._frameAdjust = Math.min(0, this._frameAdjust) - 1; + return FrameLog; + }()); + es.FrameLog = FrameLog; + var MarkerCollection = (function () { + function MarkerCollection() { + this.markers = new Array(TimeRuler.maxSamples); + this.markCount = 0; + this.markerNests = new Array(TimeRuler.maxNestCall); + this.nestCount = 0; + this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); + this.markerNests.fill(0, 0, TimeRuler.maxNestCall); } - if (Math.max(this._frameAdjust) > TimeRuler.autoAdjustDelay) { - this.sampleFrames = Math.min(TimeRuler.maxSampleFrames, this.sampleFrames); - this.sampleFrames = Math.max(this.targetSampleFrames, (maxTime / frameSpan) + 1); - this._frameAdjust = 0; + return MarkerCollection; + }()); + es.MarkerCollection = MarkerCollection; + var Marker = (function () { + function Marker() { + this.markerId = 0; + this.beginTime = 0; + this.endTime = 0; + this.color = 0x000000; } - var msToPs = width / sampleSpan; - var startY = position.y - (height - TimeRuler.barHeight); - var y = startY; - }; - TimeRuler.maxBars = 8; - TimeRuler.maxSamples = 256; - TimeRuler.maxNestCall = 32; - TimeRuler.barHeight = 8; - TimeRuler.maxSampleFrames = 4; - TimeRuler.logSnapDuration = 120; - TimeRuler.barPadding = 2; - TimeRuler.autoAdjustDelay = 30; - return TimeRuler; -}()); -var FrameLog = (function () { - function FrameLog() { - this.bars = new Array(TimeRuler.maxBars); - this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); - } - return FrameLog; -}()); -var MarkerCollection = (function () { - function MarkerCollection() { - this.markers = new Array(TimeRuler.maxSamples); - this.markCount = 0; - this.markerNests = new Array(TimeRuler.maxNestCall); - this.nestCount = 0; - this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); - this.markerNests.fill(0, 0, TimeRuler.maxNestCall); - } - return MarkerCollection; -}()); -var Marker = (function () { - function Marker() { - this.markerId = 0; - this.beginTime = 0; - this.endTime = 0; - this.color = 0x000000; - } - return Marker; -}()); -var MarkerInfo = (function () { - function MarkerInfo(name) { - this.logs = new Array(TimeRuler.maxBars); - this.name = name; - this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); - } - return MarkerInfo; -}()); -var MarkerLog = (function () { - function MarkerLog() { - this.snapMin = 0; - this.snapMax = 0; - this.snapAvg = 0; - this.min = 0; - this.max = 0; - this.avg = 0; - this.samples = 0; - this.color = 0x000000; - this.initialized = false; - } - return MarkerLog; -}()); + return Marker; + }()); + es.Marker = Marker; + var MarkerInfo = (function () { + function MarkerInfo(name) { + this.logs = new Array(TimeRuler.maxBars); + this.name = name; + this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); + } + return MarkerInfo; + }()); + es.MarkerInfo = MarkerInfo; + var MarkerLog = (function () { + function MarkerLog() { + this.snapMin = 0; + this.snapMax = 0; + this.snapAvg = 0; + this.min = 0; + this.max = 0; + this.avg = 0; + this.samples = 0; + this.color = 0x000000; + this.initialized = false; + } + return MarkerLog; + }()); + es.MarkerLog = MarkerLog; +})(es || (es = {})); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index d6c96e6d..21b482eb 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.endDebugUpdate(),t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t.startDebugUpdate=function(){TimeRuler.Instance.startFrame(),TimeRuler.Instance.beginMark("update",65280)},t.endDebugUpdate=function(){TimeRuler.Instance.endMark("update")},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x==-t.position.x+t.origin.x&&this.y==-t.position.y+t.origin.y||(this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y,this.entity.onEntityTransformChanged(TransformComponent.position))},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t, e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(egret.DisplayObject),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.parent.x,this.parent.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.x,this.y,this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(Long.fromNumber(e,!1)).toString()},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(isNaN(o))throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=8,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars),this.bars.fill(new MarkerCollection,0,TimeRuler.maxBars)}}(),MarkerCollection=function(){return function(){this.markers=new Array(TimeRuler.maxSamples),this.markCount=0,this.markerNests=new Array(TimeRuler.maxNestCall),this.nestCount=0,this.markers.fill(new Marker,0,TimeRuler.maxSamples),this.markerNests.fill(0,0,TimeRuler.maxNestCall)}}(),Marker=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}(),MarkerInfo=function(){return function(t){this.logs=new Array(TimeRuler.maxBars),this.name=t,this.logs.fill(new MarkerLog,0,TimeRuler.maxBars)}}(),MarkerLog=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}(); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},i.prototype.zoomIn=function(t){this.zoom+=t},i.prototype.zoomOut=function(t){this.zoom-=t},i.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},i.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},i.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},i.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},i.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},i.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},i}(t.Component);t.Camera=n}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(e,"identity",{get:function(){return e._identity},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.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(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),e.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},e.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},e.multiply=function(t,n){var i=new e,r=t.m11*n.m11+t.m12*n.m21,o=t.m11*n.m12+t.m12*n.m22,s=t.m21*n.m11+t.m22*n.m21,a=t.m21*n.m12+t.m22*n.m22,c=t.m31*n.m11+t.m32*n.m21+n.m31,h=t.m31*n.m12+t.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},e.multiplyTranslation=function(t,n,i){var r=e.createTranslation(n,i);return e.multiply(t,r)},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.invert=function(t,n){void 0===n&&(n=new e);var i=1/t.determinant();return n.m11=t.m22*i,n.m12=-t.m12*i,n.m21=-t.m21*i,n.m22=t.m11*i,n.m31=(t.m32*t.m21-t.m31*t.m22)*i,n.m32=-(t.m32*t.m11-t.m31*t.m12)*i,n},e.createTranslation=function(t,n){var i=new e;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=t,i.m32=n,i},e.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},e.createRotation=function(t,n){n=new e;var i=Math.cos(t),r=Math.sin(t);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},e.createScale=function(t,n,i){return void 0===i&&(i=new e),i.m11=t,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},e.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},e._identity=new e(1,0,0,1,0,0),e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(){}}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 9ab1a179..6c72ef06 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -17,648 +17,842 @@ declare interface Array { groupBy(keySelector: Function): Array; sum(selector: any): any; } -declare class PriorityQueueNode { - priority: number; - insertionIndex: number; - queueIndex: number; +declare module es { + class PriorityQueueNode { + priority: number; + insertionIndex: number; + queueIndex: number; + } } -declare class AStarPathfinder { - static search(graph: IAstarGraph, start: T, goal: T): T[]; - private static hasKey; - private static getKey; - static recontructPath(cameFrom: Map, start: T, goal: T): T[]; +declare module es { + class AStarPathfinder { + static search(graph: IAstarGraph, start: T, goal: T): T[]; + private static hasKey; + private static getKey; + static recontructPath(cameFrom: Map, start: T, goal: T): T[]; + } + class AStarNode extends PriorityQueueNode { + data: T; + constructor(data: T); + } } -declare class AStarNode extends PriorityQueueNode { - data: T; - constructor(data: T); +declare module es { + class AstarGridGraph implements IAstarGraph { + dirs: Vector2[]; + walls: Vector2[]; + weightedNodes: Vector2[]; + defaultWeight: number; + weightedNodeWeight: number; + private _width; + private _height; + private _neighbors; + constructor(width: number, height: number); + isNodeInBounds(node: Vector2): boolean; + isNodePassable(node: Vector2): boolean; + search(start: Vector2, goal: Vector2): Vector2[]; + getNeighbors(node: Vector2): Vector2[]; + cost(from: Vector2, to: Vector2): number; + heuristic(node: Vector2, goal: Vector2): number; + } } -declare class AstarGridGraph implements IAstarGraph { - dirs: Vector2[]; - walls: Vector2[]; - weightedNodes: Vector2[]; - defaultWeight: number; - weightedNodeWeight: number; - private _width; - private _height; - private _neighbors; - constructor(width: number, height: number); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - search(start: Vector2, goal: Vector2): Vector2[]; - getNeighbors(node: Vector2): Vector2[]; - cost(from: Vector2, to: Vector2): number; - heuristic(node: Vector2, goal: Vector2): number; +declare module es { + interface IAstarGraph { + getNeighbors(node: T): Array; + cost(from: T, to: T): number; + heuristic(node: T, goal: T): any; + } } -interface IAstarGraph { - getNeighbors(node: T): Array; - cost(from: T, to: T): number; - heuristic(node: T, goal: T): any; +declare module es { + class PriorityQueue { + private _numNodes; + private _nodes; + private _numNodesEverEnqueued; + constructor(maxNodes: number); + clear(): void; + readonly count: number; + readonly maxSize: number; + contains(node: T): boolean; + enqueue(node: T, priority: number): void; + dequeue(): T; + remove(node: T): void; + isValidQueue(): boolean; + private onNodeUpdated; + private cascadeDown; + private cascadeUp; + private swap; + private hasHigherPriority; + } } -declare class PriorityQueue { - private _numNodes; - private _nodes; - private _numNodesEverEnqueued; - constructor(maxNodes: number); - clear(): void; - readonly count: number; - readonly maxSize: number; - contains(node: T): boolean; - enqueue(node: T, priority: number): void; - dequeue(): T; - remove(node: T): void; - isValidQueue(): boolean; - private onNodeUpdated; - private cascadeDown; - private cascadeUp; - private swap; - private hasHigherPriority; +declare module es { + class BreadthFirstPathfinder { + static search(graph: IUnweightedGraph, start: T, goal: T): T[]; + private static hasKey; + } } -declare class BreadthFirstPathfinder { - static search(graph: IUnweightedGraph, start: T, goal: T): T[]; - private static hasKey; +declare module es { + interface IUnweightedGraph { + getNeighbors(node: T): T[]; + } } -interface IUnweightedGraph { - getNeighbors(node: T): T[]; +declare module es { + class UnweightedGraph implements IUnweightedGraph { + edges: Map; + addEdgesForNode(node: T, edges: T[]): this; + getNeighbors(node: T): T[]; + } } -declare class UnweightedGraph implements IUnweightedGraph { - edges: Map; - addEdgesForNode(node: T, edges: T[]): this; - getNeighbors(node: T): T[]; +declare module es { + class Vector2 { + x: number; + y: number; + private static readonly unitYVector; + private static readonly unitXVector; + private static readonly unitVector2; + private static readonly zeroVector2; + static readonly zero: Vector2; + static readonly one: Vector2; + static readonly unitX: Vector2; + static readonly unitY: Vector2; + constructor(x?: number, y?: number); + static add(value1: Vector2, value2: Vector2): Vector2; + static divide(value1: Vector2, value2: Vector2): Vector2; + static multiply(value1: Vector2, value2: Vector2): Vector2; + static subtract(value1: Vector2, value2: Vector2): Vector2; + normalize(): void; + length(): number; + round(): Vector2; + static normalize(value: Vector2): Vector2; + static dot(value1: Vector2, value2: Vector2): number; + static distanceSquared(value1: Vector2, value2: Vector2): number; + static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2; + static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2; + static transform(position: Vector2, matrix: Matrix2D): Vector2; + static distance(value1: Vector2, value2: Vector2): number; + static negate(value: Vector2): Vector2; + } } -declare class Vector2 { - x: number; - y: number; - private static readonly unitYVector; - private static readonly unitXVector; - private static readonly unitVector2; - private static readonly zeroVector2; - static readonly zero: Vector2; - static readonly one: Vector2; - static readonly unitX: Vector2; - static readonly unitY: Vector2; - constructor(x?: number, y?: number); - static add(value1: Vector2, value2: Vector2): Vector2; - static divide(value1: Vector2, value2: Vector2): Vector2; - static multiply(value1: Vector2, value2: Vector2): Vector2; - static subtract(value1: Vector2, value2: Vector2): Vector2; - normalize(): void; - length(): number; - round(): Vector2; - static normalize(value: Vector2): Vector2; - static dot(value1: Vector2, value2: Vector2): number; - static distanceSquared(value1: Vector2, value2: Vector2): number; - static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2; - static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2; - static transform(position: Vector2, matrix: Matrix2D): Vector2; - static distance(value1: Vector2, value2: Vector2): number; - static negate(value: Vector2): Vector2; +declare module es { + class UnweightedGridGraph implements IUnweightedGraph { + private static readonly CARDINAL_DIRS; + private static readonly COMPASS_DIRS; + walls: Vector2[]; + private _width; + private _hegiht; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Vector2): boolean; + isNodePassable(node: Vector2): boolean; + getNeighbors(node: Vector2): Vector2[]; + search(start: Vector2, goal: Vector2): Vector2[]; + } } -declare class UnweightedGridGraph implements IUnweightedGraph { - private static readonly CARDINAL_DIRS; - private static readonly COMPASS_DIRS; - walls: Vector2[]; - private _width; - private _hegiht; - private _dirs; - private _neighbors; - constructor(width: number, height: number, allowDiagonalSearch?: boolean); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - getNeighbors(node: Vector2): Vector2[]; - search(start: Vector2, goal: Vector2): Vector2[]; +declare module es { + interface IWeightedGraph { + getNeighbors(node: T): T[]; + cost(from: T, to: T): number; + } } -interface IWeightedGraph { - getNeighbors(node: T): T[]; - cost(from: T, to: T): number; +declare module es { + class WeightedGridGraph implements IWeightedGraph { + static readonly CARDINAL_DIRS: Vector2[]; + private static readonly COMPASS_DIRS; + walls: Vector2[]; + weightedNodes: Vector2[]; + defaultWeight: number; + weightedNodeWeight: number; + private _width; + private _height; + private _dirs; + private _neighbors; + constructor(width: number, height: number, allowDiagonalSearch?: boolean); + isNodeInBounds(node: Vector2): boolean; + isNodePassable(node: Vector2): boolean; + search(start: Vector2, goal: Vector2): Vector2[]; + getNeighbors(node: Vector2): Vector2[]; + cost(from: Vector2, to: Vector2): number; + } } -declare class WeightedGridGraph implements IWeightedGraph { - static readonly CARDINAL_DIRS: Vector2[]; - private static readonly COMPASS_DIRS; - walls: Vector2[]; - weightedNodes: Vector2[]; - defaultWeight: number; - weightedNodeWeight: number; - private _width; - private _height; - private _dirs; - private _neighbors; - constructor(width: number, height: number, allowDiagonalSearch?: boolean); - isNodeInBounds(node: Vector2): boolean; - isNodePassable(node: Vector2): boolean; - search(start: Vector2, goal: Vector2): Vector2[]; - getNeighbors(node: Vector2): Vector2[]; - cost(from: Vector2, to: Vector2): number; +declare module es { + class WeightedNode extends PriorityQueueNode { + data: T; + constructor(data: T); + } + class WeightedPathfinder { + static search(graph: IWeightedGraph, start: T, goal: T): T[]; + private static hasKey; + private static getKey; + static recontructPath(cameFrom: Map, start: T, goal: T): T[]; + } } -declare class WeightedNode extends PriorityQueueNode { - data: T; - constructor(data: T); +declare module es { + class Debug { + private static _debugDrawItems; + static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void; + static render(): void; + } } -declare class WeightedPathfinder { - static search(graph: IWeightedGraph, start: T, goal: T): T[]; - private static hasKey; - private static getKey; - static recontructPath(cameFrom: Map, start: T, goal: T): T[]; +declare module es { + class DebugDefaults { + static verletParticle: number; + static verletConstraintEdge: number; + } } -declare class Debug { - private static _debugDrawItems; - static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void; - static render(): void; +declare module es { + enum DebugDrawType { + line = 0, + hollowRectangle = 1, + pixel = 2, + text = 3 + } + class DebugDrawItem { + rectangle: Rectangle; + color: number; + duration: number; + drawType: DebugDrawType; + text: string; + start: Vector2; + end: Vector2; + x: number; + y: number; + size: number; + constructor(rectangle: Rectangle, color: number, duration: number); + draw(shape: egret.Shape): boolean; + } } -declare class DebugDefaults { - static verletParticle: number; - static verletConstraintEdge: number; +declare module es { + abstract class Component { + entity: Entity; + readonly transform: Transform; + enabled: boolean; + updateOrder: number; + updateInterval: number; + private _enabled; + private _updateOrder; + initialize(): void; + onAddedToEntity(): void; + onRemovedFromEntity(): void; + onEntityTransformChanged(comp: transform.Component): void; + debugRender(): void; + onEnabled(): void; + onDisabled(): void; + update(): void; + setEnabled(isEnabled: boolean): this; + setUpdateOrder(updateOrder: number): this; + clone(): Component; + } } -declare enum DebugDrawType { - line = 0, - hollowRectangle = 1, - pixel = 2, - text = 3 +declare module es { + enum CoreEvents { + SceneChanged = 0 + } } -declare class DebugDrawItem { - rectangle: Rectangle; - color: number; - duration: number; - drawType: DebugDrawType; - text: string; - start: Vector2; - end: Vector2; - x: number; - y: number; - size: number; - constructor(rectangle: Rectangle, color: number, duration: number); - draw(shape: egret.Shape): boolean; +declare module es { + class Entity { + static _idGenerator: number; + scene: Scene; + name: string; + readonly id: number; + readonly transform: Transform; + readonly components: ComponentList; + tag: number; + updateInterval: number; + enabled: boolean; + updateOrder: number; + _isDestroyed: boolean; + readonly isDestroyed: boolean; + componentBits: BitSet; + private _tag; + private _enabled; + private _updateOrder; + parent: Transform; + readonly childCount: number; + position: Vector2; + rotation: number; + scale: Vector2; + constructor(name: string); + onTransformChanged(comp: transform.Component): void; + setTag(tag: number): Entity; + setEnabled(isEnabled: boolean): this; + setUpdateOrder(updateOrder: number): this; + destroy(): void; + detachFromScene(): void; + attachToScene(newScene: Scene): void; + clone(position?: Vector2): Entity; + protected copyFrom(entity: Entity): void; + onAddedToScene(): void; + onRemovedFromScene(): void; + update(): void; + addComponent(component: T): T; + getComponent(type: any): T; + hasComponent(type: any): boolean; + getOrCreateComponent(type: T): T; + getComponents(typeName: string | any, componentList?: any): any; + removeComponent(component: Component): void; + removeComponentForType(type: any): boolean; + removeAllComponents(): void; + toString(): string; + } } -declare abstract class Component extends egret.DisplayObjectContainer { - entity: Entity; - private _enabled; - updateInterval: number; - userData: any; - private _updateOrder; - enabled: boolean; - readonly localPosition: Vector2; - setEnabled(isEnabled: boolean): this; - updateOrder: number; - setUpdateOrder(updateOrder: number): this; - initialize(): void; - onAddedToEntity(): void; - onRemovedFromEntity(): void; - onEnabled(): void; - onDisabled(): void; - debugRender(): void; - update(): void; - onEntityTransformChanged(comp: TransformComponent): void; - registerComponent(): void; - deregisterComponent(): void; +declare module es { + class Scene extends egret.DisplayObjectContainer { + camera: Camera; + readonly content: ContentManager; + enablePostProcessing: boolean; + readonly entities: EntityList; + readonly renderableComponents: RenderableComponentList; + readonly entityProcessors: EntityProcessorList; + _renderers: Renderer[]; + readonly _postProcessors: PostProcessor[]; + _didSceneBegin: any; + static createWithDefaultRenderer(): Scene; + constructor(); + initialize(): void; + onStart(): Promise; + unload(): void; + onActive(): void; + onDeactive(): void; + begin(): Promise; + end(): void; + update(): void; + render(): void; + postRender(): void; + addRenderer(renderer: T): T; + getRenderer(type: any): T; + removeRenderer(renderer: Renderer): void; + addPostProcessor(postProcessor: T): T; + getPostProcessor(type: any): T; + removePostProcessor(postProcessor: PostProcessor): void; + createEntity(name: string): Entity; + addEntity(entity: Entity): Entity; + destroyAllEntities(): void; + findEntity(name: string): Entity; + findEntitiesWithTag(tag: number): Entity[]; + entitiesOfType(type: any): T[]; + findComponentOfType(type: any): T; + findComponentsOfType(type: any): T[]; + addEntityProcessor(processor: EntitySystem): EntitySystem; + removeEntityProcessor(processor: EntitySystem): void; + getEntityProcessor(): T; + } } -declare enum CoreEvents { - SceneChanged = 0 +declare module es { + class SceneManager { + private static _scene; + private static _nextScene; + static sceneTransition: SceneTransition; + static stage: egret.Stage; + static activeSceneChanged: Function; + static emitter: Emitter; + static content: ContentManager; + private static _instnace; + private static timerRuler; + static readonly Instance: SceneManager; + constructor(stage: egret.Stage); + static scene: Scene; + static initialize(stage: egret.Stage): void; + static update(): void; + static render(): void; + static startSceneTransition(sceneTransition: T): T; + static registerActiveSceneChanged(current: Scene, next: Scene): void; + onSceneChanged(): void; + private static startDebugUpdate; + private static endDebugUpdate; + } } -declare class Entity extends egret.DisplayObjectContainer { - private static _idGenerator; - name: string; - readonly id: number; - scene: Scene; - readonly components: ComponentList; - private _updateOrder; - private _enabled; - _isDestoryed: boolean; - private _tag; - componentBits: BitSet; - readonly isDestoryed: boolean; - position: Vector2; - scale: Vector2; - rotation: number; - enabled: boolean; - setEnabled(isEnabled: boolean): this; - tag: number; - readonly stage: egret.Stage; - constructor(name: string); - private onAddToStage; - updateOrder: number; - roundPosition(): void; - setUpdateOrder(updateOrder: number): this; - setTag(tag: number): Entity; - attachToScene(newScene: Scene): void; - detachFromScene(): void; - addComponent(component: T): T; - hasComponent(type: any): boolean; - getOrCreateComponent(type: T): T; - getComponent(type: any): T; - getComponents(typeName: string | any, componentList?: any): any; - onEntityTransformChanged(comp: TransformComponent): void; - removeComponentForType(type: any): boolean; - removeComponent(component: Component): void; - removeAllComponents(): void; - update(): void; - onAddedToScene(): void; - onRemovedFromScene(): void; - destroy(): void; +declare module transform { + enum Component { + position = 0, + scale = 1, + rotation = 2 + } } -declare enum TransformComponent { - rotation = 0, - scale = 1, - position = 2 +declare module es { + enum DirtyType { + clean = 0, + positionDirty = 1, + scaleDirty = 2, + rotationDirty = 3 + } + class Transform { + readonly entity: Entity; + parent: Transform; + readonly childCount: number; + position: Vector2; + rotation: number; + scale: Vector2; + _parent: Transform; + hierarchyDirty: DirtyType; + _children: Transform[]; + constructor(entity: Entity); + getChild(index: number): Transform; + setParent(parent: Transform): Transform; + setPosition(x: number, y: number): Transform; + setRotation(degrees: number): Transform; + setScale(scale: Vector2): Transform; + lookAt(pos: Vector2): void; + roundPosition(): void; + setDirty(dirtyFlagType: DirtyType): void; + copyFrom(transform: Transform): void; + } } -declare class Scene extends egret.DisplayObjectContainer { - camera: Camera; - readonly entities: EntityList; - readonly renderableComponents: RenderableComponentList; - readonly content: ContentManager; - enablePostProcessing: boolean; - private _renderers; - private _postProcessors; - private _didSceneBegin; - readonly entityProcessors: EntityProcessorList; - constructor(); - createEntity(name: string): Entity; - addEntity(entity: Entity): Entity; - destroyAllEntities(): void; - findEntity(name: string): Entity; - addEntityProcessor(processor: EntitySystem): EntitySystem; - removeEntityProcessor(processor: EntitySystem): void; - getEntityProcessor(): T; - addRenderer(renderer: T): T; - getRenderer(type: any): T; - removeRenderer(renderer: Renderer): void; - begin(): void; - end(): void; - protected onStart(): Promise; - protected onActive(): void; - protected onDeactive(): void; - protected unload(): void; - update(): void; - postRender(): void; - render(): void; - addPostProcessor(postProcessor: T): T; +declare module es { + enum CameraStyle { + lockOn = 0, + cameraWindow = 1 + } + class Camera extends Component { + position: Vector2; + rotation: number; + zoom: number; + minimumZoom: number; + maximumZoom: number; + readonly bounds: Rectangle; + origin: Vector2; + private _zoom; + private _minimumZoom; + private _maximumZoom; + private _origin; + followLerp: number; + deadzone: Rectangle; + focusOffset: Vector2; + mapLockEnabled: boolean; + mapSize: Vector2; + _targetEntity: Entity; + _targetCollider: Collider; + _desiredPositionDelta: Vector2; + _cameraStyle: CameraStyle; + _worldSpaceDeadZone: Rectangle; + constructor(targetEntity?: Entity, cameraStyle?: CameraStyle); + onSceneSizeChanged(newWidth: number, newHeight: number): void; + setPosition(position: Vector2): this; + setRotation(rotation: number): Camera; + setZoom(zoom: number): Camera; + setMinimumZoom(minZoom: number): Camera; + setMaximumZoom(maxZoom: number): Camera; + zoomIn(deltaZoom: number): void; + zoomOut(deltaZoom: number): void; + onAddedToEntity(): void; + update(): void; + clampToMapSize(position: Vector2): Vector2; + updateFollow(): void; + follow(targetEntity: Entity, cameraStyle?: CameraStyle): void; + setCenteredDeadzone(width: number, height: number): void; + } } -declare class SceneManager { - private static _scene; - private static _nextScene; - static sceneTransition: SceneTransition; - static stage: egret.Stage; - static activeSceneChanged: Function; - static emitter: Emitter; - static content: ContentManager; - private static _instnace; - private static timerRuler; - static readonly Instance: SceneManager; - constructor(stage: egret.Stage); - static scene: Scene; - static initialize(stage: egret.Stage): void; - static update(): void; - static render(): void; - static startSceneTransition(sceneTransition: T): T; - static registerActiveSceneChanged(current: Scene, next: Scene): void; - onSceneChanged(): void; - private static startDebugUpdate; - private static endDebugUpdate; +declare module es { + class ComponentPool { + private _cache; + private _type; + constructor(typeClass: any); + obtain(): T; + free(component: T): void; + } } -declare class Camera extends Component { - private _zoom; - private _origin; - private _minimumZoom; - private _maximumZoom; - private _position; - followLerp: number; - deadzone: Rectangle; - focusOffset: Vector2; - mapLockEnabled: boolean; - mapSize: Vector2; - targetEntity: Entity; - private _worldSpaceDeadZone; - private _desiredPositionDelta; - private _targetCollider; - cameraStyle: CameraStyle; - zoom: number; - minimumZoom: number; - maximumZoom: number; - origin: Vector2; - position: Vector2; - x: number; - y: number; - constructor(); - onSceneSizeChanged(newWidth: number, newHeight: number): void; - setMinimumZoom(minZoom: number): Camera; - setMaximumZoom(maxZoom: number): Camera; - setZoom(zoom: number): Camera; - setRotation(rotation: number): Camera; - setPosition(position: Vector2): this; - follow(targetEntity: Entity, cameraStyle?: CameraStyle): void; - update(): void; - private clampToMapSize; - private updateFollow; +declare module es { + class IUpdatableComparer { + compare(a: Component, b: Component): number; + } } -declare enum CameraStyle { - lockOn = 0, - cameraWindow = 1 +declare module es { + abstract class PooledComponent extends Component { + abstract reset(): any; + } } -declare class ComponentPool { - private _cache; - private _type; - constructor(typeClass: any); - obtain(): T; - free(component: T): void; +declare module es { + abstract class RenderableComponent extends Component implements IRenderable { + readonly width: number; + readonly height: number; + readonly bounds: Rectangle; + renderLayer: number; + color: number; + localOffset: Vector2; + isVisible: boolean; + protected _localOffset: Vector2; + protected _renderLayer: number; + protected _bounds: Rectangle; + private _isVisible; + protected _areBoundsDirty: boolean; + onEntityTransformChanged(comp: transform.Component): void; + abstract render(camera: Camera): any; + protected onBecameVisible(): void; + protected onBecameInvisible(): void; + isVisibleFromCamera(camera: Camera): boolean; + setRenderLayer(renderLayer: number): RenderableComponent; + setColor(color: number): RenderableComponent; + setLocalOffset(offset: Vector2): RenderableComponent; + toString(): string; + } } -declare abstract class PooledComponent extends Component { - abstract reset(): any; +declare module es { + class Mesh extends RenderableComponent { + private _mesh; + constructor(); + setTexture(texture: egret.Texture): Mesh; + reset(): void; + render(camera: es.Camera): void; + } } -declare abstract class RenderableComponent extends PooledComponent implements IRenderable { - private _isVisible; - protected _areBoundsDirty: boolean; - protected _bounds: Rectangle; - protected _localOffset: Vector2; - color: number; - readonly width: number; - readonly height: number; - isVisible: boolean; - readonly bounds: Rectangle; - protected getWidth(): number; - protected getHeight(): number; - protected onBecameVisible(): void; - protected onBecameInvisible(): void; - abstract render(camera: Camera): any; - isVisibleFromCamera(camera: Camera): boolean; +declare module es { + class SpriteRenderer extends RenderableComponent { + readonly bounds: Rectangle; + origin: Vector2; + originNormalized: Vector2; + sprite: Sprite; + protected _origin: Vector2; + protected _sprite: Sprite; + constructor(sprite?: Sprite | egret.Texture); + setSprite(sprite: Sprite): SpriteRenderer; + setOrigin(origin: Vector2): SpriteRenderer; + setOriginNormalized(value: Vector2): SpriteRenderer; + render(camera: Camera): void; + } } -declare class Mesh extends RenderableComponent { - private _mesh; - constructor(); - setTexture(texture: egret.Texture): Mesh; - onAddedToEntity(): void; - onRemovedFromEntity(): void; - render(camera: Camera): void; - reset(): void; +declare module es { + class TiledSpriteRenderer extends SpriteRenderer { + protected sourceRect: Rectangle; + protected leftTexture: egret.Bitmap; + protected rightTexture: egret.Bitmap; + scrollX: number; + scrollY: number; + constructor(sprite: Sprite); + render(camera: es.Camera): void; + } } -declare class SpriteRenderer extends RenderableComponent { - private _sprite; - protected bitmap: egret.Bitmap; - sprite: Sprite; - setSprite(sprite: Sprite): SpriteRenderer; - setColor(color: number): SpriteRenderer; - isVisibleFromCamera(camera: Camera): boolean; - render(camera: Camera): void; - onRemovedFromEntity(): void; - reset(): void; +declare module es { + class ScrollingSpriteRenderer extends TiledSpriteRenderer { + scrollSpeedX: number; + scroolSpeedY: number; + private _scrollX; + private _scrollY; + update(): void; + render(camera: Camera): void; + } } -declare class TiledSpriteRenderer extends SpriteRenderer { - protected sourceRect: Rectangle; - protected leftTexture: egret.Bitmap; - protected rightTexture: egret.Bitmap; - scrollX: number; - scrollY: number; - constructor(sprite: Sprite); - render(camera: Camera): void; +declare module es { + class Sprite { + texture2D: egret.Texture; + readonly sourceRect: Rectangle; + readonly center: Vector2; + origin: Vector2; + readonly uvs: Rectangle; + constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2); + } } -declare class ScrollingSpriteRenderer extends TiledSpriteRenderer { - scrollSpeedX: number; - scroolSpeedY: number; - private _scrollX; - private _scrollY; - update(): void; - render(camera: Camera): void; +declare module es { + class SpriteAnimation { + readonly sprites: Sprite[]; + readonly frameRate: number; + constructor(sprites: Sprite[], frameRate: number); + } } -declare class Sprite { - texture2D: egret.Texture; - readonly sourceRect: Rectangle; - readonly center: Vector2; - origin: Vector2; - readonly uvs: Rectangle; - constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2); +declare module es { + enum LoopMode { + loop = 0, + once = 1, + clampForever = 2, + pingPong = 3, + pingPongOnce = 4 + } + enum State { + none = 0, + running = 1, + paused = 2, + completed = 3 + } + class SpriteAnimator extends SpriteRenderer { + onAnimationCompletedEvent: (string: any) => {}; + speed: number; + animationState: State; + currentAnimation: SpriteAnimation; + currentAnimationName: string; + currentFrame: number; + readonly isRunning: boolean; + readonly animations: Map; + private _animations; + _elapsedTime: number; + _loopMode: LoopMode; + constructor(sprite?: Sprite); + update(): void; + addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator; + play(name: string, loopMode?: LoopMode): void; + isAnimationActive(name: string): boolean; + pause(): void; + unPause(): void; + stop(): void; + } } -declare class SpriteAnimation { - readonly sprites: Sprite[]; - readonly frameRate: number; - constructor(sprites: Sprite[], frameRate: number); +declare module es { + interface ITriggerListener { + onTriggerEnter(other: Collider, local: Collider): any; + onTriggerExit(other: Collider, local: Collider): any; + } } -declare class SpriteAnimator extends SpriteRenderer { - onAnimationCompletedEvent: Function; - speed: number; - animationState: State; - currentAnimation: SpriteAnimation; - currentAnimationName: string; - currentFrame: number; - readonly isRunning: boolean; - readonly animations: Map; - private _animations; - private _elapsedTime; - private _loopMode; - constructor(sprite?: Sprite); - addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator; - play(name: string, loopMode?: LoopMode): void; - isAnimationActive(name: string): boolean; - pause(): void; - unPause(): void; - stop(): void; - update(): void; +declare module es { + class Mover extends Component { + private _triggerHelper; + onAddedToEntity(): void; + calculateMovement(motion: Vector2): { + collisionResult: CollisionResult; + motion: Vector2; + }; + applyMovement(motion: Vector2): void; + move(motion: Vector2): CollisionResult; + } } -declare enum LoopMode { - loop = 0, - once = 1, - clampForever = 2, - pingPong = 3, - pingPongOnce = 4 +declare module es { + class ProjectileMover extends Component { + private _tempTriggerList; + private _collider; + onAddedToEntity(): void; + move(motion: Vector2): boolean; + private notifyTriggerListeners; + } } -declare enum State { - none = 0, - running = 1, - paused = 2, - completed = 3 +declare module es { + abstract class Collider extends Component { + shape: Shape; + localOffset: Vector2; + readonly absolutePosition: Vector2; + readonly rotation: number; + isTrigger: boolean; + physicsLayer: number; + collidesWithLayers: number; + shouldColliderScaleAndRotateWithTransform: boolean; + readonly bounds: Rectangle; + registeredPhysicsBounds: Rectangle; + protected _colliderRequiresAutoSizing: any; + protected _localOffset: Vector2; + _localOffsetLength: number; + protected _isParentEntityAddedToScene: any; + protected _isColliderRegistered: any; + setLocalOffset(offset: Vector2): Collider; + setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider; + onAddedToEntity(): void; + onRemovedFromEntity(): void; + onEntityTransformChanged(comp: transform.Component): void; + onEnabled(): void; + onDisabled(): void; + registerColliderWithPhysicsSystem(): void; + unregisterColliderWithPhysicsSystem(): void; + overlaps(other: Collider): any; + collidesWith(collider: Collider, motion: Vector2): CollisionResult; + } } -interface ITriggerListener { - onTriggerEnter(other: Collider, local: Collider): any; - onTriggerExit(other: Collider, local: Collider): any; +declare module es { + class BoxCollider extends Collider { + width: number; + height: number; + constructor(); + setSize(width: number, height: number): this; + setWidth(width: number): BoxCollider; + setHeight(height: number): void; + toString(): string; + } } -declare class Mover extends Component { - private _triggerHelper; - onAddedToEntity(): void; - calculateMovement(motion: Vector2): { - collisionResult: CollisionResult; - motion: Vector2; - }; - applyMovement(motion: Vector2): void; - move(motion: Vector2): CollisionResult; +declare module es { + class CircleCollider extends Collider { + radius: number; + constructor(radius?: number); + setRadius(radius: number): CircleCollider; + toString(): string; + } } -declare class ProjectileMover extends Component { - private _tempTriggerList; - private _collider; - onAddedToEntity(): void; - move(motion: Vector2): boolean; - private notifyTriggerListeners; +declare module es { + class PolygonCollider extends Collider { + constructor(points: Vector2[]); + } } -declare abstract class Collider extends Component { - shape: Shape; - physicsLayer: number; - isTrigger: boolean; - registeredPhysicsBounds: Rectangle; - shouldColliderScaleAndRotateWithTransform: boolean; - collidesWithLayers: number; - protected _isParentEntityAddedToScene: any; - protected _colliderRequiresAutoSizing: any; - protected _isColliderRegistered: any; - readonly bounds: Rectangle; - registerColliderWithPhysicsSystem(): void; - unregisterColliderWithPhysicsSystem(): void; - overlaps(other: Collider): any; - collidesWith(collider: Collider, motion: Vector2): CollisionResult; - onAddedToEntity(): void; - onRemovedFromEntity(): void; - onEnabled(): void; - onDisabled(): void; - onEntityTransformChanged(comp: TransformComponent): void; - update(): void; +declare module es { + class EntitySystem { + private _scene; + private _entities; + private _matcher; + readonly matcher: Matcher; + scene: Scene; + constructor(matcher?: Matcher); + initialize(): void; + onChanged(entity: Entity): void; + add(entity: Entity): void; + onAdded(entity: Entity): void; + remove(entity: Entity): void; + onRemoved(entity: Entity): void; + update(): void; + lateUpdate(): void; + protected begin(): void; + protected process(entities: Entity[]): void; + protected lateProcess(entities: Entity[]): void; + protected end(): void; + } } -declare class BoxCollider extends Collider { - width: number; - setWidth(width: number): BoxCollider; - height: number; - setHeight(height: number): void; - constructor(); - setSize(width: number, height: number): this; +declare module es { + abstract class EntityProcessingSystem extends EntitySystem { + constructor(matcher: Matcher); + abstract processEntity(entity: Entity): any; + lateProcessEntity(entity: Entity): void; + protected process(entities: Entity[]): void; + protected lateProcess(entities: Entity[]): void; + } } -declare class CircleCollider extends Collider { - radius: number; - constructor(radius?: number); - setRadius(radius: number): CircleCollider; +declare module es { + abstract class PassiveSystem extends EntitySystem { + onChanged(entity: Entity): void; + protected process(entities: Entity[]): void; + } } -declare class PolygonCollider extends Collider { - constructor(points: Vector2[]); +declare module es { + abstract class ProcessingSystem extends EntitySystem { + onChanged(entity: Entity): void; + protected process(entities: Entity[]): void; + abstract processSystem(): any; + } } -declare class EntitySystem { - private _scene; - private _entities; - private _matcher; - readonly matcher: Matcher; - scene: Scene; - constructor(matcher?: Matcher); - initialize(): void; - onChanged(entity: Entity): void; - add(entity: Entity): void; - onAdded(entity: Entity): void; - remove(entity: Entity): void; - onRemoved(entity: Entity): void; - update(): void; - lateUpdate(): void; - protected begin(): void; - protected process(entities: Entity[]): void; - protected lateProcess(entities: Entity[]): void; - protected end(): void; +declare module es { + class BitSet { + private static LONG_MASK; + private _bits; + constructor(nbits?: number); + and(bs: BitSet): void; + andNot(bs: BitSet): void; + cardinality(): number; + clear(pos?: number): void; + private ensure; + get(pos: number): boolean; + intersects(set: BitSet): boolean; + isEmpty(): boolean; + nextSetBit(from: number): number; + set(pos: number, value?: boolean): void; + } } -declare abstract class EntityProcessingSystem extends EntitySystem { - constructor(matcher: Matcher); - abstract processEntity(entity: Entity): any; - lateProcessEntity(entity: Entity): void; - protected process(entities: Entity[]): void; - protected lateProcess(entities: Entity[]): void; +declare module es { + class ComponentList { + static compareUpdatableOrder: IUpdatableComparer; + _entity: Entity; + _components: Component[]; + _componentsToAdd: Component[]; + _componentsToRemove: Component[]; + _tempBufferList: Component[]; + _isComponentListUnsorted: boolean; + constructor(entity: Entity); + readonly count: number; + readonly buffer: Component[]; + markEntityListUnsorted(): void; + add(component: Component): void; + remove(component: Component): void; + removeAllComponents(): void; + deregisterAllComponents(): void; + registerAllComponents(): void; + updateLists(): void; + handleRemove(component: Component): void; + getComponent(type: any, onlyReturnInitializedComponents: boolean): T; + getComponents(typeName: string | any, components?: any): any; + update(): void; + onEntityTransformChanged(comp: transform.Component): void; + onEntityEnabled(): void; + onEntityDisabled(): void; + } } -declare abstract class PassiveSystem extends EntitySystem { - onChanged(entity: Entity): void; - protected process(entities: Entity[]): void; +declare module es { + class ComponentTypeManager { + private static _componentTypesMask; + static add(type: any): void; + static getIndexFor(type: any): number; + } } -declare abstract class ProcessingSystem extends EntitySystem { - onChanged(entity: Entity): void; - protected process(entities: Entity[]): void; - abstract processSystem(): any; +declare module es { + class EntityList { + scene: Scene; + private _entitiesToRemove; + private _entitiesToAdded; + private _tempEntityList; + private _entities; + private _entityDict; + private _unsortedTags; + constructor(scene: Scene); + readonly count: number; + readonly buffer: Entity[]; + add(entity: Entity): void; + remove(entity: Entity): void; + findEntity(name: string): Entity; + entitiesWithTag(tag: number): Entity[]; + entitiesOfType(type: any): T[]; + findComponentOfType(type: any): T; + findComponentsOfType(type: any): T[]; + getTagList(tag: number): Entity[]; + addToTagList(entity: Entity): void; + removeFromTagList(entity: Entity): void; + update(): void; + removeAllEntities(): void; + updateLists(): void; + } } -declare class BitSet { - private static LONG_MASK; - private _bits; - constructor(nbits?: number); - and(bs: BitSet): void; - andNot(bs: BitSet): void; - cardinality(): number; - clear(pos?: number): void; - private ensure; - get(pos: number): boolean; - intersects(set: BitSet): boolean; - isEmpty(): boolean; - nextSetBit(from: number): number; - set(pos: number, value?: boolean): void; +declare module es { + class EntityProcessorList { + private _processors; + add(processor: EntitySystem): void; + remove(processor: EntitySystem): void; + onComponentAdded(entity: Entity): void; + onComponentRemoved(entity: Entity): void; + onEntityAdded(entity: Entity): void; + onEntityRemoved(entity: Entity): void; + protected notifyEntityChanged(entity: Entity): void; + protected removeFromProcessors(entity: Entity): void; + begin(): void; + update(): void; + lateUpdate(): void; + end(): void; + getProcessor(): T; + } } -declare class ComponentList { - private _entity; - private _components; - private _componentsToAdd; - private _componentsToRemove; - private _tempBufferList; - constructor(entity: Entity); - readonly count: number; - readonly buffer: Component[]; - add(component: Component): void; - remove(component: Component): void; - removeAllComponents(): void; - deregisterAllComponents(): void; - registerAllComponents(): void; - updateLists(): void; - onEntityTransformChanged(comp: TransformComponent): void; - private handleRemove; - getComponent(type: any, onlyReturnInitializedComponents: boolean): T; - getComponents(typeName: string | any, components?: any): any; - update(): void; -} -declare class ComponentTypeManager { - private static _componentTypesMask; - static add(type: any): void; - static getIndexFor(type: any): number; -} -declare class EntityList { - scene: Scene; - private _entitiesToRemove; - private _entitiesToAdded; - private _tempEntityList; - private _entities; - private _entityDict; - private _unsortedTags; - constructor(scene: Scene); - readonly count: number; - readonly buffer: Entity[]; - add(entity: Entity): void; - remove(entity: Entity): void; - findEntity(name: string): Entity; - getTagList(tag: number): Entity[]; - addToTagList(entity: Entity): void; - removeFromTagList(entity: Entity): void; - update(): void; - removeAllEntities(): void; - updateLists(): void; -} -declare class EntityProcessorList { - private _processors; - add(processor: EntitySystem): void; - remove(processor: EntitySystem): void; - onComponentAdded(entity: Entity): void; - onComponentRemoved(entity: Entity): void; - onEntityAdded(entity: Entity): void; - onEntityRemoved(entity: Entity): void; - protected notifyEntityChanged(entity: Entity): void; - protected removeFromProcessors(entity: Entity): void; - begin(): void; - update(): void; - lateUpdate(): void; - end(): void; - getProcessor(): T; -} -declare class Matcher { - protected allSet: BitSet; - protected exclusionSet: BitSet; - protected oneSet: BitSet; - static empty(): Matcher; - getAllSet(): BitSet; - getExclusionSet(): BitSet; - getOneSet(): BitSet; - IsIntersted(e: Entity): boolean; - all(...types: any[]): Matcher; - exclude(...types: any[]): this; - one(...types: any[]): this; +declare module es { + class Matcher { + protected allSet: BitSet; + protected exclusionSet: BitSet; + protected oneSet: BitSet; + static empty(): Matcher; + getAllSet(): BitSet; + getExclusionSet(): BitSet; + getOneSet(): BitSet; + IsIntersted(e: Entity): boolean; + all(...types: any[]): Matcher; + exclude(...types: any[]): this; + one(...types: any[]): this; + } } declare class ObjectUtils { static clone(p: any, c?: T): T; } -declare class RenderableComponentList { - private _components; - readonly count: number; - readonly buffer: IRenderable[]; - add(component: IRenderable): void; - remove(component: IRenderable): void; - updateList(): void; +declare module es { + interface IRenderable { + bounds: Rectangle; + enabled: boolean; + renderLayer: number; + isVisible: boolean; + isVisibleFromCamera(camera: Camera): any; + render(camera: Camera): any; + } + class RenderableComparer { + compare(self: IRenderable, other: IRenderable): number; + } +} +declare module es { + class RenderableComponentList { + static compareUpdatableOrder: RenderableComparer; + _components: IRenderable[]; + _componentsByRenderLayer: Map; + _unsortedRenderLayers: number[]; + _componentsNeedSort: boolean; + readonly count: number; + readonly buffer: IRenderable[]; + add(component: IRenderable): void; + remove(component: IRenderable): void; + updateRenderableRenderLayer(component: IRenderable, oldRenderLayer: number, newRenderLayer: number): void; + setRenderLayerNeedsComponentSort(renderLayer: number): void; + setNeedsComponentSort(): void; + addToRenderLayerList(component: IRenderable, renderLayer: number): void; + componentsWithRenderLayer(renderLayer: number): IRenderable[]; + updateList(): void; + } } declare class StringUtils { static matchChineseWord(str: string): string[]; @@ -674,25 +868,29 @@ declare class StringUtils { static cutOff(str: string, start: number, len: number, order?: boolean): string; static strReplace(str: string, rStr: string[]): string; } -declare class TextureUtils { - static sharedCanvas: HTMLCanvasElement; - static sharedContext: CanvasRenderingContext2D; - static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement; - static toDataURL(type: string, texture: egret.Texture, rect?: egret.Rectangle, encoderOptions?: any): string; - static eliFoTevas(type: string, texture: egret.Texture, filePath: string, rect?: egret.Rectangle, encoderOptions?: any): void; - static getPixel32(texture: egret.Texture, x: number, y: number): number[]; - static getPixels(texture: egret.Texture, x: number, y: number, width?: number, height?: number): number[]; +declare module es { + class TextureUtils { + static sharedCanvas: HTMLCanvasElement; + static sharedContext: CanvasRenderingContext2D; + static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement; + static toDataURL(type: string, texture: egret.Texture, rect?: egret.Rectangle, encoderOptions?: any): string; + static eliFoTevas(type: string, texture: egret.Texture, filePath: string, rect?: egret.Rectangle, encoderOptions?: any): void; + static getPixel32(texture: egret.Texture, x: number, y: number): number[]; + static getPixels(texture: egret.Texture, x: number, y: number, width?: number, height?: number): number[]; + } } -declare class Time { - static unscaledDeltaTime: any; - static deltaTime: number; - static timeScale: number; - static frameCount: number; - private static _lastTime; - static _timeSinceSceneLoad: any; - static update(currentTime: number): void; - static sceneChanged(): void; - static checkEvery(interval: number): boolean; +declare module es { + class Time { + static unscaledDeltaTime: any; + static deltaTime: number; + static timeScale: number; + static frameCount: number; + private static _lastTime; + static _timeSinceSceneLoad: any; + static update(currentTime: number): void; + static sceneChanged(): void; + static checkEvery(interval: number): boolean; + } } declare class TimeUtils { static monthId(d?: Date): number; @@ -708,362 +906,417 @@ declare class TimeUtils { static secondToTime(time?: number, partition?: string, showHour?: boolean): string; static timeToMillisecond(time: string, partition?: string): string; } -declare class GraphicsCapabilities extends egret.Capabilities { - initialize(device: GraphicsDevice): void; - private platformInitialize; +declare module es { + class GraphicsCapabilities extends egret.Capabilities { + initialize(device: GraphicsDevice): void; + private platformInitialize; + } } -declare class GraphicsDevice { - private viewport; - graphicsCapabilities: GraphicsCapabilities; - constructor(); +declare module es { + class GraphicsDevice { + private viewport; + graphicsCapabilities: GraphicsCapabilities; + constructor(); + } } -declare class Viewport { - private _x; - private _y; - private _width; - private _height; - private _minDepth; - private _maxDepth; - readonly aspectRatio: number; - bounds: Rectangle; - constructor(x: number, y: number, width: number, height: number); -} -declare class GaussianBlurEffect extends egret.CustomFilter { - private static blur_frag; - constructor(); -} -declare class PolygonLightEffect extends egret.CustomFilter { - private static vertSrc; - private static fragmentSrc; - constructor(); -} -declare class PostProcessor { - enable: boolean; - effect: egret.Filter; - scene: Scene; - shape: egret.Shape; - static default_vert: string; - constructor(effect?: egret.Filter); - onAddedToScene(scene: Scene): void; - process(): void; - onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; - protected drawFullscreenQuad(): void; - unload(): void; -} -declare class GaussianBlurPostProcessor extends PostProcessor { - onAddedToScene(scene: Scene): void; -} -declare abstract class Renderer { - camera: Camera; - onAddedToScene(scene: Scene): void; - protected beginRender(cam: Camera): void; - abstract render(scene: Scene): any; - unload(): void; - protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void; -} -declare class DefaultRenderer extends Renderer { - render(scene: Scene): void; -} -interface IRenderable { - bounds: Rectangle; - enabled: boolean; - isVisible: boolean; - isVisibleFromCamera(camera: Camera): any; - render(camera: Camera): any; -} -declare class ScreenSpaceRenderer extends Renderer { - render(scene: Scene): void; -} -declare class PolyLight extends RenderableComponent { - power: number; - protected _radius: number; - private _lightEffect; - private _indices; - radius: number; - constructor(radius: number, color: number, power: number); - private computeTriangleIndices; - setRadius(radius: number): void; - render(camera: Camera): void; - reset(): void; -} -declare abstract class SceneTransition { - private _hasPreviousSceneRender; - loadsNewScene: boolean; - isNewSceneLoaded: boolean; - protected sceneLoadAction: Function; - onScreenObscured: Function; - onTransitionCompleted: Function; - readonly hasPreviousSceneRender: boolean; - constructor(sceneLoadAction: Function); - preRender(): void; - render(): void; - onBeginTransition(): Promise; - protected transitionComplete(): void; - protected loadNextScene(): Promise; - tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise; -} -declare class FadeTransition extends SceneTransition { - fadeToColor: number; - fadeOutDuration: number; - fadeEaseType: Function; - delayBeforeFadeInDuration: number; - private _mask; - private _alpha; - constructor(sceneLoadAction: Function); - onBeginTransition(): Promise; - render(): void; -} -declare class WindTransition extends SceneTransition { - private _mask; - private _windEffect; - duration: number; - windSegments: number; - size: number; - easeType: (t: number) => number; - constructor(sceneLoadAction: Function); - onBeginTransition(): Promise; -} -declare class Bezier { - static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; - static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; - static getFirstDerivativeThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; - static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; - static getOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, end: Vector2, distanceTolerance?: number): Vector2[]; - private static recursiveGetOptimizedDrawingPoints; -} -declare class Flags { - static isFlagSet(self: number, flag: number): boolean; - static isUnshiftedFlagSet(self: number, flag: number): boolean; - static setFlagExclusive(self: number, flag: number): number; - static setFlag(self: number, flag: number): number; - static unsetFlag(self: number, flag: number): number; - static invertFlags(self: number): number; -} -declare class MathHelper { - static readonly Epsilon: number; - static readonly Rad2Deg: number; - static readonly Deg2Rad: number; - static toDegrees(radians: number): number; - static toRadians(degrees: number): number; - static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number; - static lerp(value1: number, value2: number, amount: number): number; - static clamp(value: number, min: number, max: number): number; - static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2; - static isEven(value: number): boolean; - static clamp01(value: number): number; - static angleBetweenVectors(from: Vector2, to: Vector2): number; -} -declare class Matrix2D { - m11: number; - m12: number; - m21: number; - m22: number; - m31: number; - m32: number; - private static _identity; - static readonly identity: Matrix2D; - constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number); - translation: Vector2; - rotation: number; - rotationDegrees: number; - scale: Vector2; - static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static divide(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D; - determinant(): number; - static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D; - static createTranslation(xPosition: number, yPosition: number): Matrix2D; - static createTranslationVector(position: Vector2): Matrix2D; - static createRotation(radians: number, result?: Matrix2D): Matrix2D; - static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; - toEgretMatrix(): egret.Matrix; -} -declare class Rectangle extends egret.Rectangle { - readonly max: Vector2; - readonly center: Vector2; - location: Vector2; - size: Vector2; - intersects(value: egret.Rectangle): boolean; - containsRect(value: Rectangle): boolean; - getHalfSize(): Vector2; - static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; - getClosestPointOnRectangleBorderToPoint(point: Vector2): { - res: Vector2; - edgeNormal: Vector2; - }; - getClosestPointOnBoundsToOrigin(): Vector2; - setEgretRect(rect: egret.Rectangle): Rectangle; - static rectEncompassingPoints(points: Vector2[]): Rectangle; -} -declare class Vector3 { - x: number; - y: number; - z: number; - constructor(x: number, y: number, z: number); -} -declare class ColliderTriggerHelper { - private _entity; - private _activeTriggerIntersections; - private _previousTriggerIntersections; - private _tempTriggerList; - constructor(entity: Entity); - update(): void; - private checkForExitedColliders; - private notifyTriggerListeners; -} -declare enum PointSectors { - center = 0, - top = 1, - bottom = 2, - topLeft = 9, - topRight = 5, - left = 8, - right = 4, - bottomLeft = 10, - bottomRight = 6 -} -declare class Collisions { - static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean; - static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2; - static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; - static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean; - static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean; - static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean; - static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean; - static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean; - static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean; - static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors; -} -declare class Physics { - private static _spatialHash; - static spatialHashCellSize: number; - static readonly allLayers: number; - static reset(): void; - static clear(): void; - static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; - static boxcastBroadphase(rect: Rectangle, layerMask?: number): { - colliders: Collider[]; - rect: Rectangle; - }; - static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): { - tempHashSet: Collider[]; +declare module es { + class Viewport { + private _x; + private _y; + private _width; + private _height; + private _minDepth; + private _maxDepth; + readonly aspectRatio: number; bounds: Rectangle; - }; - static addCollider(collider: Collider): void; - static removeCollider(collider: Collider): void; - static updateCollider(collider: Collider): void; - static debugDraw(secondsToDisplay: any): void; + constructor(x: number, y: number, width: number, height: number); + } } -declare abstract class Shape extends egret.DisplayObject { - abstract bounds: Rectangle; - abstract center: Vector2; - abstract position: Vector2; - abstract pointCollidesWithShape(point: Vector2): CollisionResult; - abstract overlaps(other: Shape): any; - abstract collidesWithShape(other: Shape): CollisionResult; +declare module es { + class GaussianBlurEffect extends egret.CustomFilter { + private static blur_frag; + constructor(); + } } -declare class Polygon extends Shape { - points: Vector2[]; - private _polygonCenter; - private _areEdgeNormalsDirty; - protected _originalPoints: Vector2[]; - center: Vector2; - readonly position: Vector2; - readonly bounds: Rectangle; - _edgeNormals: Vector2[]; - readonly edgeNormals: Vector2[]; - isBox: boolean; - constructor(points: Vector2[], isBox?: boolean); - private buildEdgeNormals; - setPoints(points: Vector2[]): void; - collidesWithShape(other: Shape): any; - recalculateCenterAndEdgeNormals(): void; - overlaps(other: Shape): any; - static findPolygonCenter(points: Vector2[]): Vector2; - static recenterPolygonVerts(points: Vector2[]): void; - static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { - closestPoint: any; - distanceSquared: any; - edgeNormal: any; - }; - pointCollidesWithShape(point: Vector2): CollisionResult; - containsPoint(point: Vector2): boolean; - static buildSymmertricalPolygon(vertCount: number, radius: number): any[]; +declare module es { + class PolygonLightEffect extends egret.CustomFilter { + private static vertSrc; + private static fragmentSrc; + constructor(); + } } -declare class Box extends Polygon { - constructor(width: number, height: number); - private static buildBox; - overlaps(other: Shape): any; - collidesWithShape(other: Shape): any; - updateBox(width: number, height: number): void; - containsPoint(point: Vector2): boolean; +declare module es { + class PostProcessor { + enabled: boolean; + effect: egret.Filter; + scene: Scene; + shape: egret.Shape; + static default_vert: string; + constructor(effect?: egret.Filter); + onAddedToScene(scene: Scene): void; + process(): void; + onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; + protected drawFullscreenQuad(): void; + unload(): void; + } } -declare class Circle extends Shape { - radius: number; - _originalRadius: number; - center: Vector2; - readonly position: Vector2; - readonly bounds: Rectangle; - constructor(radius: number); - pointCollidesWithShape(point: Vector2): CollisionResult; - collidesWithShape(other: Shape): CollisionResult; - overlaps(other: Shape): any; +declare module es { + class GaussianBlurPostProcessor extends PostProcessor { + onAddedToScene(scene: Scene): void; + } } -declare class CollisionResult { - collider: Collider; - minimumTranslationVector: Vector2; - normal: Vector2; - point: Vector2; - invertResult(): void; +declare module es { + abstract class Renderer { + camera: Camera; + onAddedToScene(scene: Scene): void; + protected beginRender(cam: Camera): void; + abstract render(scene: Scene): any; + unload(): void; + protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void; + } } -declare class ShapeCollisions { - static polygonToPolygon(first: Polygon, second: Polygon): CollisionResult; - static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number; - static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): { - min: number; - max: number; - }; - static circleToPolygon(circle: Circle, polygon: Polygon): CollisionResult; - static circleToBox(circle: Circle, box: Box): CollisionResult; - static pointToCircle(point: Vector2, circle: Circle): CollisionResult; - static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; - static pointToPoly(point: Vector2, poly: Polygon): CollisionResult; - static circleToCircle(first: Circle, second: Circle): CollisionResult; - static boxToBox(first: Box, second: Box): CollisionResult; - private static minkowskiDifference; +declare module es { + class DefaultRenderer extends Renderer { + render(scene: Scene): void; + } } -declare class SpatialHash { - gridBounds: Rectangle; - private _raycastParser; - private _cellSize; - private _inverseCellSize; - private _overlapTestCircle; - private _tempHashSet; - private _cellDict; - constructor(cellSize?: number); - remove(collider: Collider): void; - register(collider: Collider): void; - clear(): void; - overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; - aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): { - tempHashSet: Collider[]; +declare module es { + class ScreenSpaceRenderer extends Renderer { + render(scene: Scene): void; + } +} +declare module es { + class PolyLight extends RenderableComponent { + power: number; + protected _radius: number; + private _lightEffect; + private _indices; + radius: number; + constructor(radius: number, color: number, power: number); + private computeTriangleIndices; + setRadius(radius: number): void; + render(camera: Camera): void; + reset(): void; + } +} +declare module es { + abstract class SceneTransition { + private _hasPreviousSceneRender; + loadsNewScene: boolean; + isNewSceneLoaded: boolean; + protected sceneLoadAction: Function; + onScreenObscured: Function; + onTransitionCompleted: Function; + readonly hasPreviousSceneRender: boolean; + constructor(sceneLoadAction: Function); + preRender(): void; + render(): void; + onBeginTransition(): Promise; + protected transitionComplete(): void; + protected loadNextScene(): Promise; + tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection?: boolean): Promise; + } +} +declare module es { + class FadeTransition extends SceneTransition { + fadeToColor: number; + fadeOutDuration: number; + fadeEaseType: Function; + delayBeforeFadeInDuration: number; + private _mask; + private _alpha; + constructor(sceneLoadAction: Function); + onBeginTransition(): Promise; + render(): void; + } +} +declare module es { + class WindTransition extends SceneTransition { + private _mask; + private _windEffect; + duration: number; + windSegments: number; + size: number; + easeType: (t: number) => number; + constructor(sceneLoadAction: Function); + onBeginTransition(): Promise; + } +} +declare module es { + class Bezier { + static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; + static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2; + static getFirstDerivativeThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; + static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2; + static getOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, end: Vector2, distanceTolerance?: number): Vector2[]; + private static recursiveGetOptimizedDrawingPoints; + } +} +declare module es { + class Flags { + static isFlagSet(self: number, flag: number): boolean; + static isUnshiftedFlagSet(self: number, flag: number): boolean; + static setFlagExclusive(self: number, flag: number): number; + static setFlag(self: number, flag: number): number; + static unsetFlag(self: number, flag: number): number; + static invertFlags(self: number): number; + } +} +declare module es { + class MathHelper { + static readonly Epsilon: number; + static readonly Rad2Deg: number; + static readonly Deg2Rad: number; + static toDegrees(radians: number): number; + static toRadians(degrees: number): number; + static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number; + static lerp(value1: number, value2: number, amount: number): number; + static clamp(value: number, min: number, max: number): number; + static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2; + static isEven(value: number): boolean; + static clamp01(value: number): number; + static angleBetweenVectors(from: Vector2, to: Vector2): number; + } +} +declare module es { + class Matrix2D { + m11: number; + m12: number; + m21: number; + m22: number; + m31: number; + m32: number; + private static _identity; + static readonly identity: Matrix2D; + constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number); + translation: Vector2; + rotation: number; + rotationDegrees: number; + scale: Vector2; + static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; + static divide(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; + static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; + static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D; + determinant(): number; + static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D; + static createTranslation(xPosition: number, yPosition: number): Matrix2D; + static createTranslationVector(position: Vector2): Matrix2D; + static createRotation(radians: number, result?: Matrix2D): Matrix2D; + static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; + toEgretMatrix(): egret.Matrix; + } +} +declare module es { + class Rectangle extends egret.Rectangle { + readonly max: Vector2; + readonly center: Vector2; + location: Vector2; + size: Vector2; + intersects(value: egret.Rectangle): boolean; + containsRect(value: Rectangle): boolean; + getHalfSize(): Vector2; + static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; + getClosestPointOnRectangleBorderToPoint(point: Vector2): { + res: Vector2; + edgeNormal: Vector2; + }; + getClosestPointOnBoundsToOrigin(): Vector2; + calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void; + setEgretRect(rect: egret.Rectangle): Rectangle; + static rectEncompassingPoints(points: Vector2[]): Rectangle; + } +} +declare module es { + class Vector3 { + x: number; + y: number; + z: number; + constructor(x: number, y: number, z: number); + } +} +declare module es { + class ColliderTriggerHelper { + private _entity; + private _activeTriggerIntersections; + private _previousTriggerIntersections; + private _tempTriggerList; + constructor(entity: Entity); + update(): void; + private checkForExitedColliders; + private notifyTriggerListeners; + } +} +declare module es { + enum PointSectors { + center = 0, + top = 1, + bottom = 2, + topLeft = 9, + topRight = 5, + left = 8, + right = 4, + bottomLeft = 10, + bottomRight = 6 + } + class Collisions { + static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean; + static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2; + static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; + static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean; + static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean; + static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean; + static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean; + static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean; + static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean; + static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors; + } +} +declare module es { + class Physics { + private static _spatialHash; + static spatialHashCellSize: number; + static readonly allLayers: number; + static reset(): void; + static clear(): void; + static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; + static boxcastBroadphase(rect: Rectangle, layerMask?: number): { + colliders: Collider[]; + rect: Rectangle; + }; + static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): { + tempHashSet: Collider[]; + bounds: Rectangle; + }; + static addCollider(collider: Collider): void; + static removeCollider(collider: Collider): void; + static updateCollider(collider: Collider): void; + static debugDraw(secondsToDisplay: any): void; + } +} +declare module es { + abstract class Shape { + position: Vector2; + center: Vector2; bounds: Rectangle; - }; - private cellAtPosition; - private cellCoords; - debugDraw(secondsToDisplay: number, textScale?: number): void; - private debugDrawCellDetails; + abstract recalculateBounds(collider: Collider): any; + abstract pointCollidesWithShape(point: Vector2): CollisionResult; + abstract overlaps(other: Shape): any; + abstract collidesWithShape(other: Shape): CollisionResult; + } } -declare class RaycastResultParser { +declare module es { + class Polygon extends Shape { + points: Vector2[]; + readonly edgeNormals: Vector2[]; + _areEdgeNormalsDirty: boolean; + _edgeNormals: Vector2[]; + _originalPoints: Vector2[]; + _polygonCenter: Vector2; + isBox: boolean; + isUnrotated: boolean; + constructor(points: Vector2[], isBox?: boolean); + setPoints(points: Vector2[]): void; + recalculateCenterAndEdgeNormals(): void; + buildEdgeNormals(): void; + static buildSymmetricalPolygon(vertCount: number, radius: number): any[]; + static recenterPolygonVerts(points: Vector2[]): void; + static findPolygonCenter(points: Vector2[]): Vector2; + static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { + closestPoint: any; + distanceSquared: any; + edgeNormal: any; + }; + recalculateBounds(collider: Collider): void; + overlaps(other: Shape): any; + collidesWithShape(other: Shape): any; + containsPoint(point: Vector2): boolean; + pointCollidesWithShape(point: Vector2): CollisionResult; + } } -declare class NumberDictionary { - private _store; - private getKey; - add(x: number, y: number, list: Collider[]): void; - remove(obj: Collider): void; - tryGetValue(x: number, y: number): Collider[]; - clear(): void; +declare module es { + class Box extends Polygon { + width: number; + height: number; + constructor(width: number, height: number); + private static buildBox; + updateBox(width: number, height: number): void; + overlaps(other: Shape): any; + collidesWithShape(other: Shape): any; + containsPoint(point: Vector2): boolean; + } +} +declare module es { + class Circle extends Shape { + radius: number; + _originalRadius: number; + constructor(radius: number); + recalculateBounds(collider: es.Collider): void; + overlaps(other: Shape): any; + collidesWithShape(other: Shape): CollisionResult; + pointCollidesWithShape(point: Vector2): CollisionResult; + } +} +declare module es { + class CollisionResult { + collider: Collider; + minimumTranslationVector: Vector2; + normal: Vector2; + point: Vector2; + invertResult(): void; + } +} +declare module es { + class ShapeCollisions { + static polygonToPolygon(first: Polygon, second: Polygon): CollisionResult; + static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number; + static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): { + min: number; + max: number; + }; + static circleToPolygon(circle: Circle, polygon: Polygon): CollisionResult; + static circleToBox(circle: Circle, box: Box): CollisionResult; + static pointToCircle(point: Vector2, circle: Circle): CollisionResult; + static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; + static pointToPoly(point: Vector2, poly: Polygon): CollisionResult; + static circleToCircle(first: Circle, second: Circle): CollisionResult; + static boxToBox(first: Box, second: Box): CollisionResult; + private static minkowskiDifference; + } +} +declare module es { + class SpatialHash { + gridBounds: Rectangle; + _raycastParser: RaycastResultParser; + _cellSize: number; + _inverseCellSize: number; + _overlapTestCircle: Circle; + _cellDict: NumberDictionary; + _tempHashSet: Collider[]; + constructor(cellSize?: number); + private cellCoords; + private cellAtPosition; + register(collider: Collider): void; + remove(collider: Collider): void; + removeWithBruteForce(obj: Collider): void; + clear(): void; + debugDraw(secondsToDisplay: number, textScale?: number): void; + private debugDrawCellDetails; + aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): { + tempHashSet: Collider[]; + bounds: Rectangle; + }; + overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; + } + class NumberDictionary { + _store: Map; + private getKey; + add(x: number, y: number, list: Collider[]): void; + remove(obj: Collider): void; + tryGetValue(x: number, y: number): Collider[]; + clear(): void; + } + class RaycastResultParser { + } } declare class ArrayUtils { static bubbleSort(ary: number[]): void; @@ -1090,72 +1343,83 @@ declare class Base64Utils { private static _utf8_decode; private static getConfKey; } -declare class ContentManager { - protected loadedAssets: Map; - loadRes(name: string, local?: boolean): Promise; - dispose(): void; +declare module es { + class ContentManager { + protected loadedAssets: Map; + loadRes(name: string, local?: boolean): Promise; + dispose(): void; + } } -declare class DrawUtils { - static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void; - static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void; - static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void; - static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void; - static drawPixel(shape: egret.Shape, position: Vector2, color: number, size?: number): void; +declare module es { + class DrawUtils { + static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness?: number): void; + static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness?: number): void; + static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness?: number): void; + static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness?: number): void; + static drawPixel(shape: egret.Shape, position: Vector2, color: number, size?: number): void; + static getColorMatrix(color: number): egret.ColorMatrixFilter; + } } -declare class Emitter { - private _messageTable; - constructor(); - addObserver(eventType: T, handler: Function, context: any): void; - removeObserver(eventType: T, handler: Function): void; - emit(eventType: T, data?: any): void; +declare module es { + class FuncPack { + func: Function; + context: any; + constructor(func: Function, context: any); + } + class Emitter { + private _messageTable; + constructor(); + addObserver(eventType: T, handler: Function, context: any): void; + removeObserver(eventType: T, handler: Function): void; + emit(eventType: T, data?: any): void; + } } -declare class FuncPack { - func: Function; - context: any; - constructor(func: Function, context: any); +declare module es { + class GlobalManager { + static globalManagers: GlobalManager[]; + private _enabled; + enabled: boolean; + setEnabled(isEnabled: boolean): void; + onEnabled(): void; + onDisabled(): void; + update(): void; + static registerGlobalManager(manager: GlobalManager): void; + static unregisterGlobalManager(manager: GlobalManager): void; + static getGlobalManager(type: any): T; + } } -declare class GlobalManager { - static globalManagers: GlobalManager[]; - private _enabled; - enabled: boolean; - setEnabled(isEnabled: boolean): void; - onEnabled(): void; - onDisabled(): void; - update(): void; - static registerGlobalManager(manager: GlobalManager): void; - static unregisterGlobalManager(manager: GlobalManager): void; - static getGlobalManager(type: any): T; -} -declare class TouchState { - x: number; - y: number; - touchPoint: number; - touchDown: boolean; - readonly position: Vector2; - reset(): void; -} -declare class Input { - private static _init; - private static _stage; - private static _previousTouchState; - private static _gameTouchs; - private static _resolutionOffset; - private static _resolutionScale; - private static _touchIndex; - private static _totalTouchCount; - static readonly touchPosition: Vector2; - static maxSupportedTouch: number; - static readonly resolutionScale: Vector2; - static readonly totalTouchCount: number; - static readonly gameTouchs: TouchState[]; - static readonly touchPositionDelta: Vector2; - static initialize(stage: egret.Stage): void; - private static initTouchCache; - private static touchBegin; - private static touchMove; - private static touchEnd; - private static setpreviousTouchState; - static scaledPosition(position: Vector2): Vector2; +declare module es { + class TouchState { + x: number; + y: number; + touchPoint: number; + touchDown: boolean; + readonly position: Vector2; + reset(): void; + } + class Input { + private static _init; + private static _stage; + private static _previousTouchState; + private static _gameTouchs; + private static _resolutionOffset; + private static _resolutionScale; + private static _touchIndex; + private static _totalTouchCount; + static readonly touchPosition: Vector2; + static maxSupportedTouch: number; + static readonly resolutionScale: Vector2; + static readonly totalTouchCount: number; + static readonly gameTouchs: TouchState[]; + static readonly touchPositionDelta: Vector2; + static initialize(stage: egret.Stage): void; + private static initTouchCache; + private static touchBegin; + private static touchMove; + private static touchEnd; + private static setpreviousTouchState; + static scaledPosition(position: Vector2): Vector2; + } } declare class KeyboardUtils { static TYPE_KEY_DOWN: number; @@ -1241,13 +1505,15 @@ declare class KeyboardUtils { private static keyCodeToString; static destroy(): void; } -declare class ListPool { - private static readonly _objectQueue; - static warmCache(cacheCount: number): void; - static trimCache(cacheCount: any): void; - static clearCache(): void; - static obtain(): Array; - static free(obj: Array): void; +declare module es { + class ListPool { + private static readonly _objectQueue; + static warmCache(cacheCount: number): void; + static trimCache(cacheCount: any): void; + static clearCache(): void; + static obtain(): T[]; + static free(obj: Array): void; + } } declare const THREAD_ID: string; declare const setItem: any; @@ -1260,12 +1526,14 @@ declare class LockUtils { constructor(key: any); lock(): Promise<{}>; } -declare class Pair { - first: T; - second: T; - constructor(first: T, second: T); - clear(): void; - equals(other: Pair): boolean; +declare module es { + class Pair { + first: T; + second: T; + constructor(first: T, second: T); + clear(): void; + equals(other: Pair): boolean; + } } declare class RandomUtils { static randrange(start: number, stop: number, step?: number): number; @@ -1278,53 +1546,61 @@ declare class RandomUtils { static random(): number; static boolean(chance?: number): boolean; } -declare class RectangleExt { - static union(first: Rectangle, point: Vector2): Rectangle; +declare module es { + class RectangleExt { + static union(first: Rectangle, point: Vector2): Rectangle; + } } -declare class Triangulator { - triangleIndices: number[]; - private _triPrev; - private _triNext; - triangulate(points: Vector2[], arePointsCCW?: boolean): void; - private initialize; - static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean; +declare module es { + class Triangulator { + triangleIndices: number[]; + private _triPrev; + private _triNext; + triangulate(points: Vector2[], arePointsCCW?: boolean): void; + private initialize; + static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean; + } } -declare class Vector2Ext { - static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean; - static cross(u: Vector2, v: Vector2): number; - static perpendicular(first: Vector2, second: Vector2): Vector2; - static normalize(vec: Vector2): Vector2; - static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void; - static transformR(position: Vector2, matrix: Matrix2D): Vector2; - static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void; - static round(vec: Vector2): Vector2; +declare module es { + class Vector2Ext { + static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean; + static cross(u: Vector2, v: Vector2): number; + static perpendicular(first: Vector2, second: Vector2): Vector2; + static normalize(vec: Vector2): Vector2; + static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void; + static transformR(position: Vector2, matrix: Matrix2D): Vector2; + static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void; + static round(vec: Vector2): Vector2; + } } declare class WebGLUtils { static getContext(): CanvasRenderingContext2D; } -declare class Layout { - clientArea: Rectangle; - safeArea: Rectangle; - constructor(); - place(size: Vector2, horizontalMargin: number, verticalMargine: number, alignment: Alignment): Rectangle; -} -declare enum Alignment { - none = 0, - left = 1, - right = 2, - horizontalCenter = 4, - top = 8, - bottom = 16, - verticalCenter = 32, - topLeft = 9, - topRight = 10, - topCenter = 12, - bottomLeft = 17, - bottomRight = 18, - bottomCenter = 20, - centerLeft = 33, - centerRight = 34, - center = 36 +declare module es { + class Layout { + clientArea: Rectangle; + safeArea: Rectangle; + constructor(); + place(size: Vector2, horizontalMargin: number, verticalMargine: number, alignment: Alignment): Rectangle; + } + enum Alignment { + none = 0, + left = 1, + right = 2, + horizontalCenter = 4, + top = 8, + bottom = 16, + verticalCenter = 32, + topLeft = 9, + topRight = 10, + topCenter = 12, + bottomLeft = 17, + bottomRight = 18, + bottomCenter = 20, + centerLeft = 33, + centerRight = 34, + center = 36 + } } declare namespace stopwatch { class Stopwatch { @@ -1365,72 +1641,74 @@ declare namespace stopwatch { readonly duration: number; } } -declare class TimeRuler { - static readonly maxBars: number; - static readonly maxSamples: number; - static readonly maxNestCall: number; - static readonly barHeight: number; - static readonly maxSampleFrames: number; - static readonly logSnapDuration: number; - static readonly barPadding: number; - static readonly autoAdjustDelay: number; - static Instance: TimeRuler; - private _frameKey; - private _logKey; - private _logs; - private sampleFrames; - targetSampleFrames: number; - width: number; - enabled: true; - private _position; - private _prevLog; - private _curLog; - private frameCount; - private markers; - private stopwacth; - private _markerNameToIdMap; - private _updateCount; - showLog: boolean; - private _frameAdjust; - constructor(); - private onGraphicsDeviceReset; - startFrame(): void; - beginMark(markerName: string, color: number, barIndex?: number): void; - endMark(markerName: string, barIndex?: number): void; - getAverageTime(barIndex: number, markerName: string): number; - resetLog(): void; - render(position?: Vector2, width?: number): void; -} -declare class FrameLog { - bars: MarkerCollection[]; - constructor(); -} -declare class MarkerCollection { - markers: Marker[]; - markCount: number; - markerNests: number[]; - nestCount: number; - constructor(); -} -declare class Marker { - markerId: number; - beginTime: number; - endTime: number; - color: number; -} -declare class MarkerInfo { - name: string; - logs: MarkerLog[]; - constructor(name: any); -} -declare class MarkerLog { - snapMin: number; - snapMax: number; - snapAvg: number; - min: number; - max: number; - avg: number; - samples: number; - color: number; - initialized: boolean; +declare module es { + class TimeRuler { + static readonly maxBars: number; + static readonly maxSamples: number; + static readonly maxNestCall: number; + static readonly barHeight: number; + static readonly maxSampleFrames: number; + static readonly logSnapDuration: number; + static readonly barPadding: number; + static readonly autoAdjustDelay: number; + static Instance: TimeRuler; + private _frameKey; + private _logKey; + private _logs; + private sampleFrames; + targetSampleFrames: number; + width: number; + enabled: true; + private _position; + private _prevLog; + private _curLog; + private frameCount; + private markers; + private stopwacth; + private _markerNameToIdMap; + private _updateCount; + showLog: boolean; + private _frameAdjust; + constructor(); + private onGraphicsDeviceReset; + startFrame(): void; + beginMark(markerName: string, color: number, barIndex?: number): void; + endMark(markerName: string, barIndex?: number): void; + getAverageTime(barIndex: number, markerName: string): number; + resetLog(): void; + render(position?: Vector2, width?: number): void; + } + class FrameLog { + bars: MarkerCollection[]; + constructor(); + } + class MarkerCollection { + markers: Marker[]; + markCount: number; + markerNests: number[]; + nestCount: number; + constructor(); + } + class Marker { + markerId: number; + beginTime: number; + endTime: number; + color: number; + } + class MarkerInfo { + name: string; + logs: MarkerLog[]; + constructor(name: any); + } + class MarkerLog { + snapMin: number; + snapMax: number; + snapAvg: number; + min: number; + max: number; + avg: number; + samples: number; + color: number; + initialized: boolean; + } } diff --git a/source/bin/framework.js b/source/bin/framework.js index c729622d..c83321cc 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -273,2772 +273,3282 @@ Array.prototype.sum = function (selector) { } return sum(this, selector); }; -var PriorityQueueNode = (function () { - function PriorityQueueNode() { - this.priority = 0; - this.insertionIndex = 0; - this.queueIndex = 0; - } - return PriorityQueueNode; -}()); -var AStarPathfinder = (function () { - function AStarPathfinder() { - } - AStarPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new AStarNode(start), 0); - costSoFar.set(start, 0); - var _loop_2 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priority = newCost + graph.heuristic(next, goal); - frontier.enqueue(new AStarNode(next), priority); - cameFrom.set(next, current.data); +var es; +(function (es) { + var PriorityQueueNode = (function () { + function PriorityQueueNode() { + this.priority = 0; + this.insertionIndex = 0; + this.queueIndex = 0; + } + return PriorityQueueNode; + }()); + es.PriorityQueueNode = PriorityQueueNode; +})(es || (es = {})); +var es; +(function (es) { + var AStarPathfinder = (function () { + function AStarPathfinder() { + } + AStarPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new es.PriorityQueue(1000); + frontier.enqueue(new AStarNode(start), 0); + costSoFar.set(start, 0); + var _loop_2 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; } - }); + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priority = newCost + graph.heuristic(next, goal); + frontier.enqueue(new AStarNode(next), priority); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_1 = _loop_2(); + if (state_1 === "break") + break; + } + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; }; - while (frontier.count > 0) { - var state_1 = _loop_2(); - if (state_1 === "break") - break; + AStarPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } + return false; + }; + AStarPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + AStarPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return AStarPathfinder; + }()); + es.AStarPathfinder = AStarPathfinder; + var AStarNode = (function (_super) { + __extends(AStarNode, _super); + function AStarNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - AStarPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; + return AStarNode; + }(es.PriorityQueueNode)); + es.AStarNode = AStarNode; +})(es || (es = {})); +var es; +(function (es) { + var AstarGridGraph = (function () { + function AstarGridGraph(width, height) { + this.dirs = [ + new es.Vector2(1, 0), + new es.Vector2(0, -1), + new es.Vector2(-1, 0), + new es.Vector2(0, 1) + ]; + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; } - return false; - }; - AStarPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; + AstarGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + AstarGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + AstarGridGraph.prototype.search = function (start, goal) { + return es.AStarPathfinder.search(this, start, goal); + }; + AstarGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this.dirs.forEach(function (dir) { + var next = new es.Vector2(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + AstarGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + AstarGridGraph.prototype.heuristic = function (node, goal) { + return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); + }; + return AstarGridGraph; + }()); + es.AstarGridGraph = AstarGridGraph; +})(es || (es = {})); +var es; +(function (es) { + var PriorityQueue = (function () { + function PriorityQueue(maxNodes) { + this._numNodes = 0; + this._nodes = new Array(maxNodes + 1); + this._numNodesEverEnqueued = 0; } - return null; - }; - AStarPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return AStarPathfinder; -}()); -var AStarNode = (function (_super) { - __extends(AStarNode, _super); - function AStarNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return AStarNode; -}(PriorityQueueNode)); -var AstarGridGraph = (function () { - function AstarGridGraph(width, height) { - this.dirs = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - } - AstarGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - }; - AstarGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - AstarGridGraph.prototype.search = function (start, goal) { - return AStarPathfinder.search(this, start, goal); - }; - AstarGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this.dirs.forEach(function (dir) { - var next = new Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); + PriorityQueue.prototype.clear = function () { + this._nodes.splice(1, this._numNodes); + this._numNodes = 0; + }; + Object.defineProperty(PriorityQueue.prototype, "count", { + get: function () { + return this._numNodes; + }, + enumerable: true, + configurable: true }); - return this._neighbors; - }; - AstarGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (p) { return JSON.stringify(p) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; - }; - AstarGridGraph.prototype.heuristic = function (node, goal) { - return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); - }; - return AstarGridGraph; -}()); -var PriorityQueue = (function () { - function PriorityQueue(maxNodes) { - this._numNodes = 0; - this._nodes = new Array(maxNodes + 1); - this._numNodesEverEnqueued = 0; - } - PriorityQueue.prototype.clear = function () { - this._nodes.splice(1, this._numNodes); - this._numNodes = 0; - }; - Object.defineProperty(PriorityQueue.prototype, "count", { - get: function () { - return this._numNodes; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(PriorityQueue.prototype, "maxSize", { - get: function () { - return this._nodes.length - 1; - }, - enumerable: true, - configurable: true - }); - PriorityQueue.prototype.contains = function (node) { - if (!node) { - console.error("node cannot be null"); - return false; - } - if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length) { - console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); - return false; - } - return (this._nodes[node.queueIndex] == node); - }; - PriorityQueue.prototype.enqueue = function (node, priority) { - node.priority = priority; - this._numNodes++; - this._nodes[this._numNodes] = node; - node.queueIndex = this._numNodes; - node.insertionIndex = this._numNodesEverEnqueued++; - this.cascadeUp(this._nodes[this._numNodes]); - }; - PriorityQueue.prototype.dequeue = function () { - var returnMe = this._nodes[1]; - this.remove(returnMe); - return returnMe; - }; - PriorityQueue.prototype.remove = function (node) { - if (node.queueIndex == this._numNodes) { - this._nodes[this._numNodes] = null; + Object.defineProperty(PriorityQueue.prototype, "maxSize", { + get: function () { + return this._nodes.length - 1; + }, + enumerable: true, + configurable: true + }); + PriorityQueue.prototype.contains = function (node) { + if (!node) { + console.error("node cannot be null"); + return false; + } + if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length) { + console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); + return false; + } + return (this._nodes[node.queueIndex] == node); + }; + PriorityQueue.prototype.enqueue = function (node, priority) { + node.priority = priority; + this._numNodes++; + this._nodes[this._numNodes] = node; + node.queueIndex = this._numNodes; + node.insertionIndex = this._numNodesEverEnqueued++; + this.cascadeUp(this._nodes[this._numNodes]); + }; + PriorityQueue.prototype.dequeue = function () { + var returnMe = this._nodes[1]; + this.remove(returnMe); + return returnMe; + }; + PriorityQueue.prototype.remove = function (node) { + if (node.queueIndex == this._numNodes) { + this._nodes[this._numNodes] = null; + this._numNodes--; + return; + } + var formerLastNode = this._nodes[this._numNodes]; + this.swap(node, formerLastNode); + delete this._nodes[this._numNodes]; this._numNodes--; - return; - } - var formerLastNode = this._nodes[this._numNodes]; - this.swap(node, formerLastNode); - delete this._nodes[this._numNodes]; - this._numNodes--; - this.onNodeUpdated(formerLastNode); - }; - PriorityQueue.prototype.isValidQueue = function () { - for (var i = 1; i < this._nodes.length; i++) { - if (this._nodes[i]) { - var childLeftIndex = 2 * i; - if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && - this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) - return false; + this.onNodeUpdated(formerLastNode); + }; + PriorityQueue.prototype.isValidQueue = function () { + for (var i = 1; i < this._nodes.length; i++) { + if (this._nodes[i]) { + var childLeftIndex = 2 * i; + if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && + this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) + return false; + var childRightIndex = childLeftIndex + 1; + if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && + this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) + return false; + } + } + return true; + }; + PriorityQueue.prototype.onNodeUpdated = function (node) { + var parentIndex = Math.floor(node.queueIndex / 2); + var parentNode = this._nodes[parentIndex]; + if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { + this.cascadeUp(node); + } + else { + this.cascadeDown(node); + } + }; + PriorityQueue.prototype.cascadeDown = function (node) { + var newParent; + var finalQueueIndex = node.queueIndex; + while (true) { + newParent = node; + var childLeftIndex = 2 * finalQueueIndex; + if (childLeftIndex > this._numNodes) { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } + var childLeft = this._nodes[childLeftIndex]; + if (this.hasHigherPriority(childLeft, newParent)) { + newParent = childLeft; + } var childRightIndex = childLeftIndex + 1; - if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && - this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) - return false; - } - } - return true; - }; - PriorityQueue.prototype.onNodeUpdated = function (node) { - var parentIndex = Math.floor(node.queueIndex / 2); - var parentNode = this._nodes[parentIndex]; - if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { - this.cascadeUp(node); - } - else { - this.cascadeDown(node); - } - }; - PriorityQueue.prototype.cascadeDown = function (node) { - var newParent; - var finalQueueIndex = node.queueIndex; - while (true) { - newParent = node; - var childLeftIndex = 2 * finalQueueIndex; - if (childLeftIndex > this._numNodes) { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - var childLeft = this._nodes[childLeftIndex]; - if (this.hasHigherPriority(childLeft, newParent)) { - newParent = childLeft; - } - var childRightIndex = childLeftIndex + 1; - if (childRightIndex <= this._numNodes) { - var childRight = this._nodes[childRightIndex]; - if (this.hasHigherPriority(childRight, newParent)) { - newParent = childRight; + if (childRightIndex <= this._numNodes) { + var childRight = this._nodes[childRightIndex]; + if (this.hasHigherPriority(childRight, newParent)) { + newParent = childRight; + } + } + if (newParent != node) { + this._nodes[finalQueueIndex] = newParent; + var temp = newParent.queueIndex; + newParent.queueIndex = finalQueueIndex; + finalQueueIndex = temp; + } + else { + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; } } - if (newParent != node) { - this._nodes[finalQueueIndex] = newParent; - var temp = newParent.queueIndex; - newParent.queueIndex = finalQueueIndex; - finalQueueIndex = temp; - } - else { - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - } - }; - PriorityQueue.prototype.cascadeUp = function (node) { - var parent = Math.floor(node.queueIndex / 2); - while (parent >= 1) { - var parentNode = this._nodes[parent]; - if (this.hasHigherPriority(parentNode, node)) - break; - this.swap(node, parentNode); - parent = Math.floor(node.queueIndex / 2); - } - }; - PriorityQueue.prototype.swap = function (node1, node2) { - this._nodes[node1.queueIndex] = node2; - this._nodes[node2.queueIndex] = node1; - var temp = node1.queueIndex; - node1.queueIndex = node2.queueIndex; - node2.queueIndex = temp; - }; - PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { - return (higher.priority < lower.priority || - (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); - }; - return PriorityQueue; -}()); -var BreadthFirstPathfinder = (function () { - function BreadthFirstPathfinder() { - } - BreadthFirstPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var frontier = []; - frontier.unshift(start); - var cameFrom = new Map(); - cameFrom.set(start, start); - var _loop_3 = function () { - var current = frontier.shift(); - if (JSON.stringify(current) == JSON.stringify(goal)) { - foundPath = true; - return "break"; - } - graph.getNeighbors(current).forEach(function (next) { - if (!_this.hasKey(cameFrom, next)) { - frontier.unshift(next); - cameFrom.set(next, current); - } - }); }; - while (frontier.length > 0) { - var state_2 = _loop_3(); - if (state_2 === "break") - break; - } - return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null; - }; - BreadthFirstPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - return false; - }; - return BreadthFirstPathfinder; -}()); -var UnweightedGraph = (function () { - function UnweightedGraph() { - this.edges = new Map(); - } - UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { - this.edges.set(node, edges); - return this; - }; - UnweightedGraph.prototype.getNeighbors = function (node) { - return this.edges.get(node); - }; - return UnweightedGraph; -}()); -var Vector2 = (function () { - function Vector2(x, y) { - this.x = 0; - this.y = 0; - this.x = x ? x : 0; - this.y = y ? y : this.x; - } - Object.defineProperty(Vector2, "zero", { - get: function () { - return Vector2.zeroVector2; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "one", { - get: function () { - return Vector2.unitVector2; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "unitX", { - get: function () { - return Vector2.unitXVector; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Vector2, "unitY", { - get: function () { - return Vector2.unitYVector; - }, - enumerable: true, - configurable: true - }); - Vector2.add = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x + value2.x; - result.y = value1.y + value2.y; - return result; - }; - Vector2.divide = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x / value2.x; - result.y = value1.y / value2.y; - return result; - }; - Vector2.multiply = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - }; - Vector2.subtract = function (value1, value2) { - var result = new Vector2(0, 0); - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - }; - Vector2.prototype.normalize = function () { - var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); - this.x *= val; - this.y *= val; - }; - Vector2.prototype.length = function () { - return Math.sqrt((this.x * this.x) + (this.y * this.y)); - }; - Vector2.prototype.round = function () { - return new Vector2(Math.round(this.x), Math.round(this.y)); - }; - Vector2.normalize = function (value) { - var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); - value.x *= val; - value.y *= val; - return value; - }; - Vector2.dot = function (value1, value2) { - return (value1.x * value2.x) + (value1.y * value2.y); - }; - Vector2.distanceSquared = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return (v1 * v1) + (v2 * v2); - }; - Vector2.clamp = function (value1, min, max) { - return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y)); - }; - Vector2.lerp = function (value1, value2, amount) { - return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount)); - }; - Vector2.transform = function (position, matrix) { - return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); - }; - Vector2.distance = function (value1, value2) { - var v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return Math.sqrt((v1 * v1) + (v2 * v2)); - }; - Vector2.negate = function (value) { - var result = new Vector2(); - result.x = -value.x; - result.y = -value.y; - return result; - }; - Vector2.unitYVector = new Vector2(0, 1); - Vector2.unitXVector = new Vector2(1, 0); - Vector2.unitVector2 = new Vector2(1, 1); - Vector2.zeroVector2 = new Vector2(0, 0); - return Vector2; -}()); -var UnweightedGridGraph = (function () { - function UnweightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } - this.walls = []; - this._neighbors = new Array(4); - this._width = width; - this._hegiht = height; - this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; - } - UnweightedGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; - }; - UnweightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - UnweightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - UnweightedGridGraph.prototype.search = function (start, goal) { - return BreadthFirstPathfinder.search(this, start, goal); - }; - UnweightedGridGraph.CARDINAL_DIRS = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, -1) - ]; - UnweightedGridGraph.COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; - return UnweightedGridGraph; -}()); -var WeightedGridGraph = (function () { - function WeightedGridGraph(width, height, allowDiagonalSearch) { - if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } - this.walls = []; - this.weightedNodes = []; - this.defaultWeight = 1; - this.weightedNodeWeight = 5; - this._neighbors = new Array(4); - this._width = width; - this._height = height; - this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; - } - WeightedGridGraph.prototype.isNodeInBounds = function (node) { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - }; - WeightedGridGraph.prototype.isNodePassable = function (node) { - return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); - }; - WeightedGridGraph.prototype.search = function (start, goal) { - return WeightedPathfinder.search(this, start, goal); - }; - WeightedGridGraph.prototype.getNeighbors = function (node) { - var _this = this; - this._neighbors.length = 0; - this._dirs.forEach(function (dir) { - var next = new Vector2(node.x + dir.x, node.y + dir.y); - if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) - _this._neighbors.push(next); - }); - return this._neighbors; - }; - WeightedGridGraph.prototype.cost = function (from, to) { - return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; - }; - WeightedGridGraph.CARDINAL_DIRS = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; - WeightedGridGraph.COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; - return WeightedGridGraph; -}()); -var WeightedNode = (function (_super) { - __extends(WeightedNode, _super); - function WeightedNode(data) { - var _this = _super.call(this) || this; - _this.data = data; - return _this; - } - return WeightedNode; -}(PriorityQueueNode)); -var WeightedPathfinder = (function () { - function WeightedPathfinder() { - } - WeightedPathfinder.search = function (graph, start, goal) { - var _this = this; - var foundPath = false; - var cameFrom = new Map(); - cameFrom.set(start, start); - var costSoFar = new Map(); - var frontier = new PriorityQueue(1000); - frontier.enqueue(new WeightedNode(start), 0); - costSoFar.set(start, 0); - var _loop_4 = function () { - var current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)) { - foundPath = true; - return "break"; + PriorityQueue.prototype.cascadeUp = function (node) { + var parent = Math.floor(node.queueIndex / 2); + while (parent >= 1) { + var parentNode = this._nodes[parent]; + if (this.hasHigherPriority(parentNode, node)) + break; + this.swap(node, parentNode); + parent = Math.floor(node.queueIndex / 2); } - graph.getNeighbors(current.data).forEach(function (next) { - var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { - costSoFar.set(next, newCost); - var priprity = newCost; - frontier.enqueue(new WeightedNode(next), priprity); - cameFrom.set(next, current.data); - } - }); }; - while (frontier.count > 0) { - var state_3 = _loop_4(); - if (state_3 === "break") - break; + PriorityQueue.prototype.swap = function (node1, node2) { + this._nodes[node1.queueIndex] = node2; + this._nodes[node2.queueIndex] = node1; + var temp = node1.queueIndex; + node1.queueIndex = node2.queueIndex; + node2.queueIndex = temp; + }; + PriorityQueue.prototype.hasHigherPriority = function (higher, lower) { + return (higher.priority < lower.priority || + (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); + }; + return PriorityQueue; + }()); + es.PriorityQueue = PriorityQueue; +})(es || (es = {})); +var es; +(function (es) { + var BreadthFirstPathfinder = (function () { + function BreadthFirstPathfinder() { } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - }; - WeightedPathfinder.hasKey = function (map, compareKey) { - var iterator = map.keys(); - var r; - while (r = iterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; - } - return false; - }; - WeightedPathfinder.getKey = function (map, compareKey) { - var iterator = map.keys(); - var valueIterator = map.values(); - var r; - var v; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; - } - return null; - }; - WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { - var path = []; - var current = goal; - path.push(goal); - while (current != start) { - current = this.getKey(cameFrom, current); - path.push(current); - } - path.reverse(); - return path; - }; - return WeightedPathfinder; -}()); -var Debug = (function () { - function Debug() { - } - Debug.drawHollowRect = function (rectanle, color, duration) { - if (duration === void 0) { duration = 0; } - this._debugDrawItems.push(new DebugDrawItem(rectanle, color, duration)); - }; - Debug.render = function () { - if (this._debugDrawItems.length > 0) { - var debugShape = new egret.Shape(); - if (SceneManager.scene) { - SceneManager.scene.addChild(debugShape); + BreadthFirstPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var frontier = []; + frontier.unshift(start); + var cameFrom = new Map(); + cameFrom.set(start, start); + var _loop_3 = function () { + var current = frontier.shift(); + if (JSON.stringify(current) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current).forEach(function (next) { + if (!_this.hasKey(cameFrom, next)) { + frontier.unshift(next); + cameFrom.set(next, current); + } + }); + }; + while (frontier.length > 0) { + var state_2 = _loop_3(); + if (state_2 === "break") + break; } - for (var i = this._debugDrawItems.length - 1; i >= 0; i--) { - var item = this._debugDrawItems[i]; - if (item.draw(debugShape)) - this._debugDrawItems.removeAt(i); + return foundPath ? es.AStarPathfinder.recontructPath(cameFrom, start, goal) : null; + }; + BreadthFirstPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; } + return false; + }; + return BreadthFirstPathfinder; + }()); + es.BreadthFirstPathfinder = BreadthFirstPathfinder; +})(es || (es = {})); +var es; +(function (es) { + var UnweightedGraph = (function () { + function UnweightedGraph() { + this.edges = new Map(); } - }; - Debug._debugDrawItems = []; - return Debug; -}()); -var DebugDefaults = (function () { - function DebugDefaults() { - } - DebugDefaults.verletParticle = 0xDC345E; - DebugDefaults.verletConstraintEdge = 0x433E36; - return DebugDefaults; -}()); -var DebugDrawType; -(function (DebugDrawType) { - DebugDrawType[DebugDrawType["line"] = 0] = "line"; - DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle"; - DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel"; - DebugDrawType[DebugDrawType["text"] = 3] = "text"; -})(DebugDrawType || (DebugDrawType = {})); -var DebugDrawItem = (function () { - function DebugDrawItem(rectangle, color, duration) { - this.rectangle = rectangle; - this.color = color; - this.duration = duration; - this.drawType = DebugDrawType.hollowRectangle; - } - DebugDrawItem.prototype.draw = function (shape) { - switch (this.drawType) { - case DebugDrawType.line: - DrawUtils.drawLine(shape, this.start, this.end, this.color); - break; - case DebugDrawType.hollowRectangle: - DrawUtils.drawHollowRect(shape, this.rectangle, this.color); - break; - case DebugDrawType.pixel: - DrawUtils.drawPixel(shape, new Vector2(this.x, this.y), this.color, this.size); - break; - case DebugDrawType.text: - break; + UnweightedGraph.prototype.addEdgesForNode = function (node, edges) { + this.edges.set(node, edges); + return this; + }; + UnweightedGraph.prototype.getNeighbors = function (node) { + return this.edges.get(node); + }; + return UnweightedGraph; + }()); + es.UnweightedGraph = UnweightedGraph; +})(es || (es = {})); +var es; +(function (es) { + var Vector2 = (function () { + function Vector2(x, y) { + this.x = 0; + this.y = 0; + this.x = x ? x : 0; + this.y = y ? y : this.x; } - this.duration -= Time.deltaTime; - return this.duration < 0; - }; - return DebugDrawItem; -}()); -var Component = (function (_super) { - __extends(Component, _super); - function Component() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._enabled = true; - _this.updateInterval = 1; - _this._updateOrder = 0; - return _this; - } - Object.defineProperty(Component.prototype, "enabled", { - get: function () { - return this.entity ? this.entity.enabled && this._enabled : this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Component.prototype, "localPosition", { - get: function () { - return new Vector2(this.entity.x + this.x, this.entity.y + this.y); - }, - enumerable: true, - configurable: true - }); - Component.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); + Object.defineProperty(Vector2, "zero", { + get: function () { + return Vector2.zeroVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "one", { + get: function () { + return Vector2.unitVector2; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitX", { + get: function () { + return Vector2.unitXVector; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Vector2, "unitY", { + get: function () { + return Vector2.unitYVector; + }, + enumerable: true, + configurable: true + }); + Vector2.add = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x + value2.x; + result.y = value1.y + value2.y; + return result; + }; + Vector2.divide = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x / value2.x; + result.y = value1.y / value2.y; + return result; + }; + Vector2.multiply = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x * value2.x; + result.y = value1.y * value2.y; + return result; + }; + Vector2.subtract = function (value1, value2) { + var result = new Vector2(0, 0); + result.x = value1.x - value2.x; + result.y = value1.y - value2.y; + return result; + }; + Vector2.prototype.normalize = function () { + var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); + this.x *= val; + this.y *= val; + }; + Vector2.prototype.length = function () { + return Math.sqrt((this.x * this.x) + (this.y * this.y)); + }; + Vector2.prototype.round = function () { + return new Vector2(Math.round(this.x), Math.round(this.y)); + }; + Vector2.normalize = function (value) { + var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); + value.x *= val; + value.y *= val; + return value; + }; + Vector2.dot = function (value1, value2) { + return (value1.x * value2.x) + (value1.y * value2.y); + }; + Vector2.distanceSquared = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return (v1 * v1) + (v2 * v2); + }; + Vector2.clamp = function (value1, min, max) { + return new Vector2(es.MathHelper.clamp(value1.x, min.x, max.x), es.MathHelper.clamp(value1.y, min.y, max.y)); + }; + Vector2.lerp = function (value1, value2, amount) { + return new Vector2(es.MathHelper.lerp(value1.x, value2.x, amount), es.MathHelper.lerp(value1.y, value2.y, amount)); + }; + Vector2.transform = function (position, matrix) { + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + }; + Vector2.distance = function (value1, value2) { + var v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return Math.sqrt((v1 * v1) + (v2 * v2)); + }; + Vector2.negate = function (value) { + var result = new Vector2(); + result.x = -value.x; + result.y = -value.y; + return result; + }; + Vector2.unitYVector = new Vector2(0, 1); + Vector2.unitXVector = new Vector2(1, 0); + Vector2.unitVector2 = new Vector2(1, 1); + Vector2.zeroVector2 = new Vector2(0, 0); + return Vector2; + }()); + es.Vector2 = Vector2; +})(es || (es = {})); +var es; +(function (es) { + var UnweightedGridGraph = (function () { + function UnweightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this._neighbors = new Array(4); + this._width = width; + this._hegiht = height; + this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; + } + UnweightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; + }; + UnweightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + UnweightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new es.Vector2(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + UnweightedGridGraph.prototype.search = function (start, goal) { + return es.BreadthFirstPathfinder.search(this, start, goal); + }; + UnweightedGridGraph.CARDINAL_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(0, -1), + new es.Vector2(-1, 0), + new es.Vector2(0, -1) + ]; + UnweightedGridGraph.COMPASS_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(1, -1), + new es.Vector2(0, -1), + new es.Vector2(-1, -1), + new es.Vector2(-1, 0), + new es.Vector2(-1, 1), + new es.Vector2(0, 1), + new es.Vector2(1, 1), + ]; + return UnweightedGridGraph; + }()); + es.UnweightedGridGraph = UnweightedGridGraph; +})(es || (es = {})); +var es; +(function (es) { + var WeightedGridGraph = (function () { + function WeightedGridGraph(width, height, allowDiagonalSearch) { + if (allowDiagonalSearch === void 0) { allowDiagonalSearch = false; } + this.walls = []; + this.weightedNodes = []; + this.defaultWeight = 1; + this.weightedNodeWeight = 5; + this._neighbors = new Array(4); + this._width = width; + this._height = height; + this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; + } + WeightedGridGraph.prototype.isNodeInBounds = function (node) { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + }; + WeightedGridGraph.prototype.isNodePassable = function (node) { + return !this.walls.firstOrDefault(function (wall) { return JSON.stringify(wall) == JSON.stringify(node); }); + }; + WeightedGridGraph.prototype.search = function (start, goal) { + return es.WeightedPathfinder.search(this, start, goal); + }; + WeightedGridGraph.prototype.getNeighbors = function (node) { + var _this = this; + this._neighbors.length = 0; + this._dirs.forEach(function (dir) { + var next = new es.Vector2(node.x + dir.x, node.y + dir.y); + if (_this.isNodeInBounds(next) && _this.isNodePassable(next)) + _this._neighbors.push(next); + }); + return this._neighbors; + }; + WeightedGridGraph.prototype.cost = function (from, to) { + return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight; + }; + WeightedGridGraph.CARDINAL_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(0, -1), + new es.Vector2(-1, 0), + new es.Vector2(0, 1) + ]; + WeightedGridGraph.COMPASS_DIRS = [ + new es.Vector2(1, 0), + new es.Vector2(1, -1), + new es.Vector2(0, -1), + new es.Vector2(-1, -1), + new es.Vector2(-1, 0), + new es.Vector2(-1, 1), + new es.Vector2(0, 1), + new es.Vector2(1, 1), + ]; + return WeightedGridGraph; + }()); + es.WeightedGridGraph = WeightedGridGraph; +})(es || (es = {})); +var es; +(function (es) { + var WeightedNode = (function (_super) { + __extends(WeightedNode, _super); + function WeightedNode(data) { + var _this = _super.call(this) || this; + _this.data = data; + return _this; + } + return WeightedNode; + }(es.PriorityQueueNode)); + es.WeightedNode = WeightedNode; + var WeightedPathfinder = (function () { + function WeightedPathfinder() { + } + WeightedPathfinder.search = function (graph, start, goal) { + var _this = this; + var foundPath = false; + var cameFrom = new Map(); + cameFrom.set(start, start); + var costSoFar = new Map(); + var frontier = new es.PriorityQueue(1000); + frontier.enqueue(new WeightedNode(start), 0); + costSoFar.set(start, 0); + var _loop_4 = function () { + var current = frontier.dequeue(); + if (JSON.stringify(current.data) == JSON.stringify(goal)) { + foundPath = true; + return "break"; + } + graph.getNeighbors(current.data).forEach(function (next) { + var newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!_this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)) { + costSoFar.set(next, newCost); + var priprity = newCost; + frontier.enqueue(new WeightedNode(next), priprity); + cameFrom.set(next, current.data); + } + }); + }; + while (frontier.count > 0) { + var state_3 = _loop_4(); + if (state_3 === "break") + break; } - else { - this.onDisabled(); + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; + }; + WeightedPathfinder.hasKey = function (map, compareKey) { + var iterator = map.keys(); + var r; + while (r = iterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; } + return false; + }; + WeightedPathfinder.getKey = function (map, compareKey) { + var iterator = map.keys(); + var valueIterator = map.values(); + var r; + var v; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } + return null; + }; + WeightedPathfinder.recontructPath = function (cameFrom, start, goal) { + var path = []; + var current = goal; + path.push(goal); + while (current != start) { + current = this.getKey(cameFrom, current); + path.push(current); + } + path.reverse(); + return path; + }; + return WeightedPathfinder; + }()); + es.WeightedPathfinder = WeightedPathfinder; +})(es || (es = {})); +var es; +(function (es) { + var Debug = (function () { + function Debug() { } - return this; - }; - Object.defineProperty(Component.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (value) { - this.setUpdateOrder(value); - }, - enumerable: true, - configurable: true - }); - Component.prototype.setUpdateOrder = function (updateOrder) { - if (this._updateOrder != updateOrder) { - this._updateOrder = updateOrder; + Debug.drawHollowRect = function (rectanle, color, duration) { + if (duration === void 0) { duration = 0; } + this._debugDrawItems.push(new es.DebugDrawItem(rectanle, color, duration)); + }; + Debug.render = function () { + if (this._debugDrawItems.length > 0) { + var debugShape = new egret.Shape(); + if (es.SceneManager.scene) { + es.SceneManager.scene.addChild(debugShape); + } + for (var i = this._debugDrawItems.length - 1; i >= 0; i--) { + var item = this._debugDrawItems[i]; + if (item.draw(debugShape)) + this._debugDrawItems.removeAt(i); + } + } + }; + Debug._debugDrawItems = []; + return Debug; + }()); + es.Debug = Debug; +})(es || (es = {})); +var es; +(function (es) { + var DebugDefaults = (function () { + function DebugDefaults() { } - return this; - }; - Component.prototype.initialize = function () { - }; - Component.prototype.onAddedToEntity = function () { - }; - Component.prototype.onRemovedFromEntity = function () { - }; - Component.prototype.onEnabled = function () { - }; - Component.prototype.onDisabled = function () { - }; - Component.prototype.debugRender = function () { - }; - Component.prototype.update = function () { - }; - Component.prototype.onEntityTransformChanged = function (comp) { - }; - Component.prototype.registerComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false); - this.entity.scene.entityProcessors.onComponentAdded(this.entity); - }; - Component.prototype.deregisterComponent = function () { - this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)); - this.entity.scene.entityProcessors.onComponentRemoved(this.entity); - }; - return Component; -}(egret.DisplayObjectContainer)); -var CoreEvents; -(function (CoreEvents) { - CoreEvents[CoreEvents["SceneChanged"] = 0] = "SceneChanged"; -})(CoreEvents || (CoreEvents = {})); -var Entity = (function (_super) { - __extends(Entity, _super); - function Entity(name) { - var _this = _super.call(this) || this; - _this._updateOrder = 0; - _this._enabled = true; - _this._tag = 0; - _this.name = name; - _this.components = new ComponentList(_this); - _this.id = Entity._idGenerator++; - _this.componentBits = new BitSet(); - _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this); - return _this; - } - Object.defineProperty(Entity.prototype, "isDestoryed", { - get: function () { - return this._isDestoryed; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (value) { - this.$setX(value.x); - this.$setY(value.y); - this.onEntityTransformChanged(TransformComponent.position); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "scale", { - get: function () { - return new Vector2(this.scaleX, this.scaleY); - }, - set: function (value) { - this.$setScaleX(value.x); - this.$setScaleY(value.y); - this.onEntityTransformChanged(TransformComponent.scale); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "rotation", { - get: function () { - return this.$getRotation(); - }, - set: function (value) { - this.$setRotation(value); - this.onEntityTransformChanged(TransformComponent.rotation); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true - }); - Entity.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; + DebugDefaults.verletParticle = 0xDC345E; + DebugDefaults.verletConstraintEdge = 0x433E36; + return DebugDefaults; + }()); + es.DebugDefaults = DebugDefaults; +})(es || (es = {})); +var es; +(function (es) { + var DebugDrawType; + (function (DebugDrawType) { + DebugDrawType[DebugDrawType["line"] = 0] = "line"; + DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle"; + DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel"; + DebugDrawType[DebugDrawType["text"] = 3] = "text"; + })(DebugDrawType = es.DebugDrawType || (es.DebugDrawType = {})); + var DebugDrawItem = (function () { + function DebugDrawItem(rectangle, color, duration) { + this.rectangle = rectangle; + this.color = color; + this.duration = duration; + this.drawType = DebugDrawType.hollowRectangle; } - return this; - }; - Object.defineProperty(Entity.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (value) { - this.setTag(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Entity.prototype, "stage", { - get: function () { - if (!this.scene) - return null; - return this.scene.stage; - }, - enumerable: true, - configurable: true - }); - Entity.prototype.onAddToStage = function () { - this.onEntityTransformChanged(TransformComponent.position); - }; - Object.defineProperty(Entity.prototype, "updateOrder", { - get: function () { - return this._updateOrder; - }, - set: function (value) { - this.setUpdateOrder(value); - }, - enumerable: true, - configurable: true - }); - Entity.prototype.roundPosition = function () { - this.position = Vector2Ext.round(this.position); - }; - Entity.prototype.setUpdateOrder = function (updateOrder) { - if (this._updateOrder != updateOrder) { - this._updateOrder = updateOrder; - if (this.scene) { + DebugDrawItem.prototype.draw = function (shape) { + switch (this.drawType) { + case DebugDrawType.line: + es.DrawUtils.drawLine(shape, this.start, this.end, this.color); + break; + case DebugDrawType.hollowRectangle: + es.DrawUtils.drawHollowRect(shape, this.rectangle, this.color); + break; + case DebugDrawType.pixel: + es.DrawUtils.drawPixel(shape, new es.Vector2(this.x, this.y), this.color, this.size); + break; + case DebugDrawType.text: + break; + } + this.duration -= es.Time.deltaTime; + return this.duration < 0; + }; + return DebugDrawItem; + }()); + es.DebugDrawItem = DebugDrawItem; +})(es || (es = {})); +var es; +(function (es) { + var Component = (function () { + function Component() { + this.updateInterval = 1; + this._enabled = true; + this._updateOrder = 0; + } + Object.defineProperty(Component.prototype, "transform", { + get: function () { + return this.entity.transform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Component.prototype, "enabled", { + get: function () { + return this.entity ? this.entity.enabled && this._enabled : this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Component.prototype, "updateOrder", { + get: function () { + return this._updateOrder; + }, + set: function (value) { + this.setUpdateOrder(value); + }, + enumerable: true, + configurable: true + }); + Component.prototype.initialize = function () { + }; + Component.prototype.onAddedToEntity = function () { + }; + Component.prototype.onRemovedFromEntity = function () { + }; + Component.prototype.onEntityTransformChanged = function (comp) { + }; + Component.prototype.debugRender = function () { + }; + Component.prototype.onEnabled = function () { + }; + Component.prototype.onDisabled = function () { + }; + Component.prototype.update = function () { + }; + Component.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } } return this; - } - }; - Entity.prototype.setTag = function (tag) { - if (this._tag != tag) { - if (this.scene) { - this.scene.entities.removeFromTagList(this); - } - this._tag = tag; - if (this.scene) { - this.scene.entities.addToTagList(this); + }; + Component.prototype.setUpdateOrder = function (updateOrder) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; } + return this; + }; + Component.prototype.clone = function () { + var component = ObjectUtils.clone(this); + component.entity = null; + return component; + }; + return Component; + }()); + es.Component = Component; +})(es || (es = {})); +var es; +(function (es) { + var CoreEvents; + (function (CoreEvents) { + CoreEvents[CoreEvents["SceneChanged"] = 0] = "SceneChanged"; + })(CoreEvents = es.CoreEvents || (es.CoreEvents = {})); +})(es || (es = {})); +var es; +(function (es) { + var Entity = (function () { + function Entity(name) { + this.updateInterval = 1; + this._tag = 0; + this._enabled = true; + this._updateOrder = 0; + this.components = new es.ComponentList(this); + this.transform = new es.Transform(this); + this.name = name; + this.id = Entity._idGenerator++; + this.componentBits = new es.BitSet(); } - return this; - }; - Entity.prototype.attachToScene = function (newScene) { - this.scene = newScene; - newScene.entities.add(this); - this.components.registerAllComponents(); - for (var i = 0; i < this.numChildren; i++) { - this.getChildAt(i).entity.attachToScene(newScene); - } - }; - Entity.prototype.detachFromScene = function () { - this.scene.entities.remove(this); - this.components.deregisterAllComponents(); - for (var i = 0; i < this.numChildren; i++) - this.getChildAt(i).entity.detachFromScene(); - }; - Entity.prototype.addComponent = function (component) { - component.entity = this; - this.components.add(component); - this.addChild(component); - component.initialize(); - return component; - }; - Entity.prototype.hasComponent = function (type) { - return this.components.getComponent(type, false) != null; - }; - Entity.prototype.getOrCreateComponent = function (type) { - var comp = this.components.getComponent(type, true); - if (!comp) { - comp = this.addComponent(type); - } - return comp; - }; - Entity.prototype.getComponent = function (type) { - return this.components.getComponent(type, false); - }; - Entity.prototype.getComponents = function (typeName, componentList) { - return this.components.getComponents(typeName, componentList); - }; - Entity.prototype.onEntityTransformChanged = function (comp) { - this.components.onEntityTransformChanged(comp); - }; - Entity.prototype.removeComponentForType = function (type) { - var comp = this.getComponent(type); - if (comp) { - this.removeComponent(comp); - return true; - } - return false; - }; - Entity.prototype.removeComponent = function (component) { - this.components.remove(component); - }; - Entity.prototype.removeAllComponents = function () { - for (var i = 0; i < this.components.count; i++) { - this.removeComponent(this.components.buffer[i]); - } - }; - Entity.prototype.update = function () { - this.components.update(); - }; - Entity.prototype.onAddedToScene = function () { - }; - Entity.prototype.onRemovedFromScene = function () { - if (this._isDestoryed) - this.components.removeAllComponents(); - }; - Entity.prototype.destroy = function () { - this._isDestoryed = true; - this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); - this.scene.entities.remove(this); - this.removeChildren(); - if (this.parent) - this.parent.removeChild(this); - for (var i = this.numChildren - 1; i >= 0; i--) { - var child = this.getChildAt(i); - child.entity.destroy(); - } - }; - return Entity; -}(egret.DisplayObjectContainer)); -var TransformComponent; -(function (TransformComponent) { - TransformComponent[TransformComponent["rotation"] = 0] = "rotation"; - TransformComponent[TransformComponent["scale"] = 1] = "scale"; - TransformComponent[TransformComponent["position"] = 2] = "position"; -})(TransformComponent || (TransformComponent = {})); -var Scene = (function (_super) { - __extends(Scene, _super); - function Scene() { - var _this = _super.call(this) || this; - _this.enablePostProcessing = true; - _this._renderers = []; - _this._postProcessors = []; - _this.entityProcessors = new EntityProcessorList(); - _this.renderableComponents = new RenderableComponentList(); - _this.entities = new EntityList(_this); - _this.content = new ContentManager(); - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); - _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); - return _this; - } - Scene.prototype.createEntity = function (name) { - var entity = new Entity(name); - entity.position = new Vector2(0, 0); - return this.addEntity(entity); - }; - Scene.prototype.addEntity = function (entity) { - this.entities.add(entity); - entity.scene = this; - this.addChild(entity); - for (var i = 0; i < entity.numChildren; i++) - this.addEntity(entity.getChildAt(i).entity); - return entity; - }; - Scene.prototype.destroyAllEntities = function () { - for (var i = 0; i < this.entities.count; i++) { - this.entities.buffer[i].destroy(); - } - }; - Scene.prototype.findEntity = function (name) { - return this.entities.findEntity(name); - }; - Scene.prototype.addEntityProcessor = function (processor) { - processor.scene = this; - this.entityProcessors.add(processor); - return processor; - }; - Scene.prototype.removeEntityProcessor = function (processor) { - this.entityProcessors.remove(processor); - }; - Scene.prototype.getEntityProcessor = function () { - return this.entityProcessors.getProcessor(); - }; - Scene.prototype.addRenderer = function (renderer) { - this._renderers.push(renderer); - this._renderers.sort(); - renderer.onAddedToScene(this); - return renderer; - }; - Scene.prototype.getRenderer = function (type) { - for (var i = 0; i < this._renderers.length; i++) { - if (this._renderers[i] instanceof type) - return this._renderers[i]; - } - return null; - }; - Scene.prototype.removeRenderer = function (renderer) { - this._renderers.remove(renderer); - renderer.unload(); - }; - Scene.prototype.begin = function () { - if (SceneManager.sceneTransition) { - SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); - } - else { - SceneManager.stage.addChild(this); - } - if (this._renderers.length == 0) { - this.addRenderer(new DefaultRenderer()); - console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); - } - this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); - Physics.reset(); - if (this.entityProcessors) - this.entityProcessors.begin(); - this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); - this._didSceneBegin = true; - this.onStart(); - }; - Scene.prototype.end = function () { - this._didSceneBegin = false; - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].unload(); - } - for (var i = 0; i < this._postProcessors.length; i++) { - this._postProcessors[i].unload(); - } - this.entities.removeAllEntities(); - this.removeChildren(); - Physics.clear(); - this.camera = null; - this.content.dispose(); - if (this.entityProcessors) - this.entityProcessors.end(); - this.unload(); - if (this.parent) - this.parent.removeChild(this); - }; - Scene.prototype.onStart = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2]; - }); + Object.defineProperty(Entity.prototype, "tag", { + get: function () { + return this._tag; + }, + set: function (value) { + this.setTag(value); + }, + enumerable: true, + configurable: true }); - }; - Scene.prototype.onActive = function () { - }; - Scene.prototype.onDeactive = function () { - }; - Scene.prototype.unload = function () { }; - Scene.prototype.update = function () { - this.entities.updateLists(); - if (this.entityProcessors) - this.entityProcessors.update(); - this.entities.update(); - if (this.entityProcessors) - this.entityProcessors.lateUpdate(); - this.renderableComponents.updateList(); - }; - Scene.prototype.postRender = function () { - var enabledCounter = 0; - if (this.enablePostProcessing) { + Object.defineProperty(Entity.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "updateOrder", { + get: function () { + return this._updateOrder; + }, + set: function (value) { + this.setUpdateOrder(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "isDestroyed", { + get: function () { + return this._isDestroyed; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "parent", { + get: function () { + return this.transform.parent; + }, + set: function (value) { + this.transform.setParent(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "childCount", { + get: function () { + return this.transform.childCount; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "position", { + get: function () { + return this.transform.position; + }, + set: function (value) { + this.transform.setPosition(value.x, value.y); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "rotation", { + get: function () { + return this.transform.rotation; + }, + set: function (value) { + this.transform.setRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "scale", { + get: function () { + return this.transform.scale; + }, + set: function (value) { + this.transform.setScale(value); + }, + enumerable: true, + configurable: true + }); + Entity.prototype.onTransformChanged = function (comp) { + this.components.onEntityTransformChanged(comp); + }; + Entity.prototype.setTag = function (tag) { + if (this._tag != tag) { + if (this.scene) + this.scene.entities.removeFromTagList(this); + this._tag = tag; + if (this.scene) + this.scene.entities.addToTagList(this); + } + return this; + }; + Entity.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) + this.components.onEntityEnabled(); + else + this.components.onEntityDisabled(); + } + return this; + }; + Entity.prototype.setUpdateOrder = function (updateOrder) { + if (this._updateOrder != updateOrder) { + this._updateOrder = updateOrder; + if (this.scene) { + } + return this; + } + }; + Entity.prototype.destroy = function () { + this._isDestroyed = true; + this.scene.entities.remove(this); + this.transform.parent = null; + for (var i = this.transform.childCount - 1; i >= 0; i--) { + var child = this.transform.getChild(i); + child.entity.destroy(); + } + }; + Entity.prototype.detachFromScene = function () { + this.scene.entities.remove(this); + this.components.deregisterAllComponents(); + for (var i = 0; i < this.transform.childCount; i++) + this.transform.getChild(i).entity.detachFromScene(); + }; + Entity.prototype.attachToScene = function (newScene) { + this.scene = newScene; + newScene.entities.add(this); + this.components.registerAllComponents(); + for (var i = 0; i < this.transform.childCount; i++) { + this.transform.getChild(i).entity.attachToScene(newScene); + } + }; + Entity.prototype.clone = function (position) { + if (position === void 0) { position = new es.Vector2(); } + var entity = new Entity(this.name + "(clone)"); + entity.copyFrom(this); + entity.transform.position = position; + return entity; + }; + Entity.prototype.copyFrom = function (entity) { + this.tag = entity.tag; + this.updateInterval = entity.updateInterval; + this.updateOrder = entity.updateOrder; + this.enabled = entity.enabled; + this.transform.scale = entity.transform.scale; + this.transform.rotation = entity.transform.rotation; + for (var i = 0; i < entity.components.count; i++) + this.addComponent(entity.components.buffer[i].clone()); + for (var i = 0; i < entity.components._componentsToAdd.length; i++) + this.addComponent(entity.components._componentsToAdd[i].clone()); + for (var i = 0; i < entity.transform.childCount; i++) { + var child = entity.transform.getChild(i).entity; + var childClone = child.clone(); + childClone.transform.copyFrom(child.transform); + childClone.transform.parent = this.transform; + } + }; + Entity.prototype.onAddedToScene = function () { + }; + Entity.prototype.onRemovedFromScene = function () { + if (this._isDestroyed) + this.components.removeAllComponents(); + }; + Entity.prototype.update = function () { + this.components.update(); + }; + Entity.prototype.addComponent = function (component) { + component.entity = this; + this.components.add(component); + component.initialize(); + return component; + }; + Entity.prototype.getComponent = function (type) { + return this.components.getComponent(type, false); + }; + Entity.prototype.hasComponent = function (type) { + return this.components.getComponent(type, false) != null; + }; + Entity.prototype.getOrCreateComponent = function (type) { + var comp = this.components.getComponent(type, true); + if (!comp) { + comp = this.addComponent(type); + } + return comp; + }; + Entity.prototype.getComponents = function (typeName, componentList) { + return this.components.getComponents(typeName, componentList); + }; + Entity.prototype.removeComponent = function (component) { + this.components.remove(component); + }; + Entity.prototype.removeComponentForType = function (type) { + var comp = this.getComponent(type); + if (comp) { + this.removeComponent(comp); + return true; + } + return false; + }; + Entity.prototype.removeAllComponents = function () { + for (var i = 0; i < this.components.count; i++) { + this.removeComponent(this.components.buffer[i]); + } + }; + Entity.prototype.toString = function () { + return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]"; + }; + return Entity; + }()); + es.Entity = Entity; +})(es || (es = {})); +var es; +(function (es) { + var Scene = (function (_super) { + __extends(Scene, _super); + function Scene() { + var _this = _super.call(this) || this; + _this.enablePostProcessing = true; + _this._renderers = []; + _this._postProcessors = []; + _this.entities = new es.EntityList(_this); + _this.renderableComponents = new es.RenderableComponentList(); + _this.content = new es.ContentManager(); + _this.entityProcessors = new es.EntityProcessorList(); + _this.width = es.SceneManager.stage.stageWidth; + _this.height = es.SceneManager.stage.stageHeight; + _this.initialize(); + return _this; + } + Scene.createWithDefaultRenderer = function () { + var scene = new Scene(); + scene.addRenderer(new es.DefaultRenderer()); + return scene; + }; + Scene.prototype.initialize = function () { }; + Scene.prototype.onStart = function () { + return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { + return [2]; + }); }); + }; + Scene.prototype.unload = function () { }; + Scene.prototype.onActive = function () { }; + Scene.prototype.onDeactive = function () { }; + Scene.prototype.begin = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + if (es.SceneManager.sceneTransition) { + es.SceneManager.stage.addChildAt(this, es.SceneManager.stage.numChildren - 1); + } + else { + es.SceneManager.stage.addChild(this); + } + if (this._renderers.length == 0) { + this.addRenderer(new es.DefaultRenderer()); + console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); + } + this.camera = this.createEntity("camera").getOrCreateComponent(new es.Camera()); + es.Physics.reset(); + if (this.entityProcessors) + this.entityProcessors.begin(); + this.addEventListener(egret.Event.ACTIVATE, this.onActive, this); + this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + this._didSceneBegin = true; + this.onStart(); + return [2]; + }); + }); + }; + Scene.prototype.end = function () { + this._didSceneBegin = false; + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].unload(); + } for (var i = 0; i < this._postProcessors.length; i++) { - if (this._postProcessors[i].enable) { - var isEven = MathHelper.isEven(enabledCounter); - enabledCounter++; - this._postProcessors[i].process(); - } + this._postProcessors[i].unload(); } - } - }; - Scene.prototype.render = function () { - for (var i = 0; i < this._renderers.length; i++) { - this._renderers[i].render(this); - } - }; - Scene.prototype.addPostProcessor = function (postProcessor) { - this._postProcessors.push(postProcessor); - this._postProcessors.sort(); - postProcessor.onAddedToScene(this); - if (this._didSceneBegin) { - postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); - } - return postProcessor; - }; - return Scene; -}(egret.DisplayObjectContainer)); -var SceneManager = (function () { - function SceneManager(stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - SceneManager._instnace = this; - SceneManager.emitter = new Emitter(); - SceneManager.content = new ContentManager(); - SceneManager.stage = stage; - SceneManager.initialize(stage); - SceneManager.timerRuler = new TimeRuler(); - } - Object.defineProperty(SceneManager, "Instance", { - get: function () { - return this._instnace; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SceneManager, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - if (!value) - throw new Error("场景不能为空"); - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - SceneManager.Instance.onSceneChanged(); + this.entities.removeAllEntities(); + this.removeChildren(); + this.camera = null; + this.content.dispose(); + if (this.entityProcessors) + this.entityProcessors.end(); + if (this.parent) + this.parent.removeChild(this); + this.unload(); + }; + Scene.prototype.update = function () { + this.entities.updateLists(); + if (this.entityProcessors) + this.entityProcessors.update(); + this.entities.update(); + if (this.entityProcessors) + this.entityProcessors.lateUpdate(); + this.renderableComponents.updateList(); + }; + Scene.prototype.render = function () { + if (this._renderers.length == 0) { + console.error("there are no renderers in the scene!"); + return; } - else { - this._nextScene = value; + for (var i = 0; i < this._renderers.length; i++) { + this._renderers[i].render(this); } - this.registerActiveSceneChanged(this._scene, this._nextScene); - }, - enumerable: true, - configurable: true - }); - SceneManager.initialize = function (stage) { - Input.initialize(stage); - }; - SceneManager.update = function () { - SceneManager.startDebugUpdate(); - Time.update(egret.getTimer()); - if (SceneManager._scene) { - for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } - if (!SceneManager.sceneTransition || - (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { - SceneManager._scene.update(); - } - if (SceneManager._nextScene) { - SceneManager._scene.end(); - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._instnace.onSceneChanged(); - SceneManager._scene.begin(); - } - } - SceneManager.endDebugUpdate(); - SceneManager.render(); - }; - SceneManager.render = function () { - if (this.sceneTransition) { - this.sceneTransition.preRender(); - if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } - else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { - this._scene.render(); - this._scene.postRender(); - } - this.sceneTransition.render(); - } - } - else if (this._scene) { - this._scene.render(); - Debug.render(); - this._scene.postRender(); - } - }; - SceneManager.startSceneTransition = function (sceneTransition) { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; - } - this.sceneTransition = sceneTransition; - return sceneTransition; - }; - SceneManager.registerActiveSceneChanged = function (current, next) { - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - }; - SceneManager.prototype.onSceneChanged = function () { - SceneManager.emitter.emit(CoreEvents.SceneChanged); - Time.sceneChanged(); - }; - SceneManager.startDebugUpdate = function () { - TimeRuler.Instance.startFrame(); - TimeRuler.Instance.beginMark("update", 0x00FF00); - }; - SceneManager.endDebugUpdate = function () { - TimeRuler.Instance.endMark("update"); - }; - return SceneManager; -}()); -var Camera = (function (_super) { - __extends(Camera, _super); - function Camera() { - var _this = _super.call(this) || this; - _this._origin = Vector2.zero; - _this._minimumZoom = 0.3; - _this._maximumZoom = 3; - _this._position = Vector2.zero; - _this.followLerp = 0.1; - _this.deadzone = new Rectangle(); - _this.focusOffset = new Vector2(); - _this.mapLockEnabled = false; - _this.mapSize = new Vector2(); - _this._worldSpaceDeadZone = new Rectangle(); - _this._desiredPositionDelta = new Vector2(); - _this.cameraStyle = CameraStyle.lockOn; - _this.width = SceneManager.stage.stageWidth; - _this.height = SceneManager.stage.stageHeight; - _this.setZoom(0); - return _this; - } - Object.defineProperty(Camera.prototype, "zoom", { - get: function () { - if (this._zoom == 0) - return 1; - if (this._zoom < 1) - return MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); - return MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); - }, - set: function (value) { - this.setZoom(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "minimumZoom", { - get: function () { - return this._minimumZoom; - }, - set: function (value) { - this.setMinimumZoom(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "maximumZoom", { - get: function () { - return this._maximumZoom; - }, - set: function (value) { - this.setMaximumZoom(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "origin", { - get: function () { - return this._origin; - }, - set: function (value) { - if (this._origin != value) { - this._origin = value; - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "position", { - get: function () { - return this._position; - }, - set: function (value) { - this._position = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "x", { - get: function () { - return this._position.x; - }, - set: function (value) { - this._position.x = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Camera.prototype, "y", { - get: function () { - return this._position.y; - }, - set: function (value) { - this._position.y = value; - }, - enumerable: true, - configurable: true - }); - Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { - var oldOrigin = this._origin; - this.origin = new Vector2(newWidth / 2, newHeight / 2); - this.entity.position = Vector2.add(this.entity.position, Vector2.subtract(this._origin, oldOrigin)); - }; - Camera.prototype.setMinimumZoom = function (minZoom) { - if (this._zoom < minZoom) - this._zoom = this.minimumZoom; - this._minimumZoom = minZoom; - return this; - }; - Camera.prototype.setMaximumZoom = function (maxZoom) { - if (this._zoom > maxZoom) - this._zoom = maxZoom; - this._maximumZoom = maxZoom; - return this; - }; - Camera.prototype.setZoom = function (zoom) { - var newZoom = MathHelper.clamp(zoom, -1, 1); - if (newZoom == 0) { - this._zoom = 1; - } - else if (newZoom < 0) { - this._zoom = MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); - } - else { - this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); - } - SceneManager.scene.scaleX = this._zoom; - SceneManager.scene.scaleY = this._zoom; - return this; - }; - Camera.prototype.setRotation = function (rotation) { - SceneManager.scene.rotation = rotation; - return this; - }; - Camera.prototype.setPosition = function (position) { - this.entity.position = position; - return this; - }; - Camera.prototype.follow = function (targetEntity, cameraStyle) { - if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; } - this.targetEntity = targetEntity; - this.cameraStyle = cameraStyle; - var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - switch (this.cameraStyle) { - case CameraStyle.cameraWindow: - var w = cameraBounds.width / 6; - var h = cameraBounds.height / 3; - this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h); - break; - case CameraStyle.lockOn: - this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10); - break; - } - }; - Camera.prototype.update = function () { - var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); - this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; - this._worldSpaceDeadZone.width = this.deadzone.width; - this._worldSpaceDeadZone.height = this.deadzone.height; - if (this.targetEntity) - this.updateFollow(); - this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); - this.entity.roundPosition(); - if (this.mapLockEnabled) { - this.position = this.clampToMapSize(this.position); - this.entity.roundPosition(); - } - }; - Camera.prototype.clampToMapSize = function (position) { - var cameraBounds = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - var halfScreen = Vector2.multiply(new Vector2(cameraBounds.width, cameraBounds.height), new Vector2(0.5)); - var cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); - return Vector2.clamp(position, halfScreen, cameraMax); - }; - Camera.prototype.updateFollow = function () { - this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; - if (this.cameraStyle == CameraStyle.lockOn) { - var targetX = this.targetEntity.position.x; - var targetY = this.targetEntity.position.y; - if (this._worldSpaceDeadZone.x > targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - else if (this._worldSpaceDeadZone.x < targetX) - this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; - if (this._worldSpaceDeadZone.y < targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - else if (this._worldSpaceDeadZone.y > targetY) - this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; - } - else { - if (!this._targetCollider) { - this._targetCollider = this.targetEntity.getComponent(Collider); - if (!this._targetCollider) - return; - } - var targetBounds = this.targetEntity.getComponent(Collider).bounds; - if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { - if (this._worldSpaceDeadZone.left > targetBounds.left) - this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; - else if (this._worldSpaceDeadZone.right < targetBounds.right) - this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; - if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) - this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; - else if (this._worldSpaceDeadZone.top > targetBounds.top) - this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; - } - } - }; - return Camera; -}(Component)); -var CameraStyle; -(function (CameraStyle) { - CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; - CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; -})(CameraStyle || (CameraStyle = {})); -var ComponentPool = (function () { - function ComponentPool(typeClass) { - this._type = typeClass; - this._cache = []; - } - ComponentPool.prototype.obtain = function () { - try { - return this._cache.length > 0 ? this._cache.shift() : new this._type(); - } - catch (err) { - throw new Error(this._type + err); - } - }; - ComponentPool.prototype.free = function (component) { - component.reset(); - this._cache.push(component); - }; - return ComponentPool; -}()); -var PooledComponent = (function (_super) { - __extends(PooledComponent, _super); - function PooledComponent() { - return _super !== null && _super.apply(this, arguments) || this; - } - return PooledComponent; -}(Component)); -var RenderableComponent = (function (_super) { - __extends(RenderableComponent, _super); - function RenderableComponent() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._areBoundsDirty = true; - _this._bounds = new Rectangle(); - _this._localOffset = Vector2.zero; - _this.color = 0x000000; - return _this; - } - Object.defineProperty(RenderableComponent.prototype, "width", { - get: function () { - return this.getWidth(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "height", { - get: function () { - return this.getHeight(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "isVisible", { - get: function () { - return this._isVisible; - }, - set: function (value) { - this._isVisible = value; - if (this._isVisible) - this.onBecameVisible(); - else - this.onBecameInvisible(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponent.prototype, "bounds", { - get: function () { - return new Rectangle(this.getBounds().x, this.getBounds().y, this.getBounds().width, this.getBounds().height); - }, - enumerable: true, - configurable: true - }); - RenderableComponent.prototype.getWidth = function () { - return this.bounds.width; - }; - RenderableComponent.prototype.getHeight = function () { - return this.bounds.height; - }; - RenderableComponent.prototype.onBecameVisible = function () { }; - RenderableComponent.prototype.onBecameInvisible = function () { }; - RenderableComponent.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = camera.getBounds().intersects(this.getBounds()); - return this.isVisible; - }; - return RenderableComponent; -}(PooledComponent)); -var Mesh = (function (_super) { - __extends(Mesh, _super); - function Mesh() { - var _this = _super.call(this) || this; - _this._mesh = new egret.Mesh(); - return _this; - } - Mesh.prototype.setTexture = function (texture) { - this._mesh.texture = texture; - return this; - }; - Mesh.prototype.onAddedToEntity = function () { - this.addChild(this._mesh); - }; - Mesh.prototype.onRemovedFromEntity = function () { - this.removeChild(this._mesh); - }; - Mesh.prototype.render = function (camera) { - this.x = this.entity.position.x - camera.position.x + camera.origin.x; - this.y = this.entity.position.y - camera.position.y + camera.origin.y; - }; - Mesh.prototype.reset = function () { - }; - return Mesh; -}(RenderableComponent)); -var SpriteRenderer = (function (_super) { - __extends(SpriteRenderer, _super); - function SpriteRenderer() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(SpriteRenderer.prototype, "sprite", { - get: function () { - return this._sprite; - }, - set: function (value) { - this.setSprite(value); - }, - enumerable: true, - configurable: true - }); - SpriteRenderer.prototype.setSprite = function (sprite) { - this.removeChildren(); - this._sprite = sprite; - if (this._sprite) { - this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width; - this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height; - } - this.bitmap = new egret.Bitmap(sprite.texture2D); - this.addChild(this.bitmap); - return this; - }; - SpriteRenderer.prototype.setColor = function (color) { - var colorMatrix = [ - 1, 0, 0, 0, 0, - 0, 1, 0, 0, 0, - 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0 - ]; - colorMatrix[0] = Math.floor(color / 256 / 256) / 255; - colorMatrix[6] = Math.floor(color / 256 % 256) / 255; - colorMatrix[12] = color % 256 / 255; - var colorFilter = new egret.ColorMatrixFilter(colorMatrix); - this.filters = [colorFilter]; - return this; - }; - SpriteRenderer.prototype.isVisibleFromCamera = function (camera) { - this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds); - this.visible = this.isVisible; - return this.isVisible; - }; - SpriteRenderer.prototype.render = function (camera) { - if (this.x != -camera.position.x + camera.origin.x || - this.y != -camera.position.y + camera.origin.y) { - this.x = -camera.position.x + camera.origin.x; - this.y = -camera.position.y + camera.origin.y; - this.entity.onEntityTransformChanged(TransformComponent.position); - } - }; - SpriteRenderer.prototype.onRemovedFromEntity = function () { - if (this.parent) - this.parent.removeChild(this); - }; - SpriteRenderer.prototype.reset = function () { - }; - return SpriteRenderer; -}(RenderableComponent)); -var TiledSpriteRenderer = (function (_super) { - __extends(TiledSpriteRenderer, _super); - function TiledSpriteRenderer(sprite) { - var _this = _super.call(this) || this; - _this.leftTexture = new egret.Bitmap(); - _this.rightTexture = new egret.Bitmap(); - _this.leftTexture.texture = sprite.texture2D; - _this.rightTexture.texture = sprite.texture2D; - _this.setSprite(sprite); - _this.sourceRect = sprite.sourceRect; - return _this; - } - Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", { - get: function () { - return this.sourceRect.x; - }, - set: function (value) { - this.sourceRect.x = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", { - get: function () { - return this.sourceRect.y; - }, - set: function (value) { - this.sourceRect.y = value; - }, - enumerable: true, - configurable: true - }); - TiledSpriteRenderer.prototype.render = function (camera) { - if (!this.sprite) - return; - _super.prototype.render.call(this, camera); - var renderTexture = new egret.RenderTexture(); - var cacheBitmap = new egret.DisplayObjectContainer(); - cacheBitmap.removeChildren(); - cacheBitmap.addChild(this.leftTexture); - cacheBitmap.addChild(this.rightTexture); - this.leftTexture.x = this.sourceRect.x; - this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; - this.leftTexture.y = this.sourceRect.y; - this.rightTexture.y = this.sourceRect.y; - cacheBitmap.cacheAsBitmap = true; - renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); - this.bitmap.texture = renderTexture; - }; - return TiledSpriteRenderer; -}(SpriteRenderer)); -var ScrollingSpriteRenderer = (function (_super) { - __extends(ScrollingSpriteRenderer, _super); - function ScrollingSpriteRenderer() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.scrollSpeedX = 15; - _this.scroolSpeedY = 0; - _this._scrollX = 0; - _this._scrollY = 0; - return _this; - } - ScrollingSpriteRenderer.prototype.update = function () { - this._scrollX += this.scrollSpeedX * Time.deltaTime; - this._scrollY += this.scroolSpeedY * Time.deltaTime; - this.sourceRect.x = this._scrollX; - this.sourceRect.y = this._scrollY; - }; - ScrollingSpriteRenderer.prototype.render = function (camera) { - if (!this.sprite) - return; - _super.prototype.render.call(this, camera); - var renderTexture = new egret.RenderTexture(); - var cacheBitmap = new egret.DisplayObjectContainer(); - cacheBitmap.removeChildren(); - cacheBitmap.addChild(this.leftTexture); - cacheBitmap.addChild(this.rightTexture); - this.leftTexture.x = this.sourceRect.x; - this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; - this.leftTexture.y = this.sourceRect.y; - this.rightTexture.y = this.sourceRect.y; - cacheBitmap.cacheAsBitmap = true; - renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); - this.bitmap.texture = renderTexture; - }; - return ScrollingSpriteRenderer; -}(TiledSpriteRenderer)); -var Sprite = (function () { - function Sprite(texture, sourceRect, origin) { - if (sourceRect === void 0) { sourceRect = new Rectangle(0, 0, texture.textureWidth, texture.textureHeight); } - if (origin === void 0) { origin = sourceRect.getHalfSize(); } - this.uvs = new Rectangle(); - this.texture2D = texture; - this.sourceRect = sourceRect; - this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); - this.origin = origin; - var inverseTexW = 1 / texture.textureWidth; - var inverseTexH = 1 / texture.textureHeight; - this.uvs.x = sourceRect.x * inverseTexW; - this.uvs.y = sourceRect.y * inverseTexH; - this.uvs.width = sourceRect.width * inverseTexW; - this.uvs.height = sourceRect.height * inverseTexH; - } - return Sprite; -}()); -var SpriteAnimation = (function () { - function SpriteAnimation(sprites, frameRate) { - this.sprites = sprites; - this.frameRate = frameRate; - } - return SpriteAnimation; -}()); -var SpriteAnimator = (function (_super) { - __extends(SpriteAnimator, _super); - function SpriteAnimator(sprite) { - var _this = _super.call(this) || this; - _this.speed = 1; - _this.animationState = State.none; - _this._animations = new Map(); - _this._elapsedTime = 0; - if (sprite) - _this.setSprite(sprite); - return _this; - } - Object.defineProperty(SpriteAnimator.prototype, "isRunning", { - get: function () { - return this.animationState == State.running; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SpriteAnimator.prototype, "animations", { - get: function () { - return this._animations; - }, - enumerable: true, - configurable: true - }); - SpriteAnimator.prototype.addAnimation = function (name, animation) { - if (!this.sprite && animation.sprites.length > 0) - this.setSprite(animation.sprites[0]); - this._animations[name] = animation; - return this; - }; - SpriteAnimator.prototype.play = function (name, loopMode) { - if (loopMode === void 0) { loopMode = null; } - this.currentAnimation = this._animations[name]; - this.currentAnimationName = name; - this.currentFrame = 0; - this.animationState = State.running; - this.sprite = this.currentAnimation.sprites[0]; - this._elapsedTime = 0; - this._loopMode = loopMode ? loopMode : LoopMode.loop; - }; - SpriteAnimator.prototype.isAnimationActive = function (name) { - return this.currentAnimation && this.currentAnimationName == name; - }; - SpriteAnimator.prototype.pause = function () { - this.animationState = State.paused; - }; - SpriteAnimator.prototype.unPause = function () { - this.animationState = State.running; - }; - SpriteAnimator.prototype.stop = function () { - this.currentAnimation = null; - this.currentAnimationName = null; - this.currentFrame = 0; - this.animationState = State.none; - }; - SpriteAnimator.prototype.update = function () { - if (this.animationState != State.running || !this.currentAnimation) - return; - var animation = this.currentAnimation; - var secondsPerFrame = 1 / (animation.frameRate * this.speed); - var iterationDuration = secondsPerFrame * animation.sprites.length; - this._elapsedTime += Time.deltaTime; - var time = Math.abs(this._elapsedTime); - if (this._loopMode == LoopMode.once && time > iterationDuration || - this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) { - this.animationState = State.completed; - this._elapsedTime = 0; - this.currentFrame = 0; - this.sprite = animation.sprites[this.currentFrame]; - return; - } - var i = Math.floor(time / secondsPerFrame); - var n = animation.sprites.length; - if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) { - var maxIndex = n - 1; - this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2)); - } - else { - this.currentFrame = i % n; - } - this.sprite = animation.sprites[this.currentFrame]; - }; - return SpriteAnimator; -}(SpriteRenderer)); -var LoopMode; -(function (LoopMode) { - LoopMode[LoopMode["loop"] = 0] = "loop"; - LoopMode[LoopMode["once"] = 1] = "once"; - LoopMode[LoopMode["clampForever"] = 2] = "clampForever"; - LoopMode[LoopMode["pingPong"] = 3] = "pingPong"; - LoopMode[LoopMode["pingPongOnce"] = 4] = "pingPongOnce"; -})(LoopMode || (LoopMode = {})); -var State; -(function (State) { - State[State["none"] = 0] = "none"; - State[State["running"] = 1] = "running"; - State[State["paused"] = 2] = "paused"; - State[State["completed"] = 3] = "completed"; -})(State || (State = {})); -var Mover = (function (_super) { - __extends(Mover, _super); - function Mover() { - return _super !== null && _super.apply(this, arguments) || this; - } - Mover.prototype.onAddedToEntity = function () { - this._triggerHelper = new ColliderTriggerHelper(this.entity); - }; - Mover.prototype.calculateMovement = function (motion) { - var collisionResult = new CollisionResult(); - if (!this.entity.getComponent(Collider) || !this._triggerHelper) { - return null; - } - var colliders = this.entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - if (collider.isTrigger) - continue; - var bounds = collider.bounds; - bounds.x += motion.x; - bounds.y += motion.y; - var boxcastResult = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); - bounds = boxcastResult.bounds; - var neighbors = boxcastResult.tempHashSet; - for (var j = 0; j < neighbors.length; j++) { - var neighbor = neighbors[j]; - if (neighbor.isTrigger) - continue; - var _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult) { - motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); - if (_internalcollisionResult.collider) { - collisionResult = _internalcollisionResult; + }; + Scene.prototype.postRender = function () { + if (this.enablePostProcessing) { + for (var i = 0; i < this._postProcessors.length; i++) { + if (this._postProcessors[i].enabled) { + this._postProcessors[i].process(); } } } - } - ListPool.free(colliders); - return { collisionResult: collisionResult, motion: motion }; - }; - Mover.prototype.applyMovement = function (motion) { - this.entity.position = Vector2.add(this.entity.position, motion); - if (this._triggerHelper) - this._triggerHelper.update(); - }; - Mover.prototype.move = function (motion) { - var movementResult = this.calculateMovement(motion); - var collisionResult = movementResult.collisionResult; - motion = movementResult.motion; - this.applyMovement(motion); - return collisionResult; - }; - return Mover; -}(Component)); -var ProjectileMover = (function (_super) { - __extends(ProjectileMover, _super); - function ProjectileMover() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._tempTriggerList = []; - return _this; - } - ProjectileMover.prototype.onAddedToEntity = function () { - this._collider = this.entity.getComponent(Collider); - if (!this._collider) - console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!"); - }; - ProjectileMover.prototype.move = function (motion) { - if (!this._collider) - return false; - var didCollide = false; - this.entity.position = Vector2.add(this.entity.position, motion); - var neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); - for (var i = 0; i < neighbors.colliders.length; i++) { - var neighbor = neighbors.colliders[i]; - if (this._collider.overlaps(neighbor) && neighbor.enabled) { - didCollide = true; - this.notifyTriggerListeners(this._collider, neighbor); + }; + Scene.prototype.addRenderer = function (renderer) { + this._renderers.push(renderer); + this._renderers.sort(); + renderer.onAddedToScene(this); + return renderer; + }; + Scene.prototype.getRenderer = function (type) { + for (var i = 0; i < this._renderers.length; i++) { + if (this._renderers[i] instanceof type) + return this._renderers[i]; } - } - return didCollide; - }; - ProjectileMover.prototype.notifyTriggerListeners = function (self, other) { - other.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i = 0; i < this._tempTriggerList.length; i++) { - this._tempTriggerList[i].onTriggerEnter(self, other); - } - this._tempTriggerList.length = 0; - this.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i = 0; i < this._tempTriggerList.length; i++) { - this._tempTriggerList[i].onTriggerEnter(other, self); - } - this._tempTriggerList.length = 0; - }; - return ProjectileMover; -}(Component)); -var Collider = (function (_super) { - __extends(Collider, _super); - function Collider() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this.physicsLayer = 1 << 0; - _this.registeredPhysicsBounds = new Rectangle(); - _this.shouldColliderScaleAndRotateWithTransform = true; - _this.collidesWithLayers = Physics.allLayers; - return _this; - } - Object.defineProperty(Collider.prototype, "bounds", { - get: function () { - var shapeBounds = this.shape.bounds; - var colliderBuonds = new Rectangle(this.entity.x, this.entity.y, shapeBounds.width, shapeBounds.height); - return colliderBuonds; - }, - enumerable: true, - configurable: true - }); - Collider.prototype.registerColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { - Physics.addCollider(this); - this._isColliderRegistered = true; - } - }; - Collider.prototype.unregisterColliderWithPhysicsSystem = function () { - if (this._isParentEntityAddedToScene && this._isColliderRegistered) { - Physics.removeCollider(this); - } - this._isColliderRegistered = false; - }; - Collider.prototype.overlaps = function (other) { - return this.shape.overlaps(other.shape); - }; - Collider.prototype.collidesWith = function (collider, motion) { - var oldPosition = this.entity.position; - this.entity.position = Vector2.add(this.entity.position, motion); - var result = this.shape.collidesWithShape(collider.shape); - if (result) - result.collider = collider; - this.entity.position = oldPosition; - return result; - }; - Collider.prototype.onAddedToEntity = function () { - if (this._colliderRequiresAutoSizing) { - if (!(this instanceof BoxCollider || this instanceof CircleCollider)) { - console.error("Only box and circle colliders can be created automatically"); + return null; + }; + Scene.prototype.removeRenderer = function (renderer) { + if (!this._renderers.contains(renderer)) + return; + this._renderers.remove(renderer); + renderer.unload(); + }; + Scene.prototype.addPostProcessor = function (postProcessor) { + this._postProcessors.push(postProcessor); + this._postProcessors.sort(); + postProcessor.onAddedToScene(this); + if (this._didSceneBegin) { + postProcessor.onSceneBackBufferSizeChanged(this.stage.stageWidth, this.stage.stageHeight); } - var renderable = this.entity.getComponent(RenderableComponent); - if (renderable) { - var bounds = renderable.bounds; - var width = bounds.width / this.entity.scale.x; - var height = bounds.height / this.entity.scale.y; - if (this instanceof CircleCollider) { - var circleCollider = this; - circleCollider.radius = Math.max(width, height) * 0.5; + return postProcessor; + }; + Scene.prototype.getPostProcessor = function (type) { + for (var i = 0; i < this._postProcessors.length; i++) { + if (this._postProcessors[i] instanceof type) + return this._postProcessors[i]; + } + return null; + }; + Scene.prototype.removePostProcessor = function (postProcessor) { + if (!this._postProcessors.contains(postProcessor)) + return; + this._postProcessors.remove(postProcessor); + postProcessor.unload(); + }; + Scene.prototype.createEntity = function (name) { + var entity = new es.Entity(name); + return this.addEntity(entity); + }; + Scene.prototype.addEntity = function (entity) { + if (this.entities.buffer.contains(entity)) + console.warn("You are attempting to add the same entity to a scene twice: " + entity); + this.entities.add(entity); + entity.scene = this; + for (var i = 0; i < entity.transform.childCount; i++) + this.addEntity(entity.transform.getChild(i).entity); + return entity; + }; + Scene.prototype.destroyAllEntities = function () { + for (var i = 0; i < this.entities.count; i++) { + this.entities.buffer[i].destroy(); + } + }; + Scene.prototype.findEntity = function (name) { + return this.entities.findEntity(name); + }; + Scene.prototype.findEntitiesWithTag = function (tag) { + return this.entities.entitiesWithTag(tag); + }; + Scene.prototype.entitiesOfType = function (type) { + return this.entities.entitiesOfType(type); + }; + Scene.prototype.findComponentOfType = function (type) { + return this.entities.findComponentOfType(type); + }; + Scene.prototype.findComponentsOfType = function (type) { + return this.entities.findComponentsOfType(type); + }; + Scene.prototype.addEntityProcessor = function (processor) { + processor.scene = this; + this.entityProcessors.add(processor); + return processor; + }; + Scene.prototype.removeEntityProcessor = function (processor) { + this.entityProcessors.remove(processor); + }; + Scene.prototype.getEntityProcessor = function () { + return this.entityProcessors.getProcessor(); + }; + return Scene; + }(egret.DisplayObjectContainer)); + es.Scene = Scene; +})(es || (es = {})); +var es; +(function (es) { + var SceneManager = (function () { + function SceneManager(stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); + SceneManager._instnace = this; + SceneManager.emitter = new es.Emitter(); + SceneManager.content = new es.ContentManager(); + SceneManager.stage = stage; + SceneManager.initialize(stage); + SceneManager.timerRuler = new es.TimeRuler(); + } + Object.defineProperty(SceneManager, "Instance", { + get: function () { + return this._instnace; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SceneManager, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + if (!value) + throw new Error("场景不能为空"); + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + SceneManager.Instance.onSceneChanged(); } else { - this.width = width; - this.height = height; + this._nextScene = value; } - this.addChild(this.shape); + this.registerActiveSceneChanged(this._scene, this._nextScene); + }, + enumerable: true, + configurable: true + }); + SceneManager.initialize = function (stage) { + es.Input.initialize(stage); + }; + SceneManager.update = function () { + SceneManager.startDebugUpdate(); + es.Time.update(egret.getTimer()); + if (SceneManager._scene) { + for (var i = es.GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (es.GlobalManager.globalManagers[i].enabled) + es.GlobalManager.globalManagers[i].update(); + } + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + SceneManager._scene.update(); + } + if (SceneManager._nextScene) { + SceneManager._scene.end(); + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + SceneManager._instnace.onSceneChanged(); + SceneManager._scene.begin(); + } + } + SceneManager.endDebugUpdate(); + SceneManager.render(); + }; + SceneManager.render = function () { + if (this.sceneTransition) { + this.sceneTransition.preRender(); + if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { + this._scene.render(); + this._scene.postRender(); + this.sceneTransition.onBeginTransition(); + } + else if (this.sceneTransition) { + if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + this.sceneTransition.render(); + } + } + else if (this._scene) { + this._scene.render(); + es.Debug.render(); + this._scene.postRender(); + } + }; + SceneManager.startSceneTransition = function (sceneTransition) { + if (this.sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } + this.sceneTransition = sceneTransition; + return sceneTransition; + }; + SceneManager.registerActiveSceneChanged = function (current, next) { + if (this.activeSceneChanged) + this.activeSceneChanged(current, next); + }; + SceneManager.prototype.onSceneChanged = function () { + SceneManager.emitter.emit(es.CoreEvents.SceneChanged); + es.Time.sceneChanged(); + }; + SceneManager.startDebugUpdate = function () { + es.TimeRuler.Instance.startFrame(); + es.TimeRuler.Instance.beginMark("update", 0x00FF00); + }; + SceneManager.endDebugUpdate = function () { + es.TimeRuler.Instance.endMark("update"); + }; + return SceneManager; + }()); + es.SceneManager = SceneManager; +})(es || (es = {})); +var transform; +(function (transform) { + var Component; + (function (Component) { + Component[Component["position"] = 0] = "position"; + Component[Component["scale"] = 1] = "scale"; + Component[Component["rotation"] = 2] = "rotation"; + })(Component = transform.Component || (transform.Component = {})); +})(transform || (transform = {})); +var es; +(function (es) { + var DirtyType; + (function (DirtyType) { + DirtyType[DirtyType["clean"] = 0] = "clean"; + DirtyType[DirtyType["positionDirty"] = 1] = "positionDirty"; + DirtyType[DirtyType["scaleDirty"] = 2] = "scaleDirty"; + DirtyType[DirtyType["rotationDirty"] = 3] = "rotationDirty"; + })(DirtyType = es.DirtyType || (es.DirtyType = {})); + var Transform = (function () { + function Transform(entity) { + this.entity = entity; + this.scale = es.Vector2.one; + this._children = []; + } + Object.defineProperty(Transform.prototype, "parent", { + get: function () { + return this._parent; + }, + set: function (value) { + this.setParent(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "childCount", { + get: function () { + return this._children.length; + }, + enumerable: true, + configurable: true + }); + Transform.prototype.getChild = function (index) { + return this._children[index]; + }; + Transform.prototype.setParent = function (parent) { + if (this._parent == parent) + return this; + if (!this._parent) { + this._parent._children.remove(this); + this._parent._children.push(this); + } + this._parent = parent; + this.setDirty(DirtyType.positionDirty); + return this; + }; + Transform.prototype.setPosition = function (x, y) { + this.position = new es.Vector2(x, y); + this.setDirty(DirtyType.positionDirty); + return this; + }; + Transform.prototype.setRotation = function (degrees) { + this.rotation = degrees; + this.setDirty(DirtyType.rotationDirty); + return this; + }; + Transform.prototype.setScale = function (scale) { + this.scale = scale; + this.setDirty(DirtyType.scaleDirty); + return this; + }; + Transform.prototype.lookAt = function (pos) { + var sign = this.position.x > pos.x ? -1 : 1; + var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos)); + this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY)); + }; + Transform.prototype.roundPosition = function () { + this.position = this.position.round(); + }; + Transform.prototype.setDirty = function (dirtyFlagType) { + if ((this.hierarchyDirty & dirtyFlagType) == 0) { + this.hierarchyDirty |= dirtyFlagType; + switch (dirtyFlagType) { + case es.DirtyType.positionDirty: + this.entity.onTransformChanged(transform.Component.position); + break; + case es.DirtyType.rotationDirty: + this.entity.onTransformChanged(transform.Component.rotation); + break; + case es.DirtyType.scaleDirty: + this.entity.onTransformChanged(transform.Component.scale); + break; + } + if (!this._children) + this._children = []; + for (var i = 0; i < this._children.length; i++) + this._children[i].setDirty(dirtyFlagType); + } + }; + Transform.prototype.copyFrom = function (transform) { + this.position = transform.position; + this.rotation = transform.rotation; + this.scale = transform.scale; + this.setDirty(DirtyType.positionDirty); + this.setDirty(DirtyType.rotationDirty); + this.setDirty(DirtyType.scaleDirty); + }; + return Transform; + }()); + es.Transform = Transform; +})(es || (es = {})); +var es; +(function (es) { + var CameraStyle; + (function (CameraStyle) { + CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; + CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; + })(CameraStyle = es.CameraStyle || (es.CameraStyle = {})); + var Camera = (function (_super) { + __extends(Camera, _super); + function Camera(targetEntity, cameraStyle) { + if (targetEntity === void 0) { targetEntity = null; } + if (cameraStyle === void 0) { cameraStyle = CameraStyle.lockOn; } + var _this = _super.call(this) || this; + _this._minimumZoom = 0.3; + _this._maximumZoom = 3; + _this._origin = es.Vector2.zero; + _this.followLerp = 0.1; + _this.deadzone = new es.Rectangle(); + _this.focusOffset = new es.Vector2(); + _this.mapLockEnabled = false; + _this.mapSize = new es.Vector2(); + _this._desiredPositionDelta = new es.Vector2(); + _this._worldSpaceDeadZone = new es.Rectangle(); + _this._targetEntity = targetEntity; + _this._cameraStyle = cameraStyle; + _this.setZoom(0); + return _this; + } + Object.defineProperty(Camera.prototype, "position", { + get: function () { + return this.entity.transform.position; + }, + set: function (value) { + this.entity.transform.position = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "rotation", { + get: function () { + return this.entity.transform.rotation; + }, + set: function (value) { + this.entity.transform.rotation = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "zoom", { + get: function () { + if (this._zoom == 0) + return 1; + if (this._zoom < 1) + return es.MathHelper.map(this._zoom, this._minimumZoom, 1, -1, 0); + return es.MathHelper.map(this._zoom, 1, this._maximumZoom, 0, 1); + }, + set: function (value) { + this.setZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "minimumZoom", { + get: function () { + return this._minimumZoom; + }, + set: function (value) { + this.setMinimumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "maximumZoom", { + get: function () { + return this._maximumZoom; + }, + set: function (value) { + this.setMaximumZoom(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "bounds", { + get: function () { + return new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + if (this._origin != value) { + this._origin = value; + } + }, + enumerable: true, + configurable: true + }); + Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) { + var oldOrigin = this._origin; + this.origin = new es.Vector2(newWidth / 2, newHeight / 2); + this.entity.transform.position = es.Vector2.add(this.entity.transform.position, es.Vector2.subtract(this._origin, oldOrigin)); + }; + Camera.prototype.setPosition = function (position) { + this.entity.transform.setPosition(position.x, position.y); + return this; + }; + Camera.prototype.setRotation = function (rotation) { + this.entity.transform.setRotation(rotation); + return this; + }; + Camera.prototype.setZoom = function (zoom) { + var newZoom = es.MathHelper.clamp(zoom, -1, 1); + if (newZoom == 0) { + this._zoom = 1; + } + else if (newZoom < 0) { + this._zoom = es.MathHelper.map(newZoom, -1, 0, this._minimumZoom, 1); } else { - console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); + this._zoom = es.MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); } - } - this._isParentEntityAddedToScene = true; - this.registerColliderWithPhysicsSystem(); - }; - Collider.prototype.onRemovedFromEntity = function () { - this.unregisterColliderWithPhysicsSystem(); - this._isParentEntityAddedToScene = false; - this.removeChild(this.shape); - }; - Collider.prototype.onEnabled = function () { - this.registerColliderWithPhysicsSystem(); - }; - Collider.prototype.onDisabled = function () { - this.unregisterColliderWithPhysicsSystem(); - }; - Collider.prototype.onEntityTransformChanged = function (comp) { - if (this._isColliderRegistered) - Physics.updateCollider(this); - }; - Collider.prototype.update = function () { - var renderable = this.entity.getComponent(RenderableComponent); - if (renderable) { - this.$setX(renderable.x); - this.$setY(renderable.y); - } - }; - return Collider; -}(Component)); -var BoxCollider = (function (_super) { - __extends(BoxCollider, _super); - function BoxCollider() { - var _this = _super.call(this) || this; - _this.shape = new Box(1, 1); - _this._colliderRequiresAutoSizing = true; - return _this; - } - Object.defineProperty(BoxCollider.prototype, "width", { - get: function () { - return this.shape.width; - }, - set: function (value) { - this.setWidth(value); - }, - enumerable: true, - configurable: true - }); - BoxCollider.prototype.setWidth = function (width) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width) { - box.updateBox(width, box.height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - Object.defineProperty(BoxCollider.prototype, "height", { - get: function () { - return this.shape.height; - }, - set: function (value) { - this.setHeight(value); - }, - enumerable: true, - configurable: true - }); - BoxCollider.prototype.setHeight = function (height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (height != box.height) { - box.updateBox(box.width, height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - }; - BoxCollider.prototype.setSize = function (width, height) { - this._colliderRequiresAutoSizing = false; - var box = this.shape; - if (width != box.width || height != box.height) { - box.updateBox(width, height); - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - return BoxCollider; -}(Collider)); -var CircleCollider = (function (_super) { - __extends(CircleCollider, _super); - function CircleCollider(radius) { - var _this = _super.call(this) || this; - if (radius) - _this._colliderRequiresAutoSizing = true; - _this.shape = new Circle(radius ? radius : 1); - return _this; - } - Object.defineProperty(CircleCollider.prototype, "radius", { - get: function () { - return this.shape.radius; - }, - set: function (value) { - this.setRadius(value); - }, - enumerable: true, - configurable: true - }); - CircleCollider.prototype.setRadius = function (radius) { - this._colliderRequiresAutoSizing = false; - var circle = this.shape; - if (radius != circle.radius) { - circle.radius = radius; - circle._originalRadius = radius; - if (this.entity && this._isParentEntityAddedToScene) - Physics.updateCollider(this); - } - return this; - }; - return CircleCollider; -}(Collider)); -var PolygonCollider = (function (_super) { - __extends(PolygonCollider, _super); - function PolygonCollider(points) { - var _this = _super.call(this) || this; - var isPolygonClosed = points[0] == points[points.length - 1]; - if (isPolygonClosed) - points.splice(points.length - 1, 1); - Polygon.recenterPolygonVerts(points); - _this.shape = new Polygon(points); - return _this; - } - return PolygonCollider; -}(Collider)); -var EntitySystem = (function () { - function EntitySystem(matcher) { - this._entities = []; - this._matcher = matcher ? matcher : Matcher.empty(); - } - Object.defineProperty(EntitySystem.prototype, "matcher", { - get: function () { - return this._matcher; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(EntitySystem.prototype, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - this._scene = value; - this._entities = []; - }, - enumerable: true, - configurable: true - }); - EntitySystem.prototype.initialize = function () { - }; - EntitySystem.prototype.onChanged = function (entity) { - var contains = this._entities.contains(entity); - var interest = this._matcher.IsIntersted(entity); - if (interest && !contains) - this.add(entity); - else if (!interest && contains) - this.remove(entity); - }; - EntitySystem.prototype.add = function (entity) { - this._entities.push(entity); - this.onAdded(entity); - }; - EntitySystem.prototype.onAdded = function (entity) { - }; - EntitySystem.prototype.remove = function (entity) { - this._entities.remove(entity); - this.onRemoved(entity); - }; - EntitySystem.prototype.onRemoved = function (entity) { - }; - EntitySystem.prototype.update = function () { - this.begin(); - this.process(this._entities); - }; - EntitySystem.prototype.lateUpdate = function () { - this.lateProcess(this._entities); - this.end(); - }; - EntitySystem.prototype.begin = function () { - }; - EntitySystem.prototype.process = function (entities) { - }; - EntitySystem.prototype.lateProcess = function (entities) { - }; - EntitySystem.prototype.end = function () { - }; - return EntitySystem; -}()); -var EntityProcessingSystem = (function (_super) { - __extends(EntityProcessingSystem, _super); - function EntityProcessingSystem(matcher) { - return _super.call(this, matcher) || this; - } - EntityProcessingSystem.prototype.lateProcessEntity = function (entity) { - }; - EntityProcessingSystem.prototype.process = function (entities) { - var _this = this; - entities.forEach(function (entity) { return _this.processEntity(entity); }); - }; - EntityProcessingSystem.prototype.lateProcess = function (entities) { - var _this = this; - entities.forEach(function (entity) { return _this.lateProcessEntity(entity); }); - }; - return EntityProcessingSystem; -}(EntitySystem)); -var PassiveSystem = (function (_super) { - __extends(PassiveSystem, _super); - function PassiveSystem() { - return _super !== null && _super.apply(this, arguments) || this; - } - PassiveSystem.prototype.onChanged = function (entity) { - }; - PassiveSystem.prototype.process = function (entities) { - this.begin(); - this.end(); - }; - return PassiveSystem; -}(EntitySystem)); -var ProcessingSystem = (function (_super) { - __extends(ProcessingSystem, _super); - function ProcessingSystem() { - return _super !== null && _super.apply(this, arguments) || this; - } - ProcessingSystem.prototype.onChanged = function (entity) { - }; - ProcessingSystem.prototype.process = function (entities) { - this.begin(); - this.processSystem(); - this.end(); - }; - return ProcessingSystem; -}(EntitySystem)); -var BitSet = (function () { - function BitSet(nbits) { - if (nbits === void 0) { nbits = 64; } - var length = nbits >> 6; - if ((nbits & BitSet.LONG_MASK) != 0) - length++; - this._bits = new Array(length); - } - BitSet.prototype.and = function (bs) { - var max = Math.min(this._bits.length, bs._bits.length); - var i; - for (var i_1 = 0; i_1 < max; ++i_1) - this._bits[i_1] &= bs._bits[i_1]; - while (i < this._bits.length) - this._bits[i++] = 0; - }; - BitSet.prototype.andNot = function (bs) { - var i = Math.min(this._bits.length, bs._bits.length); - while (--i >= 0) - this._bits[i] &= ~bs._bits[i]; - }; - BitSet.prototype.cardinality = function () { - var card = 0; - for (var i = this._bits.length - 1; i >= 0; i--) { - var a = this._bits[i]; - if (a == 0) - continue; - if (a == -1) { - card += 64; - continue; + es.SceneManager.scene.scaleX = this._zoom; + es.SceneManager.scene.scaleY = this._zoom; + return this; + }; + Camera.prototype.setMinimumZoom = function (minZoom) { + if (this._zoom < minZoom) + this._zoom = this.minimumZoom; + this._minimumZoom = minZoom; + return this; + }; + Camera.prototype.setMaximumZoom = function (maxZoom) { + if (maxZoom <= 0) { + console.error("maximumZoom must be greater than zero"); + return; } - a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); - a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); - var b = ((a >> 32) + a); - b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); - b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); - card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); - } - return card; - }; - BitSet.prototype.clear = function (pos) { - if (pos != undefined) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] &= ~(1 << pos); - } - else { - for (var i = 0; i < this._bits.length; i++) - this._bits[i] = 0; - } - }; - BitSet.prototype.ensure = function (lastElt) { - if (lastElt >= this._bits.length) { - var nd = new Number[lastElt + 1]; - nd = this._bits.copyWithin(0, 0, this._bits.length); - this._bits = nd; - } - }; - BitSet.prototype.get = function (pos) { - var offset = pos >> 6; - if (offset >= this._bits.length) - return false; - return (this._bits[offset] & (1 << pos)) != 0; - }; - BitSet.prototype.intersects = function (set) { - var i = Math.min(this._bits.length, set._bits.length); - while (--i >= 0) { - if ((this._bits[i] & set._bits[i]) != 0) - return true; - } - return false; - }; - BitSet.prototype.isEmpty = function () { - for (var i = this._bits.length - 1; i >= 0; i--) { - if (this._bits[i]) - return false; - } - return true; - }; - BitSet.prototype.nextSetBit = function (from) { - var offset = from >> 6; - var mask = 1 << from; - while (offset < this._bits.length) { - var h = this._bits[offset]; - do { - if ((h & mask) != 0) - return from; - mask <<= 1; - from++; - } while (mask != 0); - mask = 1; - offset++; - } - return -1; - }; - BitSet.prototype.set = function (pos, value) { - if (value === void 0) { value = true; } - if (value) { - var offset = pos >> 6; - this.ensure(offset); - this._bits[offset] |= 1 << pos; - } - else { - this.clear(pos); - } - }; - BitSet.LONG_MASK = 0x3f; - return BitSet; -}()); -var ComponentList = (function () { - function ComponentList(entity) { - this._components = []; - this._componentsToAdd = []; - this._componentsToRemove = []; - this._tempBufferList = []; - this._entity = entity; - } - Object.defineProperty(ComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true - }); - ComponentList.prototype.add = function (component) { - this._componentsToAdd.push(component); - }; - ComponentList.prototype.remove = function (component) { - if (this._componentsToRemove.contains(component)) - console.warn("You are trying to remove a Component (" + component + ") that you already removed"); - if (this._componentsToAdd.contains(component)) { - this._componentsToAdd.remove(component); - return; - } - this._componentsToRemove.push(component); - }; - ComponentList.prototype.removeAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - this.handleRemove(this._components[i]); - } - this._components.length = 0; - this._componentsToAdd.length = 0; - this._componentsToRemove.length = 0; - }; - ComponentList.prototype.deregisterAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - } - }; - ComponentList.prototype.registerAllComponents = function () { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - } - }; - ComponentList.prototype.updateLists = function () { - if (this._componentsToRemove.length > 0) { - for (var i = 0; i < this._componentsToRemove.length; i++) { - this.handleRemove(this._componentsToRemove[i]); - this._components.remove(this._componentsToRemove[i]); + if (this._zoom > maxZoom) + this._zoom = maxZoom; + this._maximumZoom = maxZoom; + return this; + }; + Camera.prototype.zoomIn = function (deltaZoom) { + this.zoom += deltaZoom; + }; + Camera.prototype.zoomOut = function (deltaZoom) { + this.zoom -= deltaZoom; + }; + Camera.prototype.onAddedToEntity = function () { + this.follow(this._targetEntity, this._cameraStyle); + }; + Camera.prototype.update = function () { + var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)); + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.width = this.deadzone.width; + this._worldSpaceDeadZone.height = this.deadzone.height; + if (this._targetEntity) + this.updateFollow(); + this.position = es.Vector2.lerp(this.position, es.Vector2.add(this.position, this._desiredPositionDelta), this.followLerp); + this.entity.transform.roundPosition(); + if (this.mapLockEnabled) { + this.position = this.clampToMapSize(this.position); + this.entity.transform.roundPosition(); } - this._componentsToRemove.length = 0; - } - if (this._componentsToAdd.length > 0) { - for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { - var component = this._componentsToAdd[i]; - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.add(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); - this._entity.scene.entityProcessors.onComponentAdded(this._entity); - this._components.push(component); - this._tempBufferList.push(component); + }; + Camera.prototype.clampToMapSize = function (position) { + var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)); + var cameraMax = new es.Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y); + return es.Vector2.clamp(position, halfScreen, cameraMax); + }; + Camera.prototype.updateFollow = function () { + this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0; + if (this._cameraStyle == CameraStyle.lockOn) { + var targetX = this._targetEntity.transform.position.x; + var targetY = this._targetEntity.transform.position.y; + if (this._worldSpaceDeadZone.x > targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + else if (this._worldSpaceDeadZone.x < targetX) + this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x; + if (this._worldSpaceDeadZone.y < targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; + else if (this._worldSpaceDeadZone.y > targetY) + this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y; } - this._componentsToAdd.length = 0; - for (var i = 0; i < this._tempBufferList.length; i++) { - var component = this._tempBufferList[i]; - component.onAddedToEntity(); - if (component.enabled) { - component.onEnabled(); + else { + if (!this._targetCollider) { + this._targetCollider = this._targetEntity.getComponent(es.Collider); + if (!this._targetCollider) + return; + } + var targetBounds = this._targetEntity.getComponent(es.Collider).bounds; + if (!this._worldSpaceDeadZone.containsRect(targetBounds)) { + if (this._worldSpaceDeadZone.left > targetBounds.left) + this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left; + else if (this._worldSpaceDeadZone.right < targetBounds.right) + this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right; + if (this._worldSpaceDeadZone.bottom < targetBounds.bottom) + this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom; + else if (this._worldSpaceDeadZone.top > targetBounds.top) + this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top; } } - this._tempBufferList.length = 0; + }; + Camera.prototype.follow = function (targetEntity, cameraStyle) { + if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; } + this._targetEntity = targetEntity; + this._cameraStyle = cameraStyle; + switch (this._cameraStyle) { + case CameraStyle.cameraWindow: + var w = this.bounds.width / 6; + var h = this.bounds.height / 3; + this.deadzone = new es.Rectangle((this.bounds.width - w) / 2, (this.bounds.height - h) / 2, w, h); + break; + case CameraStyle.lockOn: + this.deadzone = new es.Rectangle(this.bounds.width / 2, this.bounds.height / 2, 10, 10); + break; + } + }; + Camera.prototype.setCenteredDeadzone = function (width, height) { + this.deadzone = new es.Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height); + }; + return Camera; + }(es.Component)); + es.Camera = Camera; +})(es || (es = {})); +var es; +(function (es) { + var ComponentPool = (function () { + function ComponentPool(typeClass) { + this._type = typeClass; + this._cache = []; } - }; - ComponentList.prototype.onEntityTransformChanged = function (comp) { - for (var i = 0; i < this._components.length; i++) { - if (this._components[i].enabled) - this._components[i].onEntityTransformChanged(comp); + ComponentPool.prototype.obtain = function () { + try { + return this._cache.length > 0 ? this._cache.shift() : new this._type(); + } + catch (err) { + throw new Error(this._type + err); + } + }; + ComponentPool.prototype.free = function (component) { + component.reset(); + this._cache.push(component); + }; + return ComponentPool; + }()); + es.ComponentPool = ComponentPool; +})(es || (es = {})); +var es; +(function (es) { + var IUpdatableComparer = (function () { + function IUpdatableComparer() { } - for (var i = 0; i < this._componentsToAdd.length; i++) { - if (this._componentsToAdd[i].enabled) - this._componentsToAdd[i].onEntityTransformChanged(comp); + IUpdatableComparer.prototype.compare = function (a, b) { + return a.updateOrder - b.updateOrder; + }; + return IUpdatableComparer; + }()); + es.IUpdatableComparer = IUpdatableComparer; +})(es || (es = {})); +var es; +(function (es) { + var PooledComponent = (function (_super) { + __extends(PooledComponent, _super); + function PooledComponent() { + return _super !== null && _super.apply(this, arguments) || this; } - }; - ComponentList.prototype.handleRemove = function (component) { - if (component instanceof RenderableComponent) - this._entity.scene.renderableComponents.remove(component); - this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); - this._entity.scene.entityProcessors.onComponentRemoved(this._entity); - component.onRemovedFromEntity(); - component.entity = null; - }; - ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) { - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (component instanceof type) - return component; + return PooledComponent; + }(es.Component)); + es.PooledComponent = PooledComponent; +})(es || (es = {})); +var es; +(function (es) { + var RenderableComponent = (function (_super) { + __extends(RenderableComponent, _super); + function RenderableComponent() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.color = 0x000000; + _this._localOffset = es.Vector2.zero; + _this._renderLayer = 0; + _this._bounds = new es.Rectangle(); + _this._areBoundsDirty = true; + return _this; } - if (!onlyReturnInitializedComponents) { - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; + Object.defineProperty(RenderableComponent.prototype, "width", { + get: function () { + return this.bounds.width; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "height", { + get: function () { + return this.bounds.height; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "bounds", { + get: function () { + if (this._areBoundsDirty) { + this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, es.Vector2.zero, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height); + this._areBoundsDirty = false; + } + return this._bounds; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "renderLayer", { + get: function () { + return this._renderLayer; + }, + set: function (value) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "localOffset", { + get: function () { + return this._localOffset; + }, + set: function (value) { + this.setLocalOffset(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponent.prototype, "isVisible", { + get: function () { + return this._isVisible; + }, + set: function (value) { + if (this._isVisible != value) { + this._isVisible = value; + if (this._isVisible) + this.onBecameVisible(); + else + this.onBecameInvisible(); + } + }, + enumerable: true, + configurable: true + }); + RenderableComponent.prototype.onEntityTransformChanged = function (comp) { + this._areBoundsDirty = true; + }; + RenderableComponent.prototype.onBecameVisible = function () { + }; + RenderableComponent.prototype.onBecameInvisible = function () { + }; + RenderableComponent.prototype.isVisibleFromCamera = function (camera) { + this.isVisible = camera.bounds.intersects(this.bounds); + return this.isVisible; + }; + RenderableComponent.prototype.setRenderLayer = function (renderLayer) { + if (renderLayer != this._renderLayer) { + var oldRenderLayer = this._renderLayer; + this._renderLayer = renderLayer; + if (this.entity && this.entity.scene) + this.entity.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer); + } + return this; + }; + RenderableComponent.prototype.setColor = function (color) { + this.color = color; + return this; + }; + RenderableComponent.prototype.setLocalOffset = function (offset) { + if (this._localOffset != offset) { + this._localOffset = offset; + } + return this; + }; + RenderableComponent.prototype.toString = function () { + return "[RenderableComponent] " + this + ", renderLayer: " + this.renderLayer; + }; + return RenderableComponent; + }(es.Component)); + es.RenderableComponent = RenderableComponent; +})(es || (es = {})); +var es; +(function (es) { + var Mesh = (function (_super) { + __extends(Mesh, _super); + function Mesh() { + var _this = _super.call(this) || this; + _this._mesh = new egret.Mesh(); + return _this; + } + Mesh.prototype.setTexture = function (texture) { + this._mesh.texture = texture; + return this; + }; + Mesh.prototype.reset = function () { + }; + Mesh.prototype.render = function (camera) { + }; + return Mesh; + }(es.RenderableComponent)); + es.Mesh = Mesh; +})(es || (es = {})); +var es; +(function (es) { + var SpriteRenderer = (function (_super) { + __extends(SpriteRenderer, _super); + function SpriteRenderer(sprite) { + if (sprite === void 0) { sprite = null; } + var _this = _super.call(this) || this; + if (sprite instanceof es.Sprite) + _this.setSprite(sprite); + else if (sprite instanceof egret.Texture) + _this.setSprite(new es.Sprite(sprite)); + return _this; + } + Object.defineProperty(SpriteRenderer.prototype, "bounds", { + get: function () { + if (this._areBoundsDirty) { + if (this._sprite) { + this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.sourceRect.width, this._sprite.sourceRect.height); + this._areBoundsDirty = false; + } + return this._bounds; + } + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteRenderer.prototype, "origin", { + get: function () { + return this._origin; + }, + set: function (value) { + this.setOrigin(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteRenderer.prototype, "originNormalized", { + get: function () { + return new es.Vector2(this._origin.x / this.width * this.entity.transform.scale.x, this._origin.y / this.height * this.entity.transform.scale.y); + }, + set: function (value) { + this.setOrigin(new es.Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteRenderer.prototype, "sprite", { + get: function () { + return this._sprite; + }, + set: function (value) { + this.setSprite(value); + }, + enumerable: true, + configurable: true + }); + SpriteRenderer.prototype.setSprite = function (sprite) { + this._sprite = sprite; + if (this._sprite) { + this._origin = this._sprite.origin; + } + return this; + }; + SpriteRenderer.prototype.setOrigin = function (origin) { + if (this._origin != origin) { + this._origin = origin; + this._areBoundsDirty = true; + } + return this; + }; + SpriteRenderer.prototype.setOriginNormalized = function (value) { + this.setOrigin(new es.Vector2(value.x * this.width / this.entity.transform.scale.x, value.y * this.height / this.entity.transform.scale.y)); + return this; + }; + SpriteRenderer.prototype.render = function (camera) { + }; + return SpriteRenderer; + }(es.RenderableComponent)); + es.SpriteRenderer = SpriteRenderer; +})(es || (es = {})); +var es; +(function (es) { + var TiledSpriteRenderer = (function (_super) { + __extends(TiledSpriteRenderer, _super); + function TiledSpriteRenderer(sprite) { + var _this = _super.call(this, sprite) || this; + _this.leftTexture = new egret.Bitmap(); + _this.rightTexture = new egret.Bitmap(); + _this.leftTexture.texture = sprite.texture2D; + _this.rightTexture.texture = sprite.texture2D; + _this.setSprite(sprite); + _this.sourceRect = sprite.sourceRect; + return _this; + } + Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", { + get: function () { + return this.sourceRect.x; + }, + set: function (value) { + this.sourceRect.x = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", { + get: function () { + return this.sourceRect.y; + }, + set: function (value) { + this.sourceRect.y = value; + }, + enumerable: true, + configurable: true + }); + TiledSpriteRenderer.prototype.render = function (camera) { + if (!this.sprite) + return; + _super.prototype.render.call(this, camera); + var renderTexture = new egret.RenderTexture(); + var cacheBitmap = new egret.DisplayObjectContainer(); + cacheBitmap.removeChildren(); + cacheBitmap.addChild(this.leftTexture); + cacheBitmap.addChild(this.rightTexture); + this.leftTexture.x = this.sourceRect.x; + this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; + this.leftTexture.y = this.sourceRect.y; + this.rightTexture.y = this.sourceRect.y; + cacheBitmap.cacheAsBitmap = true; + renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); + }; + return TiledSpriteRenderer; + }(es.SpriteRenderer)); + es.TiledSpriteRenderer = TiledSpriteRenderer; +})(es || (es = {})); +var es; +(function (es) { + var ScrollingSpriteRenderer = (function (_super) { + __extends(ScrollingSpriteRenderer, _super); + function ScrollingSpriteRenderer() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.scrollSpeedX = 15; + _this.scroolSpeedY = 0; + _this._scrollX = 0; + _this._scrollY = 0; + return _this; + } + ScrollingSpriteRenderer.prototype.update = function () { + this._scrollX += this.scrollSpeedX * es.Time.deltaTime; + this._scrollY += this.scroolSpeedY * es.Time.deltaTime; + this.sourceRect.x = this._scrollX; + this.sourceRect.y = this._scrollY; + }; + ScrollingSpriteRenderer.prototype.render = function (camera) { + if (!this.sprite) + return; + _super.prototype.render.call(this, camera); + var renderTexture = new egret.RenderTexture(); + var cacheBitmap = new egret.DisplayObjectContainer(); + cacheBitmap.removeChildren(); + cacheBitmap.addChild(this.leftTexture); + cacheBitmap.addChild(this.rightTexture); + this.leftTexture.x = this.sourceRect.x; + this.rightTexture.x = this.sourceRect.x - this.sourceRect.width; + this.leftTexture.y = this.sourceRect.y; + this.rightTexture.y = this.sourceRect.y; + cacheBitmap.cacheAsBitmap = true; + renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height)); + }; + return ScrollingSpriteRenderer; + }(es.TiledSpriteRenderer)); + es.ScrollingSpriteRenderer = ScrollingSpriteRenderer; +})(es || (es = {})); +var es; +(function (es) { + var Sprite = (function () { + function Sprite(texture, sourceRect, origin) { + if (sourceRect === void 0) { sourceRect = new es.Rectangle(0, 0, texture.textureWidth, texture.textureHeight); } + if (origin === void 0) { origin = sourceRect.getHalfSize(); } + this.uvs = new es.Rectangle(); + this.texture2D = texture; + this.sourceRect = sourceRect; + this.center = new es.Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5); + this.origin = origin; + var inverseTexW = 1 / texture.textureWidth; + var inverseTexH = 1 / texture.textureHeight; + this.uvs.x = sourceRect.x * inverseTexW; + this.uvs.y = sourceRect.y * inverseTexH; + this.uvs.width = sourceRect.width * inverseTexW; + this.uvs.height = sourceRect.height * inverseTexH; + } + return Sprite; + }()); + es.Sprite = Sprite; +})(es || (es = {})); +var es; +(function (es) { + var SpriteAnimation = (function () { + function SpriteAnimation(sprites, frameRate) { + this.sprites = sprites; + this.frameRate = frameRate; + } + return SpriteAnimation; + }()); + es.SpriteAnimation = SpriteAnimation; +})(es || (es = {})); +var es; +(function (es) { + var LoopMode; + (function (LoopMode) { + LoopMode[LoopMode["loop"] = 0] = "loop"; + LoopMode[LoopMode["once"] = 1] = "once"; + LoopMode[LoopMode["clampForever"] = 2] = "clampForever"; + LoopMode[LoopMode["pingPong"] = 3] = "pingPong"; + LoopMode[LoopMode["pingPongOnce"] = 4] = "pingPongOnce"; + })(LoopMode = es.LoopMode || (es.LoopMode = {})); + var State; + (function (State) { + State[State["none"] = 0] = "none"; + State[State["running"] = 1] = "running"; + State[State["paused"] = 2] = "paused"; + State[State["completed"] = 3] = "completed"; + })(State = es.State || (es.State = {})); + var SpriteAnimator = (function (_super) { + __extends(SpriteAnimator, _super); + function SpriteAnimator(sprite) { + var _this = _super.call(this, sprite) || this; + _this.speed = 1; + _this.animationState = State.none; + _this._animations = new Map(); + _this._elapsedTime = 0; + return _this; + } + Object.defineProperty(SpriteAnimator.prototype, "isRunning", { + get: function () { + return this.animationState == State.running; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(SpriteAnimator.prototype, "animations", { + get: function () { + return this._animations; + }, + enumerable: true, + configurable: true + }); + SpriteAnimator.prototype.update = function () { + if (this.animationState != State.running || !this.currentAnimation) + return; + var animation = this.currentAnimation; + var secondsPerFrame = 1 / (animation.frameRate * this.speed); + var iterationDuration = secondsPerFrame * animation.sprites.length; + this._elapsedTime += es.Time.deltaTime; + var time = Math.abs(this._elapsedTime); + if (this._loopMode == LoopMode.once && time > iterationDuration || + this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) { + this.animationState = State.completed; + this._elapsedTime = 0; + this.currentFrame = 0; + this.sprite = animation.sprites[this.currentFrame]; + return; + } + var i = Math.floor(time / secondsPerFrame); + var n = animation.sprites.length; + if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) { + var maxIndex = n - 1; + this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2)); + } + else { + this.currentFrame = i % n; + } + this.sprite = animation.sprites[this.currentFrame]; + }; + SpriteAnimator.prototype.addAnimation = function (name, animation) { + if (!this.sprite && animation.sprites.length > 0) + this.setSprite(animation.sprites[0]); + this._animations[name] = animation; + return this; + }; + SpriteAnimator.prototype.play = function (name, loopMode) { + if (loopMode === void 0) { loopMode = null; } + this.currentAnimation = this._animations[name]; + this.currentAnimationName = name; + this.currentFrame = 0; + this.animationState = State.running; + this.sprite = this.currentAnimation.sprites[0]; + this._elapsedTime = 0; + this._loopMode = loopMode ? loopMode : LoopMode.loop; + }; + SpriteAnimator.prototype.isAnimationActive = function (name) { + return this.currentAnimation && this.currentAnimationName == name; + }; + SpriteAnimator.prototype.pause = function () { + this.animationState = State.paused; + }; + SpriteAnimator.prototype.unPause = function () { + this.animationState = State.running; + }; + SpriteAnimator.prototype.stop = function () { + this.currentAnimation = null; + this.currentAnimationName = null; + this.currentFrame = 0; + this.animationState = State.none; + }; + return SpriteAnimator; + }(es.SpriteRenderer)); + es.SpriteAnimator = SpriteAnimator; +})(es || (es = {})); +var es; +(function (es) { + var Mover = (function (_super) { + __extends(Mover, _super); + function Mover() { + return _super !== null && _super.apply(this, arguments) || this; + } + Mover.prototype.onAddedToEntity = function () { + this._triggerHelper = new es.ColliderTriggerHelper(this.entity); + }; + Mover.prototype.calculateMovement = function (motion) { + var collisionResult = new es.CollisionResult(); + if (!this.entity.getComponent(es.Collider) || !this._triggerHelper) { + return null; + } + var colliders = this.entity.getComponents(es.Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + if (collider.isTrigger) + continue; + var bounds = collider.bounds; + bounds.x += motion.x; + bounds.y += motion.y; + var boxcastResult = es.Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); + bounds = boxcastResult.bounds; + var neighbors = boxcastResult.tempHashSet; + for (var j = 0; j < neighbors.length; j++) { + var neighbor = neighbors[j]; + if (neighbor.isTrigger) + continue; + var _internalcollisionResult = collider.collidesWith(neighbor, motion); + if (_internalcollisionResult) { + motion = es.Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); + if (_internalcollisionResult.collider) { + collisionResult = _internalcollisionResult; + } + } + } + } + es.ListPool.free(colliders); + return { collisionResult: collisionResult, motion: motion }; + }; + Mover.prototype.applyMovement = function (motion) { + this.entity.position = es.Vector2.add(this.entity.position, motion); + if (this._triggerHelper) + this._triggerHelper.update(); + }; + Mover.prototype.move = function (motion) { + var movementResult = this.calculateMovement(motion); + var collisionResult = movementResult.collisionResult; + motion = movementResult.motion; + this.applyMovement(motion); + return collisionResult; + }; + return Mover; + }(es.Component)); + es.Mover = Mover; +})(es || (es = {})); +var es; +(function (es) { + var ProjectileMover = (function (_super) { + __extends(ProjectileMover, _super); + function ProjectileMover() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this._tempTriggerList = []; + return _this; + } + ProjectileMover.prototype.onAddedToEntity = function () { + this._collider = this.entity.getComponent(es.Collider); + if (!this._collider) + console.warn("ProjectileMover has no Collider. ProjectilMover requires a Collider!"); + }; + ProjectileMover.prototype.move = function (motion) { + if (!this._collider) + return false; + var didCollide = false; + this.entity.position = es.Vector2.add(this.entity.position, motion); + var neighbors = es.Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); + for (var i = 0; i < neighbors.colliders.length; i++) { + var neighbor = neighbors.colliders[i]; + if (this._collider.overlaps(neighbor) && neighbor.enabled) { + didCollide = true; + this.notifyTriggerListeners(this._collider, neighbor); + } + } + return didCollide; + }; + ProjectileMover.prototype.notifyTriggerListeners = function (self, other) { + other.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + this._tempTriggerList[i].onTriggerEnter(self, other); + } + this._tempTriggerList.length = 0; + this.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + this._tempTriggerList[i].onTriggerEnter(other, self); + } + this._tempTriggerList.length = 0; + }; + return ProjectileMover; + }(es.Component)); + es.ProjectileMover = ProjectileMover; +})(es || (es = {})); +var es; +(function (es) { + var Collider = (function (_super) { + __extends(Collider, _super); + function Collider() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.physicsLayer = 1 << 0; + _this.collidesWithLayers = es.Physics.allLayers; + _this.shouldColliderScaleAndRotateWithTransform = true; + _this.registeredPhysicsBounds = new es.Rectangle(); + _this._localOffset = es.Vector2.zero; + return _this; + } + Object.defineProperty(Collider.prototype, "localOffset", { + get: function () { + return this._localOffset; + }, + set: function (value) { + this.setLocalOffset(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "absolutePosition", { + get: function () { + return es.Vector2.add(this.entity.transform.position, this._localOffset); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "rotation", { + get: function () { + if (this.shouldColliderScaleAndRotateWithTransform && this.entity) + return this.entity.transform.rotation; + return 0; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Collider.prototype, "bounds", { + get: function () { + this.shape.recalculateBounds(this); + return this.shape.bounds; + }, + enumerable: true, + configurable: true + }); + Collider.prototype.setLocalOffset = function (offset) { + if (this._localOffset != offset) { + this.unregisterColliderWithPhysicsSystem(); + this._localOffset = offset; + this._localOffsetLength = this._localOffset.length(); + this.registerColliderWithPhysicsSystem(); + } + return this; + }; + Collider.prototype.setShouldColliderScaleAndRotateWithTransform = function (shouldColliderScaleAndRotationWithTransform) { + this.shouldColliderScaleAndRotateWithTransform = shouldColliderScaleAndRotationWithTransform; + return this; + }; + Collider.prototype.onAddedToEntity = function () { + if (this._colliderRequiresAutoSizing) { + if (!(this instanceof es.BoxCollider || this instanceof es.CircleCollider)) { + console.error("Only box and circle colliders can be created automatically"); + return; + } + var renderable = this.entity.getComponent(es.RenderableComponent); + if (renderable) { + var bounds = renderable.bounds; + var width = bounds.width / this.entity.scale.x; + var height = bounds.height / this.entity.scale.y; + if (this instanceof es.CircleCollider) { + var circleCollider = this; + circleCollider.radius = Math.max(width, height) * 0.5; + } + else { + this.width = width; + this.height = height; + } + this.localOffset = es.Vector2.subtract(bounds.center, this.entity.transform.position); + } + else { + console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); + } + } + this._isParentEntityAddedToScene = true; + this.registerColliderWithPhysicsSystem(); + }; + Collider.prototype.onRemovedFromEntity = function () { + this.unregisterColliderWithPhysicsSystem(); + this._isParentEntityAddedToScene = false; + }; + Collider.prototype.onEntityTransformChanged = function (comp) { + if (this._isColliderRegistered) + es.Physics.updateCollider(this); + }; + Collider.prototype.onEnabled = function () { + this.registerColliderWithPhysicsSystem(); + }; + Collider.prototype.onDisabled = function () { + this.unregisterColliderWithPhysicsSystem(); + }; + Collider.prototype.registerColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && !this._isColliderRegistered) { + es.Physics.addCollider(this); + this._isColliderRegistered = true; + } + }; + Collider.prototype.unregisterColliderWithPhysicsSystem = function () { + if (this._isParentEntityAddedToScene && this._isColliderRegistered) { + es.Physics.removeCollider(this); + } + this._isColliderRegistered = false; + }; + Collider.prototype.overlaps = function (other) { + return this.shape.overlaps(other.shape); + }; + Collider.prototype.collidesWith = function (collider, motion) { + var oldPosition = this.entity.position; + this.entity.position = es.Vector2.add(this.entity.position, motion); + var result = this.shape.collidesWithShape(collider.shape); + if (result) + result.collider = collider; + this.entity.position = oldPosition; + return result; + }; + return Collider; + }(es.Component)); + es.Collider = Collider; +})(es || (es = {})); +var es; +(function (es) { + var BoxCollider = (function (_super) { + __extends(BoxCollider, _super); + function BoxCollider() { + var _this = _super.call(this) || this; + _this.shape = new es.Box(1, 1); + _this._colliderRequiresAutoSizing = true; + return _this; + } + Object.defineProperty(BoxCollider.prototype, "width", { + get: function () { + return this.shape.width; + }, + set: function (value) { + this.setWidth(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(BoxCollider.prototype, "height", { + get: function () { + return this.shape.height; + }, + set: function (value) { + this.setHeight(value); + }, + enumerable: true, + configurable: true + }); + BoxCollider.prototype.setSize = function (width, height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width || height != box.height) { + box.updateBox(width, height); + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + return this; + }; + BoxCollider.prototype.setWidth = function (width) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (width != box.width) { + box.updateBox(width, box.height); + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + return this; + }; + BoxCollider.prototype.setHeight = function (height) { + this._colliderRequiresAutoSizing = false; + var box = this.shape; + if (height != box.height) { + box.updateBox(box.width, height); + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + }; + BoxCollider.prototype.toString = function () { + return "[BoxCollider: bounds: " + this.bounds + "]"; + }; + return BoxCollider; + }(es.Collider)); + es.BoxCollider = BoxCollider; +})(es || (es = {})); +var es; +(function (es) { + var CircleCollider = (function (_super) { + __extends(CircleCollider, _super); + function CircleCollider(radius) { + var _this = _super.call(this) || this; + if (radius) + _this._colliderRequiresAutoSizing = true; + _this.shape = new es.Circle(radius ? radius : 1); + return _this; + } + Object.defineProperty(CircleCollider.prototype, "radius", { + get: function () { + return this.shape.radius; + }, + set: function (value) { + this.setRadius(value); + }, + enumerable: true, + configurable: true + }); + CircleCollider.prototype.setRadius = function (radius) { + this._colliderRequiresAutoSizing = false; + var circle = this.shape; + if (radius != circle.radius) { + circle.radius = radius; + circle._originalRadius = radius; + if (this.entity && this._isParentEntityAddedToScene) + es.Physics.updateCollider(this); + } + return this; + }; + CircleCollider.prototype.toString = function () { + return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]"; + }; + return CircleCollider; + }(es.Collider)); + es.CircleCollider = CircleCollider; +})(es || (es = {})); +var es; +(function (es) { + var PolygonCollider = (function (_super) { + __extends(PolygonCollider, _super); + function PolygonCollider(points) { + var _this = _super.call(this) || this; + var isPolygonClosed = points[0] == points[points.length - 1]; + if (isPolygonClosed) + points.splice(points.length - 1, 1); + var center = es.Polygon.findPolygonCenter(points); + _this.setLocalOffset(center); + es.Polygon.recenterPolygonVerts(points); + _this.shape = new es.Polygon(points); + return _this; + } + return PolygonCollider; + }(es.Collider)); + es.PolygonCollider = PolygonCollider; +})(es || (es = {})); +var es; +(function (es) { + var EntitySystem = (function () { + function EntitySystem(matcher) { + this._entities = []; + this._matcher = matcher ? matcher : es.Matcher.empty(); + } + Object.defineProperty(EntitySystem.prototype, "matcher", { + get: function () { + return this._matcher; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(EntitySystem.prototype, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + this._scene = value; + this._entities = []; + }, + enumerable: true, + configurable: true + }); + EntitySystem.prototype.initialize = function () { + }; + EntitySystem.prototype.onChanged = function (entity) { + var contains = this._entities.contains(entity); + var interest = this._matcher.IsIntersted(entity); + if (interest && !contains) + this.add(entity); + else if (!interest && contains) + this.remove(entity); + }; + EntitySystem.prototype.add = function (entity) { + this._entities.push(entity); + this.onAdded(entity); + }; + EntitySystem.prototype.onAdded = function (entity) { + }; + EntitySystem.prototype.remove = function (entity) { + this._entities.remove(entity); + this.onRemoved(entity); + }; + EntitySystem.prototype.onRemoved = function (entity) { + }; + EntitySystem.prototype.update = function () { + this.begin(); + this.process(this._entities); + }; + EntitySystem.prototype.lateUpdate = function () { + this.lateProcess(this._entities); + this.end(); + }; + EntitySystem.prototype.begin = function () { + }; + EntitySystem.prototype.process = function (entities) { + }; + EntitySystem.prototype.lateProcess = function (entities) { + }; + EntitySystem.prototype.end = function () { + }; + return EntitySystem; + }()); + es.EntitySystem = EntitySystem; +})(es || (es = {})); +var es; +(function (es) { + var EntityProcessingSystem = (function (_super) { + __extends(EntityProcessingSystem, _super); + function EntityProcessingSystem(matcher) { + return _super.call(this, matcher) || this; + } + EntityProcessingSystem.prototype.lateProcessEntity = function (entity) { + }; + EntityProcessingSystem.prototype.process = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.processEntity(entity); }); + }; + EntityProcessingSystem.prototype.lateProcess = function (entities) { + var _this = this; + entities.forEach(function (entity) { return _this.lateProcessEntity(entity); }); + }; + return EntityProcessingSystem; + }(es.EntitySystem)); + es.EntityProcessingSystem = EntityProcessingSystem; +})(es || (es = {})); +var es; +(function (es) { + var PassiveSystem = (function (_super) { + __extends(PassiveSystem, _super); + function PassiveSystem() { + return _super !== null && _super.apply(this, arguments) || this; + } + PassiveSystem.prototype.onChanged = function (entity) { + }; + PassiveSystem.prototype.process = function (entities) { + this.begin(); + this.end(); + }; + return PassiveSystem; + }(es.EntitySystem)); + es.PassiveSystem = PassiveSystem; +})(es || (es = {})); +var es; +(function (es) { + var ProcessingSystem = (function (_super) { + __extends(ProcessingSystem, _super); + function ProcessingSystem() { + return _super !== null && _super.apply(this, arguments) || this; + } + ProcessingSystem.prototype.onChanged = function (entity) { + }; + ProcessingSystem.prototype.process = function (entities) { + this.begin(); + this.processSystem(); + this.end(); + }; + return ProcessingSystem; + }(es.EntitySystem)); + es.ProcessingSystem = ProcessingSystem; +})(es || (es = {})); +var es; +(function (es) { + var BitSet = (function () { + function BitSet(nbits) { + if (nbits === void 0) { nbits = 64; } + var length = nbits >> 6; + if ((nbits & BitSet.LONG_MASK) != 0) + length++; + this._bits = new Array(length); + } + BitSet.prototype.and = function (bs) { + var max = Math.min(this._bits.length, bs._bits.length); + var i; + for (var i_1 = 0; i_1 < max; ++i_1) + this._bits[i_1] &= bs._bits[i_1]; + while (i < this._bits.length) + this._bits[i++] = 0; + }; + BitSet.prototype.andNot = function (bs) { + var i = Math.min(this._bits.length, bs._bits.length); + while (--i >= 0) + this._bits[i] &= ~bs._bits[i]; + }; + BitSet.prototype.cardinality = function () { + var card = 0; + for (var i = this._bits.length - 1; i >= 0; i--) { + var a = this._bits[i]; + if (a == 0) + continue; + if (a == -1) { + card += 64; + continue; + } + a = ((a >> 1) & 0x5555555555555555) + (a & 0x5555555555555555); + a = ((a >> 2) & 0x3333333333333333) + (a & 0x3333333333333333); + var b = ((a >> 32) + a); + b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f); + b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff); + card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff); + } + return card; + }; + BitSet.prototype.clear = function (pos) { + if (pos != undefined) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] &= ~(1 << pos); + } + else { + for (var i = 0; i < this._bits.length; i++) + this._bits[i] = 0; + } + }; + BitSet.prototype.ensure = function (lastElt) { + if (lastElt >= this._bits.length) { + var nd = new Number[lastElt + 1]; + nd = this._bits.copyWithin(0, 0, this._bits.length); + this._bits = nd; + } + }; + BitSet.prototype.get = function (pos) { + var offset = pos >> 6; + if (offset >= this._bits.length) + return false; + return (this._bits[offset] & (1 << pos)) != 0; + }; + BitSet.prototype.intersects = function (set) { + var i = Math.min(this._bits.length, set._bits.length); + while (--i >= 0) { + if ((this._bits[i] & set._bits[i]) != 0) + return true; + } + return false; + }; + BitSet.prototype.isEmpty = function () { + for (var i = this._bits.length - 1; i >= 0; i--) { + if (this._bits[i]) + return false; + } + return true; + }; + BitSet.prototype.nextSetBit = function (from) { + var offset = from >> 6; + var mask = 1 << from; + while (offset < this._bits.length) { + var h = this._bits[offset]; + do { + if ((h & mask) != 0) + return from; + mask <<= 1; + from++; + } while (mask != 0); + mask = 1; + offset++; + } + return -1; + }; + BitSet.prototype.set = function (pos, value) { + if (value === void 0) { value = true; } + if (value) { + var offset = pos >> 6; + this.ensure(offset); + this._bits[offset] |= 1 << pos; + } + else { + this.clear(pos); + } + }; + BitSet.LONG_MASK = 0x3f; + return BitSet; + }()); + es.BitSet = BitSet; +})(es || (es = {})); +var es; +(function (es) { + var ComponentList = (function () { + function ComponentList(entity) { + this._components = []; + this._componentsToAdd = []; + this._componentsToRemove = []; + this._tempBufferList = []; + this._entity = entity; + } + Object.defineProperty(ComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(ComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true + }); + ComponentList.prototype.markEntityListUnsorted = function () { + this._isComponentListUnsorted = true; + }; + ComponentList.prototype.add = function (component) { + this._componentsToAdd.push(component); + }; + ComponentList.prototype.remove = function (component) { + if (this._componentsToRemove.contains(component)) + console.warn("You are trying to remove a Component (" + component + ") that you already removed"); + if (this._componentsToAdd.contains(component)) { + this._componentsToAdd.remove(component); + return; + } + this._componentsToRemove.push(component); + }; + ComponentList.prototype.removeAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + this.handleRemove(this._components[i]); + } + this._components.length = 0; + this._componentsToAdd.length = 0; + this._componentsToRemove.length = 0; + }; + ComponentList.prototype.deregisterAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + } + }; + ComponentList.prototype.registerAllComponents = function () { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + } + }; + ComponentList.prototype.updateLists = function () { + if (this._componentsToRemove.length > 0) { + for (var i = 0; i < this._componentsToRemove.length; i++) { + this.handleRemove(this._componentsToRemove[i]); + this._components.remove(this._componentsToRemove[i]); + } + this._componentsToRemove.length = 0; + } + if (this._componentsToAdd.length > 0) { + for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.add(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); + this._entity.scene.entityProcessors.onComponentAdded(this._entity); + this._components.push(component); + this._tempBufferList.push(component); + } + this._componentsToAdd.length = 0; + this._isComponentListUnsorted = true; + for (var i = 0; i < this._tempBufferList.length; i++) { + var component = this._tempBufferList[i]; + component.onAddedToEntity(); + if (component.enabled) { + component.onEnabled(); + } + } + this._tempBufferList.length = 0; + } + if (this._isComponentListUnsorted) { + this._components.sort(ComponentList.compareUpdatableOrder.compare); + this._isComponentListUnsorted = false; + } + }; + ComponentList.prototype.handleRemove = function (component) { + if (component instanceof es.RenderableComponent) + this._entity.scene.renderableComponents.remove(component); + this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); + this._entity.scene.entityProcessors.onComponentRemoved(this._entity); + component.onRemovedFromEntity(); + component.entity = null; + }; + ComponentList.prototype.getComponent = function (type, onlyReturnInitializedComponents) { + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; if (component instanceof type) return component; } - } - return null; - }; - ComponentList.prototype.getComponents = function (typeName, components) { - if (!components) - components = []; - for (var i = 0; i < this._components.length; i++) { - var component = this._components[i]; - if (typeof (typeName) == "string") { - if (egret.is(component, typeName)) { - components.push(component); + if (!onlyReturnInitializedComponents) { + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (component instanceof type) + return component; } } - else { - if (component instanceof typeName) { - components.push(component); + return null; + }; + ComponentList.prototype.getComponents = function (typeName, components) { + if (!components) + components = []; + for (var i = 0; i < this._components.length; i++) { + var component = this._components[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } } } - } - for (var i = 0; i < this._componentsToAdd.length; i++) { - var component = this._componentsToAdd[i]; - if (typeof (typeName) == "string") { - if (egret.is(component, typeName)) { - components.push(component); + for (var i = 0; i < this._componentsToAdd.length; i++) { + var component = this._componentsToAdd[i]; + if (typeof (typeName) == "string") { + if (egret.is(component, typeName)) { + components.push(component); + } + } + else { + if (component instanceof typeName) { + components.push(component); + } } } - else { - if (component instanceof typeName) { - components.push(component); - } + return components; + }; + ComponentList.prototype.update = function () { + this.updateLists(); + for (var i = 0; i < this._components.length; i++) { + var updatableComponent = this._components[i]; + if (updatableComponent.enabled && + (updatableComponent.updateInterval == 1 || + es.Time.frameCount % updatableComponent.updateInterval == 0)) + updatableComponent.update(); } - } - return components; - }; - ComponentList.prototype.update = function () { - this.updateLists(); - for (var i = 0; i < this._components.length; i++) { - var updatable = this._components[i]; - var updateableComponent = void 0; - if (updatable instanceof Component) - updateableComponent = updatable; - if (updatable.enabled && - updateableComponent.enabled && - (updateableComponent.updateInterval == 1 || - Time.frameCount % updateableComponent.updateInterval == 0)) - updatable.update(); - } - }; - return ComponentList; -}()); -var ComponentTypeManager = (function () { - function ComponentTypeManager() { - } - ComponentTypeManager.add = function (type) { - if (!this._componentTypesMask.has(type)) - this._componentTypesMask[type] = this._componentTypesMask.size; - }; - ComponentTypeManager.getIndexFor = function (type) { - var v = -1; - if (!this._componentTypesMask.has(type)) { - this.add(type); - v = this._componentTypesMask.get(type); - } - return v; - }; - ComponentTypeManager._componentTypesMask = new Map(); - return ComponentTypeManager; -}()); -var EntityList = (function () { - function EntityList(scene) { - this._entitiesToRemove = []; - this._entitiesToAdded = []; - this._tempEntityList = []; - this._entities = []; - this._entityDict = new Map(); - this._unsortedTags = []; - this.scene = scene; - } - Object.defineProperty(EntityList.prototype, "count", { - get: function () { - return this._entities.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(EntityList.prototype, "buffer", { - get: function () { - return this._entities; - }, - enumerable: true, - configurable: true - }); - EntityList.prototype.add = function (entity) { - if (this._entitiesToAdded.indexOf(entity) == -1) - this._entitiesToAdded.push(entity); - }; - EntityList.prototype.remove = function (entity) { - if (this._entitiesToAdded.contains(entity)) { - this._entitiesToAdded.remove(entity); - return; - } - if (!this._entitiesToRemove.contains(entity)) - this._entitiesToRemove.push(entity); - }; - EntityList.prototype.findEntity = function (name) { - for (var i = 0; i < this._entities.length; i++) { - if (this._entities[i].name == name) - return this._entities[i]; - } - return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; }); - }; - EntityList.prototype.getTagList = function (tag) { - var list = this._entityDict.get(tag); - if (!list) { - list = []; - this._entityDict.set(tag, list); - } - return this._entityDict.get(tag); - }; - EntityList.prototype.addToTagList = function (entity) { - var list = this.getTagList(entity.tag); - if (!list.contains(entity)) { - list.push(entity); - this._unsortedTags.push(entity.tag); - } - }; - EntityList.prototype.removeFromTagList = function (entity) { - var list = this._entityDict.get(entity.tag); - if (list) { - list.remove(entity); - } - }; - EntityList.prototype.update = function () { - for (var i = 0; i < this._entities.length; i++) { - var entity = this._entities[i]; - if (entity.enabled) - entity.update(); - } - }; - EntityList.prototype.removeAllEntities = function () { - this._entitiesToAdded.length = 0; - this.updateLists(); - for (var i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestoryed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; - } - this._entities.length = 0; - this._entityDict.clear(); - }; - EntityList.prototype.updateLists = function () { - var _this = this; - if (this._entitiesToRemove.length > 0) { - var temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - _this._entities.remove(entity); - entity.scene = null; - _this.scene.entityProcessors.onEntityRemoved(entity); - }); - this._tempEntityList.length = 0; - } - if (this._entitiesToAdded.length > 0) { - var temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - if (!_this._entities.contains(entity)) { - _this._entities.push(entity); - entity.scene = _this.scene; - _this.scene.entityProcessors.onEntityAdded(entity); - } - }); - this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); - this._tempEntityList.length = 0; - } - if (this._unsortedTags.length > 0) { - this._unsortedTags.forEach(function (tag) { - _this._entityDict.get(tag).sort(); - }); - this._unsortedTags.length = 0; - } - }; - return EntityList; -}()); -var EntityProcessorList = (function () { - function EntityProcessorList() { - this._processors = []; - } - EntityProcessorList.prototype.add = function (processor) { - this._processors.push(processor); - }; - EntityProcessorList.prototype.remove = function (processor) { - this._processors.remove(processor); - }; - EntityProcessorList.prototype.onComponentAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onComponentRemoved = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityAdded = function (entity) { - this.notifyEntityChanged(entity); - }; - EntityProcessorList.prototype.onEntityRemoved = function (entity) { - this.removeFromProcessors(entity); - }; - EntityProcessorList.prototype.notifyEntityChanged = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].onChanged(entity); - } - }; - EntityProcessorList.prototype.removeFromProcessors = function (entity) { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].remove(entity); - } - }; - EntityProcessorList.prototype.begin = function () { - }; - EntityProcessorList.prototype.update = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].update(); - } - }; - EntityProcessorList.prototype.lateUpdate = function () { - for (var i = 0; i < this._processors.length; i++) { - this._processors[i].lateUpdate(); - } - }; - EntityProcessorList.prototype.end = function () { - }; - EntityProcessorList.prototype.getProcessor = function () { - for (var i = 0; i < this._processors.length; i++) { - var processor = this._processors[i]; - if (processor instanceof EntitySystem) - return processor; - } - return null; - }; - return EntityProcessorList; -}()); -var Matcher = (function () { - function Matcher() { - this.allSet = new BitSet(); - this.exclusionSet = new BitSet(); - this.oneSet = new BitSet(); - } - Matcher.empty = function () { - return new Matcher(); - }; - Matcher.prototype.getAllSet = function () { - return this.allSet; - }; - Matcher.prototype.getExclusionSet = function () { - return this.exclusionSet; - }; - Matcher.prototype.getOneSet = function () { - return this.oneSet; - }; - Matcher.prototype.IsIntersted = function (e) { - if (!this.allSet.isEmpty()) { - for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { - if (!e.componentBits.get(i)) - return false; + }; + ComponentList.prototype.onEntityTransformChanged = function (comp) { + for (var i = 0; i < this._components.length; i++) { + if (this._components[i].enabled) + this._components[i].onEntityTransformChanged(comp); } + for (var i = 0; i < this._componentsToAdd.length; i++) { + if (this._componentsToAdd[i].enabled) + this._componentsToAdd[i].onEntityTransformChanged(comp); + } + }; + ComponentList.prototype.onEntityEnabled = function () { + for (var i = 0; i < this._components.length; i++) + this._components[i].onEnabled(); + }; + ComponentList.prototype.onEntityDisabled = function () { + for (var i = 0; i < this._components.length; i++) + this._components[i].onDisabled(); + }; + ComponentList.compareUpdatableOrder = new es.IUpdatableComparer(); + return ComponentList; + }()); + es.ComponentList = ComponentList; +})(es || (es = {})); +var es; +(function (es) { + var ComponentTypeManager = (function () { + function ComponentTypeManager() { } - if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) - return false; - if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) - return false; - return true; - }; - Matcher.prototype.all = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + ComponentTypeManager.add = function (type) { + if (!this._componentTypesMask.has(type)) + this._componentTypesMask[type] = this._componentTypesMask.size; + }; + ComponentTypeManager.getIndexFor = function (type) { + var v = -1; + if (!this._componentTypesMask.has(type)) { + this.add(type); + v = this._componentTypesMask.get(type); + } + return v; + }; + ComponentTypeManager._componentTypesMask = new Map(); + return ComponentTypeManager; + }()); + es.ComponentTypeManager = ComponentTypeManager; +})(es || (es = {})); +var es; +(function (es) { + var EntityList = (function () { + function EntityList(scene) { + this._entitiesToRemove = []; + this._entitiesToAdded = []; + this._tempEntityList = []; + this._entities = []; + this._entityDict = new Map(); + this._unsortedTags = []; + this.scene = scene; } - types.forEach(function (type) { - _this.allSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(EntityList.prototype, "count", { + get: function () { + return this._entities.length; + }, + enumerable: true, + configurable: true }); - return this; - }; - Matcher.prototype.exclude = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; - } - types.forEach(function (type) { - _this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); + Object.defineProperty(EntityList.prototype, "buffer", { + get: function () { + return this._entities; + }, + enumerable: true, + configurable: true }); - return this; - }; - Matcher.prototype.one = function () { - var _this = this; - var types = []; - for (var _i = 0; _i < arguments.length; _i++) { - types[_i] = arguments[_i]; + EntityList.prototype.add = function (entity) { + if (this._entitiesToAdded.indexOf(entity) == -1) + this._entitiesToAdded.push(entity); + }; + EntityList.prototype.remove = function (entity) { + if (this._entitiesToAdded.contains(entity)) { + this._entitiesToAdded.remove(entity); + return; + } + if (!this._entitiesToRemove.contains(entity)) + this._entitiesToRemove.push(entity); + }; + EntityList.prototype.findEntity = function (name) { + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].name == name) + return this._entities[i]; + } + return this._entitiesToAdded.firstOrDefault(function (entity) { return entity.name == name; }); + }; + EntityList.prototype.entitiesWithTag = function (tag) { + var list = this.getTagList(tag); + var returnList = es.ListPool.obtain(); + for (var i = 0; i < list.length; i++) + returnList.push(list[i]); + return returnList; + }; + EntityList.prototype.entitiesOfType = function (type) { + var list = es.ListPool.obtain(); + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i] instanceof type) + list.push(this._entities[i]); + } + this._entitiesToAdded.forEach(function (entity) { + if (entity instanceof type) + list.push(entity); + }); + return list; + }; + EntityList.prototype.findComponentOfType = function (type) { + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].enabled) { + var comp = this._entities[i].getComponent(type); + if (comp) + return comp; + } + } + for (var i = 0; i < this._entitiesToAdded.length; i++) { + var entity = this._entitiesToAdded[i]; + if (entity.enabled) { + var comp = entity.getComponent(type); + if (comp) + return comp; + } + } + return null; + }; + EntityList.prototype.findComponentsOfType = function (type) { + var comps = es.ListPool.obtain(); + for (var i = 0; i < this._entities.length; i++) { + if (this._entities[i].enabled) + this._entities[i].getComponents(type, comps); + } + for (var i = 0; i < this._entitiesToAdded.length; i++) { + var entity = this._entitiesToAdded[i]; + if (entity.enabled) + entity.getComponents(type, comps); + } + return comps; + }; + EntityList.prototype.getTagList = function (tag) { + var list = this._entityDict.get(tag); + if (!list) { + list = []; + this._entityDict.set(tag, list); + } + return this._entityDict.get(tag); + }; + EntityList.prototype.addToTagList = function (entity) { + var list = this.getTagList(entity.tag); + if (!list.contains(entity)) { + list.push(entity); + this._unsortedTags.push(entity.tag); + } + }; + EntityList.prototype.removeFromTagList = function (entity) { + var list = this._entityDict.get(entity.tag); + if (list) { + list.remove(entity); + } + }; + EntityList.prototype.update = function () { + for (var i = 0; i < this._entities.length; i++) { + var entity = this._entities[i]; + if (entity.enabled) + entity.update(); + } + }; + EntityList.prototype.removeAllEntities = function () { + this._entitiesToAdded.length = 0; + this.updateLists(); + for (var i = 0; i < this._entities.length; i++) { + this._entities[i]._isDestroyed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + this._entities.length = 0; + this._entityDict.clear(); + }; + EntityList.prototype.updateLists = function () { + var _this = this; + if (this._entitiesToRemove.length > 0) { + var temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + _this._entities.remove(entity); + entity.scene = null; + _this.scene.entityProcessors.onEntityRemoved(entity); + }); + this._tempEntityList.length = 0; + } + if (this._entitiesToAdded.length > 0) { + var temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + if (!_this._entities.contains(entity)) { + _this._entities.push(entity); + entity.scene = _this.scene; + _this.scene.entityProcessors.onEntityAdded(entity); + } + }); + this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); + this._tempEntityList.length = 0; + } + if (this._unsortedTags.length > 0) { + this._unsortedTags.forEach(function (tag) { + _this._entityDict.get(tag).sort(); + }); + this._unsortedTags.length = 0; + } + }; + return EntityList; + }()); + es.EntityList = EntityList; +})(es || (es = {})); +var es; +(function (es) { + var EntityProcessorList = (function () { + function EntityProcessorList() { + this._processors = []; } - types.forEach(function (type) { - _this.oneSet.set(ComponentTypeManager.getIndexFor(type)); - }); - return this; - }; - return Matcher; -}()); + EntityProcessorList.prototype.add = function (processor) { + this._processors.push(processor); + }; + EntityProcessorList.prototype.remove = function (processor) { + this._processors.remove(processor); + }; + EntityProcessorList.prototype.onComponentAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onComponentRemoved = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityAdded = function (entity) { + this.notifyEntityChanged(entity); + }; + EntityProcessorList.prototype.onEntityRemoved = function (entity) { + this.removeFromProcessors(entity); + }; + EntityProcessorList.prototype.notifyEntityChanged = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].onChanged(entity); + } + }; + EntityProcessorList.prototype.removeFromProcessors = function (entity) { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].remove(entity); + } + }; + EntityProcessorList.prototype.begin = function () { + }; + EntityProcessorList.prototype.update = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].update(); + } + }; + EntityProcessorList.prototype.lateUpdate = function () { + for (var i = 0; i < this._processors.length; i++) { + this._processors[i].lateUpdate(); + } + }; + EntityProcessorList.prototype.end = function () { + }; + EntityProcessorList.prototype.getProcessor = function () { + for (var i = 0; i < this._processors.length; i++) { + var processor = this._processors[i]; + if (processor instanceof es.EntitySystem) + return processor; + } + return null; + }; + return EntityProcessorList; + }()); + es.EntityProcessorList = EntityProcessorList; +})(es || (es = {})); +var es; +(function (es) { + var Matcher = (function () { + function Matcher() { + this.allSet = new es.BitSet(); + this.exclusionSet = new es.BitSet(); + this.oneSet = new es.BitSet(); + } + Matcher.empty = function () { + return new Matcher(); + }; + Matcher.prototype.getAllSet = function () { + return this.allSet; + }; + Matcher.prototype.getExclusionSet = function () { + return this.exclusionSet; + }; + Matcher.prototype.getOneSet = function () { + return this.oneSet; + }; + Matcher.prototype.IsIntersted = function (e) { + if (!this.allSet.isEmpty()) { + for (var i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)) { + if (!e.componentBits.get(i)) + return false; + } + } + if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) + return false; + if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) + return false; + return true; + }; + Matcher.prototype.all = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.allSet.set(es.ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.exclude = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.exclusionSet.set(es.ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + Matcher.prototype.one = function () { + var _this = this; + var types = []; + for (var _i = 0; _i < arguments.length; _i++) { + types[_i] = arguments[_i]; + } + types.forEach(function (type) { + _this.oneSet.set(es.ComponentTypeManager.getIndexFor(type)); + }); + return this; + }; + return Matcher; + }()); + es.Matcher = Matcher; +})(es || (es = {})); var ObjectUtils = (function () { function ObjectUtils() { } @@ -3058,34 +3568,100 @@ var ObjectUtils = (function () { }; return ObjectUtils; }()); -var RenderableComponentList = (function () { - function RenderableComponentList() { - this._components = []; - } - Object.defineProperty(RenderableComponentList.prototype, "count", { - get: function () { - return this._components.length; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(RenderableComponentList.prototype, "buffer", { - get: function () { - return this._components; - }, - enumerable: true, - configurable: true - }); - RenderableComponentList.prototype.add = function (component) { - this._components.push(component); - }; - RenderableComponentList.prototype.remove = function (component) { - this._components.remove(component); - }; - RenderableComponentList.prototype.updateList = function () { - }; - return RenderableComponentList; -}()); +var es; +(function (es) { + var RenderableComparer = (function () { + function RenderableComparer() { + } + RenderableComparer.prototype.compare = function (self, other) { + return other.renderLayer - self.renderLayer; + }; + return RenderableComparer; + }()); + es.RenderableComparer = RenderableComparer; +})(es || (es = {})); +var es; +(function (es) { + var RenderableComponentList = (function () { + function RenderableComponentList() { + this._components = []; + this._componentsByRenderLayer = new Map(); + this._unsortedRenderLayers = []; + this._componentsNeedSort = true; + } + Object.defineProperty(RenderableComponentList.prototype, "count", { + get: function () { + return this._components.length; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(RenderableComponentList.prototype, "buffer", { + get: function () { + return this._components; + }, + enumerable: true, + configurable: true + }); + RenderableComponentList.prototype.add = function (component) { + this._components.push(component); + this.addToRenderLayerList(component, component.renderLayer); + }; + RenderableComponentList.prototype.remove = function (component) { + this._components.remove(component); + this._componentsByRenderLayer.get(component.renderLayer).remove(component); + }; + RenderableComponentList.prototype.updateRenderableRenderLayer = function (component, oldRenderLayer, newRenderLayer) { + if (this._componentsByRenderLayer.has(oldRenderLayer) && this._componentsByRenderLayer.get(oldRenderLayer).contains(component)) { + this._componentsByRenderLayer.get(oldRenderLayer).remove(component); + this.addToRenderLayerList(component, newRenderLayer); + } + }; + RenderableComponentList.prototype.setRenderLayerNeedsComponentSort = function (renderLayer) { + if (!this._unsortedRenderLayers.contains(renderLayer)) + this._unsortedRenderLayers.push(renderLayer); + this._componentsNeedSort = true; + }; + RenderableComponentList.prototype.setNeedsComponentSort = function () { + this._componentsNeedSort = true; + }; + RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) { + var list = this.componentsWithRenderLayer(renderLayer); + if (!list.contains(component)) { + console.warn("Component renderLayer list already contains this component"); + return; + } + list.push(component); + if (!this._unsortedRenderLayers.contains(renderLayer)) + this._unsortedRenderLayers.push(renderLayer); + this._componentsNeedSort = true; + }; + RenderableComponentList.prototype.componentsWithRenderLayer = function (renderLayer) { + if (!this._componentsByRenderLayer.get(renderLayer)) { + this._componentsByRenderLayer.set(renderLayer, []); + } + return this._componentsByRenderLayer.get(renderLayer); + }; + RenderableComponentList.prototype.updateList = function () { + if (this._componentsNeedSort) { + this._components.sort(RenderableComponentList.compareUpdatableOrder.compare); + this._componentsNeedSort = false; + } + if (this._unsortedRenderLayers.length > 0) { + for (var i = 0, count = this._unsortedRenderLayers.length; i < count; i++) { + var renderLayerComponents = this._componentsByRenderLayer.get(this._unsortedRenderLayers[i]); + if (renderLayerComponents) { + renderLayerComponents.sort(RenderableComponentList.compareUpdatableOrder.compare); + } + } + this._unsortedRenderLayers.length = 0; + } + }; + RenderableComponentList.compareUpdatableOrder = new es.RenderableComparer(); + return RenderableComponentList; + }()); + es.RenderableComponentList = RenderableComponentList; +})(es || (es = {})); var StringUtils = (function () { function StringUtils() { } @@ -3230,155 +3806,163 @@ var StringUtils = (function () { ]; return StringUtils; }()); -var TextureUtils = (function () { - function TextureUtils() { - } - TextureUtils.convertImageToCanvas = function (texture, rect) { - if (!this.sharedCanvas) { - this.sharedCanvas = egret.sys.createCanvas(); - this.sharedContext = this.sharedCanvas.getContext("2d"); +var es; +(function (es) { + var TextureUtils = (function () { + function TextureUtils() { } - var w = texture.$getTextureWidth(); - var h = texture.$getTextureHeight(); - if (!rect) { - rect = egret.$TempRectangle; - rect.x = 0; - rect.y = 0; - rect.width = w; - rect.height = h; - } - rect.x = Math.min(rect.x, w - 1); - rect.y = Math.min(rect.y, h - 1); - rect.width = Math.min(rect.width, w - rect.x); - rect.height = Math.min(rect.height, h - rect.y); - var iWidth = Math.floor(rect.width); - var iHeight = Math.floor(rect.height); - var surface = this.sharedCanvas; - surface["style"]["width"] = iWidth + "px"; - surface["style"]["height"] = iHeight + "px"; - this.sharedCanvas.width = iWidth; - this.sharedCanvas.height = iHeight; - if (egret.Capabilities.renderMode == "webgl") { - var renderTexture = void 0; - if (!texture.$renderBuffer) { - if (egret.sys.systemRenderer["renderClear"]) { - egret.sys.systemRenderer["renderClear"](); + TextureUtils.convertImageToCanvas = function (texture, rect) { + if (!this.sharedCanvas) { + this.sharedCanvas = egret.sys.createCanvas(); + this.sharedContext = this.sharedCanvas.getContext("2d"); + } + var w = texture.$getTextureWidth(); + var h = texture.$getTextureHeight(); + if (!rect) { + rect = egret.$TempRectangle; + rect.x = 0; + rect.y = 0; + rect.width = w; + rect.height = h; + } + rect.x = Math.min(rect.x, w - 1); + rect.y = Math.min(rect.y, h - 1); + rect.width = Math.min(rect.width, w - rect.x); + rect.height = Math.min(rect.height, h - rect.y); + var iWidth = Math.floor(rect.width); + var iHeight = Math.floor(rect.height); + var surface = this.sharedCanvas; + surface["style"]["width"] = iWidth + "px"; + surface["style"]["height"] = iHeight + "px"; + this.sharedCanvas.width = iWidth; + this.sharedCanvas.height = iHeight; + if (egret.Capabilities.renderMode == "webgl") { + var renderTexture = void 0; + if (!texture.$renderBuffer) { + if (egret.sys.systemRenderer["renderClear"]) { + egret.sys.systemRenderer["renderClear"](); + } + renderTexture = new egret.RenderTexture(); + renderTexture.drawToTexture(new egret.Bitmap(texture)); } - renderTexture = new egret.RenderTexture(); - renderTexture.drawToTexture(new egret.Bitmap(texture)); + else { + renderTexture = texture; + } + var pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight); + var x = 0; + var y = 0; + for (var i = 0; i < pixels.length; i += 4) { + this.sharedContext.fillStyle = + 'rgba(' + pixels[i] + + ',' + pixels[i + 1] + + ',' + pixels[i + 2] + + ',' + (pixels[i + 3] / 255) + ')'; + this.sharedContext.fillRect(x, y, 1, 1); + x++; + if (x == iWidth) { + x = 0; + y++; + } + } + if (!texture.$renderBuffer) { + renderTexture.dispose(); + } + return surface; } else { - renderTexture = texture; + var bitmapData = texture; + var offsetX = Math.round(bitmapData.$offsetX); + var offsetY = Math.round(bitmapData.$offsetY); + var bitmapWidth = bitmapData.$bitmapWidth; + var bitmapHeight = bitmapData.$bitmapHeight; + var $TextureScaleFactor = es.SceneManager.stage.textureScaleFactor; + this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); + return surface; } - var pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight); - var x = 0; - var y = 0; - for (var i = 0; i < pixels.length; i += 4) { - this.sharedContext.fillStyle = - 'rgba(' + pixels[i] - + ',' + pixels[i + 1] - + ',' + pixels[i + 2] - + ',' + (pixels[i + 3] / 255) + ')'; - this.sharedContext.fillRect(x, y, 1, 1); - x++; - if (x == iWidth) { - x = 0; - y++; - } + }; + TextureUtils.toDataURL = function (type, texture, rect, encoderOptions) { + try { + var surface = this.convertImageToCanvas(texture, rect); + var result = surface.toDataURL(type, encoderOptions); + return result; } - if (!texture.$renderBuffer) { - renderTexture.dispose(); + catch (e) { + egret.$error(1033); } - return surface; - } - else { - var bitmapData = texture; - var offsetX = Math.round(bitmapData.$offsetX); - var offsetY = Math.round(bitmapData.$offsetY); - var bitmapWidth = bitmapData.$bitmapWidth; - var bitmapHeight = bitmapData.$bitmapHeight; - var $TextureScaleFactor = SceneManager.stage.textureScaleFactor; - this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); - return surface; - } - }; - TextureUtils.toDataURL = function (type, texture, rect, encoderOptions) { - try { + return null; + }; + TextureUtils.eliFoTevas = function (type, texture, filePath, rect, encoderOptions) { var surface = this.convertImageToCanvas(texture, rect); - var result = surface.toDataURL(type, encoderOptions); + var result = surface.toTempFilePathSync({ + fileType: type.indexOf("png") >= 0 ? "png" : "jpg" + }); + wx.getFileSystemManager().saveFile({ + tempFilePath: result, + filePath: wx.env.USER_DATA_PATH + "/" + filePath, + success: function (res) { + } + }); return result; - } - catch (e) { - egret.$error(1033); - } - return null; - }; - TextureUtils.eliFoTevas = function (type, texture, filePath, rect, encoderOptions) { - var surface = this.convertImageToCanvas(texture, rect); - var result = surface.toTempFilePathSync({ - fileType: type.indexOf("png") >= 0 ? "png" : "jpg" - }); - wx.getFileSystemManager().saveFile({ - tempFilePath: result, - filePath: wx.env.USER_DATA_PATH + "/" + filePath, - success: function (res) { + }; + TextureUtils.getPixel32 = function (texture, x, y) { + egret.$warn(1041, "getPixel32", "getPixels"); + return texture.getPixels(x, y); + }; + TextureUtils.getPixels = function (texture, x, y, width, height) { + if (width === void 0) { width = 1; } + if (height === void 0) { height = 1; } + if (egret.Capabilities.renderMode == "webgl") { + var renderTexture = void 0; + if (!texture.$renderBuffer) { + renderTexture = new egret.RenderTexture(); + renderTexture.drawToTexture(new egret.Bitmap(texture)); + } + else { + renderTexture = texture; + } + var pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height); + return pixels; } - }); - return result; - }; - TextureUtils.getPixel32 = function (texture, x, y) { - egret.$warn(1041, "getPixel32", "getPixels"); - return texture.getPixels(x, y); - }; - TextureUtils.getPixels = function (texture, x, y, width, height) { - if (width === void 0) { width = 1; } - if (height === void 0) { height = 1; } - if (egret.Capabilities.renderMode == "webgl") { - var renderTexture = void 0; - if (!texture.$renderBuffer) { - renderTexture = new egret.RenderTexture(); - renderTexture.drawToTexture(new egret.Bitmap(texture)); + try { + var surface = this.convertImageToCanvas(texture); + var result = this.sharedContext.getImageData(x, y, width, height).data; + return result; } - else { - renderTexture = texture; + catch (e) { + egret.$error(1039); } - var pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height); - return pixels; + }; + return TextureUtils; + }()); + es.TextureUtils = TextureUtils; +})(es || (es = {})); +var es; +(function (es) { + var Time = (function () { + function Time() { } - try { - var surface = this.convertImageToCanvas(texture); - var result = this.sharedContext.getImageData(x, y, width, height).data; - return result; - } - catch (e) { - egret.$error(1039); - } - }; - return TextureUtils; -}()); -var Time = (function () { - function Time() { - } - Time.update = function (currentTime) { - var dt = (currentTime - this._lastTime) / 1000; - this.deltaTime = dt * this.timeScale; - this.unscaledDeltaTime = dt; - this._timeSinceSceneLoad += dt; - this.frameCount++; - this._lastTime = currentTime; - }; - Time.sceneChanged = function () { - this._timeSinceSceneLoad = 0; - }; - Time.checkEvery = function (interval) { - return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval); - }; - Time.deltaTime = 0; - Time.timeScale = 1; - Time.frameCount = 0; - Time._lastTime = 0; - return Time; -}()); + Time.update = function (currentTime) { + var dt = (currentTime - this._lastTime) / 1000; + this.deltaTime = dt * this.timeScale; + this.unscaledDeltaTime = dt; + this._timeSinceSceneLoad += dt; + this.frameCount++; + this._lastTime = currentTime; + }; + Time.sceneChanged = function () { + this._timeSinceSceneLoad = 0; + }; + Time.checkEvery = function (interval) { + return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval); + }; + Time.deltaTime = 0; + Time.timeScale = 1; + Time.frameCount = 0; + Time._lastTime = 0; + return Time; + }()); + es.Time = Time; +})(es || (es = {})); var TimeUtils = (function () { function TimeUtils() { } @@ -3532,405 +4116,143 @@ var TimeUtils = (function () { }; return TimeUtils; }()); -var GraphicsCapabilities = (function (_super) { - __extends(GraphicsCapabilities, _super); - function GraphicsCapabilities() { - return _super !== null && _super.apply(this, arguments) || this; - } - GraphicsCapabilities.prototype.initialize = function (device) { - this.platformInitialize(device); - }; - GraphicsCapabilities.prototype.platformInitialize = function (device) { - var capabilities = this; - capabilities["isMobile"] = true; - var systemInfo = wx.getSystemInfoSync(); - var systemStr = systemInfo.system.toLowerCase(); - if (systemStr.indexOf("ios") > -1) { - capabilities["os"] = "iOS"; +var es; +(function (es) { + var GraphicsCapabilities = (function (_super) { + __extends(GraphicsCapabilities, _super); + function GraphicsCapabilities() { + return _super !== null && _super.apply(this, arguments) || this; } - else if (systemStr.indexOf("android") > -1) { - capabilities["os"] = "Android"; - } - var language = systemInfo.language; - if (language.indexOf('zh') > -1) { - language = "zh-CN"; - } - else { - language = "en-US"; - } - capabilities["language"] = language; - }; - return GraphicsCapabilities; -}(egret.Capabilities)); -var GraphicsDevice = (function () { - function GraphicsDevice() { - this.graphicsCapabilities = new GraphicsCapabilities(); - this.graphicsCapabilities.initialize(this); - } - return GraphicsDevice; -}()); -var Viewport = (function () { - function Viewport(x, y, width, height) { - this._x = x; - this._y = y; - this._width = width; - this._height = height; - this._minDepth = 0; - this._maxDepth = 1; - } - Object.defineProperty(Viewport.prototype, "aspectRatio", { - get: function () { - if ((this._height != 0) && (this._width != 0)) - return (this._width / this._height); - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Viewport.prototype, "bounds", { - get: function () { - return new Rectangle(this._x, this._y, this._width, this._height); - }, - set: function (value) { - this._x = value.x; - this._y = value.y; - this._width = value.width; - this._height = value.height; - }, - enumerable: true, - configurable: true - }); - return Viewport; -}()); -var GaussianBlurEffect = (function (_super) { - __extends(GaussianBlurEffect, _super); - function GaussianBlurEffect() { - return _super.call(this, PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight - }) || this; - } - GaussianBlurEffect.blur_frag = "precision mediump float;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float screenWidth;\n" + - "uniform float screenHeight;\n" + - "float normpdf(in float x, in float sigma)\n" + - "{\n" + - "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + - "}\n" + - "void main()\n" + - "{\n" + - "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "const int mSize = 11;\n" + - "const int kSize = (mSize - 1)/2;\n" + - "float kernel[mSize];\n" + - "vec3 final_colour = vec3(0.0);\n" + - "float sigma = 7.0;\n" + - "float z = 0.0;\n" + - "for (int j = 0; j <= kSize; ++j)\n" + - "{\n" + - "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + - "}\n" + - "for (int j = 0; j < mSize; ++j)\n" + - "{\n" + - "z += kernel[j];\n" + - "}\n" + - "for (int i = -kSize; i <= kSize; ++i)\n" + - "{\n" + - "for (int j = -kSize; j <= kSize; ++j)\n" + - "{\n" + - "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "}\n}\n" + - "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + - "}"; - return GaussianBlurEffect; -}(egret.CustomFilter)); -var PolygonLightEffect = (function (_super) { - __extends(PolygonLightEffect, _super); - function PolygonLightEffect() { - return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this; - } - PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - PolygonLightEffect.fragmentSrc = "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + - "#define SAMPLE_COUNT 15\n" + - "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + - "uniform float _sampleWeights[SAMPLE_COUNT];\n" + - "void main(void) {\n" + - "vec4 c = vec4(0, 0, 0, 0);\n" + - "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + - " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + - "gl_FragColor = c;\n" + - "}"; - return PolygonLightEffect; -}(egret.CustomFilter)); -var PostProcessor = (function () { - function PostProcessor(effect) { - if (effect === void 0) { effect = null; } - this.enable = true; - this.effect = effect; - } - PostProcessor.prototype.onAddedToScene = function (scene) { - this.scene = scene; - this.shape = new egret.Shape(); - this.shape.graphics.beginFill(0xFFFFFF, 1); - this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this.shape.graphics.endFill(); - scene.addChild(this.shape); - }; - PostProcessor.prototype.process = function () { - this.drawFullscreenQuad(); - }; - PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { }; - PostProcessor.prototype.drawFullscreenQuad = function () { - this.scene.filters = [this.effect]; - }; - PostProcessor.prototype.unload = function () { - if (this.effect) { - this.effect = null; - } - this.scene.removeChild(this.shape); - this.scene = null; - }; - PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "attribute vec2 aColor;\n" + - "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + - "varying vec4 vColor;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - "vTextureCoord = aTextureCoord;\n" + - "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + - "}"; - return PostProcessor; -}()); -var GaussianBlurPostProcessor = (function (_super) { - __extends(GaussianBlurPostProcessor, _super); - function GaussianBlurPostProcessor() { - return _super !== null && _super.apply(this, arguments) || this; - } - GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { - _super.prototype.onAddedToScene.call(this, scene); - this.effect = new GaussianBlurEffect(); - }; - return GaussianBlurPostProcessor; -}(PostProcessor)); -var Renderer = (function () { - function Renderer() { - } - Renderer.prototype.onAddedToScene = function (scene) { }; - Renderer.prototype.beginRender = function (cam) { - }; - Renderer.prototype.unload = function () { }; - Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { - renderable.render(cam); - }; - return Renderer; -}()); -var DefaultRenderer = (function (_super) { - __extends(DefaultRenderer, _super); - function DefaultRenderer() { - return _super !== null && _super.apply(this, arguments) || this; - } - DefaultRenderer.prototype.render = function (scene) { - var cam = this.camera ? this.camera : scene.camera; - this.beginRender(cam); - for (var i = 0; i < scene.renderableComponents.count; i++) { - var renderable = scene.renderableComponents.buffer[i]; - if (renderable.enabled && renderable.isVisibleFromCamera(cam)) - this.renderAfterStateCheck(renderable, cam); - } - }; - return DefaultRenderer; -}(Renderer)); -var ScreenSpaceRenderer = (function (_super) { - __extends(ScreenSpaceRenderer, _super); - function ScreenSpaceRenderer() { - return _super !== null && _super.apply(this, arguments) || this; - } - ScreenSpaceRenderer.prototype.render = function (scene) { - }; - return ScreenSpaceRenderer; -}(Renderer)); -var PolyLight = (function (_super) { - __extends(PolyLight, _super); - function PolyLight(radius, color, power) { - var _this = _super.call(this) || this; - _this._indices = []; - _this.radius = radius; - _this.power = power; - _this.color = color; - _this.computeTriangleIndices(); - return _this; - } - Object.defineProperty(PolyLight.prototype, "radius", { - get: function () { - return this._radius; - }, - set: function (value) { - this.setRadius(value); - }, - enumerable: true, - configurable: true - }); - PolyLight.prototype.computeTriangleIndices = function (totalTris) { - if (totalTris === void 0) { totalTris = 20; } - this._indices.length = 0; - for (var i = 0; i < totalTris; i += 2) { - this._indices.push(0); - this._indices.push(i + 2); - this._indices.push(i + 1); - } - }; - PolyLight.prototype.setRadius = function (radius) { - if (radius != this._radius) { - this._radius = radius; - this._areBoundsDirty = true; - } - }; - PolyLight.prototype.render = function (camera) { - }; - PolyLight.prototype.reset = function () { - }; - return PolyLight; -}(RenderableComponent)); -var SceneTransition = (function () { - function SceneTransition(sceneLoadAction) { - this.sceneLoadAction = sceneLoadAction; - this.loadsNewScene = sceneLoadAction != null; - } - Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { - get: function () { - if (!this._hasPreviousSceneRender) { - this._hasPreviousSceneRender = true; - return false; + GraphicsCapabilities.prototype.initialize = function (device) { + this.platformInitialize(device); + }; + GraphicsCapabilities.prototype.platformInitialize = function (device) { + var capabilities = this; + capabilities["isMobile"] = true; + var systemInfo = wx.getSystemInfoSync(); + var systemStr = systemInfo.system.toLowerCase(); + if (systemStr.indexOf("ios") > -1) { + capabilities["os"] = "iOS"; } - return true; - }, - enumerable: true, - configurable: true - }); - SceneTransition.prototype.preRender = function () { }; - SceneTransition.prototype.render = function () { - }; - SceneTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.loadNextScene()]; - case 1: - _a.sent(); - this.transitionComplete(); - return [2]; - } - }); - }); - }; - SceneTransition.prototype.transitionComplete = function () { - SceneManager.sceneTransition = null; - if (this.onTransitionCompleted) { - this.onTransitionCompleted(); + else if (systemStr.indexOf("android") > -1) { + capabilities["os"] = "Android"; + } + var language = systemInfo.language; + if (language.indexOf('zh') > -1) { + language = "zh-CN"; + } + else { + language = "en-US"; + } + capabilities["language"] = language; + }; + return GraphicsCapabilities; + }(egret.Capabilities)); + es.GraphicsCapabilities = GraphicsCapabilities; +})(es || (es = {})); +var es; +(function (es) { + var GraphicsDevice = (function () { + function GraphicsDevice() { + this.graphicsCapabilities = new es.GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); } - }; - SceneTransition.prototype.loadNextScene = function () { - return __awaiter(this, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (this.onScreenObscured) - this.onScreenObscured(); - if (!this.loadsNewScene) { - this.isNewSceneLoaded = true; - } - _a = SceneManager; - return [4, this.sceneLoadAction()]; - case 1: - _a.scene = _b.sent(); - this.isNewSceneLoaded = true; - return [2]; - } - }); + return GraphicsDevice; + }()); + es.GraphicsDevice = GraphicsDevice; +})(es || (es = {})); +var es; +(function (es) { + var Viewport = (function () { + function Viewport(x, y, width, height) { + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } + Object.defineProperty(Viewport.prototype, "aspectRatio", { + get: function () { + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + }, + enumerable: true, + configurable: true }); - }; - SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) { - if (reverseDirection === void 0) { reverseDirection = false; } - return new Promise(function (resolve) { - var start = reverseDirection ? 1 : 0; - var end = reverseDirection ? 0 : 1; - egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () { - resolve(); - }); + Object.defineProperty(Viewport.prototype, "bounds", { + get: function () { + return new es.Rectangle(this._x, this._y, this._width, this._height); + }, + set: function (value) { + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + }, + enumerable: true, + configurable: true }); - }; - return SceneTransition; -}()); -var FadeTransition = (function (_super) { - __extends(FadeTransition, _super); - function FadeTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.fadeToColor = 0x000000; - _this.fadeOutDuration = 0.4; - _this.fadeEaseType = egret.Ease.quadInOut; - _this.delayBeforeFadeInDuration = 0.1; - _this._alpha = 0; - _this._mask = new egret.Shape(); - return _this; - } - FadeTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this._mask.graphics.endFill(); - SceneManager.stage.addChild(this._mask); - egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) - .call(function () { return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4, this.loadNextScene()]; - case 1: - _a.sent(); - return [2]; - } - }); - }); }).wait(this.delayBeforeFadeInDuration).call(function () { - egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { - _this.transitionComplete(); - SceneManager.stage.removeChild(_this._mask); - }); - }); - return [2]; - }); - }); - }; - FadeTransition.prototype.render = function () { - this._mask.graphics.clear(); - this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this._mask.graphics.endFill(); - }; - return FadeTransition; -}(SceneTransition)); -var WindTransition = (function (_super) { - __extends(WindTransition, _super); - function WindTransition(sceneLoadAction) { - var _this = _super.call(this, sceneLoadAction) || this; - _this.duration = 1; - _this.easeType = egret.Ease.quadOut; - var vertexSrc = "attribute vec2 aVertexPosition;\n" + + return Viewport; + }()); + es.Viewport = Viewport; +})(es || (es = {})); +var es; +(function (es) { + var GaussianBlurEffect = (function (_super) { + __extends(GaussianBlurEffect, _super); + function GaussianBlurEffect() { + return _super.call(this, es.PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { + screenWidth: es.SceneManager.stage.stageWidth, + screenHeight: es.SceneManager.stage.stageHeight + }) || this; + } + GaussianBlurEffect.blur_frag = "precision mediump float;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float screenWidth;\n" + + "uniform float screenHeight;\n" + + "float normpdf(in float x, in float sigma)\n" + + "{\n" + + "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + + "}\n" + + "void main()\n" + + "{\n" + + "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "const int mSize = 11;\n" + + "const int kSize = (mSize - 1)/2;\n" + + "float kernel[mSize];\n" + + "vec3 final_colour = vec3(0.0);\n" + + "float sigma = 7.0;\n" + + "float z = 0.0;\n" + + "for (int j = 0; j <= kSize; ++j)\n" + + "{\n" + + "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + + "}\n" + + "for (int j = 0; j < mSize; ++j)\n" + + "{\n" + + "z += kernel[j];\n" + + "}\n" + + "for (int i = -kSize; i <= kSize; ++i)\n" + + "{\n" + + "for (int j = -kSize; j <= kSize; ++j)\n" + + "{\n" + + "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "}\n}\n" + + "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + + "}"; + return GaussianBlurEffect; + }(egret.CustomFilter)); + es.GaussianBlurEffect = GaussianBlurEffect; +})(es || (es = {})); +var es; +(function (es) { + var PolygonLightEffect = (function (_super) { + __extends(PolygonLightEffect, _super); + function PolygonLightEffect() { + return _super.call(this, PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc) || this; + } + PolygonLightEffect.vertSrc = "attribute vec2 aVertexPosition;\n" + "attribute vec2 aTextureCoord;\n" + "uniform vec2 projectionVector;\n" + "varying vec2 vTextureCoord;\n" + @@ -3939,1369 +4261,1761 @@ var WindTransition = (function (_super) { " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + " vTextureCoord = aTextureCoord;\n" + "}"; - var fragmentSrc = "precision lowp float;\n" + + PolygonLightEffect.fragmentSrc = "precision lowp float;\n" + "varying vec2 vTextureCoord;\n" + "uniform sampler2D uSampler;\n" + - "uniform float _progress;\n" + - "uniform float _size;\n" + - "uniform float _windSegments;\n" + + "#define SAMPLE_COUNT 15\n" + + "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + + "uniform float _sampleWeights[SAMPLE_COUNT];\n" + "void main(void) {\n" + - "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + - "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + - "float r = x - floor(x);\n" + - "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + - "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + - "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + + "vec4 c = vec4(0, 0, 0, 0);\n" + + "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + + " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + + "gl_FragColor = c;\n" + "}"; - _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { - _progress: 0, - _size: 0.3, - _windSegments: 100 - }); - _this._mask = new egret.Shape(); - _this._mask.graphics.beginFill(0xFFFFFF, 1); - _this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - _this._mask.graphics.endFill(); - _this._mask.filters = [_this._windEffect]; - SceneManager.stage.addChild(_this._mask); - return _this; - } - Object.defineProperty(WindTransition.prototype, "windSegments", { - set: function (value) { - this._windEffect.uniforms._windSegments = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(WindTransition.prototype, "size", { - set: function (value) { - this._windEffect.uniforms._size = value; - }, - enumerable: true, - configurable: true - }); - WindTransition.prototype.onBeginTransition = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - this.loadNextScene(); - return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)]; - case 1: - _a.sent(); - this.transitionComplete(); - SceneManager.stage.removeChild(this._mask); - return [2]; - } - }); - }); - }; - return WindTransition; -}(SceneTransition)); -var Bezier = (function () { - function Bezier() { - } - Bezier.getPoint = function (p0, p1, p2, t) { - t = MathHelper.clamp01(t); - var oneMinusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMinusT * oneMinusT), p0), Vector2.multiply(new Vector2(2 * oneMinusT * t), p1)), Vector2.multiply(new Vector2(t * t), p2)); - }; - Bezier.getFirstDerivative = function (p0, p1, p2, t) { - return Vector2.add(Vector2.multiply(new Vector2(2 * (1 - t)), Vector2.subtract(p1, p0)), Vector2.multiply(new Vector2(2 * t), Vector2.subtract(p2, p1))); - }; - Bezier.getFirstDerivativeThree = function (start, firstControlPoint, secondControlPoint, end, t) { - t = MathHelper.clamp01(t); - var oneMunusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT), Vector2.subtract(firstControlPoint, start)), Vector2.multiply(new Vector2(6 * oneMunusT * t), Vector2.subtract(secondControlPoint, firstControlPoint))), Vector2.multiply(new Vector2(3 * t * t), Vector2.subtract(end, secondControlPoint))); - }; - Bezier.getPointThree = function (start, firstControlPoint, secondControlPoint, end, t) { - t = MathHelper.clamp01(t); - var oneMunusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMunusT * oneMunusT * oneMunusT), start), Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT * t), firstControlPoint)), Vector2.multiply(new Vector2(3 * oneMunusT * t * t), secondControlPoint)), Vector2.multiply(new Vector2(t * t * t), end)); - }; - Bezier.getOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, distanceTolerance) { - if (distanceTolerance === void 0) { distanceTolerance = 1; } - var points = ListPool.obtain(); - points.push(start); - this.recursiveGetOptimizedDrawingPoints(start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance); - points.push(end); - return points; - }; - Bezier.recursiveGetOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance) { - var pt12 = Vector2.divide(Vector2.add(start, firstCtrlPoint), new Vector2(2)); - var pt23 = Vector2.divide(Vector2.add(firstCtrlPoint, secondCtrlPoint), new Vector2(2)); - var pt34 = Vector2.divide(Vector2.add(secondCtrlPoint, end), new Vector2(2)); - var pt123 = Vector2.divide(Vector2.add(pt12, pt23), new Vector2(2)); - var pt234 = Vector2.divide(Vector2.add(pt23, pt34), new Vector2(2)); - var pt1234 = Vector2.divide(Vector2.add(pt123, pt234), new Vector2(2)); - var deltaLine = Vector2.subtract(end, start); - var d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); - var d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); - if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) { - points.push(pt1234); - return; + return PolygonLightEffect; + }(egret.CustomFilter)); + es.PolygonLightEffect = PolygonLightEffect; +})(es || (es = {})); +var es; +(function (es) { + var PostProcessor = (function () { + function PostProcessor(effect) { + if (effect === void 0) { effect = null; } + this.enabled = true; + this.effect = effect; } - this.recursiveGetOptimizedDrawingPoints(start, pt12, pt123, pt1234, points, distanceTolerance); - this.recursiveGetOptimizedDrawingPoints(pt1234, pt234, pt34, end, points, distanceTolerance); - }; - return Bezier; -}()); -var Flags = (function () { - function Flags() { - } - Flags.isFlagSet = function (self, flag) { - return (self & flag) != 0; - }; - Flags.isUnshiftedFlagSet = function (self, flag) { - flag = 1 << flag; - return (self & flag) != 0; - }; - Flags.setFlagExclusive = function (self, flag) { - return 1 << flag; - }; - Flags.setFlag = function (self, flag) { - return (self | 1 << flag); - }; - Flags.unsetFlag = function (self, flag) { - flag = 1 << flag; - return (self & (~flag)); - }; - Flags.invertFlags = function (self) { - return ~self; - }; - return Flags; -}()); -var MathHelper = (function () { - function MathHelper() { - } - MathHelper.toDegrees = function (radians) { - return radians * 57.295779513082320876798154814105; - }; - MathHelper.toRadians = function (degrees) { - return degrees * 0.017453292519943295769236907684886; - }; - MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { - return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); - }; - MathHelper.lerp = function (value1, value2, amount) { - return value1 + (value2 - value1) * amount; - }; - MathHelper.clamp = function (value, min, max) { - if (value < min) - return min; - if (value > max) - return max; - return value; - }; - MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { - var radians = MathHelper.toRadians(angleInDegrees); - return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); - }; - MathHelper.isEven = function (value) { - return value % 2 == 0; - }; - MathHelper.clamp01 = function (value) { - if (value < 0) - return 0; - if (value > 1) - return 1; - return value; - }; - MathHelper.angleBetweenVectors = function (from, to) { - return Math.atan2(to.y - from.y, to.x - from.x); - }; - MathHelper.Epsilon = 0.00001; - MathHelper.Rad2Deg = 57.29578; - MathHelper.Deg2Rad = 0.0174532924; - return MathHelper; -}()); -var Matrix2D = (function () { - function Matrix2D(m11, m12, m21, m22, m31, m32) { - this.m11 = 0; - this.m12 = 0; - this.m21 = 0; - this.m22 = 0; - this.m31 = 0; - this.m32 = 0; - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; - } - Object.defineProperty(Matrix2D, "identity", { - get: function () { - return Matrix2D._identity; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "translation", { - get: function () { - return new Vector2(this.m31, this.m32); - }, - set: function (value) { - this.m31 = value.x; - this.m32 = value.y; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "rotation", { - get: function () { - return Math.atan2(this.m21, this.m11); - }, - set: function (value) { - var val1 = Math.cos(value); - var val2 = Math.sin(value); - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { - get: function () { - return MathHelper.toDegrees(this.rotation); - }, - set: function (value) { - this.rotation = MathHelper.toRadians(value); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "scale", { - get: function () { - return new Vector2(this.m11, this.m22); - }, - set: function (value) { - this.m11 = value.x; - this.m12 = value.y; - }, - enumerable: true, - configurable: true - }); - Matrix2D.add = function (matrix1, matrix2) { - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; - return matrix1; - }; - Matrix2D.divide = function (matrix1, matrix2) { - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; - return matrix1; - }; - Matrix2D.multiply = function (matrix1, matrix2) { - var result = new Matrix2D(); - var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); - var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); - var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); - var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); - var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; - var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; - result.m11 = m11; - result.m12 = m12; - result.m21 = m21; - result.m22 = m22; - result.m31 = m31; - result.m32 = m32; - return result; - }; - Matrix2D.multiplyTranslation = function (matrix, x, y) { - var trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); - }; - Matrix2D.prototype.determinant = function () { - return this.m11 * this.m22 - this.m12 * this.m21; - }; - Matrix2D.invert = function (matrix, result) { - if (result === void 0) { result = new Matrix2D(); } - var det = 1 / matrix.determinant(); - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - return result; - }; - Matrix2D.createTranslation = function (xPosition, yPosition) { - var result = new Matrix2D(); - result.m11 = 1; - result.m12 = 0; - result.m21 = 0; - result.m22 = 1; - result.m31 = xPosition; - result.m32 = yPosition; - return result; - }; - Matrix2D.createTranslationVector = function (position) { - return this.createTranslation(position.x, position.y); - }; - Matrix2D.createRotation = function (radians, result) { - result = new Matrix2D(); - var val1 = Math.cos(radians); - var val2 = Math.sin(radians); - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - return result; - }; - Matrix2D.createScale = function (xScale, yScale, result) { - if (result === void 0) { result = new Matrix2D(); } - result.m11 = xScale; - result.m12 = 0; - result.m21 = 0; - result.m22 = yScale; - result.m31 = 0; - result.m32 = 0; - return result; - }; - Matrix2D.prototype.toEgretMatrix = function () { - var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); - return matrix; - }; - Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); - return Matrix2D; -}()); -var Rectangle = (function (_super) { - __extends(Rectangle, _super); - function Rectangle() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(Rectangle.prototype, "max", { - get: function () { - return new Vector2(this.right, this.bottom); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Rectangle.prototype, "center", { - get: function () { - return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Rectangle.prototype, "location", { - get: function () { - return new Vector2(this.x, this.y); - }, - set: function (value) { - this.x = value.x; - this.y = value.y; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Rectangle.prototype, "size", { - get: function () { - return new Vector2(this.width, this.height); - }, - set: function (value) { - this.width = value.x; - this.height = value.y; - }, - enumerable: true, - configurable: true - }); - Rectangle.prototype.intersects = function (value) { - return value.left < this.right && - this.left < value.right && - value.top < this.bottom && - this.top < value.bottom; - }; - Rectangle.prototype.containsRect = function (value) { - return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && - (this.y <= value.y)) && - (value.y < (this.y + this.height))); - }; - Rectangle.prototype.getHalfSize = function () { - return new Vector2(this.width * 0.5, this.height * 0.5); - }; - Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { - return new Rectangle(minX, minY, maxX - minX, maxY - minY); - }; - Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { - var edgeNormal = Vector2.zero; - var res = new Vector2(); - res.x = MathHelper.clamp(point.x, this.left, this.right); - res.y = MathHelper.clamp(point.y, this.top, this.bottom); - if (this.contains(res.x, res.y)) { - var dl = res.x - this.left; - var dr = this.right - res.x; - var dt = res.y - this.top; - var db = this.bottom - res.y; - var min = Math.min(dl, dr, dt, db); - if (min == dt) { - res.y = this.top; - edgeNormal.y = -1; - } - else if (min == db) { - res.y = this.bottom; - edgeNormal.y = 1; - } - else if (min == dl) { - res.x = this.left; - edgeNormal.x = -1; - } - else { - res.x = this.right; - edgeNormal.x = 1; - } - } - else { - if (res.x == this.left) - edgeNormal.x = -1; - if (res.x == this.right) - edgeNormal.x = 1; - if (res.y == this.top) - edgeNormal.y = -1; - if (res.y == this.bottom) - edgeNormal.y = 1; - } - return { res: res, edgeNormal: edgeNormal }; - }; - Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () { - var max = this.max; - var minDist = Math.abs(this.location.x); - var boundsPoint = new Vector2(this.location.x, 0); - if (Math.abs(max.x) < minDist) { - minDist = Math.abs(max.x); - boundsPoint.x = max.x; - boundsPoint.y = 0; - } - if (Math.abs(max.y) < minDist) { - minDist = Math.abs(max.y); - boundsPoint.x = 0; - boundsPoint.y = max.y; - } - if (Math.abs(this.location.y) < minDist) { - minDist = Math.abs(this.location.y); - boundsPoint.x = 0; - boundsPoint.y = this.location.y; - } - return boundsPoint; - }; - Rectangle.prototype.setEgretRect = function (rect) { - this.x = rect.x; - this.y = rect.y; - this.width = rect.width; - this.height = rect.height; - return this; - }; - Rectangle.rectEncompassingPoints = function (points) { - var minX = Number.POSITIVE_INFINITY; - var minY = Number.POSITIVE_INFINITY; - var maxX = Number.NEGATIVE_INFINITY; - var maxY = Number.NEGATIVE_INFINITY; - for (var i = 0; i < points.length; i++) { - var pt = points[i]; - if (pt.x < minX) - minX = pt.x; - if (pt.x > maxX) - maxX = pt.x; - if (pt.y < minY) - minY = pt.y; - if (pt.y > maxY) - maxY = pt.y; - } - return this.fromMinMax(minX, minY, maxX, maxY); - }; - return Rectangle; -}(egret.Rectangle)); -var Vector3 = (function () { - function Vector3(x, y, z) { - this.x = x; - this.y = y; - this.z = z; - } - return Vector3; -}()); -var ColliderTriggerHelper = (function () { - function ColliderTriggerHelper(entity) { - this._activeTriggerIntersections = []; - this._previousTriggerIntersections = []; - this._tempTriggerList = []; - this._entity = entity; - } - ColliderTriggerHelper.prototype.update = function () { - var colliders = this._entity.getComponents(Collider); - for (var i = 0; i < colliders.length; i++) { - var collider = colliders[i]; - var boxcastResult = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); - collider.bounds = boxcastResult.rect; - var neighbors = boxcastResult.colliders; - var _loop_5 = function (j) { - var neighbor = neighbors[j]; - if (!collider.isTrigger && !neighbor.isTrigger) - return "continue"; - if (collider.overlaps(neighbor)) { - var pair_1 = new Pair(collider, neighbor); - var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) { - return value.first == pair_1.first && value.second == pair_1.second; - }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) { - return value.first == pair_1.first && value.second == pair_1.second; - }) == -1; - if (shouldReportTriggerEvent) - this_1.notifyTriggerListeners(pair_1, true); - if (!this_1._activeTriggerIntersections.contains(pair_1)) - this_1._activeTriggerIntersections.push(pair_1); - } - }; - var this_1 = this; - for (var j = 0; j < neighbors.length; j++) { - _loop_5(j); - } - } - ListPool.free(colliders); - this.checkForExitedColliders(); - }; - ColliderTriggerHelper.prototype.checkForExitedColliders = function () { - var _this = this; - var _loop_6 = function (i) { - var index = this_2._previousTriggerIntersections.findIndex(function (value) { - if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second) - return true; - return false; - }); - if (index != -1) - this_2._previousTriggerIntersections.removeAt(index); + PostProcessor.prototype.onAddedToScene = function (scene) { + this.scene = scene; + this.shape = new egret.Shape(); + this.shape.graphics.beginFill(0xFFFFFF, 1); + this.shape.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.shape.graphics.endFill(); + scene.addChild(this.shape); }; - var this_2 = this; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - _loop_6(i); - } - for (var i = 0; i < this._previousTriggerIntersections.length; i++) { - this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); - } - this._previousTriggerIntersections.length = 0; - for (var i = 0; i < this._activeTriggerIntersections.length; i++) { - if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) { - this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); + PostProcessor.prototype.process = function () { + this.drawFullscreenQuad(); + }; + PostProcessor.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { }; + PostProcessor.prototype.drawFullscreenQuad = function () { + this.scene.filters = [this.effect]; + }; + PostProcessor.prototype.unload = function () { + if (this.effect) { + this.effect = null; } + this.scene.removeChild(this.shape); + this.scene = null; + }; + PostProcessor.default_vert = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "attribute vec2 aColor;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "varying vec4 vColor;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + "vTextureCoord = aTextureCoord;\n" + + "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + + "}"; + return PostProcessor; + }()); + es.PostProcessor = PostProcessor; +})(es || (es = {})); +var es; +(function (es) { + var GaussianBlurPostProcessor = (function (_super) { + __extends(GaussianBlurPostProcessor, _super); + function GaussianBlurPostProcessor() { + return _super !== null && _super.apply(this, arguments) || this; } - this._activeTriggerIntersections.length = 0; - }; - ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) { - collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i = 0; i < this._tempTriggerList.length; i++) { - if (isEntering) { - this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); + GaussianBlurPostProcessor.prototype.onAddedToScene = function (scene) { + _super.prototype.onAddedToScene.call(this, scene); + this.effect = new es.GaussianBlurEffect(); + }; + return GaussianBlurPostProcessor; + }(es.PostProcessor)); + es.GaussianBlurPostProcessor = GaussianBlurPostProcessor; +})(es || (es = {})); +var es; +(function (es) { + var Renderer = (function () { + function Renderer() { + } + Renderer.prototype.onAddedToScene = function (scene) { }; + Renderer.prototype.beginRender = function (cam) { + }; + Renderer.prototype.unload = function () { }; + Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { + renderable.render(cam); + }; + return Renderer; + }()); + es.Renderer = Renderer; +})(es || (es = {})); +var es; +(function (es) { + var DefaultRenderer = (function (_super) { + __extends(DefaultRenderer, _super); + function DefaultRenderer() { + return _super !== null && _super.apply(this, arguments) || this; + } + DefaultRenderer.prototype.render = function (scene) { + var cam = this.camera ? this.camera : scene.camera; + this.beginRender(cam); + for (var i = 0; i < scene.renderableComponents.count; i++) { + var renderable = scene.renderableComponents.buffer[i]; + if (renderable.enabled && renderable.isVisibleFromCamera(cam)) + this.renderAfterStateCheck(renderable, cam); + } + }; + return DefaultRenderer; + }(es.Renderer)); + es.DefaultRenderer = DefaultRenderer; +})(es || (es = {})); +var es; +(function (es) { + var ScreenSpaceRenderer = (function (_super) { + __extends(ScreenSpaceRenderer, _super); + function ScreenSpaceRenderer() { + return _super !== null && _super.apply(this, arguments) || this; + } + ScreenSpaceRenderer.prototype.render = function (scene) { + }; + return ScreenSpaceRenderer; + }(es.Renderer)); + es.ScreenSpaceRenderer = ScreenSpaceRenderer; +})(es || (es = {})); +var es; +(function (es) { + var PolyLight = (function (_super) { + __extends(PolyLight, _super); + function PolyLight(radius, color, power) { + var _this = _super.call(this) || this; + _this._indices = []; + _this.radius = radius; + _this.power = power; + _this.color = color; + _this.computeTriangleIndices(); + return _this; + } + Object.defineProperty(PolyLight.prototype, "radius", { + get: function () { + return this._radius; + }, + set: function (value) { + this.setRadius(value); + }, + enumerable: true, + configurable: true + }); + PolyLight.prototype.computeTriangleIndices = function (totalTris) { + if (totalTris === void 0) { totalTris = 20; } + this._indices.length = 0; + for (var i = 0; i < totalTris; i += 2) { + this._indices.push(0); + this._indices.push(i + 2); + this._indices.push(i + 1); + } + }; + PolyLight.prototype.setRadius = function (radius) { + if (radius != this._radius) { + this._radius = radius; + this._areBoundsDirty = true; + } + }; + PolyLight.prototype.render = function (camera) { + }; + PolyLight.prototype.reset = function () { + }; + return PolyLight; + }(es.RenderableComponent)); + es.PolyLight = PolyLight; +})(es || (es = {})); +var es; +(function (es) { + var SceneTransition = (function () { + function SceneTransition(sceneLoadAction) { + this.sceneLoadAction = sceneLoadAction; + this.loadsNewScene = sceneLoadAction != null; + } + Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { + get: function () { + if (!this._hasPreviousSceneRender) { + this._hasPreviousSceneRender = true; + return false; + } + return true; + }, + enumerable: true, + configurable: true + }); + SceneTransition.prototype.preRender = function () { }; + SceneTransition.prototype.render = function () { + }; + SceneTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + this.transitionComplete(); + return [2]; + } + }); + }); + }; + SceneTransition.prototype.transitionComplete = function () { + es.SceneManager.sceneTransition = null; + if (this.onTransitionCompleted) { + this.onTransitionCompleted(); + } + }; + SceneTransition.prototype.loadNextScene = function () { + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (this.onScreenObscured) + this.onScreenObscured(); + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + } + _a = es.SceneManager; + return [4, this.sceneLoadAction()]; + case 1: + _a.scene = _b.sent(); + this.isNewSceneLoaded = true; + return [2]; + } + }); + }); + }; + SceneTransition.prototype.tickEffectProgressProperty = function (filter, duration, easeType, reverseDirection) { + if (reverseDirection === void 0) { reverseDirection = false; } + return new Promise(function (resolve) { + var start = reverseDirection ? 1 : 0; + var end = reverseDirection ? 0 : 1; + egret.Tween.get(filter.uniforms).set({ _progress: start }).to({ _progress: end }, duration * 1000, easeType).call(function () { + resolve(); + }); + }); + }; + return SceneTransition; + }()); + es.SceneTransition = SceneTransition; +})(es || (es = {})); +var es; +(function (es) { + var FadeTransition = (function (_super) { + __extends(FadeTransition, _super); + function FadeTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.fadeToColor = 0x000000; + _this.fadeOutDuration = 0.4; + _this.fadeEaseType = egret.Ease.quadInOut; + _this.delayBeforeFadeInDuration = 0.1; + _this._alpha = 0; + _this._mask = new egret.Shape(); + return _this; + } + FadeTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + var _this = this; + return __generator(this, function (_a) { + this._mask.graphics.beginFill(this.fadeToColor, 1); + this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + es.SceneManager.stage.addChild(this._mask); + egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) + .call(function () { return __awaiter(_this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4, this.loadNextScene()]; + case 1: + _a.sent(); + return [2]; + } + }); + }); }).wait(this.delayBeforeFadeInDuration).call(function () { + egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { + _this.transitionComplete(); + es.SceneManager.stage.removeChild(_this._mask); + }); + }); + return [2]; + }); + }); + }; + FadeTransition.prototype.render = function () { + this._mask.graphics.clear(); + this._mask.graphics.beginFill(this.fadeToColor, this._alpha); + this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + }; + return FadeTransition; + }(es.SceneTransition)); + es.FadeTransition = FadeTransition; +})(es || (es = {})); +var es; +(function (es) { + var WindTransition = (function (_super) { + __extends(WindTransition, _super); + function WindTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction) || this; + _this.duration = 1; + _this.easeType = egret.Ease.quadOut; + var vertexSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "uniform vec2 projectionVector;\n" + + "varying vec2 vTextureCoord;\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + var fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float _progress;\n" + + "uniform float _size;\n" + + "uniform float _windSegments;\n" + + "void main(void) {\n" + + "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + + "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + + "float r = x - floor(x);\n" + + "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + + "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + + "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + + "}"; + _this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { + _progress: 0, + _size: 0.3, + _windSegments: 100 + }); + _this._mask = new egret.Shape(); + _this._mask.graphics.beginFill(0xFFFFFF, 1); + _this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + _this._mask.graphics.endFill(); + _this._mask.filters = [_this._windEffect]; + es.SceneManager.stage.addChild(_this._mask); + return _this; + } + Object.defineProperty(WindTransition.prototype, "windSegments", { + set: function (value) { + this._windEffect.uniforms._windSegments = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(WindTransition.prototype, "size", { + set: function (value) { + this._windEffect.uniforms._size = value; + }, + enumerable: true, + configurable: true + }); + WindTransition.prototype.onBeginTransition = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.loadNextScene(); + return [4, this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType)]; + case 1: + _a.sent(); + this.transitionComplete(); + es.SceneManager.stage.removeChild(this._mask); + return [2]; + } + }); + }); + }; + return WindTransition; + }(es.SceneTransition)); + es.WindTransition = WindTransition; +})(es || (es = {})); +var es; +(function (es) { + var Bezier = (function () { + function Bezier() { + } + Bezier.getPoint = function (p0, p1, p2, t) { + t = es.MathHelper.clamp01(t); + var oneMinusT = 1 - t; + return es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(oneMinusT * oneMinusT), p0), es.Vector2.multiply(new es.Vector2(2 * oneMinusT * t), p1)), es.Vector2.multiply(new es.Vector2(t * t), p2)); + }; + Bezier.getFirstDerivative = function (p0, p1, p2, t) { + return es.Vector2.add(es.Vector2.multiply(new es.Vector2(2 * (1 - t)), es.Vector2.subtract(p1, p0)), es.Vector2.multiply(new es.Vector2(2 * t), es.Vector2.subtract(p2, p1))); + }; + Bezier.getFirstDerivativeThree = function (start, firstControlPoint, secondControlPoint, end, t) { + t = es.MathHelper.clamp01(t); + var oneMunusT = 1 - t; + return es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(3 * oneMunusT * oneMunusT), es.Vector2.subtract(firstControlPoint, start)), es.Vector2.multiply(new es.Vector2(6 * oneMunusT * t), es.Vector2.subtract(secondControlPoint, firstControlPoint))), es.Vector2.multiply(new es.Vector2(3 * t * t), es.Vector2.subtract(end, secondControlPoint))); + }; + Bezier.getPointThree = function (start, firstControlPoint, secondControlPoint, end, t) { + t = es.MathHelper.clamp01(t); + var oneMunusT = 1 - t; + return es.Vector2.add(es.Vector2.add(es.Vector2.add(es.Vector2.multiply(new es.Vector2(oneMunusT * oneMunusT * oneMunusT), start), es.Vector2.multiply(new es.Vector2(3 * oneMunusT * oneMunusT * t), firstControlPoint)), es.Vector2.multiply(new es.Vector2(3 * oneMunusT * t * t), secondControlPoint)), es.Vector2.multiply(new es.Vector2(t * t * t), end)); + }; + Bezier.getOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, distanceTolerance) { + if (distanceTolerance === void 0) { distanceTolerance = 1; } + var points = es.ListPool.obtain(); + points.push(start); + this.recursiveGetOptimizedDrawingPoints(start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance); + points.push(end); + return points; + }; + Bezier.recursiveGetOptimizedDrawingPoints = function (start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance) { + var pt12 = es.Vector2.divide(es.Vector2.add(start, firstCtrlPoint), new es.Vector2(2)); + var pt23 = es.Vector2.divide(es.Vector2.add(firstCtrlPoint, secondCtrlPoint), new es.Vector2(2)); + var pt34 = es.Vector2.divide(es.Vector2.add(secondCtrlPoint, end), new es.Vector2(2)); + var pt123 = es.Vector2.divide(es.Vector2.add(pt12, pt23), new es.Vector2(2)); + var pt234 = es.Vector2.divide(es.Vector2.add(pt23, pt34), new es.Vector2(2)); + var pt1234 = es.Vector2.divide(es.Vector2.add(pt123, pt234), new es.Vector2(2)); + var deltaLine = es.Vector2.subtract(end, start); + var d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); + var d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); + if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) { + points.push(pt1234); + return; + } + this.recursiveGetOptimizedDrawingPoints(start, pt12, pt123, pt1234, points, distanceTolerance); + this.recursiveGetOptimizedDrawingPoints(pt1234, pt234, pt34, end, points, distanceTolerance); + }; + return Bezier; + }()); + es.Bezier = Bezier; +})(es || (es = {})); +var es; +(function (es) { + var Flags = (function () { + function Flags() { + } + Flags.isFlagSet = function (self, flag) { + return (self & flag) != 0; + }; + Flags.isUnshiftedFlagSet = function (self, flag) { + flag = 1 << flag; + return (self & flag) != 0; + }; + Flags.setFlagExclusive = function (self, flag) { + return 1 << flag; + }; + Flags.setFlag = function (self, flag) { + return (self | 1 << flag); + }; + Flags.unsetFlag = function (self, flag) { + flag = 1 << flag; + return (self & (~flag)); + }; + Flags.invertFlags = function (self) { + return ~self; + }; + return Flags; + }()); + es.Flags = Flags; +})(es || (es = {})); +var es; +(function (es) { + var MathHelper = (function () { + function MathHelper() { + } + MathHelper.toDegrees = function (radians) { + return radians * 57.295779513082320876798154814105; + }; + MathHelper.toRadians = function (degrees) { + return degrees * 0.017453292519943295769236907684886; + }; + MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { + return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); + }; + MathHelper.lerp = function (value1, value2, amount) { + return value1 + (value2 - value1) * amount; + }; + MathHelper.clamp = function (value, min, max) { + if (value < min) + return min; + if (value > max) + return max; + return value; + }; + MathHelper.pointOnCirlce = function (circleCenter, radius, angleInDegrees) { + var radians = MathHelper.toRadians(angleInDegrees); + return new es.Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); + }; + MathHelper.isEven = function (value) { + return value % 2 == 0; + }; + MathHelper.clamp01 = function (value) { + if (value < 0) + return 0; + if (value > 1) + return 1; + return value; + }; + MathHelper.angleBetweenVectors = function (from, to) { + return Math.atan2(to.y - from.y, to.x - from.x); + }; + MathHelper.Epsilon = 0.00001; + MathHelper.Rad2Deg = 57.29578; + MathHelper.Deg2Rad = 0.0174532924; + return MathHelper; + }()); + es.MathHelper = MathHelper; +})(es || (es = {})); +var es; +(function (es) { + var Matrix2D = (function () { + function Matrix2D(m11, m12, m21, m22, m31, m32) { + this.m11 = 0; + this.m12 = 0; + this.m21 = 0; + this.m22 = 0; + this.m31 = 0; + this.m32 = 0; + this.m11 = m11 ? m11 : 1; + this.m12 = m12 ? m12 : 0; + this.m21 = m21 ? m21 : 0; + this.m22 = m22 ? m22 : 1; + this.m31 = m31 ? m31 : 0; + this.m32 = m32 ? m32 : 0; + } + Object.defineProperty(Matrix2D, "identity", { + get: function () { + return Matrix2D._identity; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "translation", { + get: function () { + return new es.Vector2(this.m31, this.m32); + }, + set: function (value) { + this.m31 = value.x; + this.m32 = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotation", { + get: function () { + return Math.atan2(this.m21, this.m11); + }, + set: function (value) { + var val1 = Math.cos(value); + var val2 = Math.sin(value); + this.m11 = val1; + this.m12 = val2; + this.m21 = -val2; + this.m22 = val1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { + get: function () { + return es.MathHelper.toDegrees(this.rotation); + }, + set: function (value) { + this.rotation = es.MathHelper.toRadians(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "scale", { + get: function () { + return new es.Vector2(this.m11, this.m22); + }, + set: function (value) { + this.m11 = value.x; + this.m12 = value.y; + }, + enumerable: true, + configurable: true + }); + Matrix2D.add = function (matrix1, matrix2) { + matrix1.m11 += matrix2.m11; + matrix1.m12 += matrix2.m12; + matrix1.m21 += matrix2.m21; + matrix1.m22 += matrix2.m22; + matrix1.m31 += matrix2.m31; + matrix1.m32 += matrix2.m32; + return matrix1; + }; + Matrix2D.divide = function (matrix1, matrix2) { + matrix1.m11 /= matrix2.m11; + matrix1.m12 /= matrix2.m12; + matrix1.m21 /= matrix2.m21; + matrix1.m22 /= matrix2.m22; + matrix1.m31 /= matrix2.m31; + matrix1.m32 /= matrix2.m32; + return matrix1; + }; + Matrix2D.multiply = function (matrix1, matrix2) { + var result = new Matrix2D(); + var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); + var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); + var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); + var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); + var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; + var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; + result.m11 = m11; + result.m12 = m12; + result.m21 = m21; + result.m22 = m22; + result.m31 = m31; + result.m32 = m32; + return result; + }; + Matrix2D.multiplyTranslation = function (matrix, x, y) { + var trans = Matrix2D.createTranslation(x, y); + return Matrix2D.multiply(matrix, trans); + }; + Matrix2D.prototype.determinant = function () { + return this.m11 * this.m22 - this.m12 * this.m21; + }; + Matrix2D.invert = function (matrix, result) { + if (result === void 0) { result = new Matrix2D(); } + var det = 1 / matrix.determinant(); + result.m11 = matrix.m22 * det; + result.m12 = -matrix.m12 * det; + result.m21 = -matrix.m21 * det; + result.m22 = matrix.m11 * det; + result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; + result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; + return result; + }; + Matrix2D.createTranslation = function (xPosition, yPosition) { + var result = new Matrix2D(); + result.m11 = 1; + result.m12 = 0; + result.m21 = 0; + result.m22 = 1; + result.m31 = xPosition; + result.m32 = yPosition; + return result; + }; + Matrix2D.createTranslationVector = function (position) { + return this.createTranslation(position.x, position.y); + }; + Matrix2D.createRotation = function (radians, result) { + result = new Matrix2D(); + var val1 = Math.cos(radians); + var val2 = Math.sin(radians); + result.m11 = val1; + result.m12 = val2; + result.m21 = -val2; + result.m22 = val1; + return result; + }; + Matrix2D.createScale = function (xScale, yScale, result) { + if (result === void 0) { result = new Matrix2D(); } + result.m11 = xScale; + result.m12 = 0; + result.m21 = 0; + result.m22 = yScale; + result.m31 = 0; + result.m32 = 0; + return result; + }; + Matrix2D.prototype.toEgretMatrix = function () { + var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + }; + Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); + return Matrix2D; + }()); + es.Matrix2D = Matrix2D; +})(es || (es = {})); +var es; +(function (es) { + var Rectangle = (function (_super) { + __extends(Rectangle, _super); + function Rectangle() { + return _super !== null && _super.apply(this, arguments) || this; + } + Object.defineProperty(Rectangle.prototype, "max", { + get: function () { + return new es.Vector2(this.right, this.bottom); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "center", { + get: function () { + return new es.Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "location", { + get: function () { + return new es.Vector2(this.x, this.y); + }, + set: function (value) { + this.x = value.x; + this.y = value.y; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Rectangle.prototype, "size", { + get: function () { + return new es.Vector2(this.width, this.height); + }, + set: function (value) { + this.width = value.x; + this.height = value.y; + }, + enumerable: true, + configurable: true + }); + Rectangle.prototype.intersects = function (value) { + return value.left < this.right && + this.left < value.right && + value.top < this.bottom && + this.top < value.bottom; + }; + Rectangle.prototype.containsRect = function (value) { + return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && + (this.y <= value.y)) && + (value.y < (this.y + this.height))); + }; + Rectangle.prototype.getHalfSize = function () { + return new es.Vector2(this.width * 0.5, this.height * 0.5); + }; + Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { + return new Rectangle(minX, minY, maxX - minX, maxY - minY); + }; + Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { + var edgeNormal = es.Vector2.zero; + var res = new es.Vector2(); + res.x = es.MathHelper.clamp(point.x, this.left, this.right); + res.y = es.MathHelper.clamp(point.y, this.top, this.bottom); + if (this.contains(res.x, res.y)) { + var dl = res.x - this.left; + var dr = this.right - res.x; + var dt = res.y - this.top; + var db = this.bottom - res.y; + var min = Math.min(dl, dr, dt, db); + if (min == dt) { + res.y = this.top; + edgeNormal.y = -1; + } + else if (min == db) { + res.y = this.bottom; + edgeNormal.y = 1; + } + else if (min == dl) { + res.x = this.left; + edgeNormal.x = -1; + } + else { + res.x = this.right; + edgeNormal.x = 1; + } } else { - this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); + if (res.x == this.left) + edgeNormal.x = -1; + if (res.x == this.right) + edgeNormal.x = 1; + if (res.y == this.top) + edgeNormal.y = -1; + if (res.y == this.bottom) + edgeNormal.y = 1; } - this._tempTriggerList.length = 0; - if (collisionPair.second.entity) { - collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { - if (isEntering) { - this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second); - } - else { - this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second); + return { res: res, edgeNormal: edgeNormal }; + }; + Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () { + var max = this.max; + var minDist = Math.abs(this.location.x); + var boundsPoint = new es.Vector2(this.location.x, 0); + if (Math.abs(max.x) < minDist) { + minDist = Math.abs(max.x); + boundsPoint.x = max.x; + boundsPoint.y = 0; + } + if (Math.abs(max.y) < minDist) { + minDist = Math.abs(max.y); + boundsPoint.x = 0; + boundsPoint.y = max.y; + } + if (Math.abs(this.location.y) < minDist) { + minDist = Math.abs(this.location.y); + boundsPoint.x = 0; + boundsPoint.y = this.location.y; + } + return boundsPoint; + }; + Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) { + this.x = parentPosition.x + position.x - origin.x * scale.x; + this.y = parentPosition.y + position.y - origin.y * scale.y; + this.width = width * scale.x; + this.height = height * scale.y; + }; + Rectangle.prototype.setEgretRect = function (rect) { + this.x = rect.x; + this.y = rect.y; + this.width = rect.width; + this.height = rect.height; + return this; + }; + Rectangle.rectEncompassingPoints = function (points) { + var minX = Number.POSITIVE_INFINITY; + var minY = Number.POSITIVE_INFINITY; + var maxX = Number.NEGATIVE_INFINITY; + var maxY = Number.NEGATIVE_INFINITY; + for (var i = 0; i < points.length; i++) { + var pt = points[i]; + if (pt.x < minX) + minX = pt.x; + if (pt.x > maxX) + maxX = pt.x; + if (pt.y < minY) + minY = pt.y; + if (pt.y > maxY) + maxY = pt.y; + } + return this.fromMinMax(minX, minY, maxX, maxY); + }; + return Rectangle; + }(egret.Rectangle)); + es.Rectangle = Rectangle; +})(es || (es = {})); +var es; +(function (es) { + var Vector3 = (function () { + function Vector3(x, y, z) { + this.x = x; + this.y = y; + this.z = z; + } + return Vector3; + }()); + es.Vector3 = Vector3; +})(es || (es = {})); +var es; +(function (es) { + var ColliderTriggerHelper = (function () { + function ColliderTriggerHelper(entity) { + this._activeTriggerIntersections = []; + this._previousTriggerIntersections = []; + this._tempTriggerList = []; + this._entity = entity; + } + ColliderTriggerHelper.prototype.update = function () { + var colliders = this._entity.getComponents(es.Collider); + for (var i = 0; i < colliders.length; i++) { + var collider = colliders[i]; + var boxcastResult = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); + collider.bounds = boxcastResult.rect; + var neighbors = boxcastResult.colliders; + var _loop_5 = function (j) { + var neighbor = neighbors[j]; + if (!collider.isTrigger && !neighbor.isTrigger) + return "continue"; + if (collider.overlaps(neighbor)) { + var pair_1 = new es.Pair(collider, neighbor); + var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) { + return value.first == pair_1.first && value.second == pair_1.second; + }) == -1; + if (shouldReportTriggerEvent) + this_1.notifyTriggerListeners(pair_1, true); + if (!this_1._activeTriggerIntersections.contains(pair_1)) + this_1._activeTriggerIntersections.push(pair_1); } + }; + var this_1 = this; + for (var j = 0; j < neighbors.length; j++) { + _loop_5(j); + } + } + es.ListPool.free(colliders); + this.checkForExitedColliders(); + }; + ColliderTriggerHelper.prototype.checkForExitedColliders = function () { + var _this = this; + var _loop_6 = function (i) { + var index = this_2._previousTriggerIntersections.findIndex(function (value) { + if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second) + return true; + return false; + }); + if (index != -1) + this_2._previousTriggerIntersections.removeAt(index); + }; + var this_2 = this; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + _loop_6(i); + } + for (var i = 0; i < this._previousTriggerIntersections.length; i++) { + this.notifyTriggerListeners(this._previousTriggerIntersections[i], false); + } + this._previousTriggerIntersections.length = 0; + for (var i = 0; i < this._activeTriggerIntersections.length; i++) { + if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])) { + this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); + } + } + this._activeTriggerIntersections.length = 0; + }; + ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) { + collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i = 0; i < this._tempTriggerList.length; i++) { + if (isEntering) { + this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); + } + else { + this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); } this._tempTriggerList.length = 0; + if (collisionPair.second.entity) { + collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (var i_2 = 0; i_2 < this._tempTriggerList.length; i_2++) { + if (isEntering) { + this._tempTriggerList[i_2].onTriggerEnter(collisionPair.first, collisionPair.second); + } + else { + this._tempTriggerList[i_2].onTriggerExit(collisionPair.first, collisionPair.second); + } + } + this._tempTriggerList.length = 0; + } } + }; + return ColliderTriggerHelper; + }()); + es.ColliderTriggerHelper = ColliderTriggerHelper; +})(es || (es = {})); +var es; +(function (es) { + var PointSectors; + (function (PointSectors) { + PointSectors[PointSectors["center"] = 0] = "center"; + PointSectors[PointSectors["top"] = 1] = "top"; + PointSectors[PointSectors["bottom"] = 2] = "bottom"; + PointSectors[PointSectors["topLeft"] = 9] = "topLeft"; + PointSectors[PointSectors["topRight"] = 5] = "topRight"; + PointSectors[PointSectors["left"] = 8] = "left"; + PointSectors[PointSectors["right"] = 4] = "right"; + PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft"; + PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight"; + })(PointSectors = es.PointSectors || (es.PointSectors = {})); + var Collisions = (function () { + function Collisions() { } - }; - return ColliderTriggerHelper; -}()); -var PointSectors; -(function (PointSectors) { - PointSectors[PointSectors["center"] = 0] = "center"; - PointSectors[PointSectors["top"] = 1] = "top"; - PointSectors[PointSectors["bottom"] = 2] = "bottom"; - PointSectors[PointSectors["topLeft"] = 9] = "topLeft"; - PointSectors[PointSectors["topRight"] = 5] = "topRight"; - PointSectors[PointSectors["left"] = 8] = "left"; - PointSectors[PointSectors["right"] = 4] = "right"; - PointSectors[PointSectors["bottomLeft"] = 10] = "bottomLeft"; - PointSectors[PointSectors["bottomRight"] = 6] = "bottomRight"; -})(PointSectors || (PointSectors = {})); -var Collisions = (function () { - function Collisions() { - } - Collisions.isLineToLine = function (a1, a2, b1, b2) { - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) - return false; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) - return false; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) - return false; - return true; - }; - Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { - var intersection = new Vector2(0, 0); - var b = Vector2.subtract(a2, a1); - var d = Vector2.subtract(b2, b1); - var bDotDPerp = b.x * d.y - b.y * d.x; - if (bDotDPerp == 0) - return intersection; - var c = Vector2.subtract(b1, a1); - var t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) - return intersection; - var u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) - return intersection; - intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); - return intersection; - }; - Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); - }; - Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) { - return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); - }; - Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) { - return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; - }; - Collisions.isCircleToPoint = function (circleCenter, radius, point) { - return Vector2.distanceSquared(circleCenter, point) < radius * radius; - }; - Collisions.isRectToCircle = function (rect, cPosition, cRadius) { - var ew = rect.width * 0.5; - var eh = rect.height * 0.5; - var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); - var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); - return vx * vx + vy * vy < cRadius * cRadius; - }; - Collisions.isRectToLine = function (rect, lineFrom, lineTo) { - var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); - var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); - if (fromSector == PointSectors.center || toSector == PointSectors.center) { + Collisions.isLineToLine = function (a1, a2, b1, b2) { + var b = es.Vector2.subtract(a2, a1); + var d = es.Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return false; + var c = es.Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return false; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return false; return true; - } - else if ((fromSector & toSector) != 0) { + }; + Collisions.lineToLineIntersection = function (a1, a2, b1, b2) { + var intersection = new es.Vector2(0, 0); + var b = es.Vector2.subtract(a2, a1); + var d = es.Vector2.subtract(b2, b1); + var bDotDPerp = b.x * d.y - b.y * d.x; + if (bDotDPerp == 0) + return intersection; + var c = es.Vector2.subtract(b1, a1); + var t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return intersection; + var u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return intersection; + intersection = es.Vector2.add(a1, new es.Vector2(t * b.x, t * b.y)); + return intersection; + }; + Collisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = es.Vector2.subtract(lineB, lineA); + var w = es.Vector2.subtract(closestTo, lineA); + var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v); + t = es.MathHelper.clamp(t, 0, 1); + return es.Vector2.add(lineA, new es.Vector2(v.x * t, v.y * t)); + }; + Collisions.isCircleToCircle = function (circleCenter1, circleRadius1, circleCenter2, circleRadius2) { + return es.Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); + }; + Collisions.isCircleToLine = function (circleCenter, radius, lineFrom, lineTo) { + return es.Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; + }; + Collisions.isCircleToPoint = function (circleCenter, radius, point) { + return es.Vector2.distanceSquared(circleCenter, point) < radius * radius; + }; + Collisions.isRectToCircle = function (rect, cPosition, cRadius) { + var ew = rect.width * 0.5; + var eh = rect.height * 0.5; + var vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); + var vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); + return vx * vx + vy * vy < cRadius * cRadius; + }; + Collisions.isRectToLine = function (rect, lineFrom, lineTo) { + var fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); + var toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); + if (fromSector == PointSectors.center || toSector == PointSectors.center) { + return true; + } + else if ((fromSector & toSector) != 0) { + return false; + } + else { + var both = fromSector | toSector; + var edgeFrom = void 0; + var edgeTo = void 0; + if ((both & PointSectors.top) != 0) { + edgeFrom = new es.Vector2(rect.x, rect.y); + edgeTo = new es.Vector2(rect.x + rect.width, rect.y); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.bottom) != 0) { + edgeFrom = new es.Vector2(rect.x, rect.y + rect.height); + edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.left) != 0) { + edgeFrom = new es.Vector2(rect.x, rect.y); + edgeTo = new es.Vector2(rect.x, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + if ((both & PointSectors.right) != 0) { + edgeFrom = new es.Vector2(rect.x + rect.width, rect.y); + edgeTo = new es.Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + } return false; + }; + Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { + return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; + }; + Collisions.getSector = function (rX, rY, rW, rH, point) { + var sector = PointSectors.center; + if (point.x < rX) + sector |= PointSectors.left; + else if (point.x >= rX + rW) + sector |= PointSectors.right; + if (point.y < rY) + sector |= PointSectors.top; + else if (point.y >= rY + rH) + sector |= PointSectors.bottom; + return sector; + }; + return Collisions; + }()); + es.Collisions = Collisions; +})(es || (es = {})); +var es; +(function (es) { + var Physics = (function () { + function Physics() { } - else { - var both = fromSector | toSector; - var edgeFrom = void 0; - var edgeTo = void 0; - if ((both & PointSectors.top) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + Physics.reset = function () { + this._spatialHash = new es.SpatialHash(this.spatialHashCellSize); + }; + Physics.clear = function () { + this._spatialHash.clear(); + }; + Physics.overlapCircleAll = function (center, randius, results, layerMask) { + if (layerMask === void 0) { layerMask = -1; } + return this._spatialHash.overlapCircle(center, randius, results, layerMask); + }; + Physics.boxcastBroadphase = function (rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + var boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); + return { colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds }; + }; + Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { + if (layerMask === void 0) { layerMask = this.allLayers; } + return this._spatialHash.aabbBroadphase(rect, collider, layerMask); + }; + Physics.addCollider = function (collider) { + Physics._spatialHash.register(collider); + }; + Physics.removeCollider = function (collider) { + Physics._spatialHash.remove(collider); + }; + Physics.updateCollider = function (collider) { + this._spatialHash.remove(collider); + this._spatialHash.register(collider); + }; + Physics.debugDraw = function (secondsToDisplay) { + this._spatialHash.debugDraw(secondsToDisplay, 2); + }; + Physics.spatialHashCellSize = 100; + Physics.allLayers = -1; + return Physics; + }()); + es.Physics = Physics; +})(es || (es = {})); +var es; +(function (es) { + var Shape = (function () { + function Shape() { + } + return Shape; + }()); + es.Shape = Shape; +})(es || (es = {})); +var es; +(function (es) { + var Polygon = (function (_super) { + __extends(Polygon, _super); + function Polygon(points, isBox) { + var _this = _super.call(this) || this; + _this._areEdgeNormalsDirty = true; + _this.isUnrotated = true; + _this.setPoints(points); + _this.isBox = isBox; + return _this; + } + Object.defineProperty(Polygon.prototype, "edgeNormals", { + get: function () { + if (this._areEdgeNormalsDirty) + this.buildEdgeNormals(); + return this._edgeNormals; + }, + enumerable: true, + configurable: true + }); + Polygon.prototype.setPoints = function (points) { + this.points = points; + this.recalculateCenterAndEdgeNormals(); + this._originalPoints = []; + for (var i = 0; i < this.points.length; i++) { + this._originalPoints.push(this.points[i]); } - if ((both & PointSectors.bottom) != 0) { - edgeFrom = new Vector2(rect.x, rect.y + rect.height); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + }; + Polygon.prototype.recalculateCenterAndEdgeNormals = function () { + this._polygonCenter = Polygon.findPolygonCenter(this.points); + this._areEdgeNormalsDirty = true; + }; + Polygon.prototype.buildEdgeNormals = function () { + var totalEdges = this.isBox ? 2 : this.points.length; + if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) + this._edgeNormals = new Array(totalEdges); + var p2; + for (var i = 0; i < totalEdges; i++) { + var p1 = this.points[i]; + if (i + 1 >= this.points.length) + p2 = this.points[0]; + else + p2 = this.points[i + 1]; + var perp = es.Vector2Ext.perpendicular(p1, p2); + perp = es.Vector2.normalize(perp); + this._edgeNormals[i] = perp; } - if ((both & PointSectors.left) != 0) { - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + }; + Polygon.buildSymmetricalPolygon = function (vertCount, radius) { + var verts = new Array(vertCount); + for (var i = 0; i < vertCount; i++) { + var a = 2 * Math.PI * (i / vertCount); + verts[i] = new es.Vector2(Math.cos(a), Math.sin(a) * radius); } - if ((both & PointSectors.right) != 0) { - edgeFrom = new Vector2(rect.x + rect.width, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; + return verts; + }; + Polygon.recenterPolygonVerts = function (points) { + var center = this.findPolygonCenter(points); + for (var i = 0; i < points.length; i++) + points[i] = es.Vector2.subtract(points[i], center); + }; + Polygon.findPolygonCenter = function (points) { + var x = 0, y = 0; + for (var i = 0; i < points.length; i++) { + x += points[i].x; + y += points[i].y; } + return new es.Vector2(x / points.length, y / points.length); + }; + Polygon.getClosestPointOnPolygonToPoint = function (points, point) { + var distanceSquared = Number.MAX_VALUE; + var edgeNormal = new es.Vector2(0, 0); + var closestPoint = new es.Vector2(0, 0); + var tempDistanceSquared; + for (var i = 0; i < points.length; i++) { + var j = i + 1; + if (j == points.length) + j = 0; + var closest = es.ShapeCollisions.closestPointOnLine(points[i], points[j], point); + tempDistanceSquared = es.Vector2.distanceSquared(point, closest); + if (tempDistanceSquared < distanceSquared) { + distanceSquared = tempDistanceSquared; + closestPoint = closest; + var line = es.Vector2.subtract(points[j], points[i]); + edgeNormal.x = -line.y; + edgeNormal.y = line.x; + } + } + edgeNormal = es.Vector2.normalize(edgeNormal); + return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + }; + Polygon.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotateWithTransform) { + this.isUnrotated = collider.entity.transform.rotation == 0; + } + this.position = es.Vector2.add(collider.entity.transform.position, this.center); + this.bounds = es.Rectangle.rectEncompassingPoints(this.points); + this.bounds.location = es.Vector2.add(this.bounds.location, this.position); + }; + Polygon.prototype.overlaps = function (other) { + var result; + if (other instanceof Polygon) + return es.ShapeCollisions.polygonToPolygon(this, other); + if (other instanceof es.Circle) { + result = es.ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return true; + } + return false; + } + throw new Error("overlaps of Pologon to " + other + " are not supported"); + }; + Polygon.prototype.collidesWithShape = function (other) { + var result = new es.CollisionResult(); + if (other instanceof Polygon) { + return es.ShapeCollisions.polygonToPolygon(this, other); + } + if (other instanceof es.Circle) { + result = es.ShapeCollisions.circleToPolygon(other, this); + if (result) { + result.invertResult(); + return result; + } + return null; + } + throw new Error("overlaps of Polygon to " + other + " are not supported"); + }; + Polygon.prototype.containsPoint = function (point) { + point = es.Vector2.subtract(point, this.position); + var isInside = false; + for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { + if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && + (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + + this.points[i].x)) { + isInside = !isInside; + } + } + return isInside; + }; + Polygon.prototype.pointCollidesWithShape = function (point) { + return es.ShapeCollisions.pointToPoly(point, this); + }; + return Polygon; + }(es.Shape)); + es.Polygon = Polygon; +})(es || (es = {})); +var es; +(function (es) { + var Box = (function (_super) { + __extends(Box, _super); + function Box(width, height) { + var _this = _super.call(this, Box.buildBox(width, height), true) || this; + _this.width = width; + _this.height = height; + return _this; } - return false; - }; - Collisions.isRectToPoint = function (rX, rY, rW, rH, point) { - return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; - }; - Collisions.getSector = function (rX, rY, rW, rH, point) { - var sector = PointSectors.center; - if (point.x < rX) - sector |= PointSectors.left; - else if (point.x >= rX + rW) - sector |= PointSectors.right; - if (point.y < rY) - sector |= PointSectors.top; - else if (point.y >= rY + rH) - sector |= PointSectors.bottom; - return sector; - }; - return Collisions; -}()); -var Physics = (function () { - function Physics() { - } - Physics.reset = function () { - this._spatialHash = new SpatialHash(this.spatialHashCellSize); - }; - Physics.clear = function () { - this._spatialHash.clear(); - }; - Physics.overlapCircleAll = function (center, randius, results, layerMask) { - if (layerMask === void 0) { layerMask = -1; } - return this._spatialHash.overlapCircle(center, randius, results, layerMask); - }; - Physics.boxcastBroadphase = function (rect, layerMask) { - if (layerMask === void 0) { layerMask = this.allLayers; } - var boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); - return { colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds }; - }; - Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { - if (layerMask === void 0) { layerMask = this.allLayers; } - return this._spatialHash.aabbBroadphase(rect, collider, layerMask); - }; - Physics.addCollider = function (collider) { - Physics._spatialHash.register(collider); - }; - Physics.removeCollider = function (collider) { - Physics._spatialHash.remove(collider); - }; - Physics.updateCollider = function (collider) { - this._spatialHash.remove(collider); - this._spatialHash.register(collider); - }; - Physics.debugDraw = function (secondsToDisplay) { - this._spatialHash.debugDraw(secondsToDisplay, 2); - }; - Physics.spatialHashCellSize = 100; - Physics.allLayers = -1; - return Physics; -}()); -var Shape = (function (_super) { - __extends(Shape, _super); - function Shape() { - return _super !== null && _super.apply(this, arguments) || this; - } - return Shape; -}(egret.DisplayObject)); -var Polygon = (function (_super) { - __extends(Polygon, _super); - function Polygon(points, isBox) { - var _this = _super.call(this) || this; - _this._areEdgeNormalsDirty = true; - _this.center = new Vector2(); - _this.setPoints(points); - _this.isBox = isBox; - return _this; - } - Object.defineProperty(Polygon.prototype, "position", { - get: function () { - return new Vector2(this.parent.x, this.parent.y); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Polygon.prototype, "bounds", { - get: function () { - return new Rectangle(this.x, this.y, this.width, this.height); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Polygon.prototype, "edgeNormals", { - get: function () { - if (this._areEdgeNormalsDirty) - this.buildEdgeNormals(); - return this._edgeNormals; - }, - enumerable: true, - configurable: true - }); - Polygon.prototype.buildEdgeNormals = function () { - var totalEdges = this.isBox ? 2 : this.points.length; - if (this._edgeNormals == null || this._edgeNormals.length != totalEdges) - this._edgeNormals = new Array(totalEdges); - var p2; - for (var i = 0; i < totalEdges; i++) { - var p1 = this.points[i]; - if (i + 1 >= this.points.length) - p2 = this.points[0]; - else - p2 = this.points[i + 1]; - var perp = Vector2Ext.perpendicular(p1, p2); - perp = Vector2.normalize(perp); - this._edgeNormals[i] = perp; + Box.buildBox = function (width, height) { + var halfWidth = width / 2; + var halfHeight = height / 2; + var verts = new Array(4); + verts[0] = new es.Vector2(-halfWidth, -halfHeight); + verts[1] = new es.Vector2(halfWidth, -halfHeight); + verts[2] = new es.Vector2(halfWidth, halfHeight); + verts[3] = new es.Vector2(-halfWidth, halfHeight); + return verts; + }; + Box.prototype.updateBox = function (width, height) { + this.width = width; + this.height = height; + var halfWidth = width / 2; + var halfHeight = height / 2; + this.points[0] = new es.Vector2(-halfWidth, -halfHeight); + this.points[1] = new es.Vector2(halfWidth, -halfHeight); + this.points[2] = new es.Vector2(halfWidth, halfHeight); + this.points[3] = new es.Vector2(-halfWidth, halfHeight); + for (var i = 0; i < this.points.length; i++) + this._originalPoints[i] = this.points[i]; + }; + Box.prototype.overlaps = function (other) { + if (this.isUnrotated) { + if (other instanceof Box) + return this.bounds.intersects(other.bounds); + if (other instanceof es.Circle) + return es.Collisions.isRectToCircle(this.bounds, other.position, other.radius); + } + return _super.prototype.overlaps.call(this, other); + }; + Box.prototype.collidesWithShape = function (other) { + if (other instanceof Box && other.isUnrotated) { + return es.ShapeCollisions.boxToBox(this, other); + } + return _super.prototype.collidesWithShape.call(this, other); + }; + Box.prototype.containsPoint = function (point) { + if (this.isUnrotated) + return this.bounds.contains(point.x, point.y); + return _super.prototype.containsPoint.call(this, point); + }; + return Box; + }(es.Polygon)); + es.Box = Box; +})(es || (es = {})); +var es; +(function (es) { + var Circle = (function (_super) { + __extends(Circle, _super); + function Circle(radius) { + var _this = _super.call(this) || this; + _this.radius = radius; + _this._originalRadius = radius; + return _this; } - }; - Polygon.prototype.setPoints = function (points) { - this.points = points; - this.recalculateCenterAndEdgeNormals(); - this._originalPoints = []; - for (var i = 0; i < this.points.length; i++) { - this._originalPoints.push(this.points[i]); + Circle.prototype.recalculateBounds = function (collider) { + this.center = collider.localOffset; + if (collider.shouldColliderScaleAndRotateWithTransform) { + var scale = collider.entity.transform.scale; + var hasUnitScale = scale.x == 1 && scale.y == 1; + var maxScale = Math.max(scale.x, scale.y); + this.radius = this._originalRadius * maxScale; + if (collider.entity.transform.rotation != 0) { + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg; + var offsetLength = hasUnitScale ? collider._localOffsetLength : es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); + } + } + this.position = es.Vector2.add(collider.transform.position, this.center); + this.bounds = new es.Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); + }; + Circle.prototype.overlaps = function (other) { + if (other instanceof es.Box && other.isUnrotated) + return es.Collisions.isRectToCircle(other.bounds, this.position, this.radius); + if (other instanceof Circle) + return es.Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); + if (other instanceof es.Polygon) + return es.ShapeCollisions.circleToPolygon(this, other); + throw new Error("overlaps of circle to " + other + " are not supported"); + }; + Circle.prototype.collidesWithShape = function (other) { + if (other instanceof es.Box && other.isUnrotated) { + return es.ShapeCollisions.circleToBox(this, other); + } + if (other instanceof Circle) { + return es.ShapeCollisions.circleToCircle(this, other); + } + if (other instanceof es.Polygon) { + return es.ShapeCollisions.circleToPolygon(this, other); + } + throw new Error("Collisions of Circle to " + other + " are not supported"); + }; + Circle.prototype.pointCollidesWithShape = function (point) { + return es.ShapeCollisions.pointToCircle(point, this); + }; + return Circle; + }(es.Shape)); + es.Circle = Circle; +})(es || (es = {})); +var es; +(function (es) { + var CollisionResult = (function () { + function CollisionResult() { + this.minimumTranslationVector = es.Vector2.zero; + this.normal = es.Vector2.zero; + this.point = es.Vector2.zero; } - }; - Polygon.prototype.collidesWithShape = function (other) { - var result = new CollisionResult(); - if (other instanceof Polygon) { - return ShapeCollisions.polygonToPolygon(this, other); + CollisionResult.prototype.invertResult = function () { + this.minimumTranslationVector = es.Vector2.negate(this.minimumTranslationVector); + this.normal = es.Vector2.negate(this.normal); + }; + return CollisionResult; + }()); + es.CollisionResult = CollisionResult; +})(es || (es = {})); +var es; +(function (es) { + var ShapeCollisions = (function () { + function ShapeCollisions() { } - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); + ShapeCollisions.polygonToPolygon = function (first, second) { + var result = new es.CollisionResult(); + var isIntersecting = true; + var firstEdges = first.edgeNormals; + var secondEdges = second.edgeNormals; + var minIntervalDistance = Number.POSITIVE_INFINITY; + var translationAxis = new es.Vector2(); + var polygonOffset = es.Vector2.subtract(first.position, second.position); + var axis; + for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { + if (edgeIndex < firstEdges.length) { + axis = firstEdges[edgeIndex]; + } + else { + axis = secondEdges[edgeIndex - firstEdges.length]; + } + var minA = 0; + var minB = 0; + var maxA = 0; + var maxB = 0; + var intervalDist = 0; + var ta = this.getInterval(axis, first, minA, maxA); + minA = ta.min; + minB = ta.max; + var tb = this.getInterval(axis, second, minB, maxB); + minB = tb.min; + maxB = tb.max; + var relativeIntervalOffset = es.Vector2.dot(polygonOffset, axis); + minA += relativeIntervalOffset; + maxA += relativeIntervalOffset; + intervalDist = this.intervalDistance(minA, maxA, minB, maxB); + if (intervalDist > 0) + isIntersecting = false; + if (!isIntersecting) + return null; + intervalDist = Math.abs(intervalDist); + if (intervalDist < minIntervalDistance) { + minIntervalDistance = intervalDist; + translationAxis = axis; + if (es.Vector2.dot(translationAxis, polygonOffset) < 0) + translationAxis = new es.Vector2(-translationAxis); + } + } + result.normal = translationAxis; + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-translationAxis.x, -translationAxis.y), new es.Vector2(minIntervalDistance)); + return result; + }; + ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { + if (minA < minB) + return minB - maxA; + return minA - minB; + }; + ShapeCollisions.getInterval = function (axis, polygon, min, max) { + var dot = es.Vector2.dot(polygon.points[0], axis); + min = max = dot; + for (var i = 1; i < polygon.points.length; i++) { + dot = es.Vector2.dot(polygon.points[i], axis); + if (dot < min) { + min = dot; + } + else if (dot > max) { + max = dot; + } + } + return { min: min, max: max }; + }; + ShapeCollisions.circleToPolygon = function (circle, polygon) { + var result = new es.CollisionResult(); + var poly2Circle = es.Vector2.subtract(circle.position, polygon.position); + var gpp = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); + var closestPoint = gpp.closestPoint; + var distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + var circleCenterInsidePoly = polygon.containsPoint(circle.position); + if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) + return null; + var mtv; + if (circleCenterInsidePoly) { + mtv = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared) - circle.radius)); + } + else { + if (distanceSquared == 0) { + mtv = es.Vector2.multiply(result.normal, new es.Vector2(circle.radius)); + } + else { + var distance = Math.sqrt(distanceSquared); + mtv = es.Vector2.multiply(new es.Vector2(-es.Vector2.subtract(poly2Circle, closestPoint)), new es.Vector2((circle.radius - distanceSquared) / distance)); + } + } + result.minimumTranslationVector = mtv; + result.point = es.Vector2.add(closestPoint, polygon.position); + return result; + }; + ShapeCollisions.circleToBox = function (circle, box) { + var result = new es.CollisionResult(); + var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; + if (box.containsPoint(circle.position)) { + result.point = closestPointOnBounds; + var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.subtract(result.normal, new es.Vector2(circle.radius))); + result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace); + return result; + } + var sqrDistance = es.Vector2.distanceSquared(closestPointOnBounds, circle.position); + if (sqrDistance == 0) { + result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(circle.radius)); + } + else if (sqrDistance <= circle.radius * circle.radius) { + result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds); + var depth = result.normal.length() - circle.radius; + result.normal = es.Vector2Ext.normalize(result.normal); + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal); return result; } return null; - } - throw new Error("overlaps of Polygon to " + other + " are not supported"); - }; - Polygon.prototype.recalculateCenterAndEdgeNormals = function () { - this._polygonCenter = Polygon.findPolygonCenter(this.points); - this._areEdgeNormalsDirty = true; - }; - Polygon.prototype.overlaps = function (other) { - var result; - if (other instanceof Polygon) - return ShapeCollisions.polygonToPolygon(this, other); - if (other instanceof Circle) { - result = ShapeCollisions.circleToPolygon(other, this); - if (result) { - result.invertResult(); - return true; + }; + ShapeCollisions.pointToCircle = function (point, circle) { + var result = new es.CollisionResult(); + var distanceSquared = es.Vector2.distanceSquared(point, circle.position); + var sumOfRadii = 1 + circle.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = es.Vector2.normalize(es.Vector2.subtract(point, circle.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth, -depth), result.normal); + result.point = es.Vector2.add(circle.position, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius, circle.radius))); + return result; } - return false; - } - throw new Error("overlaps of Pologon to " + other + " are not supported"); - }; - Polygon.findPolygonCenter = function (points) { - var x = 0, y = 0; - for (var i = 0; i < points.length; i++) { - x += points[i].x; - y += points[i].y; - } - return new Vector2(x / points.length, y / points.length); - }; - Polygon.recenterPolygonVerts = function (points) { - var center = this.findPolygonCenter(points); - for (var i = 0; i < points.length; i++) - points[i] = Vector2.subtract(points[i], center); - }; - Polygon.getClosestPointOnPolygonToPoint = function (points, point) { - var distanceSquared = Number.MAX_VALUE; - var edgeNormal = new Vector2(0, 0); - var closestPoint = new Vector2(0, 0); - var tempDistanceSquared; - for (var i = 0; i < points.length; i++) { - var j = i + 1; - if (j == points.length) - j = 0; - var closest = ShapeCollisions.closestPointOnLine(points[i], points[j], point); - tempDistanceSquared = Vector2.distanceSquared(point, closest); - if (tempDistanceSquared < distanceSquared) { - distanceSquared = tempDistanceSquared; - closestPoint = closest; - var line = Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; - } - } - edgeNormal = Vector2.normalize(edgeNormal); - return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; - }; - Polygon.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToPoly(point, this); - }; - Polygon.prototype.containsPoint = function (point) { - point = Vector2.subtract(point, this.position); - var isInside = false; - for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) { - if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) && - (point.x < (this.points[j].x - this.points[i].x) * (point.y - this.points[i].y) / (this.points[j].y - this.points[i].y) + - this.points[i].x)) { - isInside = !isInside; - } - } - return isInside; - }; - Polygon.buildSymmertricalPolygon = function (vertCount, radius) { - var verts = new Array(vertCount); - for (var i = 0; i < vertCount; i++) { - var a = 2 * Math.PI * (i / vertCount); - verts[i] = new Vector2(Math.cos(a), Math.sin(a) * radius); - } - return verts; - }; - return Polygon; -}(Shape)); -var Box = (function (_super) { - __extends(Box, _super); - function Box(width, height) { - var _this = _super.call(this, Box.buildBox(width, height), true) || this; - _this.width = width; - _this.height = height; - return _this; - } - Box.buildBox = function (width, height) { - var halfWidth = width / 2; - var halfHeight = height / 2; - var verts = new Array(4); - verts[0] = new Vector2(-halfWidth, -halfHeight); - verts[1] = new Vector2(halfWidth, -halfHeight); - verts[2] = new Vector2(halfWidth, halfHeight); - verts[3] = new Vector2(-halfWidth, halfHeight); - return verts; - }; - Box.prototype.overlaps = function (other) { - if (other instanceof Box) - return this.bounds.intersects(other.bounds); - if (other instanceof Circle) - return Collisions.isRectToCircle(this.bounds, other.position, other.radius); - return _super.prototype.overlaps.call(this, other); - }; - Box.prototype.collidesWithShape = function (other) { - if (other instanceof Box) { - return ShapeCollisions.boxToBox(this, other); - } - return _super.prototype.collidesWithShape.call(this, other); - }; - Box.prototype.updateBox = function (width, height) { - this.width = width; - this.height = height; - var halfWidth = width / 2; - var halfHeight = height / 2; - this.points[0] = new Vector2(-halfWidth, -halfHeight); - this.points[1] = new Vector2(halfWidth, -halfHeight); - this.points[2] = new Vector2(halfWidth, halfHeight); - this.points[3] = new Vector2(-halfWidth, halfHeight); - for (var i = 0; i < this.points.length; i++) - this._originalPoints[i] = this.points[i]; - }; - Box.prototype.containsPoint = function (point) { - return this.bounds.contains(point.x, point.y); - }; - return Box; -}(Polygon)); -var Circle = (function (_super) { - __extends(Circle, _super); - function Circle(radius) { - var _this = _super.call(this) || this; - _this.center = new Vector2(); - _this.radius = radius; - _this._originalRadius = radius; - return _this; - } - Object.defineProperty(Circle.prototype, "position", { - get: function () { - return new Vector2(this.parent.x, this.parent.y); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Circle.prototype, "bounds", { - get: function () { - return new Rectangle().setEgretRect(this.getBounds()); - }, - enumerable: true, - configurable: true - }); - Circle.prototype.pointCollidesWithShape = function (point) { - return ShapeCollisions.pointToCircle(point, this); - }; - Circle.prototype.collidesWithShape = function (other) { - if (other instanceof Box) { - return ShapeCollisions.circleToBox(this, other); - } - if (other instanceof Circle) { - return ShapeCollisions.circleToCircle(this, other); - } - if (other instanceof Polygon) { - return ShapeCollisions.circleToPolygon(this, other); - } - throw new Error("Collisions of Circle to " + other + " are not supported"); - }; - Circle.prototype.overlaps = function (other) { - if (other instanceof Box) - return Collisions.isRectToCircle(other.bounds, this.position, this.radius); - if (other instanceof Circle) - return Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); - if (other instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, other); - throw new Error("overlaps of circle to " + other + " are not supported"); - }; - return Circle; -}(Shape)); -var CollisionResult = (function () { - function CollisionResult() { - this.minimumTranslationVector = Vector2.zero; - this.normal = Vector2.zero; - this.point = Vector2.zero; - } - CollisionResult.prototype.invertResult = function () { - this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector); - this.normal = Vector2.negate(this.normal); - }; - return CollisionResult; -}()); -var ShapeCollisions = (function () { - function ShapeCollisions() { - } - ShapeCollisions.polygonToPolygon = function (first, second) { - var result = new CollisionResult(); - var isIntersecting = true; - var firstEdges = first.edgeNormals; - var secondEdges = second.edgeNormals; - var minIntervalDistance = Number.POSITIVE_INFINITY; - var translationAxis = new Vector2(); - var polygonOffset = Vector2.subtract(first.position, second.position); - var axis; - for (var edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { - if (edgeIndex < firstEdges.length) { - axis = firstEdges[edgeIndex]; - } - else { - axis = secondEdges[edgeIndex - firstEdges.length]; - } - var minA = 0; - var minB = 0; - var maxA = 0; - var maxB = 0; - var intervalDist = 0; - var ta = this.getInterval(axis, first, minA, maxA); - minA = ta.min; - minB = ta.max; - var tb = this.getInterval(axis, second, minB, maxB); - minB = tb.min; - maxB = tb.max; - var relativeIntervalOffset = Vector2.dot(polygonOffset, axis); - minA += relativeIntervalOffset; - maxA += relativeIntervalOffset; - intervalDist = this.intervalDistance(minA, maxA, minB, maxB); - if (intervalDist > 0) - isIntersecting = false; - if (!isIntersecting) - return null; - intervalDist = Math.abs(intervalDist); - if (intervalDist < minIntervalDistance) { - minIntervalDistance = intervalDist; - translationAxis = axis; - if (Vector2.dot(translationAxis, polygonOffset) < 0) - translationAxis = new Vector2(-translationAxis); - } - } - result.normal = translationAxis; - result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance)); - return result; - }; - ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { - if (minA < minB) - return minB - maxA; - return minA - minB; - }; - ShapeCollisions.getInterval = function (axis, polygon, min, max) { - var dot = Vector2.dot(polygon.points[0], axis); - min = max = dot; - for (var i = 1; i < polygon.points.length; i++) { - dot = Vector2.dot(polygon.points[i], axis); - if (dot < min) { - min = dot; - } - else if (dot > max) { - max = dot; - } - } - return { min: min, max: max }; - }; - ShapeCollisions.circleToPolygon = function (circle, polygon) { - var result = new CollisionResult(); - var poly2Circle = Vector2.subtract(circle.position, polygon.position); - var gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); - var closestPoint = gpp.closestPoint; - var distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - var circleCenterInsidePoly = polygon.containsPoint(circle.position); - if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) return null; - var mtv; - if (circleCenterInsidePoly) { - mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared) - circle.radius)); - } - else { - if (distanceSquared == 0) { - mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); + }; + ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { + var v = es.Vector2.subtract(lineB, lineA); + var w = es.Vector2.subtract(closestTo, lineA); + var t = es.Vector2.dot(w, v) / es.Vector2.dot(v, v); + t = es.MathHelper.clamp(t, 0, 1); + return es.Vector2.add(lineA, es.Vector2.multiply(v, new es.Vector2(t, t))); + }; + ShapeCollisions.pointToPoly = function (point, poly) { + var result = new es.CollisionResult(); + if (poly.containsPoint(point)) { + var distanceSquared = void 0; + var gpp = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position)); + var closestPoint = gpp.closestPoint; + distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); + result.point = es.Vector2.add(closestPoint, poly.position); + return result; } - else { - var distance = Math.sqrt(distanceSquared); - mtv = Vector2.multiply(new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), new Vector2((circle.radius - distanceSquared) / distance)); + return null; + }; + ShapeCollisions.circleToCircle = function (first, second) { + var result = new es.CollisionResult(); + var distanceSquared = es.Vector2.distanceSquared(first.position, second.position); + var sumOfRadii = first.radius + second.radius; + var collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = es.Vector2.normalize(es.Vector2.subtract(first.position, second.position)); + var depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth), result.normal); + result.point = es.Vector2.add(second.position, es.Vector2.multiply(result.normal, new es.Vector2(second.radius))); + return result; } - } - result.minimumTranslationVector = mtv; - result.point = Vector2.add(closestPoint, polygon.position); - return result; - }; - ShapeCollisions.circleToBox = function (circle, box) { - var result = new CollisionResult(); - var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; - if (box.containsPoint(circle.position)) { - result.point = closestPointOnBounds; - var safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); - result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); - return result; - } - var sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); - if (sqrDistance == 0) { - result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius)); - } - else if (sqrDistance <= circle.radius * circle.radius) { - result.normal = Vector2.subtract(circle.position, closestPointOnBounds); - var depth = result.normal.length() - circle.radius; - result.normal = Vector2Ext.normalize(result.normal); - result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); - return result; - } - return null; - }; - ShapeCollisions.pointToCircle = function (point, circle) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared(point, circle.position); - var sumOfRadii = 1 + circle.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize(Vector2.subtract(point, circle.position)); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal); - result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius))); - return result; - } - return null; - }; - ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { - var v = Vector2.subtract(lineB, lineA); - var w = Vector2.subtract(closestTo, lineA); - var t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); - }; - ShapeCollisions.pointToPoly = function (point, poly) { - var result = new CollisionResult(); - if (poly.containsPoint(point)) { - var distanceSquared = void 0; - var gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position)); - var closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); - result.point = Vector2.add(closestPoint, poly.position); - return result; - } - return null; - }; - ShapeCollisions.circleToCircle = function (first, second) { - var result = new CollisionResult(); - var distanceSquared = Vector2.distanceSquared(first.position, second.position); - var sumOfRadii = first.radius + second.radius; - var collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position)); - var depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal); - result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius))); - return result; - } - return null; - }; - ShapeCollisions.boxToBox = function (first, second) { - var result = new CollisionResult(); - var minkowskiDiff = this.minkowskiDifference(first, second); - if (minkowskiDiff.contains(0, 0)) { - result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); - if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) - return null; - result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); - result.normal.normalize(); - return result; - } - return null; - }; - ShapeCollisions.minkowskiDifference = function (first, second) { - var positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, Vector2.divide(first.bounds.size, new Vector2(2)))); - var topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max); - var fullSize = Vector2.add(first.bounds.size, second.bounds.size); - return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y); - }; - return ShapeCollisions; -}()); -var SpatialHash = (function () { - function SpatialHash(cellSize) { - if (cellSize === void 0) { cellSize = 100; } - this.gridBounds = new Rectangle(); - this._overlapTestCircle = new Circle(0); - this._tempHashSet = []; - this._cellDict = new NumberDictionary(); - this._cellSize = cellSize; - this._inverseCellSize = 1 / this._cellSize; - this._raycastParser = new RaycastResultParser(); - } - SpatialHash.prototype.remove = function (collider) { - var bounds = collider.registeredPhysicsBounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) - console.error("removing Collider [" + collider + "] from a cell that it is not present in"); - else - cell.remove(collider); + return null; + }; + ShapeCollisions.boxToBox = function (first, second) { + var result = new es.CollisionResult(); + var minkowskiDiff = this.minkowskiDifference(first, second); + if (minkowskiDiff.contains(0, 0)) { + result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); + if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) + return null; + result.normal = new es.Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); + result.normal.normalize(); + return result; } + return null; + }; + ShapeCollisions.minkowskiDifference = function (first, second) { + var positionOffset = es.Vector2.subtract(first.position, es.Vector2.add(first.bounds.location, es.Vector2.divide(first.bounds.size, new es.Vector2(2)))); + var topLeft = es.Vector2.subtract(es.Vector2.add(first.bounds.location, positionOffset), second.bounds.max); + var fullSize = es.Vector2.add(first.bounds.size, second.bounds.size); + return new es.Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y); + }; + return ShapeCollisions; + }()); + es.ShapeCollisions = ShapeCollisions; +})(es || (es = {})); +var es; +(function (es) { + var SpatialHash = (function () { + function SpatialHash(cellSize) { + if (cellSize === void 0) { cellSize = 100; } + this.gridBounds = new es.Rectangle(); + this._overlapTestCircle = new es.Circle(0); + this._cellDict = new NumberDictionary(); + this._tempHashSet = []; + this._cellSize = cellSize; + this._inverseCellSize = 1 / this._cellSize; + this._raycastParser = new RaycastResultParser(); } - }; - SpatialHash.prototype.register = function (collider) { - var bounds = collider.bounds; - collider.registeredPhysicsBounds = bounds; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - if (!this.gridBounds.contains(p1.x, p1.y)) { - this.gridBounds = RectangleExt.union(this.gridBounds, p1); - } - if (!this.gridBounds.contains(p2.x, p2.y)) { - this.gridBounds = RectangleExt.union(this.gridBounds, p2); - } - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var c = this.cellAtPosition(x, y, true); - if (c.indexOf(collider) == -1) - c.push(collider); - } - } - }; - SpatialHash.prototype.clear = function () { - this._cellDict.clear(); - }; - SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { - var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); - this._overlapTestCircle.radius = radius; - var resultCounter = 0; - var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); - bounds = aabbBroadphaseResult.bounds; - var potentials = aabbBroadphaseResult.tempHashSet; - for (var i = 0; i < potentials.length; i++) { - var collider = potentials[i]; - if (collider instanceof BoxCollider) { - results[resultCounter] = collider; - resultCounter++; - } - else if (collider instanceof CircleCollider) { - if (collider.shape.overlaps(this._overlapTestCircle)) { - results[resultCounter] = collider; - resultCounter++; + SpatialHash.prototype.cellCoords = function (x, y) { + return new es.Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); + }; + SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { + if (createCellIfEmpty === void 0) { createCellIfEmpty = false; } + var cell = this._cellDict.tryGetValue(x, y); + if (!cell) { + if (createCellIfEmpty) { + cell = []; + this._cellDict.add(x, y, cell); } } - else if (collider instanceof PolygonCollider) { - if (collider.shape.overlaps(this._overlapTestCircle)) { - results[resultCounter] = collider; - resultCounter++; + return cell; + }; + SpatialHash.prototype.register = function (collider) { + var bounds = collider.bounds; + collider.registeredPhysicsBounds = bounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + if (!this.gridBounds.contains(p1.x, p1.y)) { + this.gridBounds = es.RectangleExt.union(this.gridBounds, p1); + } + if (!this.gridBounds.contains(p2.x, p2.y)) { + this.gridBounds = es.RectangleExt.union(this.gridBounds, p2); + } + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var c = this.cellAtPosition(x, y, true); + if (c.indexOf(collider) == -1) + c.push(collider); } } - else { - throw new Error("overlapCircle against this collider type is not implemented!"); + }; + SpatialHash.prototype.remove = function (collider) { + var bounds = collider.registeredPhysicsBounds; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) + console.error("removing Collider [" + collider + "] from a cell that it is not present in"); + else + cell.remove(collider); + } } - if (resultCounter == results.length) - return resultCounter; - } - return resultCounter; - }; - SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) { - this._tempHashSet.length = 0; - var p1 = this.cellCoords(bounds.x, bounds.y); - var p2 = this.cellCoords(bounds.right, bounds.bottom); - for (var x = p1.x; x <= p2.x; x++) { - for (var y = p1.y; y <= p2.y; y++) { - var cell = this.cellAtPosition(x, y); - if (!cell) - continue; - for (var i = 0; i < cell.length; i++) { - var collider = cell[i]; - if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer)) + }; + SpatialHash.prototype.removeWithBruteForce = function (obj) { + this._cellDict.remove(obj); + }; + SpatialHash.prototype.clear = function () { + this._cellDict.clear(); + }; + SpatialHash.prototype.debugDraw = function (secondsToDisplay, textScale) { + if (textScale === void 0) { textScale = 1; } + for (var x = this.gridBounds.x; x <= this.gridBounds.right; x++) { + for (var y = this.gridBounds.y; y <= this.gridBounds.bottom; y++) { + var cell = this.cellAtPosition(x, y); + if (cell && cell.length > 0) + this.debugDrawCellDetails(x, y, cell.length, secondsToDisplay, textScale); + } + } + }; + SpatialHash.prototype.debugDrawCellDetails = function (x, y, cellCount, secondsToDisplay, textScale) { + if (secondsToDisplay === void 0) { secondsToDisplay = 0.5; } + if (textScale === void 0) { textScale = 1; } + }; + SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) { + this._tempHashSet.length = 0; + var p1 = this.cellCoords(bounds.x, bounds.y); + var p2 = this.cellCoords(bounds.right, bounds.bottom); + for (var x = p1.x; x <= p2.x; x++) { + for (var y = p1.y; y <= p2.y; y++) { + var cell = this.cellAtPosition(x, y); + if (!cell) continue; - if (bounds.intersects(collider.bounds)) { - if (this._tempHashSet.indexOf(collider) == -1) - this._tempHashSet.push(collider); + for (var i = 0; i < cell.length; i++) { + var collider = cell[i]; + if (collider == excludeCollider || !es.Flags.isFlagSet(layerMask, collider.physicsLayer)) + continue; + if (bounds.intersects(collider.bounds)) { + if (this._tempHashSet.indexOf(collider) == -1) + this._tempHashSet.push(collider); + } } } } - } - return { tempHashSet: this._tempHashSet, bounds: bounds }; - }; - SpatialHash.prototype.cellAtPosition = function (x, y, createCellIfEmpty) { - if (createCellIfEmpty === void 0) { createCellIfEmpty = false; } - var cell = this._cellDict.tryGetValue(x, y); - if (!cell) { - if (createCellIfEmpty) { - cell = []; - this._cellDict.add(x, y, cell); + return { tempHashSet: this._tempHashSet, bounds: bounds }; + }; + SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { + var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); + this._overlapTestCircle.radius = radius; + this._overlapTestCircle.position = circleCenter; + var resultCounter = 0; + var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); + bounds = aabbBroadphaseResult.bounds; + var potentials = aabbBroadphaseResult.tempHashSet; + for (var i = 0; i < potentials.length; i++) { + var collider = potentials[i]; + if (collider instanceof es.BoxCollider) { + results[resultCounter] = collider; + resultCounter++; + } + else if (collider instanceof es.CircleCollider) { + if (collider.shape.overlaps(this._overlapTestCircle)) { + results[resultCounter] = collider; + resultCounter++; + } + } + else if (collider instanceof es.PolygonCollider) { + if (collider.shape.overlaps(this._overlapTestCircle)) { + results[resultCounter] = collider; + resultCounter++; + } + } + else { + throw new Error("overlapCircle against this collider type is not implemented!"); + } + if (resultCounter == results.length) + return resultCounter; } + return resultCounter; + }; + return SpatialHash; + }()); + es.SpatialHash = SpatialHash; + var NumberDictionary = (function () { + function NumberDictionary() { + this._store = new Map(); } - return cell; - }; - SpatialHash.prototype.cellCoords = function (x, y) { - return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize)); - }; - SpatialHash.prototype.debugDraw = function (secondsToDisplay, textScale) { - if (textScale === void 0) { textScale = 1; } - for (var x = this.gridBounds.x; x <= this.gridBounds.right; x++) { - for (var y = this.gridBounds.y; y <= this.gridBounds.bottom; y++) { - var cell = this.cellAtPosition(x, y); - if (cell && cell.length > 0) - this.debugDrawCellDetails(x, y, cell.length, secondsToDisplay, textScale); - } + NumberDictionary.prototype.getKey = function (x, y) { + return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); + }; + NumberDictionary.prototype.add = function (x, y, list) { + this._store.set(this.getKey(x, y), list); + }; + NumberDictionary.prototype.remove = function (obj) { + this._store.forEach(function (list) { + if (list.contains(obj)) + list.remove(obj); + }); + }; + NumberDictionary.prototype.tryGetValue = function (x, y) { + return this._store.get(this.getKey(x, y)); + }; + NumberDictionary.prototype.clear = function () { + this._store.clear(); + }; + return NumberDictionary; + }()); + es.NumberDictionary = NumberDictionary; + var RaycastResultParser = (function () { + function RaycastResultParser() { } - }; - SpatialHash.prototype.debugDrawCellDetails = function (x, y, cellCount, secondsToDisplay, textScale) { - if (secondsToDisplay === void 0) { secondsToDisplay = 0.5; } - if (textScale === void 0) { textScale = 1; } - }; - return SpatialHash; -}()); -var RaycastResultParser = (function () { - function RaycastResultParser() { - } - return RaycastResultParser; -}()); -var NumberDictionary = (function () { - function NumberDictionary() { - this._store = new Map(); - } - NumberDictionary.prototype.getKey = function (x, y) { - return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, false)).toString(); - }; - NumberDictionary.prototype.add = function (x, y, list) { - this._store.set(this.getKey(x, y), list); - }; - NumberDictionary.prototype.remove = function (obj) { - this._store.forEach(function (list) { - if (list.contains(obj)) - list.remove(obj); - }); - }; - NumberDictionary.prototype.tryGetValue = function (x, y) { - return this._store.get(this.getKey(x, y)); - }; - NumberDictionary.prototype.clear = function () { - this._store.clear(); - }; - return NumberDictionary; -}()); + return RaycastResultParser; + }()); + es.RaycastResultParser = RaycastResultParser; +})(es || (es = {})); var ArrayUtils = (function () { function ArrayUtils() { } @@ -5588,329 +6302,363 @@ var Base64Utils = (function () { }; return Base64Utils; }()); -var ContentManager = (function () { - function ContentManager() { - this.loadedAssets = new Map(); - } - ContentManager.prototype.loadRes = function (name, local) { - var _this = this; - if (local === void 0) { local = true; } - return new Promise(function (resolve, reject) { - var res = _this.loadedAssets.get(name); - if (res) { - resolve(res); +var es; +(function (es) { + var ContentManager = (function () { + function ContentManager() { + this.loadedAssets = new Map(); + } + ContentManager.prototype.loadRes = function (name, local) { + var _this = this; + if (local === void 0) { local = true; } + return new Promise(function (resolve, reject) { + var res = _this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } + if (local) { + RES.getResAsync(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + else { + RES.getResByUrl(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }); + }; + ContentManager.prototype.dispose = function () { + this.loadedAssets.forEach(function (value) { + var assetsToRemove = value; + assetsToRemove.dispose(); + }); + this.loadedAssets.clear(); + }; + return ContentManager; + }()); + es.ContentManager = ContentManager; +})(es || (es = {})); +var es; +(function (es) { + var DrawUtils = (function () { + function DrawUtils() { + } + DrawUtils.drawLine = function (shape, start, end, color, thickness) { + if (thickness === void 0) { thickness = 1; } + this.drawLineAngle(shape, start, es.MathHelper.angleBetweenVectors(start, end), es.Vector2.distance(start, end), color, thickness); + }; + DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) { + if (thickness === void 0) { thickness = 1; } + shape.graphics.beginFill(color); + shape.graphics.drawRect(start.x, start.y, 1, 1); + shape.graphics.endFill(); + shape.scaleX = length; + shape.scaleY = thickness; + shape.$anchorOffsetX = 0; + shape.$anchorOffsetY = 0; + shape.rotation = radians; + }; + DrawUtils.drawHollowRect = function (shape, rect, color, thickness) { + if (thickness === void 0) { thickness = 1; } + this.drawHollowRectR(shape, rect.x, rect.y, rect.width, rect.height, color, thickness); + }; + DrawUtils.drawHollowRectR = function (shape, x, y, width, height, color, thickness) { + if (thickness === void 0) { thickness = 1; } + var tl = new es.Vector2(x, y).round(); + var tr = new es.Vector2(x + width, y).round(); + var br = new es.Vector2(x + width, y + height).round(); + var bl = new es.Vector2(x, y + height).round(); + this.drawLine(shape, tl, tr, color, thickness); + this.drawLine(shape, tr, br, color, thickness); + this.drawLine(shape, br, bl, color, thickness); + this.drawLine(shape, bl, tl, color, thickness); + }; + DrawUtils.drawPixel = function (shape, position, color, size) { + if (size === void 0) { size = 1; } + var destRect = new es.Rectangle(position.x, position.y, size, size); + if (size != 1) { + destRect.x -= size * 0.5; + destRect.y -= size * 0.5; + } + shape.graphics.beginFill(color); + shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height); + shape.graphics.endFill(); + }; + DrawUtils.getColorMatrix = function (color) { + var colorMatrix = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 + ]; + colorMatrix[0] = Math.floor(color / 256 / 256) / 255; + colorMatrix[6] = Math.floor(color / 256 % 256) / 255; + colorMatrix[12] = color % 256 / 255; + return new egret.ColorMatrixFilter(colorMatrix); + }; + return DrawUtils; + }()); + es.DrawUtils = DrawUtils; +})(es || (es = {})); +var es; +(function (es) { + var FuncPack = (function () { + function FuncPack(func, context) { + this.func = func; + this.context = context; + } + return FuncPack; + }()); + es.FuncPack = FuncPack; + var Emitter = (function () { + function Emitter() { + this._messageTable = new Map(); + } + Emitter.prototype.addObserver = function (eventType, handler, context) { + var list = this._messageTable.get(eventType); + if (!list) { + list = []; + this._messageTable.set(eventType, list); + } + if (list.contains(handler)) + console.warn("您试图添加相同的观察者两次"); + list.push(new FuncPack(handler, context)); + }; + Emitter.prototype.removeObserver = function (eventType, handler) { + var messageData = this._messageTable.get(eventType); + var index = messageData.findIndex(function (data) { return data.func == handler; }); + if (index != -1) + messageData.removeAt(index); + }; + Emitter.prototype.emit = function (eventType, data) { + var list = this._messageTable.get(eventType); + if (list) { + for (var i = list.length - 1; i >= 0; i--) + list[i].func.call(list[i].context, data); + } + }; + return Emitter; + }()); + es.Emitter = Emitter; +})(es || (es = {})); +var es; +(function (es) { + var GlobalManager = (function () { + function GlobalManager() { + } + Object.defineProperty(GlobalManager.prototype, "enabled", { + get: function () { + return this._enabled; + }, + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + GlobalManager.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } + } + }; + GlobalManager.prototype.onEnabled = function () { }; + GlobalManager.prototype.onDisabled = function () { }; + GlobalManager.prototype.update = function () { }; + GlobalManager.registerGlobalManager = function (manager) { + this.globalManagers.push(manager); + manager.enabled = true; + }; + GlobalManager.unregisterGlobalManager = function (manager) { + this.globalManagers.remove(manager); + manager.enabled = false; + }; + GlobalManager.getGlobalManager = function (type) { + for (var i = 0; i < this.globalManagers.length; i++) { + if (this.globalManagers[i] instanceof type) + return this.globalManagers[i]; + } + return null; + }; + GlobalManager.globalManagers = []; + return GlobalManager; + }()); + es.GlobalManager = GlobalManager; +})(es || (es = {})); +var es; +(function (es) { + var TouchState = (function () { + function TouchState() { + this.x = 0; + this.y = 0; + this.touchPoint = -1; + this.touchDown = false; + } + Object.defineProperty(TouchState.prototype, "position", { + get: function () { + return new es.Vector2(this.x, this.y); + }, + enumerable: true, + configurable: true + }); + TouchState.prototype.reset = function () { + this.x = 0; + this.y = 0; + this.touchDown = false; + this.touchPoint = -1; + }; + return TouchState; + }()); + es.TouchState = TouchState; + var Input = (function () { + function Input() { + } + Object.defineProperty(Input, "touchPosition", { + get: function () { + if (!this._gameTouchs[0]) + return es.Vector2.zero; + return this._gameTouchs[0].position; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "maxSupportedTouch", { + get: function () { + return this._stage.maxTouches; + }, + set: function (value) { + this._stage.maxTouches = value; + this.initTouchCache(); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "resolutionScale", { + get: function () { + return this._resolutionScale; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "totalTouchCount", { + get: function () { + return this._totalTouchCount; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "gameTouchs", { + get: function () { + return this._gameTouchs; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Input, "touchPositionDelta", { + get: function () { + var delta = es.Vector2.subtract(this.touchPosition, this._previousTouchState.position); + if (delta.length() > 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + return delta; + }, + enumerable: true, + configurable: true + }); + Input.initialize = function (stage) { + if (this._init) return; - } - if (local) { - RES.getResAsync(name).then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }).catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } - else { - RES.getResByUrl(name).then(function (data) { - _this.loadedAssets.set(name, data); - resolve(data); - }).catch(function (err) { - console.error("资源加载错误:", name, err); - reject(err); - }); - } - }); - }; - ContentManager.prototype.dispose = function () { - this.loadedAssets.forEach(function (value) { - var assetsToRemove = value; - assetsToRemove.dispose(); - }); - this.loadedAssets.clear(); - }; - return ContentManager; -}()); -var DrawUtils = (function () { - function DrawUtils() { - } - DrawUtils.drawLine = function (shape, start, end, color, thickness) { - if (thickness === void 0) { thickness = 1; } - this.drawLineAngle(shape, start, MathHelper.angleBetweenVectors(start, end), Vector2.distance(start, end), color, thickness); - }; - DrawUtils.drawLineAngle = function (shape, start, radians, length, color, thickness) { - if (thickness === void 0) { thickness = 1; } - shape.graphics.beginFill(color); - shape.graphics.drawRect(start.x, start.y, 1, 1); - shape.graphics.endFill(); - shape.scaleX = length; - shape.scaleY = thickness; - shape.$anchorOffsetX = 0; - shape.$anchorOffsetY = 0; - shape.rotation = radians; - }; - DrawUtils.drawHollowRect = function (shape, rect, color, thickness) { - if (thickness === void 0) { thickness = 1; } - this.drawHollowRectR(shape, rect.x, rect.y, rect.width, rect.height, color, thickness); - }; - DrawUtils.drawHollowRectR = function (shape, x, y, width, height, color, thickness) { - if (thickness === void 0) { thickness = 1; } - var tl = new Vector2(x, y).round(); - var tr = new Vector2(x + width, y).round(); - var br = new Vector2(x + width, y + height).round(); - var bl = new Vector2(x, y + height).round(); - this.drawLine(shape, tl, tr, color, thickness); - this.drawLine(shape, tr, br, color, thickness); - this.drawLine(shape, br, bl, color, thickness); - this.drawLine(shape, bl, tl, color, thickness); - }; - DrawUtils.drawPixel = function (shape, position, color, size) { - if (size === void 0) { size = 1; } - var destRect = new Rectangle(position.x, position.y, size, size); - if (size != 1) { - destRect.x -= size * 0.5; - destRect.y -= size * 0.5; - } - shape.graphics.beginFill(color); - shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height); - shape.graphics.endFill(); - }; - return DrawUtils; -}()); -var Emitter = (function () { - function Emitter() { - this._messageTable = new Map(); - } - Emitter.prototype.addObserver = function (eventType, handler, context) { - var list = this._messageTable.get(eventType); - if (!list) { - list = []; - this._messageTable.set(eventType, list); - } - if (list.contains(handler)) - console.warn("您试图添加相同的观察者两次"); - list.push(new FuncPack(handler, context)); - }; - Emitter.prototype.removeObserver = function (eventType, handler) { - var messageData = this._messageTable.get(eventType); - var index = messageData.findIndex(function (data) { return data.func == handler; }); - if (index != -1) - messageData.removeAt(index); - }; - Emitter.prototype.emit = function (eventType, data) { - var list = this._messageTable.get(eventType); - if (list) { - for (var i = list.length - 1; i >= 0; i--) - list[i].func.call(list[i].context, data); - } - }; - return Emitter; -}()); -var FuncPack = (function () { - function FuncPack(func, context) { - this.func = func; - this.context = context; - } - return FuncPack; -}()); -var GlobalManager = (function () { - function GlobalManager() { - } - Object.defineProperty(GlobalManager.prototype, "enabled", { - get: function () { - return this._enabled; - }, - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true - }); - GlobalManager.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); - } - else { - this.onDisabled(); - } - } - }; - GlobalManager.prototype.onEnabled = function () { }; - GlobalManager.prototype.onDisabled = function () { }; - GlobalManager.prototype.update = function () { }; - GlobalManager.registerGlobalManager = function (manager) { - this.globalManagers.push(manager); - manager.enabled = true; - }; - GlobalManager.unregisterGlobalManager = function (manager) { - this.globalManagers.remove(manager); - manager.enabled = false; - }; - GlobalManager.getGlobalManager = function (type) { - for (var i = 0; i < this.globalManagers.length; i++) { - if (this.globalManagers[i] instanceof type) - return this.globalManagers[i]; - } - return null; - }; - GlobalManager.globalManagers = []; - return GlobalManager; -}()); -var TouchState = (function () { - function TouchState() { - this.x = 0; - this.y = 0; - this.touchPoint = -1; - this.touchDown = false; - } - Object.defineProperty(TouchState.prototype, "position", { - get: function () { - return new Vector2(this.x, this.y); - }, - enumerable: true, - configurable: true - }); - TouchState.prototype.reset = function () { - this.x = 0; - this.y = 0; - this.touchDown = false; - this.touchPoint = -1; - }; - return TouchState; -}()); -var Input = (function () { - function Input() { - } - Object.defineProperty(Input, "touchPosition", { - get: function () { - if (!this._gameTouchs[0]) - return Vector2.zero; - return this._gameTouchs[0].position; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "maxSupportedTouch", { - get: function () { - return this._stage.maxTouches; - }, - set: function (value) { - this._stage.maxTouches = value; + this._init = true; + this._stage = stage; + this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); this.initTouchCache(); - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "resolutionScale", { - get: function () { - return this._resolutionScale; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "totalTouchCount", { - get: function () { - return this._totalTouchCount; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "gameTouchs", { - get: function () { - return this._gameTouchs; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Input, "touchPositionDelta", { - get: function () { - var delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position); - if (delta.length() > 0) { + }; + Input.initTouchCache = function () { + this._totalTouchCount = 0; + this._touchIndex = 0; + this._gameTouchs.length = 0; + for (var i = 0; i < this.maxSupportedTouch; i++) { + this._gameTouchs.push(new TouchState()); + } + }; + Input.touchBegin = function (evt) { + if (this._touchIndex < this.maxSupportedTouch) { + this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; + this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; + this._gameTouchs[this._touchIndex].x = evt.stageX; + this._gameTouchs[this._touchIndex].y = evt.stageY; + if (this._touchIndex == 0) { + this.setpreviousTouchState(this._gameTouchs[0]); + } + this._touchIndex++; + this._totalTouchCount++; + } + }; + Input.touchMove = function (evt) { + if (evt.touchPointID == this._gameTouchs[0].touchPoint) { this.setpreviousTouchState(this._gameTouchs[0]); } - return delta; - }, - enumerable: true, - configurable: true - }); - Input.initialize = function (stage) { - if (this._init) - return; - this._init = true; - this._stage = stage; - this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); - this.initTouchCache(); - }; - Input.initTouchCache = function () { - this._totalTouchCount = 0; - this._touchIndex = 0; - this._gameTouchs.length = 0; - for (var i = 0; i < this.maxSupportedTouch; i++) { - this._gameTouchs.push(new TouchState()); - } - }; - Input.touchBegin = function (evt) { - if (this._touchIndex < this.maxSupportedTouch) { - this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; - this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; - this._gameTouchs[this._touchIndex].x = evt.stageX; - this._gameTouchs[this._touchIndex].y = evt.stageY; - if (this._touchIndex == 0) { - this.setpreviousTouchState(this._gameTouchs[0]); + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.x = evt.stageX; + touchData.y = evt.stageY; } - this._touchIndex++; - this._totalTouchCount++; - } - }; - Input.touchMove = function (evt) { - if (evt.touchPointID == this._gameTouchs[0].touchPoint) { - this.setpreviousTouchState(this._gameTouchs[0]); - } - var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.x = evt.stageX; - touchData.y = evt.stageY; - } - }; - Input.touchEnd = function (evt) { - var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); - if (touchIndex != -1) { - var touchData = this._gameTouchs[touchIndex]; - touchData.reset(); - if (touchIndex == 0) - this._previousTouchState.reset(); - this._totalTouchCount--; - if (this.totalTouchCount == 0) { - this._touchIndex = 0; + }; + Input.touchEnd = function (evt) { + var touchIndex = this._gameTouchs.findIndex(function (touch) { return touch.touchPoint == evt.touchPointID; }); + if (touchIndex != -1) { + var touchData = this._gameTouchs[touchIndex]; + touchData.reset(); + if (touchIndex == 0) + this._previousTouchState.reset(); + this._totalTouchCount--; + if (this.totalTouchCount == 0) { + this._touchIndex = 0; + } } - } - }; - Input.setpreviousTouchState = function (touchState) { - this._previousTouchState = new TouchState(); - this._previousTouchState.x = touchState.position.x; - this._previousTouchState.y = touchState.position.y; - this._previousTouchState.touchPoint = touchState.touchPoint; - this._previousTouchState.touchDown = touchState.touchDown; - }; - Input.scaledPosition = function (position) { - var scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); - return Vector2.multiply(scaledPos, this.resolutionScale); - }; - Input._init = false; - Input._previousTouchState = new TouchState(); - Input._gameTouchs = []; - Input._resolutionOffset = new Vector2(); - Input._resolutionScale = Vector2.one; - Input._touchIndex = 0; - Input._totalTouchCount = 0; - return Input; -}()); + }; + Input.setpreviousTouchState = function (touchState) { + this._previousTouchState = new TouchState(); + this._previousTouchState.x = touchState.position.x; + this._previousTouchState.y = touchState.position.y; + this._previousTouchState.touchPoint = touchState.touchPoint; + this._previousTouchState.touchDown = touchState.touchDown; + }; + Input.scaledPosition = function (position) { + var scaledPos = new es.Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); + return es.Vector2.multiply(scaledPos, this.resolutionScale); + }; + Input._init = false; + Input._previousTouchState = new TouchState(); + Input._gameTouchs = []; + Input._resolutionOffset = new es.Vector2(); + Input._resolutionScale = es.Vector2.one; + Input._touchIndex = 0; + Input._totalTouchCount = 0; + return Input; + }()); + es.Input = Input; +})(es || (es = {})); var KeyboardUtils = (function () { function KeyboardUtils() { } @@ -6111,36 +6859,40 @@ var KeyboardUtils = (function () { KeyboardUtils.WINDOWS = "Windows"; return KeyboardUtils; }()); -var ListPool = (function () { - function ListPool() { - } - ListPool.warmCache = function (cacheCount) { - cacheCount -= this._objectQueue.length; - if (cacheCount > 0) { - for (var i = 0; i < cacheCount; i++) { - this._objectQueue.unshift([]); - } +var es; +(function (es) { + var ListPool = (function () { + function ListPool() { } - }; - ListPool.trimCache = function (cacheCount) { - while (cacheCount > this._objectQueue.length) - this._objectQueue.shift(); - }; - ListPool.clearCache = function () { - this._objectQueue.length = 0; - }; - ListPool.obtain = function () { - if (this._objectQueue.length > 0) - return this._objectQueue.shift(); - return []; - }; - ListPool.free = function (obj) { - this._objectQueue.unshift(obj); - obj.length = 0; - }; - ListPool._objectQueue = []; - return ListPool; -}()); + ListPool.warmCache = function (cacheCount) { + cacheCount -= this._objectQueue.length; + if (cacheCount > 0) { + for (var i = 0; i < cacheCount; i++) { + this._objectQueue.unshift([]); + } + } + }; + ListPool.trimCache = function (cacheCount) { + while (cacheCount > this._objectQueue.length) + this._objectQueue.shift(); + }; + ListPool.clearCache = function () { + this._objectQueue.length = 0; + }; + ListPool.obtain = function () { + if (this._objectQueue.length > 0) + return this._objectQueue.shift(); + return []; + }; + ListPool.free = function (obj) { + this._objectQueue.unshift(obj); + obj.length = 0; + }; + ListPool._objectQueue = []; + return ListPool; + }()); + es.ListPool = ListPool; +})(es || (es = {})); var THREAD_ID = Math.floor(Math.random() * 1000) + "-" + Date.now(); var setItem = egret.localStorage.setItem.bind(localStorage); var getItem = egret.localStorage.getItem.bind(localStorage); @@ -6182,19 +6934,23 @@ var LockUtils = (function () { }; return LockUtils; }()); -var Pair = (function () { - function Pair(first, second) { - this.first = first; - this.second = second; - } - Pair.prototype.clear = function () { - this.first = this.second = null; - }; - Pair.prototype.equals = function (other) { - return this.first == other.first && this.second == other.second; - }; - return Pair; -}()); +var es; +(function (es) { + var Pair = (function () { + function Pair(first, second) { + this.first = first; + this.second = second; + } + Pair.prototype.clear = function () { + this.first = this.second = null; + }; + Pair.prototype.equals = function (other) { + return this.first == other.first && this.second == other.second; + }; + return Pair; + }()); + es.Pair = Pair; +})(es || (es = {})); var RandomUtils = (function () { function RandomUtils() { } @@ -6262,142 +7018,154 @@ var RandomUtils = (function () { }; return RandomUtils; }()); -var RectangleExt = (function () { - function RectangleExt() { - } - RectangleExt.union = function (first, point) { - var rect = new Rectangle(point.x, point.y, 0, 0); - var result = new Rectangle(); - result.x = Math.min(first.x, rect.x); - result.y = Math.min(first.y, rect.y); - result.width = Math.max(first.right, rect.right) - result.x; - result.height = Math.max(first.bottom, result.bottom) - result.y; - return result; - }; - return RectangleExt; -}()); -var Triangulator = (function () { - function Triangulator() { - this.triangleIndices = []; - this._triPrev = new Array(12); - this._triNext = new Array(12); - } - Triangulator.prototype.triangulate = function (points, arePointsCCW) { - if (arePointsCCW === void 0) { arePointsCCW = true; } - var count = points.length; - this.initialize(count); - var iterations = 0; - var index = 0; - while (count > 3 && iterations < 500) { - iterations++; - var isEar = true; - var a = points[this._triPrev[index]]; - var b = points[index]; - var c = points[this._triNext[index]]; - if (Vector2Ext.isTriangleCCW(a, b, c)) { - var k = this._triNext[this._triNext[index]]; - do { - if (Triangulator.testPointTriangle(points[k], a, b, c)) { - isEar = false; - break; - } - k = this._triNext[k]; - } while (k != this._triPrev[index]); +var es; +(function (es) { + var RectangleExt = (function () { + function RectangleExt() { + } + RectangleExt.union = function (first, point) { + var rect = new es.Rectangle(point.x, point.y, 0, 0); + var result = new es.Rectangle(); + result.x = Math.min(first.x, rect.x); + result.y = Math.min(first.y, rect.y); + result.width = Math.max(first.right, rect.right) - result.x; + result.height = Math.max(first.bottom, result.bottom) - result.y; + return result; + }; + return RectangleExt; + }()); + es.RectangleExt = RectangleExt; +})(es || (es = {})); +var es; +(function (es) { + var Triangulator = (function () { + function Triangulator() { + this.triangleIndices = []; + this._triPrev = new Array(12); + this._triNext = new Array(12); + } + Triangulator.prototype.triangulate = function (points, arePointsCCW) { + if (arePointsCCW === void 0) { arePointsCCW = true; } + var count = points.length; + this.initialize(count); + var iterations = 0; + var index = 0; + while (count > 3 && iterations < 500) { + iterations++; + var isEar = true; + var a = points[this._triPrev[index]]; + var b = points[index]; + var c = points[this._triNext[index]]; + if (es.Vector2Ext.isTriangleCCW(a, b, c)) { + var k = this._triNext[this._triNext[index]]; + do { + if (Triangulator.testPointTriangle(points[k], a, b, c)) { + isEar = false; + break; + } + k = this._triNext[k]; + } while (k != this._triPrev[index]); + } + else { + isEar = false; + } + if (isEar) { + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); + this._triNext[this._triPrev[index]] = this._triNext[index]; + this._triPrev[this._triNext[index]] = this._triPrev[index]; + count--; + index = this._triPrev[index]; + } + else { + index = this._triNext[index]; + } + } + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); + if (!arePointsCCW) + this.triangleIndices.reverse(); + }; + Triangulator.prototype.initialize = function (count) { + this.triangleIndices.length = 0; + if (this._triNext.length < count) { + this._triNext.reverse(); + this._triNext = new Array(Math.max(this._triNext.length * 2, count)); + } + if (this._triPrev.length < count) { + this._triPrev.reverse(); + this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); + } + for (var i = 0; i < count; i++) { + this._triPrev[i] = i - 1; + this._triNext[i] = i + 1; + } + this._triPrev[0] = count - 1; + this._triNext[count - 1] = 0; + }; + Triangulator.testPointTriangle = function (point, a, b, c) { + if (es.Vector2Ext.cross(es.Vector2.subtract(point, a), es.Vector2.subtract(b, a)) < 0) + return false; + if (es.Vector2Ext.cross(es.Vector2.subtract(point, b), es.Vector2.subtract(c, b)) < 0) + return false; + if (es.Vector2Ext.cross(es.Vector2.subtract(point, c), es.Vector2.subtract(a, c)) < 0) + return false; + return true; + }; + return Triangulator; + }()); + es.Triangulator = Triangulator; +})(es || (es = {})); +var es; +(function (es) { + var Vector2Ext = (function () { + function Vector2Ext() { + } + Vector2Ext.isTriangleCCW = function (a, center, c) { + return this.cross(es.Vector2.subtract(center, a), es.Vector2.subtract(c, center)) < 0; + }; + Vector2Ext.cross = function (u, v) { + return u.y * v.x - u.x * v.y; + }; + Vector2Ext.perpendicular = function (first, second) { + return new es.Vector2(-1 * (second.y - first.y), second.x - first.x); + }; + Vector2Ext.normalize = function (vec) { + var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); + if (magnitude > es.MathHelper.Epsilon) { + vec = es.Vector2.divide(vec, new es.Vector2(magnitude)); } else { - isEar = false; + vec.x = vec.y = 0; } - if (isEar) { - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); - this._triNext[this._triPrev[index]] = this._triNext[index]; - this._triPrev[this._triNext[index]] = this._triPrev[index]; - count--; - index = this._triPrev[index]; + return vec; + }; + Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) { + for (var i = 0; i < length; i++) { + var position = sourceArray[sourceIndex + i]; + var destination = destinationArray[destinationIndex + i]; + destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + destinationArray[destinationIndex + i] = destination; } - else { - index = this._triNext[index]; - } - } - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); - if (!arePointsCCW) - this.triangleIndices.reverse(); - }; - Triangulator.prototype.initialize = function (count) { - this.triangleIndices.length = 0; - if (this._triNext.length < count) { - this._triNext.reverse(); - this._triNext = new Array(Math.max(this._triNext.length * 2, count)); - } - if (this._triPrev.length < count) { - this._triPrev.reverse(); - this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); - } - for (var i = 0; i < count; i++) { - this._triPrev[i] = i - 1; - this._triNext[i] = i + 1; - } - this._triPrev[0] = count - 1; - this._triNext[count - 1] = 0; - }; - Triangulator.testPointTriangle = function (point, a, b, c) { - if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0) - return false; - if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0) - return false; - if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0) - return false; - return true; - }; - return Triangulator; -}()); -var Vector2Ext = (function () { - function Vector2Ext() { - } - Vector2Ext.isTriangleCCW = function (a, center, c) { - return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; - }; - Vector2Ext.cross = function (u, v) { - return u.y * v.x - u.x * v.y; - }; - Vector2Ext.perpendicular = function (first, second) { - return new Vector2(-1 * (second.y - first.y), second.x - first.x); - }; - Vector2Ext.normalize = function (vec) { - var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); - if (magnitude > MathHelper.Epsilon) { - vec = Vector2.divide(vec, new Vector2(magnitude)); - } - else { - vec.x = vec.y = 0; - } - return vec; - }; - Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) { - for (var i = 0; i < length; i++) { - var position = sourceArray[sourceIndex + i]; - var destination = destinationArray[destinationIndex + i]; - destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; - destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; - destinationArray[destinationIndex + i] = destination; - } - }; - Vector2Ext.transformR = function (position, matrix) { - var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; - var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; - return new Vector2(x, y); - }; - Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { - this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); - }; - Vector2Ext.round = function (vec) { - return new Vector2(Math.round(vec.x), Math.round(vec.y)); - }; - return Vector2Ext; -}()); + }; + Vector2Ext.transformR = function (position, matrix) { + var x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + var y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + return new es.Vector2(x, y); + }; + Vector2Ext.transform = function (sourceArray, matrix, destinationArray) { + this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); + }; + Vector2Ext.round = function (vec) { + return new es.Vector2(Math.round(vec.x), Math.round(vec.y)); + }; + return Vector2Ext; + }()); + es.Vector2Ext = Vector2Ext; +})(es || (es = {})); var WebGLUtils = (function () { function WebGLUtils() { } @@ -6407,66 +7175,70 @@ var WebGLUtils = (function () { }; return WebGLUtils; }()); -var Layout = (function () { - function Layout() { - this.clientArea = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this.safeArea = this.clientArea; - } - Layout.prototype.place = function (size, horizontalMargin, verticalMargine, alignment) { - var rc = new Rectangle(0, 0, size.x, size.y); - if ((alignment & Alignment.left) != 0) { - rc.x = this.clientArea.x + (this.clientArea.width * horizontalMargin); +var es; +(function (es) { + var Layout = (function () { + function Layout() { + this.clientArea = new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.safeArea = this.clientArea; } - else if ((alignment & Alignment.right) != 0) { - rc.x = this.clientArea.x + (this.clientArea.width * (1 - horizontalMargin)) - rc.width; - } - else if ((alignment & Alignment.horizontalCenter) != 0) { - rc.x = this.clientArea.x + (this.clientArea.width - rc.width) / 2 + (horizontalMargin * this.clientArea.width); - } - else { - } - if ((alignment & Alignment.top) != 0) { - rc.y = this.clientArea.y + (this.clientArea.height * verticalMargine); - } - else if ((alignment & Alignment.bottom) != 0) { - rc.y = this.clientArea.y + (this.clientArea.height * (1 - verticalMargine)) - rc.height; - } - else if ((alignment & Alignment.verticalCenter) != 0) { - rc.y = this.clientArea.y + (this.clientArea.height - rc.height) / 2 + (verticalMargine * this.clientArea.height); - } - else { - } - if (rc.left < this.safeArea.left) - rc.x = this.safeArea.left; - if (rc.right > this.safeArea.right) - rc.x = this.safeArea.right - rc.width; - if (rc.top < this.safeArea.top) - rc.y = this.safeArea.top; - if (rc.bottom > this.safeArea.bottom) - rc.y = this.safeArea.bottom - rc.height; - return rc; - }; - return Layout; -}()); -var Alignment; -(function (Alignment) { - Alignment[Alignment["none"] = 0] = "none"; - Alignment[Alignment["left"] = 1] = "left"; - Alignment[Alignment["right"] = 2] = "right"; - Alignment[Alignment["horizontalCenter"] = 4] = "horizontalCenter"; - Alignment[Alignment["top"] = 8] = "top"; - Alignment[Alignment["bottom"] = 16] = "bottom"; - Alignment[Alignment["verticalCenter"] = 32] = "verticalCenter"; - Alignment[Alignment["topLeft"] = 9] = "topLeft"; - Alignment[Alignment["topRight"] = 10] = "topRight"; - Alignment[Alignment["topCenter"] = 12] = "topCenter"; - Alignment[Alignment["bottomLeft"] = 17] = "bottomLeft"; - Alignment[Alignment["bottomRight"] = 18] = "bottomRight"; - Alignment[Alignment["bottomCenter"] = 20] = "bottomCenter"; - Alignment[Alignment["centerLeft"] = 33] = "centerLeft"; - Alignment[Alignment["centerRight"] = 34] = "centerRight"; - Alignment[Alignment["center"] = 36] = "center"; -})(Alignment || (Alignment = {})); + Layout.prototype.place = function (size, horizontalMargin, verticalMargine, alignment) { + var rc = new es.Rectangle(0, 0, size.x, size.y); + if ((alignment & Alignment.left) != 0) { + rc.x = this.clientArea.x + (this.clientArea.width * horizontalMargin); + } + else if ((alignment & Alignment.right) != 0) { + rc.x = this.clientArea.x + (this.clientArea.width * (1 - horizontalMargin)) - rc.width; + } + else if ((alignment & Alignment.horizontalCenter) != 0) { + rc.x = this.clientArea.x + (this.clientArea.width - rc.width) / 2 + (horizontalMargin * this.clientArea.width); + } + else { + } + if ((alignment & Alignment.top) != 0) { + rc.y = this.clientArea.y + (this.clientArea.height * verticalMargine); + } + else if ((alignment & Alignment.bottom) != 0) { + rc.y = this.clientArea.y + (this.clientArea.height * (1 - verticalMargine)) - rc.height; + } + else if ((alignment & Alignment.verticalCenter) != 0) { + rc.y = this.clientArea.y + (this.clientArea.height - rc.height) / 2 + (verticalMargine * this.clientArea.height); + } + else { + } + if (rc.left < this.safeArea.left) + rc.x = this.safeArea.left; + if (rc.right > this.safeArea.right) + rc.x = this.safeArea.right - rc.width; + if (rc.top < this.safeArea.top) + rc.y = this.safeArea.top; + if (rc.bottom > this.safeArea.bottom) + rc.y = this.safeArea.bottom - rc.height; + return rc; + }; + return Layout; + }()); + es.Layout = Layout; + var Alignment; + (function (Alignment) { + Alignment[Alignment["none"] = 0] = "none"; + Alignment[Alignment["left"] = 1] = "left"; + Alignment[Alignment["right"] = 2] = "right"; + Alignment[Alignment["horizontalCenter"] = 4] = "horizontalCenter"; + Alignment[Alignment["top"] = 8] = "top"; + Alignment[Alignment["bottom"] = 16] = "bottom"; + Alignment[Alignment["verticalCenter"] = 32] = "verticalCenter"; + Alignment[Alignment["topLeft"] = 9] = "topLeft"; + Alignment[Alignment["topRight"] = 10] = "topRight"; + Alignment[Alignment["topCenter"] = 12] = "topCenter"; + Alignment[Alignment["bottomLeft"] = 17] = "bottomLeft"; + Alignment[Alignment["bottomRight"] = 18] = "bottomRight"; + Alignment[Alignment["bottomCenter"] = 20] = "bottomCenter"; + Alignment[Alignment["centerLeft"] = 33] = "centerLeft"; + Alignment[Alignment["centerRight"] = 34] = "centerRight"; + Alignment[Alignment["center"] = 36] = "center"; + })(Alignment = es.Alignment || (es.Alignment = {})); +})(es || (es = {})); var stopwatch; (function (stopwatch) { var Stopwatch = (function () { @@ -6598,251 +7370,260 @@ var stopwatch; stopwatch.setDefaultSystemTimeGetter = setDefaultSystemTimeGetter; var _defaultSystemTimeGetter = Date.now; })(stopwatch || (stopwatch = {})); -var TimeRuler = (function () { - function TimeRuler() { - this._frameKey = 'frame'; - this._logKey = 'log'; - this.markers = []; - this.stopwacth = new stopwatch.Stopwatch(); - this._markerNameToIdMap = new Map(); - this.showLog = false; - TimeRuler.Instance = this; - this._logs = new Array(2); - for (var i = 0; i < this._logs.length; ++i) - this._logs[i] = new FrameLog(); - this.sampleFrames = this.targetSampleFrames = 1; - this.width = SceneManager.stage.stageWidth * 0.8; - this.onGraphicsDeviceReset(); - } - TimeRuler.prototype.onGraphicsDeviceReset = function () { - var layout = new Layout(); - this._position = layout.place(new Vector2(this.width, TimeRuler.barHeight), 0, 0.01, Alignment.bottomCenter).location; - }; - TimeRuler.prototype.startFrame = function () { - var _this = this; - var lock = new LockUtils(this._frameKey); - lock.lock().then(function () { - _this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10); - if (isNaN(_this._updateCount)) - _this._updateCount = 0; - var count = _this._updateCount; - count += 1; - egret.localStorage.setItem(_this._frameKey, count.toString()); - if (_this.enabled && (1 < count && count < TimeRuler.maxSampleFrames)) - return; - _this._prevLog = _this._logs[_this.frameCount++ & 0x1]; - _this._curLog = _this._logs[_this.frameCount & 0x1]; - var endFrameTime = _this.stopwacth.getTime(); - for (var barIndex = 0; barIndex < _this._prevLog.bars.length; ++barIndex) { - var prevBar = _this._prevLog.bars[barIndex]; - var nextBar = _this._curLog.bars[barIndex]; - for (var nest = 0; nest < prevBar.nestCount; ++nest) { - var markerIdx = prevBar.markerNests[nest]; - prevBar.markers[markerIdx].endTime = endFrameTime; - nextBar.markerNests[nest] = nest; - nextBar.markers[nest].markerId = prevBar.markers[markerIdx].markerId; - nextBar.markers[nest].beginTime = 0; - nextBar.markers[nest].endTime = -1; - nextBar.markers[nest].color = prevBar.markers[markerIdx].color; - } - for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) { - var duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime; - var markerId = prevBar.markers[markerIdx].markerId; - var m = _this.markers[markerId]; - m.logs[barIndex].color = prevBar.markers[markerIdx].color; - if (!m.logs[barIndex].initialized) { - m.logs[barIndex].min = duration; - m.logs[barIndex].max = duration; - m.logs[barIndex].avg = duration; - m.logs[barIndex].initialized = true; +var es; +(function (es) { + var TimeRuler = (function () { + function TimeRuler() { + this._frameKey = 'frame'; + this._logKey = 'log'; + this.markers = []; + this.stopwacth = new stopwatch.Stopwatch(); + this._markerNameToIdMap = new Map(); + this.showLog = false; + TimeRuler.Instance = this; + this._logs = new Array(2); + for (var i = 0; i < this._logs.length; ++i) + this._logs[i] = new FrameLog(); + this.sampleFrames = this.targetSampleFrames = 1; + this.width = es.SceneManager.stage.stageWidth * 0.8; + this.onGraphicsDeviceReset(); + } + TimeRuler.prototype.onGraphicsDeviceReset = function () { + var layout = new es.Layout(); + this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location; + }; + TimeRuler.prototype.startFrame = function () { + var _this = this; + var lock = new LockUtils(this._frameKey); + lock.lock().then(function () { + _this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10); + if (isNaN(_this._updateCount)) + _this._updateCount = 0; + var count = _this._updateCount; + count += 1; + egret.localStorage.setItem(_this._frameKey, count.toString()); + if (_this.enabled && (1 < count && count < TimeRuler.maxSampleFrames)) + return; + _this._prevLog = _this._logs[_this.frameCount++ & 0x1]; + _this._curLog = _this._logs[_this.frameCount & 0x1]; + var endFrameTime = _this.stopwacth.getTime(); + for (var barIndex = 0; barIndex < _this._prevLog.bars.length; ++barIndex) { + var prevBar = _this._prevLog.bars[barIndex]; + var nextBar = _this._curLog.bars[barIndex]; + for (var nest = 0; nest < prevBar.nestCount; ++nest) { + var markerIdx = prevBar.markerNests[nest]; + prevBar.markers[markerIdx].endTime = endFrameTime; + nextBar.markerNests[nest] = nest; + nextBar.markers[nest].markerId = prevBar.markers[markerIdx].markerId; + nextBar.markers[nest].beginTime = 0; + nextBar.markers[nest].endTime = -1; + nextBar.markers[nest].color = prevBar.markers[markerIdx].color; } - else { - m.logs[barIndex].min = Math.min(m.logs[barIndex].min, duration); - m.logs[barIndex].max = Math.min(m.logs[barIndex].max, duration); - m.logs[barIndex].avg += duration; - m.logs[barIndex].avg *= 0.5; - if (m.logs[barIndex].samples++ >= TimeRuler.logSnapDuration) { - m.logs[barIndex].snapMin = m.logs[barIndex].min; - m.logs[barIndex].snapMax = m.logs[barIndex].max; - m.logs[barIndex].snapAvg = m.logs[barIndex].avg; - m.logs[barIndex].samples = 0; + for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) { + var duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime; + var markerId = prevBar.markers[markerIdx].markerId; + var m = _this.markers[markerId]; + m.logs[barIndex].color = prevBar.markers[markerIdx].color; + if (!m.logs[barIndex].initialized) { + m.logs[barIndex].min = duration; + m.logs[barIndex].max = duration; + m.logs[barIndex].avg = duration; + m.logs[barIndex].initialized = true; + } + else { + m.logs[barIndex].min = Math.min(m.logs[barIndex].min, duration); + m.logs[barIndex].max = Math.min(m.logs[barIndex].max, duration); + m.logs[barIndex].avg += duration; + m.logs[barIndex].avg *= 0.5; + if (m.logs[barIndex].samples++ >= TimeRuler.logSnapDuration) { + m.logs[barIndex].snapMin = m.logs[barIndex].min; + m.logs[barIndex].snapMax = m.logs[barIndex].max; + m.logs[barIndex].snapAvg = m.logs[barIndex].avg; + m.logs[barIndex].samples = 0; + } } } + nextBar.markCount = prevBar.nestCount; + nextBar.nestCount = prevBar.nestCount; } - nextBar.markCount = prevBar.nestCount; - nextBar.nestCount = prevBar.nestCount; - } - _this.stopwacth.reset(); - _this.stopwacth.start(); - }); - }; - TimeRuler.prototype.beginMark = function (markerName, color, barIndex) { - var _this = this; - if (barIndex === void 0) { barIndex = 0; } - var lock = new LockUtils(this._frameKey); - lock.lock().then(function () { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + _this.stopwacth.reset(); + _this.stopwacth.start(); + }); + }; + TimeRuler.prototype.beginMark = function (markerName, color, barIndex) { + var _this = this; + if (barIndex === void 0) { barIndex = 0; } + var lock = new LockUtils(this._frameKey); + lock.lock().then(function () { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + throw new Error("barIndex argument out of range"); + var bar = _this._curLog.bars[barIndex]; + if (bar.markCount >= TimeRuler.maxSamples) { + throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count"); + } + if (bar.nestCount >= TimeRuler.maxNestCall) { + throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); + } + var markerId = _this._markerNameToIdMap.get(markerName); + if (isNaN(markerId)) { + markerId = _this.markers.length; + _this._markerNameToIdMap.set(markerName, markerId); + } + bar.markerNests[bar.nestCount++] = bar.markCount; + bar.markers[bar.markCount].markerId = markerId; + bar.markers[bar.markCount].color = color; + bar.markers[bar.markCount].beginTime = _this.stopwacth.getTime(); + bar.markers[bar.markCount].endTime = -1; + }); + }; + TimeRuler.prototype.endMark = function (markerName, barIndex) { + var _this = this; + if (barIndex === void 0) { barIndex = 0; } + var lock = new LockUtils(this._frameKey); + lock.lock().then(function () { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + throw new Error("barIndex argument out of range"); + var bar = _this._curLog.bars[barIndex]; + if (bar.nestCount <= 0) { + throw new Error("call beginMark method before calling endMark method"); + } + var markerId = _this._markerNameToIdMap.get(markerName); + if (isNaN(markerId)) { + throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method"); + } + var markerIdx = bar.markerNests[--bar.nestCount]; + if (bar.markers[markerIdx].markerId != markerId) { + throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B)."); + } + bar.markers[markerIdx].endTime = _this.stopwacth.getTime(); + }); + }; + TimeRuler.prototype.getAverageTime = function (barIndex, markerName) { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) { throw new Error("barIndex argument out of range"); - var bar = _this._curLog.bars[barIndex]; - if (bar.markCount >= TimeRuler.maxSamples) { - throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count"); } - if (bar.nestCount >= TimeRuler.maxNestCall) { - throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); + var result = 0; + var markerId = this._markerNameToIdMap.get(markerName); + if (markerId) { + result = this.markers[markerId].logs[barIndex].avg; } - var markerId = _this._markerNameToIdMap.get(markerName); - if (isNaN(markerId)) { - markerId = _this.markers.length; - _this._markerNameToIdMap.set(markerName, markerId); - } - bar.markerNests[bar.nestCount++] = bar.markCount; - bar.markers[bar.markCount].markerId = markerId; - bar.markers[bar.markCount].color = color; - bar.markers[bar.markCount].beginTime = _this.stopwacth.getTime(); - bar.markers[bar.markCount].endTime = -1; - }); - }; - TimeRuler.prototype.endMark = function (markerName, barIndex) { - var _this = this; - if (barIndex === void 0) { barIndex = 0; } - var lock = new LockUtils(this._frameKey); - lock.lock().then(function () { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) - throw new Error("barIndex argument out of range"); - var bar = _this._curLog.bars[barIndex]; - if (bar.nestCount <= 0) { - throw new Error("call beginMark method before calling endMark method"); - } - var markerId = _this._markerNameToIdMap.get(markerName); - if (isNaN(markerId)) { - throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method"); - } - var markerIdx = bar.markerNests[--bar.nestCount]; - if (bar.markers[markerIdx].markerId != markerId) { - throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B)."); - } - bar.markers[markerIdx].endTime = _this.stopwacth.getTime(); - }); - }; - TimeRuler.prototype.getAverageTime = function (barIndex, markerName) { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) { - throw new Error("barIndex argument out of range"); - } - var result = 0; - var markerId = this._markerNameToIdMap.get(markerName); - if (markerId) { - result = this.markers[markerId].logs[barIndex].avg; - } - return result; - }; - TimeRuler.prototype.resetLog = function () { - var _this = this; - var lock = new LockUtils(this._logKey); - lock.lock().then(function () { - var count = parseInt(egret.localStorage.getItem(_this._logKey), 10); - count += 1; - egret.localStorage.setItem(_this._logKey, count.toString()); - _this.markers.forEach(function (markerInfo) { - for (var i = 0; i < markerInfo.logs.length; ++i) { - markerInfo.logs[i].initialized = false; - markerInfo.logs[i].snapMin = 0; - markerInfo.logs[i].snapMax = 0; - markerInfo.logs[i].snapAvg = 0; - markerInfo.logs[i].min = 0; - markerInfo.logs[i].max = 0; - markerInfo.logs[i].avg = 0; - markerInfo.logs[i].samples = 0; + return result; + }; + TimeRuler.prototype.resetLog = function () { + var _this = this; + var lock = new LockUtils(this._logKey); + lock.lock().then(function () { + var count = parseInt(egret.localStorage.getItem(_this._logKey), 10); + count += 1; + egret.localStorage.setItem(_this._logKey, count.toString()); + _this.markers.forEach(function (markerInfo) { + for (var i = 0; i < markerInfo.logs.length; ++i) { + markerInfo.logs[i].initialized = false; + markerInfo.logs[i].snapMin = 0; + markerInfo.logs[i].snapMax = 0; + markerInfo.logs[i].snapAvg = 0; + markerInfo.logs[i].min = 0; + markerInfo.logs[i].max = 0; + markerInfo.logs[i].avg = 0; + markerInfo.logs[i].samples = 0; + } + }); + }); + }; + TimeRuler.prototype.render = function (position, width) { + if (position === void 0) { position = this._position; } + if (width === void 0) { width = this.width; } + egret.localStorage.setItem(this._frameKey, "0"); + if (!this.showLog) + return; + var height = 0; + var maxTime = 0; + this._prevLog.bars.forEach(function (bar) { + if (bar.markCount > 0) { + height += TimeRuler.barHeight + TimeRuler.barPadding * 2; + maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime); } }); - }); - }; - TimeRuler.prototype.render = function (position, width) { - if (position === void 0) { position = this._position; } - if (width === void 0) { width = this.width; } - egret.localStorage.setItem(this._frameKey, "0"); - if (!this.showLog) - return; - var height = 0; - var maxTime = 0; - this._prevLog.bars.forEach(function (bar) { - if (bar.markCount > 0) { - height += TimeRuler.barHeight + TimeRuler.barPadding * 2; - maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime); + var frameSpan = 1 / 60 * 1000; + var sampleSpan = this.sampleFrames * frameSpan; + if (maxTime > sampleSpan) { + this._frameAdjust = Math.max(0, this._frameAdjust) + 1; } - }); - var frameSpan = 1 / 60 * 1000; - var sampleSpan = this.sampleFrames * frameSpan; - if (maxTime > sampleSpan) { - this._frameAdjust = Math.max(0, this._frameAdjust) + 1; + else { + this._frameAdjust = Math.min(0, this._frameAdjust) - 1; + } + if (Math.max(this._frameAdjust) > TimeRuler.autoAdjustDelay) { + this.sampleFrames = Math.min(TimeRuler.maxSampleFrames, this.sampleFrames); + this.sampleFrames = Math.max(this.targetSampleFrames, (maxTime / frameSpan) + 1); + this._frameAdjust = 0; + } + var msToPs = width / sampleSpan; + var startY = position.y - (height - TimeRuler.barHeight); + var y = startY; + }; + TimeRuler.maxBars = 8; + TimeRuler.maxSamples = 256; + TimeRuler.maxNestCall = 32; + TimeRuler.barHeight = 8; + TimeRuler.maxSampleFrames = 4; + TimeRuler.logSnapDuration = 120; + TimeRuler.barPadding = 2; + TimeRuler.autoAdjustDelay = 30; + return TimeRuler; + }()); + es.TimeRuler = TimeRuler; + var FrameLog = (function () { + function FrameLog() { + this.bars = new Array(TimeRuler.maxBars); + this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); } - else { - this._frameAdjust = Math.min(0, this._frameAdjust) - 1; + return FrameLog; + }()); + es.FrameLog = FrameLog; + var MarkerCollection = (function () { + function MarkerCollection() { + this.markers = new Array(TimeRuler.maxSamples); + this.markCount = 0; + this.markerNests = new Array(TimeRuler.maxNestCall); + this.nestCount = 0; + this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); + this.markerNests.fill(0, 0, TimeRuler.maxNestCall); } - if (Math.max(this._frameAdjust) > TimeRuler.autoAdjustDelay) { - this.sampleFrames = Math.min(TimeRuler.maxSampleFrames, this.sampleFrames); - this.sampleFrames = Math.max(this.targetSampleFrames, (maxTime / frameSpan) + 1); - this._frameAdjust = 0; + return MarkerCollection; + }()); + es.MarkerCollection = MarkerCollection; + var Marker = (function () { + function Marker() { + this.markerId = 0; + this.beginTime = 0; + this.endTime = 0; + this.color = 0x000000; } - var msToPs = width / sampleSpan; - var startY = position.y - (height - TimeRuler.barHeight); - var y = startY; - }; - TimeRuler.maxBars = 8; - TimeRuler.maxSamples = 256; - TimeRuler.maxNestCall = 32; - TimeRuler.barHeight = 8; - TimeRuler.maxSampleFrames = 4; - TimeRuler.logSnapDuration = 120; - TimeRuler.barPadding = 2; - TimeRuler.autoAdjustDelay = 30; - return TimeRuler; -}()); -var FrameLog = (function () { - function FrameLog() { - this.bars = new Array(TimeRuler.maxBars); - this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); - } - return FrameLog; -}()); -var MarkerCollection = (function () { - function MarkerCollection() { - this.markers = new Array(TimeRuler.maxSamples); - this.markCount = 0; - this.markerNests = new Array(TimeRuler.maxNestCall); - this.nestCount = 0; - this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); - this.markerNests.fill(0, 0, TimeRuler.maxNestCall); - } - return MarkerCollection; -}()); -var Marker = (function () { - function Marker() { - this.markerId = 0; - this.beginTime = 0; - this.endTime = 0; - this.color = 0x000000; - } - return Marker; -}()); -var MarkerInfo = (function () { - function MarkerInfo(name) { - this.logs = new Array(TimeRuler.maxBars); - this.name = name; - this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); - } - return MarkerInfo; -}()); -var MarkerLog = (function () { - function MarkerLog() { - this.snapMin = 0; - this.snapMax = 0; - this.snapAvg = 0; - this.min = 0; - this.max = 0; - this.avg = 0; - this.samples = 0; - this.color = 0x000000; - this.initialized = false; - } - return MarkerLog; -}()); + return Marker; + }()); + es.Marker = Marker; + var MarkerInfo = (function () { + function MarkerInfo(name) { + this.logs = new Array(TimeRuler.maxBars); + this.name = name; + this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); + } + return MarkerInfo; + }()); + es.MarkerInfo = MarkerInfo; + var MarkerLog = (function () { + function MarkerLog() { + this.snapMin = 0; + this.snapMax = 0; + this.snapAvg = 0; + this.min = 0; + this.max = 0; + this.avg = 0; + this.samples = 0; + this.color = 0x000000; + this.initialized = false; + } + return MarkerLog; + }()); + es.MarkerLog = MarkerLog; +})(es || (es = {})); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index d6c96e6d..21b482eb 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(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._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return r?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return r?this.recontructPath(o,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},t}(),Debug=function(){function t(){}return t.drawHollowRect=function(t,e,n){void 0===n&&(n=0),this._debugDrawItems.push(new DebugDrawItem(t,e,n))},t.render=function(){if(this._debugDrawItems.length>0){var t=new egret.Shape;SceneManager.scene&&SceneManager.scene.addChild(t);for(var e=this._debugDrawItems.length-1;e>=0;e--){this._debugDrawItems[e].draw(t)&&this._debugDrawItems.removeAt(e)}}},t._debugDrawItems=[],t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(DebugDrawType||(DebugDrawType={}));var CoreEvents,DebugDrawItem=function(){function t(t,e,n){this.rectangle=t,this.color=e,this.duration=n,this.drawType=DebugDrawType.hollowRectangle}return t.prototype.draw=function(t){switch(this.drawType){case DebugDrawType.line:DrawUtils.drawLine(t,this.start,this.end,this.color);break;case DebugDrawType.hollowRectangle:DrawUtils.drawHollowRect(t,this.rectangle,this.color);break;case DebugDrawType.pixel:DrawUtils.drawPixel(t,new Vector2(this.x,this.y),this.color,this.size);break;case DebugDrawType.text:}return this.duration-=Time.deltaTime,this.duration<0},t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e._updateOrder=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"localPosition",{get:function(){return new Vector2(this.entity.x+this.x,this.entity.y+this.y)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.debugRender=function(){},e.prototype.update=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer);!function(t){t[t.SceneChanged=0]="SceneChanged"}(CoreEvents||(CoreEvents={}));var TransformComponent,Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.$getRotation()},set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),e.prototype.onAddToStage=function(){this.onEntityTransformChanged(TransformComponent.position)},Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene&&(t._scene.end(),t._scene=t._nextScene,t._nextScene=null,t._instnace.onSceneChanged(),t._scene.begin())}t.endDebugUpdate(),t.render()},t.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),Debug.render(),this._scene.postRender())},t.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},t.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},t.prototype.onSceneChanged=function(){t.emitter.emit(CoreEvents.SceneChanged),Time.sceneChanged()},t.startDebugUpdate=function(){TimeRuler.Instance.startFrame(),TimeRuler.Instance.beginMark("update",65280)},t.endDebugUpdate=function(){TimeRuler.Instance.endMark("update")},t}(),Camera=function(t){function e(){var e=t.call(this)||this;return e._origin=Vector2.zero,e._minimumZoom=.3,e._maximumZoom=3,e._position=Vector2.zero,e.followLerp=.1,e.deadzone=new Rectangle,e.focusOffset=new Vector2,e.mapLockEnabled=!1,e.mapSize=new Vector2,e._worldSpaceDeadZone=new Rectangle,e._desiredPositionDelta=new Vector2,e.cameraStyle=CameraStyle.lockOn,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.setZoom(0),e}return __extends(e,t),Object.defineProperty(e.prototype,"zoom",{get:function(){return 0==this._zoom?1:this._zoom<1?MathHelper.map(this._zoom,this._minimumZoom,1,-1,0):MathHelper.map(this._zoom,1,this._maximumZoom,0,1)},set:function(t){this.setZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"minimumZoom",{get:function(){return this._minimumZoom},set:function(t){this.setMinimumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maximumZoom",{get:function(){return this._maximumZoom},set:function(t){this.setMaximumZoom(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this._origin!=t&&(this._origin=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"x",{get:function(){return this._position.x},set:function(t){this._position.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"y",{get:function(){return this._position.y},set:function(t){this._position.y=t},enumerable:!0,configurable:!0}),e.prototype.onSceneSizeChanged=function(t,e){var n=this._origin;this.origin=new Vector2(t/2,e/2),this.entity.position=Vector2.add(this.entity.position,Vector2.subtract(this._origin,n))},e.prototype.setMinimumZoom=function(t){return this._zoomt&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,r=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-r)/2,i,r);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),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.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x==-t.position.x+t.origin.x&&this.y==-t.position.y+t.origin.y||(this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y,this.entity.onEntityTransformChanged(TransformComponent.position))},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(SpriteRenderer),ScrollingSpriteRenderer=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.scrollSpeedX=15,e.scroolSpeedY=0,e._scrollX=0,e._scrollY=0,e}return __extends(e,t),e.prototype.update=function(){this._scrollX+=this.scrollSpeedX*Time.deltaTime,this._scrollY+=this.scroolSpeedY*Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height)),this.bitmap.texture=n}},e}(TiledSpriteRenderer),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,r=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*r,this.uvs.width=e.width*i,this.uvs.height=e.height*r}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var r=Math.floor(i/e),o=t.sprites.length;if(o>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=o-1;this.currentFrame=s-Math.abs(s-r%(2*s))}else this.currentFrame=r%o;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;n=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}(),TextureUtils=function(){function t(){}return t.convertImageToCanvas=function(t,e){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var n=t.$getTextureWidth(),i=t.$getTextureHeight();e||((e=egret.$TempRectangle).x=0,e.y=0,e.width=n,e.height=i),e.x=Math.min(e.x,n-1),e.y=Math.min(e.y,i-1),e.width=Math.min(e.width,n-e.x),e.height=Math.min(e.height,i-e.y);var r=Math.floor(e.width),o=Math.floor(e.height),s=this.sharedCanvas;if(s.style.width=r+"px",s.style.height=o+"px",this.sharedCanvas.width=r,this.sharedCanvas.height=o,"webgl"==egret.Capabilities.renderMode){var a=void 0;t.$renderBuffer?a=t:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(a=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)));for(var c=a.$renderBuffer.getPixels(e.x,e.y,r,o),h=0,u=0,l=0;l=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},t.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},t.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},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._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities),GraphicsDevice=function(){return function(){this.graphicsCapabilities=new GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}(),Viewport=function(){function t(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(t.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bounds",{get:function(){return new Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),t}(),GaussianBlurEffect=function(t){function e(){return t.call(this,PostProcessor.default_vert,e.blur_frag,{screenWidth:SceneManager.stage.stageWidth,screenHeight:SceneManager.stage.stageHeight})||this}return __extends(e,t),e.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",e}(egret.CustomFilter),PolygonLightEffect=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter),PostProcessor=function(){function t(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return t.prototype.onAddedToScene=function(t){this.scene=t,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),this.shape.graphics.endFill(),t.addChild(this.shape)},t.prototype.process=function(){this.drawFullscreenQuad()},t.prototype.onSceneBackBufferSizeChanged=function(t, e){},t.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},t.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},t.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",t}(),GaussianBlurPostProcessor=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToScene=function(e){t.prototype.onAddedToScene.call(this,e),this.effect=new GaussianBlurEffect},e}(PostProcessor),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}(),DefaultRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var r=t.toRadians(i);return new Vector2(Math.cos(r)*r+e.x,Math.sin(r)*r+e.y)},t.isEven=function(t){return t%2==0},t.clamp01=function(t){return t<0?0:t>1?1:t},t.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,r=e.m11*n.m11+e.m12*n.m21,o=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var r=t.createTranslation(n,i);return t.multiply(e,r)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),r=Math.sin(e);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*r.y-a.y*r.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var r=new Vector2(0,0),o=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=o.x*s.y-o.y*s.x;if(0==a)return r;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return r;var u=(c.x*o.y-c.y*o.x)/a;return u<0||u>1?r:r=Vector2.add(t,new Vector2(h*o.x,h*o.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),r=Vector2.subtract(n,t),o=Vector2.dot(r,i)/Vector2.dot(i,i);return o=MathHelper.clamp(o,0,1),Vector2.add(t,new Vector2(i.x*o,i.y*o))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&r.y>=e&&r.x=t+n&&(o|=PointSectors.right),r.y=e+i&&(o|=PointSectors.bottom),o},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(egret.DisplayObject),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i._areEdgeNormalsDirty=!0,i.center=new Vector2,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.parent.x,this.parent.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.x,this.y,this.width,this.height)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var r=Vector2Ext.perpendicular(i,t);r=Vector2.normalize(r),this._edgeNormals[n]=r}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(r=!1),!r)return null;(g=Math.abs(g))i&&(i=r);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),r=Polygon.getClosestPointOnPolygonToPoint(e.points,i),o=r.closestPoint,s=r.distanceSquared;n.normal=r.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,o)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(o,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var r=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,r),n}var o=Vector2.distanceSquared(i,t.position);if(0==o)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(o<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),r=1+e.radius;if(i0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},t.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},t}(),RaycastResultParser=function(){return function(){}}(),NumberDictionary=function(){function t(){this._store=new Map}return t.prototype.getKey=function(t,e){return Long.fromNumber(t).shiftLeft(32).or(Long.fromNumber(e,!1)).toString()},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ArrayUtils=function(){function t(){}return t.bubbleSort=function(t){for(var e=!1,n=0;nn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),DrawUtils=function(){function t(){}return t.drawLine=function(t,e,n,i,r){void 0===r&&(r=1),this.drawLineAngle(t,e,MathHelper.angleBetweenVectors(e,n),Vector2.distance(e,n),i,r)},t.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},t.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},t.drawHollowRectR=function(t,e,n,i,r,o,s){void 0===s&&(s=1);var a=new Vector2(e,n).round(),c=new Vector2(e+i,n).round(),h=new Vector2(e+i,n+r).round(),u=new Vector2(e,n+r).round();this.drawLine(t,a,c,o,s),this.drawLine(t,c,h,o,s),this.drawLine(t,h,u,o,s),this.drawLine(t,u,a,o,s)},t.drawPixel=function(t,e,n,i){void 0===i&&(i=1);var r=new Rectangle(e.x,e.y,i,i);1!=i&&(r.x-=.5*i,r.y-=.5*i),t.graphics.beginFill(n),t.graphics.drawRect(r.x,r.y,r.width,r.height),t.graphics.endFill()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e,n){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(new FuncPack(e,n))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}(),FuncPack=function(){return function(t,e){this.func=t,this.context=e}}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},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}(),RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&r<500;){r++;var s=!0,a=e[this._triPrev[o]],c=e[o],h=e[this._triNext[o]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[o]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[o])}else s=!1;s?(this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),this._triNext[this._triPrev[o]]=this._triNext[o],this._triPrev[this._triNext[o]]=this._triPrev[o],i--,o=this._triPrev[o]):o=this._triNext[o]}this.triangleIndices.push(this._triPrev[o]),this.triangleIndices.push(o),this.triangleIndices.push(this._triNext[o]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(r.x=this.safeArea.right-r.width),r.topthis.safeArea.bottom&&(r.y=this.safeArea.bottom-r.height),r},t}();!function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(Alignment||(Alignment={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={}));var TimeRuler=function(){function t(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,t.Instance=this,this._logs=new Array(2);for(var e=0;e=t.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}e.stopwacth.reset(),e.stopwacth.start()}})},t.prototype.beginMark=function(e,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=t.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=t.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=t.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(e);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(e,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},t.prototype.endMark=function(e,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=t.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(e);if(isNaN(o))throw new Error("Marker "+e+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},t.prototype.getAverageTime=function(e,n){if(e<0||e>=t.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[e].avg),i},t.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=t.barHeight+2*t.barPadding,r=Math.max(r,e.markers[e.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>t.autoAdjustDelay&&(this.sampleFrames=Math.min(t.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);e.y,t.barHeight}},t.maxBars=8,t.maxSamples=256,t.maxNestCall=32,t.barHeight=8,t.maxSampleFrames=4,t.logSnapDuration=120,t.barPadding=2,t.autoAdjustDelay=30,t}(),FrameLog=function(){return function(){this.bars=new Array(TimeRuler.maxBars),this.bars.fill(new MarkerCollection,0,TimeRuler.maxBars)}}(),MarkerCollection=function(){return function(){this.markers=new Array(TimeRuler.maxSamples),this.markCount=0,this.markerNests=new Array(TimeRuler.maxNestCall),this.nestCount=0,this.markers.fill(new Marker,0,TimeRuler.maxSamples),this.markerNests.fill(0,0,TimeRuler.maxNestCall)}}(),Marker=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}(),MarkerInfo=function(){return function(t){this.logs=new Array(TimeRuler.maxBars),this.name=t,this.logs.fill(new MarkerLog,0,TimeRuler.maxBars)}}(),MarkerLog=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}(); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},i.prototype.zoomIn=function(t){this.zoom+=t},i.prototype.zoomOut=function(t){this.zoom-=t},i.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},i.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},i.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},i.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},i.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},i.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},i}(t.Component);t.Camera=n}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(e,"identity",{get:function(){return e._identity},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.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(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),e.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},e.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},e.multiply=function(t,n){var i=new e,r=t.m11*n.m11+t.m12*n.m21,o=t.m11*n.m12+t.m12*n.m22,s=t.m21*n.m11+t.m22*n.m21,a=t.m21*n.m12+t.m22*n.m22,c=t.m31*n.m11+t.m32*n.m21+n.m31,h=t.m31*n.m12+t.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},e.multiplyTranslation=function(t,n,i){var r=e.createTranslation(n,i);return e.multiply(t,r)},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.invert=function(t,n){void 0===n&&(n=new e);var i=1/t.determinant();return n.m11=t.m22*i,n.m12=-t.m12*i,n.m21=-t.m21*i,n.m22=t.m11*i,n.m31=(t.m32*t.m21-t.m31*t.m22)*i,n.m32=-(t.m32*t.m11-t.m31*t.m12)*i,n},e.createTranslation=function(t,n){var i=new e;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=t,i.m32=n,i},e.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},e.createRotation=function(t,n){n=new e;var i=Math.cos(t),r=Math.sin(t);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},e.createScale=function(t,n,i){return void 0===i&&(i=new e),i.m11=t,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},e.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},e._identity=new e(1,0,0,1,0,0),e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(){}}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/lib/wxgame.d.ts b/source/lib/wxgame.d.ts index 5ffbcf7e..b8adb9dd 100644 --- a/source/lib/wxgame.d.ts +++ b/source/lib/wxgame.d.ts @@ -1008,7 +1008,129 @@ declare class Video { */ exitFullScreen(): Promise; } +/** + * 相机对象 + */ +declare class Camera { + /** + * 相机的左上角横坐标 + */ + x: number; + /** + * 相机的左上角纵坐标 + */ + y: number; + + /** + * 相机的宽度 + */ + width: number; + + /** + * 相机的高度 + */ + height: number; + + /** + * 摄像头朝向 + */ + devicePosition: "front" | "back"; + + /** + * 闪光灯状态 + */ + flash: "auto" | "on" | "off"; + + /** + * 帧数据图像尺寸 + */ + size: "small" | "medium" | "large"; + + /** + * 拍照,可指定质量,成功则返回图片 + * @param quality 图片质量 + */ + takePhoto(quality?: "high" | "normal" | "low"): Promise<{ + /** + * 临时图片路径 + */ + tempImagePath: string, + /** + * 图片宽度 + */ + width: string, + /** + * 图片高度 + */ + height: string + }>; + + /** + * 开始录像 + */ + startRecord(): Promise; + + /** + * 结束录像,成功则返回封面与视频 + * @param compressed 是否压缩录制视频 + */ + stopRecord(compressed: boolean): Promise<{ + /** + * 临时视频路径 + */ + tempThumbPath: string, + /** + * 临时封面路径 + */ + tempVideoPath: string + }>; + + /** + * 监听用户不允许授权使用摄像头的情况 + * @param callback 回调函数 + */ + onAuthCancel(callback: () => void): void; + + /** + * 监听摄像头非正常终止事件,如退出后台等情况 + * @param callback 回调函数 + */ + onStop(callback: () => void): void; + + /** + * 监听摄像头实时帧数据 + */ + onCameraFrame(callback: (res: { + /** + * 图像数据矩形的宽度 + */ + width: number, + /** + * 图像数据矩形的高度 + */ + height: number, + /** + * 图像像素点数据,一维数组,每四项表示一个像素点的 rgba + */ + data: ArrayBuffer + }) => void): void; + + /** + * 开启监听帧数据 + */ + listenFrameChange(): void; + + /** + * 关闭监听帧数据 + */ + closeFrameChange(): void; + + /** + * 销毁相机 + */ + destroy(): void; +} /** * banner 广告组件。banner 广告组件是一个原生组件,层级比上屏 Canvas 高,会覆盖在上屏 Canvas 上。banner 广告组件默认是隐藏的,需要调用 BannerAd.show() 将其显示。banner 广告会根据开发者设置的宽度进行等比缩放,缩放后的尺寸将通过 BannerAd.onResize() 事件中提供。 */ diff --git a/source/src/AI/Pathfinding/AStar/AStarPathfinder.ts b/source/src/AI/Pathfinding/AStar/AStarPathfinder.ts index 9d6ed0b3..2be43c70 100644 --- a/source/src/AI/Pathfinding/AStar/AStarPathfinder.ts +++ b/source/src/AI/Pathfinding/AStar/AStarPathfinder.ts @@ -1,101 +1,103 @@ /// -/** - * 计算路径给定的IAstarGraph和开始/目标位置 - */ -class AStarPathfinder { +module es { /** - * 尽可能从开始到目标找到一条路径。如果没有找到路径,则返回null。 - * @param graph - * @param start - * @param goal + * 计算路径给定的IAstarGraph和开始/目标位置 */ - public static search(graph: IAstarGraph, start: T, goal: T){ - let foundPath = false; - let cameFrom = new Map(); - cameFrom.set(start, start); + export class AStarPathfinder { + /** + * 尽可能从开始到目标找到一条路径。如果没有找到路径,则返回null。 + * @param graph + * @param start + * @param goal + */ + public static search(graph: IAstarGraph, start: T, goal: T){ + let foundPath = false; + let cameFrom = new Map(); + cameFrom.set(start, start); - let costSoFar = new Map(); - let frontier = new PriorityQueue>(1000); - frontier.enqueue(new AStarNode(start), 0); + let costSoFar = new Map(); + let frontier = new PriorityQueue>(1000); + frontier.enqueue(new AStarNode(start), 0); - costSoFar.set(start, 0); + costSoFar.set(start, 0); - while (frontier.count > 0){ - let current = frontier.dequeue(); + while (frontier.count > 0){ + let current = frontier.dequeue(); - if (JSON.stringify(current.data) == JSON.stringify(goal)){ - foundPath = true; - break; + if (JSON.stringify(current.data) == JSON.stringify(goal)){ + foundPath = true; + break; + } + + graph.getNeighbors(current.data).forEach(next => { + let newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)){ + costSoFar.set(next, newCost); + let priority = newCost + graph.heuristic(next, goal); + frontier.enqueue(new AStarNode(next), priority); + cameFrom.set(next, current.data); + } + }); } - graph.getNeighbors(current.data).forEach(next => { - let newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)){ - costSoFar.set(next, newCost); - let priority = newCost + graph.heuristic(next, goal); - frontier.enqueue(new AStarNode(next), priority); - cameFrom.set(next, current.data); - } - }); + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; } - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - } + private static hasKey(map: Map, compareKey: T){ + let iterator = map.keys(); + let r: IteratorResult; + while (r = iterator.next() , !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } - private static hasKey(map: Map, compareKey: T){ - let iterator = map.keys(); - let r: IteratorResult; - while (r = iterator.next() , !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; + return false; } - return false; - } + private static getKey(map: Map, compareKey: T){ + let iterator = map.keys(); + let valueIterator = map.values(); + let r: IteratorResult; + let v: IteratorResult; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } - private static getKey(map: Map, compareKey: T){ - let iterator = map.keys(); - let valueIterator = map.values(); - let r: IteratorResult; - let v: IteratorResult; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; + return null; } - return null; + /** + * 从cameFrom字典重新构造路径 + * @param cameFrom + * @param start + * @param goal + */ + public static recontructPath(cameFrom: Map, start: T, goal: T): T[]{ + let path = []; + let current = goal; + path.push(goal); + + while (current != start){ + current = this.getKey(cameFrom, current); + path.push(current); + } + + path.reverse(); + + return path; + } } /** - * 从cameFrom字典重新构造路径 - * @param cameFrom - * @param start - * @param goal + * 使用PriorityQueue需要的额外字段将原始数据封装在一个小类中 */ - public static recontructPath(cameFrom: Map, start: T, goal: T): T[]{ - let path = []; - let current = goal; - path.push(goal); + export class AStarNode extends PriorityQueueNode { + public data: T; - while (current != start){ - current = this.getKey(cameFrom, current); - path.push(current); + constructor(data: T){ + super(); + this.data = data; } - - path.reverse(); - - return path; } } - -/** - * 使用PriorityQueue需要的额外字段将原始数据封装在一个小类中 - */ -class AStarNode extends PriorityQueueNode { - public data: T; - - constructor(data: T){ - super(); - this.data = data; - } -} \ No newline at end of file diff --git a/source/src/AI/Pathfinding/AStar/AstarGridGraph.ts b/source/src/AI/Pathfinding/AStar/AstarGridGraph.ts index 0bb470e7..8c35b25e 100644 --- a/source/src/AI/Pathfinding/AStar/AstarGridGraph.ts +++ b/source/src/AI/Pathfinding/AStar/AstarGridGraph.ts @@ -1,72 +1,74 @@ -/** - * 基本静态网格图与A*一起使用 - * 将walls添加到walls HashSet,并将加权节点添加到weightedNodes - */ -class AstarGridGraph implements IAstarGraph { - public dirs: Vector2[] = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; - - public walls: Vector2[] = []; - public weightedNodes: Vector2[] = []; - public defaultWeight: number = 1; - public weightedNodeWeight = 5; - - private _width; - private _height; - private _neighbors: Vector2[] = new Array(4); - - constructor(width: number, height: number){ - this._width = width; - this._height = height; - } - +module es { /** - * 确保节点在网格图的边界内 - * @param node + * 基本静态网格图与A*一起使用 + * 将walls添加到walls HashSet,并将加权节点添加到weightedNodes */ - public isNodeInBounds(node: Vector2): boolean { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + export class AstarGridGraph implements IAstarGraph { + public dirs: Vector2[] = [ + new Vector2(1, 0), + new Vector2(0, -1), + new Vector2(-1, 0), + new Vector2(0, 1) + ]; + + public walls: Vector2[] = []; + public weightedNodes: Vector2[] = []; + public defaultWeight: number = 1; + public weightedNodeWeight = 5; + + private _width; + private _height; + private _neighbors: Vector2[] = new Array(4); + + constructor(width: number, height: number){ + this._width = width; + this._height = height; + } + + /** + * 确保节点在网格图的边界内 + * @param node + */ + public isNodeInBounds(node: Vector2): boolean { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + } + + /** + * 检查节点是否可以通过。walls是不可逾越的。 + * @param node + */ + public isNodePassable(node: Vector2): boolean { + return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); + } + + /** + * 调用AStarPathfinder.search的快捷方式 + * @param start + * @param goal + */ + public search(start: Vector2, goal: Vector2){ + return AStarPathfinder.search(this, start, goal); + } + + public getNeighbors(node: Vector2): Vector2[] { + this._neighbors.length = 0; + + this.dirs.forEach(dir => { + let next = new Vector2(node.x + dir.x, node.y + dir.y); + if (this.isNodeInBounds(next) && this.isNodePassable(next)) + this._neighbors.push(next); + }); + + return this._neighbors; + } + + public cost(from: Vector2, to: Vector2): number { + return this.weightedNodes.find((p)=> JSON.stringify(p) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight; + } + + public heuristic(node: Vector2, goal: Vector2) { + return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); + } + } - - /** - * 检查节点是否可以通过。walls是不可逾越的。 - * @param node - */ - public isNodePassable(node: Vector2): boolean { - return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); - } - - /** - * 调用AStarPathfinder.search的快捷方式 - * @param start - * @param goal - */ - public search(start: Vector2, goal: Vector2){ - return AStarPathfinder.search(this, start, goal); - } - - public getNeighbors(node: Vector2): Vector2[] { - this._neighbors.length = 0; - - this.dirs.forEach(dir => { - let next = new Vector2(node.x + dir.x, node.y + dir.y); - if (this.isNodeInBounds(next) && this.isNodePassable(next)) - this._neighbors.push(next); - }); - - return this._neighbors; - } - - public cost(from: Vector2, to: Vector2): number { - return this.weightedNodes.find((p)=> JSON.stringify(p) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight; - } - - public heuristic(node: Vector2, goal: Vector2) { - return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y); - } - -} \ No newline at end of file +} diff --git a/source/src/AI/Pathfinding/AStar/IAstarGraph.ts b/source/src/AI/Pathfinding/AStar/IAstarGraph.ts index f25957d0..6b0fc08f 100644 --- a/source/src/AI/Pathfinding/AStar/IAstarGraph.ts +++ b/source/src/AI/Pathfinding/AStar/IAstarGraph.ts @@ -1,22 +1,24 @@ -/** - * graph的接口,可以提供给AstarPathfinder.search方法 - */ -interface IAstarGraph { +module es { /** - * getNeighbors方法应该返回从传入的节点可以到达的任何相邻节点 - * @param node + * graph的接口,可以提供给AstarPathfinder.search方法 */ - getNeighbors(node: T): Array; - /** - * 计算从从from到to的成本 - * @param from - * @param to - */ - cost(from: T, to: T): number; - /** - * 计算从node到to的启发式。参见WeightedGridGraph了解常用的Manhatten方法。 - * @param node - * @param goal - */ - heuristic(node: T, goal: T); -} \ No newline at end of file + export interface IAstarGraph { + /** + * getNeighbors方法应该返回从传入的节点可以到达的任何相邻节点 + * @param node + */ + getNeighbors(node: T): Array; + /** + * 计算从从from到to的成本 + * @param from + * @param to + */ + cost(from: T, to: T): number; + /** + * 计算从node到to的启发式。参见WeightedGridGraph了解常用的Manhatten方法。 + * @param node + * @param goal + */ + heuristic(node: T, goal: T); + } +} diff --git a/source/src/AI/Pathfinding/AStar/PriorityQueue.ts b/source/src/AI/Pathfinding/AStar/PriorityQueue.ts index 5dd4acfd..85c0a318 100644 --- a/source/src/AI/Pathfinding/AStar/PriorityQueue.ts +++ b/source/src/AI/Pathfinding/AStar/PriorityQueue.ts @@ -1,234 +1,236 @@ -/** - * 使用堆实现最小优先级队列 O(1)复杂度 - * 这种查找速度比使用字典快5-10倍 - * 但是,由于IPriorityQueue.contains()是许多寻路算法中调用最多的方法,因此尽可能快地实现它对于我们的应用程序非常重要。 - */ -class PriorityQueue { - private _numNodes: number; - private _nodes: T[]; - private _numNodesEverEnqueued; - +module es { /** - * 实例化一个新的优先级队列 - * @param maxNodes 允许加入队列的最大节点(执行此操作将导致undefined的行为) + * 使用堆实现最小优先级队列 O(1)复杂度 + * 这种查找速度比使用字典快5-10倍 + * 但是,由于IPriorityQueue.contains()是许多寻路算法中调用最多的方法,因此尽可能快地实现它对于我们的应用程序非常重要。 */ - constructor(maxNodes: number) { - this._numNodes = 0; - this._nodes = new Array(maxNodes + 1); - this._numNodesEverEnqueued = 0; - } + export class PriorityQueue { + private _numNodes: number; + private _nodes: T[]; + private _numNodesEverEnqueued; - /** - * 从队列中删除每个节点。 - * O(n)复杂度 所有尽可能少调用该方法 - */ - public clear() { - this._nodes.splice(1, this._numNodes); - this._numNodes = 0; - } - - /** - * 返回队列中的节点数。 - * O(1)复杂度 - */ - public get count() { - return this._numNodes; - } - - /** - * 返回可同时进入此队列的最大项数。一旦你达到这个数字(即。一旦Count == MaxSize),尝试加入另一个项目将导致undefined的行为 - * O(1)复杂度 - */ - public get maxSize() { - return this._nodes.length - 1; - } - - /** - * 返回(在O(1)中)给定节点是否在队列中 - * O (1)复杂度 - * @param node - */ - public contains(node: T): boolean { - if (!node){ - console.error("node cannot be null"); - return false; + /** + * 实例化一个新的优先级队列 + * @param maxNodes 允许加入队列的最大节点(执行此操作将导致undefined的行为) + */ + constructor(maxNodes: number) { + this._numNodes = 0; + this._nodes = new Array(maxNodes + 1); + this._numNodesEverEnqueued = 0; } - if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length){ - console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); - return false; + /** + * 从队列中删除每个节点。 + * O(n)复杂度 所有尽可能少调用该方法 + */ + public clear() { + this._nodes.splice(1, this._numNodes); + this._numNodes = 0; } - return (this._nodes[node.queueIndex] == node); - } + /** + * 返回队列中的节点数。 + * O(1)复杂度 + */ + public get count() { + return this._numNodes; + } - /** - * 将节点放入优先队列 较低的值放在前面 先入先出 - * 如果队列已满,则结果undefined。如果节点已经加入队列,则结果undefined。 - * O(log n) - * @param node - * @param priority - */ - public enqueue(node: T, priority: number) { - node.priority = priority; - this._numNodes++; - this._nodes[this._numNodes] = node; - node.queueIndex = this._numNodes; - node.insertionIndex = this._numNodesEverEnqueued++; - this.cascadeUp(this._nodes[this._numNodes]); - } + /** + * 返回可同时进入此队列的最大项数。一旦你达到这个数字(即。一旦Count == MaxSize),尝试加入另一个项目将导致undefined的行为 + * O(1)复杂度 + */ + public get maxSize() { + return this._nodes.length - 1; + } - /** - * 删除队列头(具有最小优先级的节点;按插入顺序断开连接),并返回它。如果队列为空,结果undefined - * O(log n) - */ - public dequeue(): T { - let returnMe = this._nodes[1]; - this.remove(returnMe); - return returnMe; - } + /** + * 返回(在O(1)中)给定节点是否在队列中 + * O (1)复杂度 + * @param node + */ + public contains(node: T): boolean { + if (!node){ + console.error("node cannot be null"); + return false; + } - /** - * 从队列中删除一个节点。节点不需要是队列的头。如果节点不在队列中,则结果未定义。如果不确定,首先检查Contains() - * O(log n) - * @param node - */ - public remove(node: T) { - if (node.queueIndex == this._numNodes) { - this._nodes[this._numNodes] = null; + if (node.queueIndex < 0 || node.queueIndex >= this._nodes.length){ + console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"); + return false; + } + + return (this._nodes[node.queueIndex] == node); + } + + /** + * 将节点放入优先队列 较低的值放在前面 先入先出 + * 如果队列已满,则结果undefined。如果节点已经加入队列,则结果undefined。 + * O(log n) + * @param node + * @param priority + */ + public enqueue(node: T, priority: number) { + node.priority = priority; + this._numNodes++; + this._nodes[this._numNodes] = node; + node.queueIndex = this._numNodes; + node.insertionIndex = this._numNodesEverEnqueued++; + this.cascadeUp(this._nodes[this._numNodes]); + } + + /** + * 删除队列头(具有最小优先级的节点;按插入顺序断开连接),并返回它。如果队列为空,结果undefined + * O(log n) + */ + public dequeue(): T { + let returnMe = this._nodes[1]; + this.remove(returnMe); + return returnMe; + } + + /** + * 从队列中删除一个节点。节点不需要是队列的头。如果节点不在队列中,则结果未定义。如果不确定,首先检查Contains() + * O(log n) + * @param node + */ + public remove(node: T) { + if (node.queueIndex == this._numNodes) { + this._nodes[this._numNodes] = null; + this._numNodes--; + return; + } + + let formerLastNode = this._nodes[this._numNodes]; + this.swap(node, formerLastNode); + delete this._nodes[this._numNodes]; this._numNodes--; - return; + + this.onNodeUpdated(formerLastNode); } - let formerLastNode = this._nodes[this._numNodes]; - this.swap(node, formerLastNode); - delete this._nodes[this._numNodes]; - this._numNodes--; + /** + * 检查以确保队列仍然处于有效状态。用于测试/调试队列。 + */ + public isValidQueue(): boolean { + for (let i = 1; i < this._nodes.length; i++) { + if (this._nodes[i]) { + let childLeftIndex = 2 * i; + if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && + this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) + return false; - this.onNodeUpdated(formerLastNode); - } - - /** - * 检查以确保队列仍然处于有效状态。用于测试/调试队列。 - */ - public isValidQueue(): boolean { - for (let i = 1; i < this._nodes.length; i++) { - if (this._nodes[i]) { - let childLeftIndex = 2 * i; - if (childLeftIndex < this._nodes.length && this._nodes[childLeftIndex] && - this.hasHigherPriority(this._nodes[childLeftIndex], this._nodes[i])) - return false; - - let childRightIndex = childLeftIndex + 1; - if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && - this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) - return false; - } - } - - return true; - } - - private onNodeUpdated(node: T) { - // 将更新后的节点按适当的方式向上或向下冒泡 - let parentIndex = Math.floor(node.queueIndex / 2); - let parentNode = this._nodes[parentIndex]; - - if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { - this.cascadeUp(node); - } else { - // 注意,如果parentNode == node(即节点是根),则将调用CascadeDown。 - this.cascadeDown(node); - } - } - - private cascadeDown(node: T) { - // 又名Heapify-down - let newParent: T; - let finalQueueIndex = node.queueIndex; - while (true) { - newParent = node; - let childLeftIndex = 2 * finalQueueIndex; - - // 检查左子节点的优先级是否高于当前节点 - if (childLeftIndex > this._numNodes) { - // 这可以放在循环之外,但是我们必须检查newParent != node两次 - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; - } - - let childLeft = this._nodes[childLeftIndex]; - if (this.hasHigherPriority(childLeft, newParent)) { - newParent = childLeft; - } - - // 检查右子节点的优先级是否高于当前节点或左子节点 - let childRightIndex = childLeftIndex + 1; - if (childRightIndex <= this._numNodes) { - let childRight = this._nodes[childRightIndex]; - if (this.hasHigherPriority(childRight, newParent)) { - newParent = childRight; + let childRightIndex = childLeftIndex + 1; + if (childRightIndex < this._nodes.length && this._nodes[childRightIndex] && + this.hasHigherPriority(this._nodes[childRightIndex], this._nodes[i])) + return false; } } - // 如果其中一个子节点具有更高(更小)的优先级,则交换并继续级联 - if (newParent != node) { - // 将新的父节点移动到它的新索引 - // 节点将被移动一次,这样做比调用Swap()少一个赋值操作。 - this._nodes[finalQueueIndex] = newParent; + return true; + } - let temp = newParent.queueIndex; - newParent.queueIndex = finalQueueIndex; - finalQueueIndex = temp; + private onNodeUpdated(node: T) { + // 将更新后的节点按适当的方式向上或向下冒泡 + let parentIndex = Math.floor(node.queueIndex / 2); + let parentNode = this._nodes[parentIndex]; + + if (parentIndex > 0 && this.hasHigherPriority(node, parentNode)) { + this.cascadeUp(node); } else { - // 参见上面的笔记 - node.queueIndex = finalQueueIndex; - this._nodes[finalQueueIndex] = node; - break; + // 注意,如果parentNode == node(即节点是根),则将调用CascadeDown。 + this.cascadeDown(node); } } - } - /** - * 当没有内联时,性能会稍微好一些 - * @param node - */ - private cascadeUp(node: T) { - // 又名Heapify-up - let parent = Math.floor(node.queueIndex / 2); - while (parent >= 1) { - let parentNode = this._nodes[parent]; - if (this.hasHigherPriority(parentNode, node)) - break; + private cascadeDown(node: T) { + // 又名Heapify-down + let newParent: T; + let finalQueueIndex = node.queueIndex; + while (true) { + newParent = node; + let childLeftIndex = 2 * finalQueueIndex; - // 节点具有较低的优先级值,因此将其向上移动到堆中 - // 出于某种原因,使用Swap()比使用单独的操作更快,如CascadeDown() - this.swap(node, parentNode); + // 检查左子节点的优先级是否高于当前节点 + if (childLeftIndex > this._numNodes) { + // 这可以放在循环之外,但是我们必须检查newParent != node两次 + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } - parent = Math.floor(node.queueIndex / 2); + let childLeft = this._nodes[childLeftIndex]; + if (this.hasHigherPriority(childLeft, newParent)) { + newParent = childLeft; + } + + // 检查右子节点的优先级是否高于当前节点或左子节点 + let childRightIndex = childLeftIndex + 1; + if (childRightIndex <= this._numNodes) { + let childRight = this._nodes[childRightIndex]; + if (this.hasHigherPriority(childRight, newParent)) { + newParent = childRight; + } + } + + // 如果其中一个子节点具有更高(更小)的优先级,则交换并继续级联 + if (newParent != node) { + // 将新的父节点移动到它的新索引 + // 节点将被移动一次,这样做比调用Swap()少一个赋值操作。 + this._nodes[finalQueueIndex] = newParent; + + let temp = newParent.queueIndex; + newParent.queueIndex = finalQueueIndex; + finalQueueIndex = temp; + } else { + // 参见上面的笔记 + node.queueIndex = finalQueueIndex; + this._nodes[finalQueueIndex] = node; + break; + } + } + } + + /** + * 当没有内联时,性能会稍微好一些 + * @param node + */ + private cascadeUp(node: T) { + // 又名Heapify-up + let parent = Math.floor(node.queueIndex / 2); + while (parent >= 1) { + let parentNode = this._nodes[parent]; + if (this.hasHigherPriority(parentNode, node)) + break; + + // 节点具有较低的优先级值,因此将其向上移动到堆中 + // 出于某种原因,使用Swap()比使用单独的操作更快,如CascadeDown() + this.swap(node, parentNode); + + parent = Math.floor(node.queueIndex / 2); + } + } + + private swap(node1: T, node2: T) { + // 交换节点 + this._nodes[node1.queueIndex] = node2; + this._nodes[node2.queueIndex] = node1; + + // 交换他们的indicies + let temp = node1.queueIndex; + node1.queueIndex = node2.queueIndex; + node2.queueIndex = temp; + } + + /** + * 如果higher的优先级高于lower,则返回true,否则返回false。 + * 注意,调用HasHigherPriority(节点,节点)(即。两个参数为同一个节点)将返回false + * @param higher + * @param lower + */ + private hasHigherPriority(higher: T, lower: T) { + return (higher.priority < lower.priority || + (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); } } - - private swap(node1: T, node2: T) { - // 交换节点 - this._nodes[node1.queueIndex] = node2; - this._nodes[node2.queueIndex] = node1; - - // 交换他们的indicies - let temp = node1.queueIndex; - node1.queueIndex = node2.queueIndex; - node2.queueIndex = temp; - } - - /** - * 如果higher的优先级高于lower,则返回true,否则返回false。 - * 注意,调用HasHigherPriority(节点,节点)(即。两个参数为同一个节点)将返回false - * @param higher - * @param lower - */ - private hasHigherPriority(higher: T, lower: T) { - return (higher.priority < lower.priority || - (higher.priority == lower.priority && higher.insertionIndex < lower.insertionIndex)); - } -} \ No newline at end of file +} diff --git a/source/src/AI/Pathfinding/AStar/PriorityQueueNode.ts b/source/src/AI/Pathfinding/AStar/PriorityQueueNode.ts index 44edbc9e..29c86e2c 100644 --- a/source/src/AI/Pathfinding/AStar/PriorityQueueNode.ts +++ b/source/src/AI/Pathfinding/AStar/PriorityQueueNode.ts @@ -1,14 +1,16 @@ -class PriorityQueueNode { - /** - * 插入此节点的优先级。在将节点添加到队列之前必须设置 - */ - public priority: number = 0; - /** - * 由优先级队列使用-不要编辑此值。表示插入节点的顺序 - */ - public insertionIndex: number = 0; - /** - * 由优先级队列使用-不要编辑此值。表示队列中的当前位置 - */ - public queueIndex: number = 0; -} \ No newline at end of file +module es { + export class PriorityQueueNode { + /** + * 插入此节点的优先级。在将节点添加到队列之前必须设置 + */ + public priority: number = 0; + /** + * 由优先级队列使用-不要编辑此值。表示插入节点的顺序 + */ + public insertionIndex: number = 0; + /** + * 由优先级队列使用-不要编辑此值。表示队列中的当前位置 + */ + public queueIndex: number = 0; + } +} diff --git a/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts b/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts index 429af42c..4cad3f8e 100644 --- a/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts +++ b/source/src/AI/Pathfinding/BreadthFirst/BreadthFirstPathfinder.ts @@ -1,41 +1,43 @@ -/** - * 计算路径给定的IUnweightedGraph和开始/目标位置 - */ -class BreadthFirstPathfinder { - public static search(graph: IUnweightedGraph, start: T, goal: T): T[]{ - let foundPath = false; - let frontier = []; - frontier.unshift(start); +module es { + /** + * 计算路径给定的IUnweightedGraph和开始/目标位置 + */ + export class BreadthFirstPathfinder { + public static search(graph: IUnweightedGraph, start: T, goal: T): T[]{ + let foundPath = false; + let frontier = []; + frontier.unshift(start); - let cameFrom = new Map(); - cameFrom.set(start, start); + let cameFrom = new Map(); + cameFrom.set(start, start); - while (frontier.length > 0){ - let current = frontier.shift(); - if (JSON.stringify(current) == JSON.stringify(goal)){ - foundPath = true; - break; + while (frontier.length > 0){ + let current = frontier.shift(); + if (JSON.stringify(current) == JSON.stringify(goal)){ + foundPath = true; + break; + } + + graph.getNeighbors(current).forEach(next => { + if (!this.hasKey(cameFrom, next)){ + frontier.unshift(next); + cameFrom.set(next, current); + } + }); } - graph.getNeighbors(current).forEach(next => { - if (!this.hasKey(cameFrom, next)){ - frontier.unshift(next); - cameFrom.set(next, current); - } - }); + return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null; } - return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null; - } + private static hasKey(map: Map, compareKey: T){ + let iterator = map.keys(); + let r: IteratorResult; + while (r = iterator.next() , !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } - private static hasKey(map: Map, compareKey: T){ - let iterator = map.keys(); - let r: IteratorResult; - while (r = iterator.next() , !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; + return false; } - - return false; } -} \ No newline at end of file +} diff --git a/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts index 26a6af36..60c07253 100644 --- a/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts +++ b/source/src/AI/Pathfinding/BreadthFirst/IUnweightedGraph.ts @@ -1,7 +1,9 @@ -interface IUnweightedGraph{ - /** - * getNeighbors方法应该返回从传入的节点可以到达的任何相邻节点。 - * @param node - */ - getNeighbors(node: T): T[]; -} \ No newline at end of file +module es { + export interface IUnweightedGraph{ + /** + * getNeighbors方法应该返回从传入的节点可以到达的任何相邻节点。 + * @param node + */ + getNeighbors(node: T): T[]; + } +} diff --git a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts index e37120bc..745b1eb6 100644 --- a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts +++ b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGraph.ts @@ -1,16 +1,18 @@ -/** - * 一个未加权图的基本实现。所有的边都被缓存。这种类型的图最适合于非基于网格的图。 - * 作为边添加的任何节点都必须在边字典中有一个条目作为键。 - */ -class UnweightedGraph implements IUnweightedGraph { - public edges: Map = new Map(); +module es { + /** + * 一个未加权图的基本实现。所有的边都被缓存。这种类型的图最适合于非基于网格的图。 + * 作为边添加的任何节点都必须在边字典中有一个条目作为键。 + */ + export class UnweightedGraph implements IUnweightedGraph { + public edges: Map = new Map(); - public addEdgesForNode(node: T, edges: T[]){ - this.edges.set(node, edges); - return this; - } + public addEdgesForNode(node: T, edges: T[]){ + this.edges.set(node, edges); + return this; + } - public getNeighbors(node: T){ - return this.edges.get(node); + public getNeighbors(node: T){ + return this.edges.get(node); + } } -} \ No newline at end of file +} diff --git a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts index f769f398..e0516a93 100644 --- a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts +++ b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts @@ -1,61 +1,63 @@ /// -/** - * 基本的未加权网格图形用于BreadthFirstPathfinder - */ -class UnweightedGridGraph implements IUnweightedGraph { - private static readonly CARDINAL_DIRS: Vector2[] = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, -1) - ]; +module es { + /** + * 基本的未加权网格图形用于BreadthFirstPathfinder + */ + export class UnweightedGridGraph implements IUnweightedGraph { + private static readonly CARDINAL_DIRS: Vector2[] = [ + new Vector2(1, 0), + new Vector2(0, -1), + new Vector2(-1, 0), + new Vector2(0, -1) + ]; - private static readonly COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; + private static readonly COMPASS_DIRS = [ + new Vector2(1, 0), + new Vector2(1, -1), + new Vector2(0, -1), + new Vector2(-1, -1), + new Vector2(-1, 0), + new Vector2(-1, 1), + new Vector2(0, 1), + new Vector2(1, 1), + ]; - public walls: Vector2[] = []; + public walls: Vector2[] = []; - private _width: number; - private _hegiht: number; + private _width: number; + private _hegiht: number; - private _dirs: Vector2[]; - private _neighbors: Vector2[] = new Array(4); + private _dirs: Vector2[]; + private _neighbors: Vector2[] = new Array(4); - constructor(width: number, height: number, allowDiagonalSearch: boolean = false) { - this._width = width; - this._hegiht = height; - this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; + constructor(width: number, height: number, allowDiagonalSearch: boolean = false) { + this._width = width; + this._hegiht = height; + this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS; + } + + public isNodeInBounds(node: Vector2): boolean { + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; + } + + public isNodePassable(node: Vector2): boolean { + return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); + } + + public getNeighbors(node: Vector2) { + this._neighbors.length = 0; + + this._dirs.forEach(dir => { + let next = new Vector2(node.x + dir.x, node.y + dir.y); + if (this.isNodeInBounds(next) && this.isNodePassable(next)) + this._neighbors.push(next); + }); + + return this._neighbors; + } + + public search(start: Vector2, goal: Vector2): Vector2[] { + return BreadthFirstPathfinder.search(this, start, goal); + } } - - public isNodeInBounds(node: Vector2): boolean { - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht; - } - - public isNodePassable(node: Vector2): boolean { - return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); - } - - public getNeighbors(node: Vector2) { - this._neighbors.length = 0; - - this._dirs.forEach(dir => { - let next = new Vector2(node.x + dir.x, node.y + dir.y); - if (this.isNodeInBounds(next) && this.isNodePassable(next)) - this._neighbors.push(next); - }); - - return this._neighbors; - } - - public search(start: Vector2, goal: Vector2): Vector2[] { - return BreadthFirstPathfinder.search(this, start, goal); - } -} \ No newline at end of file +} diff --git a/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts b/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts index 7ce1e30e..2a6223e8 100644 --- a/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts +++ b/source/src/AI/Pathfinding/Dijkstra/IWeightedGraph.ts @@ -1,14 +1,16 @@ -interface IWeightedGraph{ - /** - * - * @param node - */ - getNeighbors(node: T): T[]; +module es { + export interface IWeightedGraph{ + /** + * + * @param node + */ + getNeighbors(node: T): T[]; - /** - * - * @param from - * @param to - */ - cost(from: T, to: T): number; -} \ No newline at end of file + /** + * + * @param from + * @param to + */ + cost(from: T, to: T): number; + } +} diff --git a/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts b/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts index 474535c1..1de59287 100644 --- a/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts +++ b/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts @@ -1,67 +1,69 @@ /// -/** - * 支持一种加权节点的基本网格图 - */ -class WeightedGridGraph implements IWeightedGraph { - public static readonly CARDINAL_DIRS = [ - new Vector2(1, 0), - new Vector2(0, -1), - new Vector2(-1, 0), - new Vector2(0, 1) - ]; +module es { + /** + * 支持一种加权节点的基本网格图 + */ + export class WeightedGridGraph implements IWeightedGraph { + public static readonly CARDINAL_DIRS = [ + new Vector2(1, 0), + new Vector2(0, -1), + new Vector2(-1, 0), + new Vector2(0, 1) + ]; - private static readonly COMPASS_DIRS = [ - new Vector2(1, 0), - new Vector2(1, -1), - new Vector2(0, -1), - new Vector2(-1, -1), - new Vector2(-1, 0), - new Vector2(-1, 1), - new Vector2(0, 1), - new Vector2(1, 1), - ]; + private static readonly COMPASS_DIRS = [ + new Vector2(1, 0), + new Vector2(1, -1), + new Vector2(0, -1), + new Vector2(-1, -1), + new Vector2(-1, 0), + new Vector2(-1, 1), + new Vector2(0, 1), + new Vector2(1, 1), + ]; - public walls: Vector2[] = []; - public weightedNodes: Vector2[] = []; - public defaultWeight = 1; - public weightedNodeWeight = 5; + public walls: Vector2[] = []; + public weightedNodes: Vector2[] = []; + public defaultWeight = 1; + public weightedNodeWeight = 5; - private _width: number; - private _height: number; - private _dirs: Vector2[]; - private _neighbors: Vector2[] = new Array(4); + private _width: number; + private _height: number; + private _dirs: Vector2[]; + private _neighbors: Vector2[] = new Array(4); - constructor(width: number, height: number, allowDiagonalSearch: boolean = false){ - this._width = width; - this._height = height; - this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; + constructor(width: number, height: number, allowDiagonalSearch: boolean = false){ + this._width = width; + this._height = height; + this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS; + } + + public isNodeInBounds(node: Vector2){ + return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; + } + + public isNodePassable(node: Vector2): boolean { + return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); + } + + public search(start: Vector2, goal: Vector2){ + return WeightedPathfinder.search(this, start, goal); + } + + public getNeighbors(node: Vector2): Vector2[]{ + this._neighbors.length = 0; + + this._dirs.forEach(dir => { + let next = new Vector2(node.x + dir.x, node.y + dir.y); + if (this.isNodeInBounds(next) && this.isNodePassable(next)) + this._neighbors.push(next); + }); + + return this._neighbors; + } + + public cost(from: Vector2, to: Vector2): number{ + return this.weightedNodes.find(t => JSON.stringify(t) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight; + } } - - public isNodeInBounds(node: Vector2){ - return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height; - } - - public isNodePassable(node: Vector2): boolean { - return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node)); - } - - public search(start: Vector2, goal: Vector2){ - return WeightedPathfinder.search(this, start, goal); - } - - public getNeighbors(node: Vector2): Vector2[]{ - this._neighbors.length = 0; - - this._dirs.forEach(dir => { - let next = new Vector2(node.x + dir.x, node.y + dir.y); - if (this.isNodeInBounds(next) && this.isNodePassable(next)) - this._neighbors.push(next); - }); - - return this._neighbors; - } - - public cost(from: Vector2, to: Vector2): number{ - return this.weightedNodes.find(t => JSON.stringify(t) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight; - } -} \ No newline at end of file +} diff --git a/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts b/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts index 1150e696..6c609356 100644 --- a/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts +++ b/source/src/AI/Pathfinding/Dijkstra/WeightedPathfinder.ts @@ -1,83 +1,85 @@ -class WeightedNode extends PriorityQueueNode { - public data: T; +module es { + export class WeightedNode extends PriorityQueueNode { + public data: T; - constructor(data: T){ - super(); - this.data = data; + constructor(data: T){ + super(); + this.data = data; + } } -} -class WeightedPathfinder { - public static search(graph: IWeightedGraph, start: T, goal: T){ - let foundPath = false; + export class WeightedPathfinder { + public static search(graph: IWeightedGraph, start: T, goal: T){ + let foundPath = false; - let cameFrom = new Map(); - cameFrom.set(start, start); + let cameFrom = new Map(); + cameFrom.set(start, start); - let costSoFar = new Map(); - let frontier = new PriorityQueue>(1000); - frontier.enqueue(new WeightedNode(start), 0); + let costSoFar = new Map(); + let frontier = new PriorityQueue>(1000); + frontier.enqueue(new WeightedNode(start), 0); - costSoFar.set(start, 0); + costSoFar.set(start, 0); - while (frontier.count > 0){ - let current = frontier.dequeue(); - - if (JSON.stringify(current.data) == JSON.stringify(goal)){ - foundPath = true; - break; + while (frontier.count > 0){ + let current = frontier.dequeue(); + + if (JSON.stringify(current.data) == JSON.stringify(goal)){ + foundPath = true; + break; + } + + graph.getNeighbors(current.data).forEach(next => { + let newCost = costSoFar.get(current.data) + graph.cost(current.data, next); + if (!this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)){ + costSoFar.set(next, newCost); + let priprity = newCost; + frontier.enqueue(new WeightedNode(next), priprity); + cameFrom.set(next, current.data); + } + }); } - graph.getNeighbors(current.data).forEach(next => { - let newCost = costSoFar.get(current.data) + graph.cost(current.data, next); - if (!this.hasKey(costSoFar, next) || newCost < costSoFar.get(next)){ - costSoFar.set(next, newCost); - let priprity = newCost; - frontier.enqueue(new WeightedNode(next), priprity); - cameFrom.set(next, current.data); - } - }); - } - - return foundPath ? this.recontructPath(cameFrom, start, goal) : null; - } - - private static hasKey(map: Map, compareKey: T){ - let iterator = map.keys(); - let r: IteratorResult; - while (r = iterator.next() , !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return true; + return foundPath ? this.recontructPath(cameFrom, start, goal) : null; } - return false; - } + private static hasKey(map: Map, compareKey: T){ + let iterator = map.keys(); + let r: IteratorResult; + while (r = iterator.next() , !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return true; + } - private static getKey(map: Map, compareKey: T){ - let iterator = map.keys(); - let valueIterator = map.values(); - let r: IteratorResult; - let v: IteratorResult; - while (r = iterator.next(), v = valueIterator.next(), !r.done) { - if (JSON.stringify(r.value) == JSON.stringify(compareKey)) - return v.value; + return false; } - return null; - } + private static getKey(map: Map, compareKey: T){ + let iterator = map.keys(); + let valueIterator = map.values(); + let r: IteratorResult; + let v: IteratorResult; + while (r = iterator.next(), v = valueIterator.next(), !r.done) { + if (JSON.stringify(r.value) == JSON.stringify(compareKey)) + return v.value; + } - public static recontructPath(cameFrom: Map, start: T, goal: T): T[]{ - let path = []; - let current = goal; - path.push(goal); - - while (current != start){ - current = this.getKey(cameFrom, current); - path.push(current); + return null; } - path.reverse(); + public static recontructPath(cameFrom: Map, start: T, goal: T): T[]{ + let path = []; + let current = goal; + path.push(goal); - return path; + while (current != start){ + current = this.getKey(cameFrom, current); + path.push(current); + } + + path.reverse(); + + return path; + } } -} \ No newline at end of file +} diff --git a/source/src/Debug/Debug.ts b/source/src/Debug/Debug.ts index 18121259..a1ebdce9 100644 --- a/source/src/Debug/Debug.ts +++ b/source/src/Debug/Debug.ts @@ -1,22 +1,24 @@ -class Debug { - private static _debugDrawItems: DebugDrawItem[] = []; +module es { + export class Debug { + private static _debugDrawItems: DebugDrawItem[] = []; - public static drawHollowRect(rectanle: Rectangle, color: number, duration = 0){ - this._debugDrawItems.push(new DebugDrawItem(rectanle, color, duration)); - } + public static drawHollowRect(rectanle: Rectangle, color: number, duration = 0){ + this._debugDrawItems.push(new DebugDrawItem(rectanle, color, duration)); + } - public static render(){ - if (this._debugDrawItems.length > 0){ - let debugShape = new egret.Shape(); - if (SceneManager.scene){ - SceneManager.scene.addChild(debugShape); - } + public static render(){ + if (this._debugDrawItems.length > 0){ + let debugShape = new egret.Shape(); + if (SceneManager.scene){ + SceneManager.scene.addChild(debugShape); + } - for (let i = this._debugDrawItems.length - 1; i >= 0; i --){ - let item = this._debugDrawItems[i]; - if (item.draw(debugShape)) - this._debugDrawItems.removeAt(i); + for (let i = this._debugDrawItems.length - 1; i >= 0; i --){ + let item = this._debugDrawItems[i]; + if (item.draw(debugShape)) + this._debugDrawItems.removeAt(i); + } } } } -} \ No newline at end of file +} diff --git a/source/src/Debug/DebugDefaults.ts b/source/src/Debug/DebugDefaults.ts index 9b79445c..febc8a01 100644 --- a/source/src/Debug/DebugDefaults.ts +++ b/source/src/Debug/DebugDefaults.ts @@ -1,4 +1,6 @@ -class DebugDefaults { - public static verletParticle = 0xDC345E; - public static verletConstraintEdge = 0x433E36; -} \ No newline at end of file +module es { + export class DebugDefaults { + public static verletParticle = 0xDC345E; + public static verletConstraintEdge = 0x433E36; + } +} diff --git a/source/src/Debug/DebugDrawItem.ts b/source/src/Debug/DebugDrawItem.ts index bca31275..a13011fe 100644 --- a/source/src/Debug/DebugDrawItem.ts +++ b/source/src/Debug/DebugDrawItem.ts @@ -1,46 +1,49 @@ -enum DebugDrawType { - line, - hollowRectangle, - pixel, - text -} - -class DebugDrawItem { - public rectangle: Rectangle; - public color: number; - public duration: number; - public drawType: DebugDrawType; - public text: string; - public start: Vector2; - public end: Vector2; - public x: number; - public y: number; - public size: number; - - constructor(rectangle: Rectangle, color: number, duration: number){ - this.rectangle = rectangle; - this.color = color; - this.duration = duration; - this.drawType = DebugDrawType.hollowRectangle; +module es { + export enum DebugDrawType { + line, + hollowRectangle, + pixel, + text } - public draw(shape: egret.Shape): boolean{ - switch (this.drawType){ - case DebugDrawType.line: - DrawUtils.drawLine(shape, this.start, this.end, this.color); - break; - case DebugDrawType.hollowRectangle: - DrawUtils.drawHollowRect(shape, this.rectangle, this.color); - break; - case DebugDrawType.pixel: - DrawUtils.drawPixel(shape, new Vector2(this.x, this.y), this.color, this.size); - break; - case DebugDrawType.text: - break; + export class DebugDrawItem { + public rectangle: Rectangle; + public color: number; + public duration: number; + public drawType: DebugDrawType; + public text: string; + public start: Vector2; + public end: Vector2; + public x: number; + public y: number; + public size: number; + + constructor(rectangle: Rectangle, color: number, duration: number){ + this.rectangle = rectangle; + this.color = color; + this.duration = duration; + this.drawType = DebugDrawType.hollowRectangle; } - this.duration -= Time.deltaTime; - return this.duration < 0; + public draw(shape: egret.Shape): boolean{ + switch (this.drawType){ + case DebugDrawType.line: + DrawUtils.drawLine(shape, this.start, this.end, this.color); + break; + case DebugDrawType.hollowRectangle: + DrawUtils.drawHollowRect(shape, this.rectangle, this.color); + break; + case DebugDrawType.pixel: + DrawUtils.drawPixel(shape, new Vector2(this.x, this.y), this.color, this.size); + break; + case DebugDrawType.text: + break; + } + + this.duration -= Time.deltaTime; + return this.duration < 0; + } } } + diff --git a/source/src/ECS/CoreEvents.ts b/source/src/ECS/CoreEvents.ts index 552d9572..c9893382 100644 --- a/source/src/ECS/CoreEvents.ts +++ b/source/src/ECS/CoreEvents.ts @@ -1,4 +1,6 @@ -enum CoreEvents{ - /** 当场景发生变化时触发 */ - SceneChanged, -} \ No newline at end of file +module es { + export enum CoreEvents{ + /** 当场景发生变化时触发 */ + SceneChanged, + } +} diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index d5c85859..84fb8f65 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -36,7 +36,7 @@ module es { */ public static createWithDefaultRenderer(){ let scene = new Scene(); - scene.addRenderer(new DefaultRenderer()); + scene.addRenderer(new DefaultRenderer()); return scene; } diff --git a/source/src/ECS/SceneManager.ts b/source/src/ECS/SceneManager.ts index 37c726f5..cf5b74b7 100644 --- a/source/src/ECS/SceneManager.ts +++ b/source/src/ECS/SceneManager.ts @@ -1,144 +1,146 @@ -/** 运行时的场景管理。 */ -class SceneManager { - private static _scene: Scene; - private static _nextScene: Scene; - public static sceneTransition: SceneTransition; - public static stage: egret.Stage; - /** 订阅此事件以在活动场景发生更改时得到通知。 */ - public static activeSceneChanged: Function; - /** 核心发射器。只发出核心级别的事件 */ - public static emitter: Emitter; - /** 全局内容管理器加载任何应该停留在场景之间的资产 */ - public static content: ContentManager; - /** 简化对内部类的全局内容实例的访问 */ - private static _instnace: SceneManager; - private static timerRuler: TimeRuler; - public static get Instance(){ - return this._instnace; - } - - constructor(stage: egret.Stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - - SceneManager._instnace = this; - SceneManager.emitter = new Emitter(); - SceneManager.content = new ContentManager(); - - SceneManager.stage = stage; - SceneManager.initialize(stage); - SceneManager.timerRuler = new TimeRuler(); - } - - public static get scene() { - return this._scene; - } - public static set scene(value: Scene) { - if (!value) - throw new Error("场景不能为空"); - - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - SceneManager.Instance.onSceneChanged(); - } else { - this._nextScene = value; +module es { + /** 运行时的场景管理。 */ + export class SceneManager { + private static _scene: Scene; + private static _nextScene: Scene; + public static sceneTransition: SceneTransition; + public static stage: egret.Stage; + /** 订阅此事件以在活动场景发生更改时得到通知。 */ + public static activeSceneChanged: Function; + /** 核心发射器。只发出核心级别的事件 */ + public static emitter: Emitter; + /** 全局内容管理器加载任何应该停留在场景之间的资产 */ + public static content: ContentManager; + /** 简化对内部类的全局内容实例的访问 */ + private static _instnace: SceneManager; + private static timerRuler: TimeRuler; + public static get Instance(){ + return this._instnace; } - this.registerActiveSceneChanged(this._scene, this._nextScene); - } + constructor(stage: egret.Stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - public static initialize(stage: egret.Stage) { - Input.initialize(stage); - } + SceneManager._instnace = this; + SceneManager.emitter = new Emitter(); + SceneManager.content = new ContentManager(); - public static update() { - SceneManager.startDebugUpdate(); - Time.update(egret.getTimer()); + SceneManager.stage = stage; + SceneManager.initialize(stage); + SceneManager.timerRuler = new TimeRuler(); + } - if (SceneManager._scene) { - for (let i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); + public static get scene() { + return this._scene; + } + public static set scene(value: Scene) { + if (!value) + throw new Error("场景不能为空"); + + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + SceneManager.Instance.onSceneChanged(); + } else { + this._nextScene = value; } - if (!SceneManager.sceneTransition || - (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + this.registerActiveSceneChanged(this._scene, this._nextScene); + } + + public static initialize(stage: egret.Stage) { + Input.initialize(stage); + } + + public static update() { + SceneManager.startDebugUpdate(); + Time.update(egret.getTimer()); + + if (SceneManager._scene) { + for (let i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (GlobalManager.globalManagers[i].enabled) + GlobalManager.globalManagers[i].update(); + } + + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { SceneManager._scene.update(); + } + + if (SceneManager._nextScene) { + SceneManager._scene.end(); + + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + SceneManager._instnace.onSceneChanged(); + + SceneManager._scene.begin(); + } } - if (SceneManager._nextScene) { - SceneManager._scene.end(); - - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._instnace.onSceneChanged(); - - SceneManager._scene.begin(); - } + SceneManager.endDebugUpdate(); + SceneManager.render(); } - SceneManager.endDebugUpdate(); - SceneManager.render(); - } + public static render() { + if (this.sceneTransition){ + this.sceneTransition.preRender(); - public static render() { - if (this.sceneTransition){ - this.sceneTransition.preRender(); - - if (this._scene && !this.sceneTransition.hasPreviousSceneRender){ - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { + if (this._scene && !this.sceneTransition.hasPreviousSceneRender){ this._scene.render(); this._scene.postRender(); + this.sceneTransition.onBeginTransition(); + } else if (this.sceneTransition) { + if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + + this.sceneTransition.render(); } - - this.sceneTransition.render(); + } else if (this._scene) { + this._scene.render(); + + Debug.render(); + + this._scene.postRender(); } - } else if (this._scene) { - this._scene.render(); - - Debug.render(); - - this._scene.postRender(); - } - } - - /** - * 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。 - * @param sceneTransition - */ - public static startSceneTransition(sceneTransition: T): T { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; } - this.sceneTransition = sceneTransition; - return sceneTransition; - } + /** + * 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。 + * @param sceneTransition + */ + public static startSceneTransition(sceneTransition: T): T { + if (this.sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } - public static registerActiveSceneChanged(current: Scene, next: Scene){ - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - } + this.sceneTransition = sceneTransition; + return sceneTransition; + } - /** - * 在一个场景结束后,下一个场景开始之前调用 - */ - public onSceneChanged(){ - SceneManager.emitter.emit(CoreEvents.SceneChanged); - Time.sceneChanged(); - } + public static registerActiveSceneChanged(current: Scene, next: Scene){ + if (this.activeSceneChanged) + this.activeSceneChanged(current, next); + } - private static startDebugUpdate(){ - TimeRuler.Instance.startFrame(); - TimeRuler.Instance.beginMark("update", 0x00FF00); - } + /** + * 在一个场景结束后,下一个场景开始之前调用 + */ + public onSceneChanged(){ + SceneManager.emitter.emit(CoreEvents.SceneChanged); + Time.sceneChanged(); + } - private static endDebugUpdate(){ - TimeRuler.Instance.endMark("update"); + private static startDebugUpdate(){ + TimeRuler.Instance.startFrame(); + TimeRuler.Instance.beginMark("update", 0x00FF00); + } + + private static endDebugUpdate(){ + TimeRuler.Instance.endMark("update"); + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Systems/EntityProcessingSystem.ts b/source/src/ECS/Systems/EntityProcessingSystem.ts index 5eebfedf..15022a35 100644 --- a/source/src/ECS/Systems/EntityProcessingSystem.ts +++ b/source/src/ECS/Systems/EntityProcessingSystem.ts @@ -1,32 +1,34 @@ /// -/** - * 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础 - */ -abstract class EntityProcessingSystem extends EntitySystem { - constructor(matcher: Matcher) { - super(matcher); - } - - +module es { /** - * 处理特定的实体 - * @param entity + * 基本实体处理系统。将其用作处理具有特定组件的许多实体的基础 */ - public abstract processEntity(entity: Entity); + export abstract class EntityProcessingSystem extends EntitySystem { + constructor(matcher: Matcher) { + super(matcher); + } - public lateProcessEntity(entity: Entity) { + /** + * 处理特定的实体 + * @param entity + */ + public abstract processEntity(entity: Entity); + + public lateProcessEntity(entity: Entity) { + + } + + /** + * 遍历这个系统的所有实体并逐个处理它们 + * @param entities + */ + protected process(entities: Entity[]) { + entities.forEach(entity => this.processEntity(entity)); + } + + protected lateProcess(entities: Entity[]) { + entities.forEach(entity => this.lateProcessEntity(entity)); + } } - - /** - * 遍历这个系统的所有实体并逐个处理它们 - * @param entities - */ - protected process(entities: Entity[]) { - entities.forEach(entity => this.processEntity(entity)); - } - - protected lateProcess(entities: Entity[]) { - entities.forEach(entity => this.lateProcessEntity(entity)); - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Systems/EntitySystem.ts b/source/src/ECS/Systems/EntitySystem.ts index 8ec9cdc6..5f823fa5 100644 --- a/source/src/ECS/Systems/EntitySystem.ts +++ b/source/src/ECS/Systems/EntitySystem.ts @@ -1,79 +1,81 @@ -class EntitySystem { - private _scene: Scene; - private _entities: Entity[] = []; - private _matcher: Matcher; +module es { + export class EntitySystem { + private _scene: Scene; + private _entities: Entity[] = []; + private _matcher: Matcher; - public get matcher(){ - return this._matcher; + public get matcher(){ + return this._matcher; + } + + public get scene(){ + return this._scene; + } + + public set scene(value: Scene){ + this._scene = value; + this._entities = []; + } + + constructor(matcher?: Matcher){ + this._matcher = matcher ? matcher : Matcher.empty(); + } + + public initialize(){ + + } + + public onChanged(entity: Entity){ + let contains = this._entities.contains(entity); + let interest = this._matcher.IsIntersted(entity); + + if (interest && !contains) + this.add(entity); + else if(!interest && contains) + this.remove(entity); + } + + public add(entity: Entity){ + this._entities.push(entity); + this.onAdded(entity); + } + + public onAdded(entity: Entity){ + } + + public remove(entity: Entity){ + this._entities.remove(entity); + this.onRemoved(entity); + } + + public onRemoved(entity: Entity){ + + } + + public update(){ + this.begin(); + this.process(this._entities); + } + + public lateUpdate(){ + this.lateProcess(this._entities); + this.end(); + } + + protected begin(){ + + } + + protected process(entities: Entity[]){ + + } + + protected lateProcess(entities: Entity[]){ + + } + + protected end(){ + + } } - - public get scene(){ - return this._scene; - } - - public set scene(value: Scene){ - this._scene = value; - this._entities = []; - } - - constructor(matcher?: Matcher){ - this._matcher = matcher ? matcher : Matcher.empty(); - } - - public initialize(){ - - } - - public onChanged(entity: Entity){ - let contains = this._entities.contains(entity); - let interest = this._matcher.IsIntersted(entity); - - if (interest && !contains) - this.add(entity); - else if(!interest && contains) - this.remove(entity); - } - - public add(entity: Entity){ - this._entities.push(entity); - this.onAdded(entity); - } - - public onAdded(entity: Entity){ - } - - public remove(entity: Entity){ - this._entities.remove(entity); - this.onRemoved(entity); - } - - public onRemoved(entity: Entity){ - - } - - public update(){ - this.begin(); - this.process(this._entities); - } - - public lateUpdate(){ - this.lateProcess(this._entities); - this.end(); - } - - protected begin(){ - - } - - protected process(entities: Entity[]){ - - } - - protected lateProcess(entities: Entity[]){ - - } - - protected end(){ - - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Systems/PassiveSystem.ts b/source/src/ECS/Systems/PassiveSystem.ts index 97fbd0d1..09a36a49 100644 --- a/source/src/ECS/Systems/PassiveSystem.ts +++ b/source/src/ECS/Systems/PassiveSystem.ts @@ -1,11 +1,13 @@ -abstract class PassiveSystem extends EntitySystem { - public onChanged(entity: Entity){ +module es { + export abstract class PassiveSystem extends EntitySystem { + public onChanged(entity: Entity){ - } + } - protected process(entities: Entity[]){ - // 我们用我们自己的不考虑实体的基本实体系统来代替 - this.begin(); - this.end(); + protected process(entities: Entity[]){ + // 我们用我们自己的不考虑实体的基本实体系统来代替 + this.begin(); + this.end(); + } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Systems/ProcessingSystem.ts b/source/src/ECS/Systems/ProcessingSystem.ts index 39a4eb9e..d567c281 100644 --- a/source/src/ECS/Systems/ProcessingSystem.ts +++ b/source/src/ECS/Systems/ProcessingSystem.ts @@ -1,15 +1,17 @@ /** 用于协调其他系统的通用系统基类 */ -abstract class ProcessingSystem extends EntitySystem { - public onChanged(entity: Entity){ +module es { + export abstract class ProcessingSystem extends EntitySystem { + public onChanged(entity: Entity){ + } + + protected process(entities: Entity[]){ + this.begin(); + this.processSystem(); + this.end(); + } + + /** 处理我们的系统 每帧调用 */ + public abstract processSystem(); } - - protected process(entities: Entity[]){ - this.begin(); - this.processSystem(); - this.end(); - } - - /** 处理我们的系统 每帧调用 */ - public abstract processSystem(); -} \ No newline at end of file +} diff --git a/source/src/ECS/Utils/EntityList.ts b/source/src/ECS/Utils/EntityList.ts index 943e78e0..a30961a0 100644 --- a/source/src/ECS/Utils/EntityList.ts +++ b/source/src/ECS/Utils/EntityList.ts @@ -160,7 +160,7 @@ module es { this.updateLists(); for (let i = 0; i < this._entities.length; i ++){ - this._entities[i]._isDestoryed = true; + this._entities[i]._isDestroyed = true; this._entities[i].onRemovedFromScene(); this._entities[i].scene = null; } diff --git a/source/src/ECS/Utils/Matcher.ts b/source/src/ECS/Utils/Matcher.ts index c827d0b3..7b5797cb 100644 --- a/source/src/ECS/Utils/Matcher.ts +++ b/source/src/ECS/Utils/Matcher.ts @@ -1,62 +1,64 @@ -class Matcher{ - protected allSet = new BitSet(); - protected exclusionSet = new BitSet(); - protected oneSet = new BitSet(); +module es { + export class Matcher{ + protected allSet = new BitSet(); + protected exclusionSet = new BitSet(); + protected oneSet = new BitSet(); - public static empty(){ - return new Matcher(); - } - - public getAllSet(){ - return this.allSet; - } - - public getExclusionSet(){ - return this.exclusionSet; - } - - public getOneSet(){ - return this.oneSet; - } - - public IsIntersted(e: Entity){ - if (!this.allSet.isEmpty()){ - for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)){ - if (!e.componentBits.get(i)) - return false; - } + public static empty(){ + return new Matcher(); } - if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) - return false; + public getAllSet(){ + return this.allSet; + } - if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) - return false; + public getExclusionSet(){ + return this.exclusionSet; + } - return true; + public getOneSet(){ + return this.oneSet; + } + + public IsIntersted(e: Entity){ + if (!this.allSet.isEmpty()){ + for (let i = this.allSet.nextSetBit(0); i >= 0; i = this.allSet.nextSetBit(i + 1)){ + if (!e.componentBits.get(i)) + return false; + } + } + + if (!this.exclusionSet.isEmpty() && this.exclusionSet.intersects(e.componentBits)) + return false; + + if (!this.oneSet.isEmpty() && !this.oneSet.intersects(e.componentBits)) + return false; + + return true; + } + + public all(...types: any[]): Matcher{ + types.forEach(type => { + this.allSet.set(ComponentTypeManager.getIndexFor(type)); + }); + + return this; + } + + public exclude(...types: any[]){ + types.forEach(type => { + this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); + }); + + return this; + } + + public one(...types: any[]){ + types.forEach(type => { + this.oneSet.set(ComponentTypeManager.getIndexFor(type)); + }); + + return this; + } } - - public all(...types: any[]): Matcher{ - types.forEach(type => { - this.allSet.set(ComponentTypeManager.getIndexFor(type)); - }); - - return this; - } - - public exclude(...types: any[]){ - types.forEach(type => { - this.exclusionSet.set(ComponentTypeManager.getIndexFor(type)); - }); - - return this; - } - - public one(...types: any[]){ - types.forEach(type => { - this.oneSet.set(ComponentTypeManager.getIndexFor(type)); - }); - - return this; - } -} \ No newline at end of file +} diff --git a/source/src/ECS/Utils/TextureUtils.ts b/source/src/ECS/Utils/TextureUtils.ts index f4d9b89a..2da8e6e3 100644 --- a/source/src/ECS/Utils/TextureUtils.ts +++ b/source/src/ECS/Utils/TextureUtils.ts @@ -1,154 +1,156 @@ -/** - * 纹理帮助类 - */ -class TextureUtils { - public static sharedCanvas: HTMLCanvasElement; - public static sharedContext: CanvasRenderingContext2D; +module es { + /** + * 纹理帮助类 + */ + export class TextureUtils { + public static sharedCanvas: HTMLCanvasElement; + public static sharedContext: CanvasRenderingContext2D; - public static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement{ - if (!this.sharedCanvas){ - this.sharedCanvas = egret.sys.createCanvas(); - this.sharedContext = this.sharedCanvas.getContext("2d"); - } + public static convertImageToCanvas(texture: egret.Texture, rect?: egret.Rectangle): HTMLCanvasElement{ + if (!this.sharedCanvas){ + this.sharedCanvas = egret.sys.createCanvas(); + this.sharedContext = this.sharedCanvas.getContext("2d"); + } - let w = texture.$getTextureWidth(); - let h = texture.$getTextureHeight(); - if (!rect){ - rect = egret.$TempRectangle; - rect.x = 0; - rect.y = 0; - rect.width = w; - rect.height = h; - } - - rect.x = Math.min(rect.x, w - 1); - rect.y = Math.min(rect.y, h - 1); - rect.width = Math.min(rect.width, w - rect.x); - rect.height = Math.min(rect.height, h - rect.y); + let w = texture.$getTextureWidth(); + let h = texture.$getTextureHeight(); + if (!rect){ + rect = egret.$TempRectangle; + rect.x = 0; + rect.y = 0; + rect.width = w; + rect.height = h; + } - let iWidth = Math.floor(rect.width); - let iHeight = Math.floor(rect.height); - let surface = this.sharedCanvas; - surface["style"]["width"] = iWidth + "px"; - surface["style"]["height"] = iHeight + "px"; - this.sharedCanvas.width = iWidth; - this.sharedCanvas.height = iHeight; + rect.x = Math.min(rect.x, w - 1); + rect.y = Math.min(rect.y, h - 1); + rect.width = Math.min(rect.width, w - rect.x); + rect.height = Math.min(rect.height, h - rect.y); - if (egret.Capabilities.renderMode == "webgl") { - let renderTexture: egret.RenderTexture; - //webgl下非RenderTexture纹理先画到RenderTexture - if (!(texture).$renderBuffer) { - if (egret.sys.systemRenderer["renderClear"]) { - egret.sys.systemRenderer["renderClear"](); + let iWidth = Math.floor(rect.width); + let iHeight = Math.floor(rect.height); + let surface = this.sharedCanvas; + surface["style"]["width"] = iWidth + "px"; + surface["style"]["height"] = iHeight + "px"; + this.sharedCanvas.width = iWidth; + this.sharedCanvas.height = iHeight; + + if (egret.Capabilities.renderMode == "webgl") { + let renderTexture: egret.RenderTexture; + //webgl下非RenderTexture纹理先画到RenderTexture + if (!(texture).$renderBuffer) { + if (egret.sys.systemRenderer["renderClear"]) { + egret.sys.systemRenderer["renderClear"](); + } + renderTexture = new egret.RenderTexture(); + renderTexture.drawToTexture(new egret.Bitmap(texture)); } - renderTexture = new egret.RenderTexture(); - renderTexture.drawToTexture(new egret.Bitmap(texture)); + else { + renderTexture = texture; + } + //从RenderTexture中读取像素数据,填入canvas + let pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight); + let x = 0; + let y = 0; + for (let i = 0; i < pixels.length; i += 4) { + this.sharedContext.fillStyle = + 'rgba(' + pixels[i] + + ',' + pixels[i + 1] + + ',' + pixels[i + 2] + + ',' + (pixels[i + 3] / 255) + ')'; + this.sharedContext.fillRect(x, y, 1, 1); + x++; + if (x == iWidth) { + x = 0; + y++; + } + } + + if (!(texture).$renderBuffer) { + renderTexture.dispose(); + } + + return surface; } else { - renderTexture = texture; + let bitmapData = texture; + let offsetX: number = Math.round(bitmapData.$offsetX); + let offsetY: number = Math.round(bitmapData.$offsetY); + let bitmapWidth: number = bitmapData.$bitmapWidth; + let bitmapHeight: number = bitmapData.$bitmapHeight; + let $TextureScaleFactor = SceneManager.stage.textureScaleFactor; + this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, + bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); + return surface; } - //从RenderTexture中读取像素数据,填入canvas - let pixels = renderTexture.$renderBuffer.getPixels(rect.x, rect.y, iWidth, iHeight); - let x = 0; - let y = 0; - for (let i = 0; i < pixels.length; i += 4) { - this.sharedContext.fillStyle = - 'rgba(' + pixels[i] - + ',' + pixels[i + 1] - + ',' + pixels[i + 2] - + ',' + (pixels[i + 3] / 255) + ')'; - this.sharedContext.fillRect(x, y, 1, 1); - x++; - if (x == iWidth) { - x = 0; - y++; - } - } - - if (!(texture).$renderBuffer) { - renderTexture.dispose(); - } - - return surface; } - else { - let bitmapData = texture; - let offsetX: number = Math.round(bitmapData.$offsetX); - let offsetY: number = Math.round(bitmapData.$offsetY); - let bitmapWidth: number = bitmapData.$bitmapWidth; - let bitmapHeight: number = bitmapData.$bitmapHeight; - let $TextureScaleFactor = SceneManager.stage.textureScaleFactor; - this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, - bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); - return surface; - } - } - public static toDataURL(type: string, texture: egret.Texture, rect?: egret.Rectangle, encoderOptions?): string { - try { + public static toDataURL(type: string, texture: egret.Texture, rect?: egret.Rectangle, encoderOptions?): string { + try { + let surface = this.convertImageToCanvas(texture, rect); + let result = surface.toDataURL(type, encoderOptions); + return result; + } + catch (e) { + egret.$error(1033); + } + return null; + } + + /** + * 有些杀毒软件认为 saveToFile 可能是一个病毒文件 + * @param type + * @param texture + * @param filePath + * @param rect + * @param encoderOptions + */ + public static eliFoTevas(type: string, texture: egret.Texture, filePath: string, rect?: egret.Rectangle, encoderOptions?): void { let surface = this.convertImageToCanvas(texture, rect); - let result = surface.toDataURL(type, encoderOptions); + let result = (surface as any).toTempFilePathSync({ + fileType: type.indexOf("png") >= 0 ? "png" : "jpg" + }); + + wx.getFileSystemManager().saveFile({ + tempFilePath: result, + filePath: `${wx.env.USER_DATA_PATH}/${filePath}`, + success: function (res) { + //todo + } + }) + return result; } - catch (e) { - egret.$error(1033); + + public static getPixel32(texture: egret.Texture, x: number, y: number): number[] { + egret.$warn(1041, "getPixel32", "getPixels"); + return texture.getPixels(x, y); } - return null; - } - /** - * 有些杀毒软件认为 saveToFile 可能是一个病毒文件 - * @param type - * @param texture - * @param filePath - * @param rect - * @param encoderOptions - */ - public static eliFoTevas(type: string, texture: egret.Texture, filePath: string, rect?: egret.Rectangle, encoderOptions?): void { - let surface = this.convertImageToCanvas(texture, rect); - let result = (surface as any).toTempFilePathSync({ - fileType: type.indexOf("png") >= 0 ? "png" : "jpg" - }); - - wx.getFileSystemManager().saveFile({ - tempFilePath: result, - filePath: `${wx.env.USER_DATA_PATH}/${filePath}`, - success: function (res) { - //todo + public static getPixels(texture: egret.Texture, x: number, y: number, width: number = 1, height: number = 1): number[] { + //webgl环境下不需要转换成canvas获取像素信息 + if (egret.Capabilities.renderMode == "webgl") { + let renderTexture: egret.RenderTexture; + //webgl下非RenderTexture纹理先画到RenderTexture + if (!(texture).$renderBuffer) { + renderTexture = new egret.RenderTexture(); + renderTexture.drawToTexture(new egret.Bitmap(texture)); + } + else { + renderTexture = texture; + } + //从RenderTexture中读取像素数据 + let pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height); + return pixels; } - }) - - return result; - } - - public static getPixel32(texture: egret.Texture, x: number, y: number): number[] { - egret.$warn(1041, "getPixel32", "getPixels"); - return texture.getPixels(x, y); - } - - public static getPixels(texture: egret.Texture, x: number, y: number, width: number = 1, height: number = 1): number[] { - //webgl环境下不需要转换成canvas获取像素信息 - if (egret.Capabilities.renderMode == "webgl") { - let renderTexture: egret.RenderTexture; - //webgl下非RenderTexture纹理先画到RenderTexture - if (!(texture).$renderBuffer) { - renderTexture = new egret.RenderTexture(); - renderTexture.drawToTexture(new egret.Bitmap(texture)); + try { + let surface = this.convertImageToCanvas(texture); + let result = this.sharedContext.getImageData(x, y, width, height).data; + return result; } - else { - renderTexture = texture; + catch (e) { + egret.$error(1039); } - //从RenderTexture中读取像素数据 - let pixels = renderTexture.$renderBuffer.getPixels(x, y, width, height); - return pixels; - } - try { - let surface = this.convertImageToCanvas(texture); - let result = this.sharedContext.getImageData(x, y, width, height).data; - return result; - } - catch (e) { - egret.$error(1039); } } -} \ No newline at end of file +} diff --git a/source/src/ECS/Utils/Time.ts b/source/src/ECS/Utils/Time.ts index d03d77ca..31c2387e 100644 --- a/source/src/ECS/Utils/Time.ts +++ b/source/src/ECS/Utils/Time.ts @@ -1,38 +1,40 @@ -/** 提供帧定时信息 */ -class Time { - /** deltaTime的未缩放版本。不受时间尺度的影响 */ - public static unscaledDeltaTime; - /** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */ - public static deltaTime: number = 0; - /** 时间刻度缩放 */ - public static timeScale = 1; - /** 已传递的帧总数 */ - public static frameCount = 0; - - private static _lastTime = 0; - /** 自场景加载以来的总时间 */ - public static _timeSinceSceneLoad; +module es { + /** 提供帧定时信息 */ + export class Time { + /** deltaTime的未缩放版本。不受时间尺度的影响 */ + public static unscaledDeltaTime; + /** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */ + public static deltaTime: number = 0; + /** 时间刻度缩放 */ + public static timeScale = 1; + /** 已传递的帧总数 */ + public static frameCount = 0; - public static update(currentTime: number){ - let dt = (currentTime - this._lastTime) / 1000; - this.deltaTime = dt * this.timeScale; - this.unscaledDeltaTime = dt; - this._timeSinceSceneLoad += dt; - this.frameCount ++; + private static _lastTime = 0; + /** 自场景加载以来的总时间 */ + public static _timeSinceSceneLoad; - this._lastTime = currentTime; + public static update(currentTime: number){ + let dt = (currentTime - this._lastTime) / 1000; + this.deltaTime = dt * this.timeScale; + this.unscaledDeltaTime = dt; + this._timeSinceSceneLoad += dt; + this.frameCount ++; + + this._lastTime = currentTime; + } + + public static sceneChanged(){ + this._timeSinceSceneLoad = 0; + } + + /** + * 允许在间隔检查。只应该使用高于delta的间隔值,否则它将始终返回true。 + * @param interval + */ + public static checkEvery(interval: number){ + // 我们减去了delta,因为timeSinceSceneLoad已经包含了这个update ticks delta + return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval); + } } - - public static sceneChanged(){ - this._timeSinceSceneLoad = 0; - } - - /** - * 允许在间隔检查。只应该使用高于delta的间隔值,否则它将始终返回true。 - * @param interval - */ - public static checkEvery(interval: number){ - // 我们减去了delta,因为timeSinceSceneLoad已经包含了这个update ticks delta - return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval); - } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Effects/GaussianBlurEffect.ts b/source/src/Graphics/Effects/GaussianBlurEffect.ts index 7b9c92a3..50f0b03c 100644 --- a/source/src/Graphics/Effects/GaussianBlurEffect.ts +++ b/source/src/Graphics/Effects/GaussianBlurEffect.ts @@ -1,72 +1,74 @@ -class GaussianBlurEffect extends egret.CustomFilter { - // private static blur_frag = "precision mediump float;\n" + - // "uniform vec2 blur;\n" + - // "uniform sampler2D uSampler;\n" + - // "varying vec2 vTextureCoord;\n" + - // "uniform vec2 uTextureSize;\n" + - // "void main()\n" + - // "{\n " + - // "const int sampleRadius = 5;\n" + - // "const int samples = sampleRadius * 2 + 1;\n" + - // "vec2 blurUv = blur / uTextureSize;\n" + - // "vec4 color = vec4(0, 0, 0, 0);\n" + - // "vec2 uv = vec2(0.0, 0.0);\n" + - // "blurUv /= float(sampleRadius);\n" + - - // "for (int i = -sampleRadius; i <= sampleRadius; i++) {\n" + - // "uv.x = vTextureCoord.x + float(i) * blurUv.x;\n" + - // "uv.y = vTextureCoord.y + float(i) * blurUv.y;\n" + - // "color += texture2D(uSampler, uv);\n" + - // "}\n" + - - // "color /= float(samples);\n" + - // "gl_FragColor = color;\n" + - // "}"; +module es { + export class GaussianBlurEffect extends egret.CustomFilter { + // private static blur_frag = "precision mediump float;\n" + + // "uniform vec2 blur;\n" + + // "uniform sampler2D uSampler;\n" + + // "varying vec2 vTextureCoord;\n" + + // "uniform vec2 uTextureSize;\n" + + // "void main()\n" + + // "{\n " + + // "const int sampleRadius = 5;\n" + + // "const int samples = sampleRadius * 2 + 1;\n" + + // "vec2 blurUv = blur / uTextureSize;\n" + + // "vec4 color = vec4(0, 0, 0, 0);\n" + + // "vec2 uv = vec2(0.0, 0.0);\n" + + // "blurUv /= float(sampleRadius);\n" + - private static blur_frag = "precision mediump float;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float screenWidth;\n" + - "uniform float screenHeight;\n" + + // "for (int i = -sampleRadius; i <= sampleRadius; i++) {\n" + + // "uv.x = vTextureCoord.x + float(i) * blurUv.x;\n" + + // "uv.y = vTextureCoord.y + float(i) * blurUv.y;\n" + + // "color += texture2D(uSampler, uv);\n" + + // "}\n" + - "float normpdf(in float x, in float sigma)\n" + - "{\n" + - "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + - "}\n" + + // "color /= float(samples);\n" + + // "gl_FragColor = color;\n" + + // "}"; - "void main()\n" + - "{\n" + - "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + + private static blur_frag = "precision mediump float;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float screenWidth;\n" + + "uniform float screenHeight;\n" + - "const int mSize = 11;\n" + - "const int kSize = (mSize - 1)/2;\n" + - "float kernel[mSize];\n" + - "vec3 final_colour = vec3(0.0);\n" + + "float normpdf(in float x, in float sigma)\n" + + "{\n" + + "return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n" + + "}\n" + - "float sigma = 7.0;\n" + - "float z = 0.0;\n" + - "for (int j = 0; j <= kSize; ++j)\n" + - "{\n" + - "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + - "}\n" + - - "for (int j = 0; j < mSize; ++j)\n" + - "{\n" + - "z += kernel[j];\n" + - "}\n" + + "void main()\n" + + "{\n" + + "vec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "for (int i = -kSize; i <= kSize; ++i)\n" + - "{\n" + - "for (int j = -kSize; j <= kSize; ++j)\n" + - "{\n" + - "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + - "}\n}\n" + - "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + - "}"; + "const int mSize = 11;\n" + + "const int kSize = (mSize - 1)/2;\n" + + "float kernel[mSize];\n" + + "vec3 final_colour = vec3(0.0);\n" + - constructor(){ - super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag,{ - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight - }); + "float sigma = 7.0;\n" + + "float z = 0.0;\n" + + "for (int j = 0; j <= kSize; ++j)\n" + + "{\n" + + "kernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n" + + "}\n" + + + "for (int j = 0; j < mSize; ++j)\n" + + "{\n" + + "z += kernel[j];\n" + + "}\n" + + + "for (int i = -kSize; i <= kSize; ++i)\n" + + "{\n" + + "for (int j = -kSize; j <= kSize; ++j)\n" + + "{\n" + + "final_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n" + + "}\n}\n" + + "gl_FragColor = vec4(final_colour/(z*z), 1.0);\n" + + "}"; + + constructor(){ + super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag,{ + screenWidth: SceneManager.stage.stageWidth, + screenHeight: SceneManager.stage.stageHeight + }); + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Effects/PolygonLightEffect.ts b/source/src/Graphics/Effects/PolygonLightEffect.ts index 84d38be7..ce40e82e 100644 --- a/source/src/Graphics/Effects/PolygonLightEffect.ts +++ b/source/src/Graphics/Effects/PolygonLightEffect.ts @@ -1,34 +1,36 @@ -class PolygonLightEffect extends egret.CustomFilter { - private static vertSrc = "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + +module es { + export class PolygonLightEffect extends egret.CustomFilter { + private static vertSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + - "uniform vec2 projectionVector;\n" + + "uniform vec2 projectionVector;\n" + - "varying vec2 vTextureCoord;\n" + + "varying vec2 vTextureCoord;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + + "const vec2 center = vec2(-1.0, 1.0);\n" + - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - private static fragmentSrc = "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + private static fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + - "#define SAMPLE_COUNT 15\n" + + "#define SAMPLE_COUNT 15\n" + - "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + - "uniform float _sampleWeights[SAMPLE_COUNT];\n" + + "uniform vec2 _sampleOffsets[SAMPLE_COUNT];\n" + + "uniform float _sampleWeights[SAMPLE_COUNT];\n" + - "void main(void) {\n" + - "vec4 c = vec4(0, 0, 0, 0);\n" + - "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + - " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + - "gl_FragColor = c;\n" + - "}"; + "void main(void) {\n" + + "vec4 c = vec4(0, 0, 0, 0);\n" + + "for( int i = 0; i < SAMPLE_COUNT; i++ )\n" + + " c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\n" + + "gl_FragColor = c;\n" + + "}"; - constructor(){ - super(PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc); + constructor(){ + super(PolygonLightEffect.vertSrc, PolygonLightEffect.fragmentSrc); + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/GraphicsCapabilities.ts b/source/src/Graphics/GraphicsCapabilities.ts index 100e8077..99f94864 100644 --- a/source/src/Graphics/GraphicsCapabilities.ts +++ b/source/src/Graphics/GraphicsCapabilities.ts @@ -1,27 +1,29 @@ -class GraphicsCapabilities extends egret.Capabilities { +module es { + export class GraphicsCapabilities extends egret.Capabilities { - public initialize(device: GraphicsDevice){ - this.platformInitialize(device); - } - - private platformInitialize(device: GraphicsDevice){ - let capabilities = this; - capabilities["isMobile"] = true; - - let systemInfo = wx.getSystemInfoSync(); - let systemStr = systemInfo.system.toLowerCase(); - if (systemStr.indexOf("ios") > -1){ - capabilities["os"] = "iOS"; - } else if(systemStr.indexOf("android") > -1){ - capabilities["os"] = "Android"; + public initialize(device: GraphicsDevice){ + this.platformInitialize(device); } - let language = systemInfo.language; - if (language.indexOf('zh') > -1){ - language = "zh-CN"; - } else { - language = "en-US"; + private platformInitialize(device: GraphicsDevice){ + let capabilities = this; + capabilities["isMobile"] = true; + + let systemInfo = wx.getSystemInfoSync(); + let systemStr = systemInfo.system.toLowerCase(); + if (systemStr.indexOf("ios") > -1){ + capabilities["os"] = "iOS"; + } else if(systemStr.indexOf("android") > -1){ + capabilities["os"] = "Android"; + } + + let language = systemInfo.language; + if (language.indexOf('zh') > -1){ + language = "zh-CN"; + } else { + language = "en-US"; + } + capabilities["language"] = language; } - capabilities["language"] = language; } -} \ No newline at end of file +} diff --git a/source/src/Graphics/GraphicsDevice.ts b/source/src/Graphics/GraphicsDevice.ts index 6deacb10..f1878e1e 100644 --- a/source/src/Graphics/GraphicsDevice.ts +++ b/source/src/Graphics/GraphicsDevice.ts @@ -1,10 +1,12 @@ -class GraphicsDevice { - private viewport: Viewport; +module es { + export class GraphicsDevice { + private viewport: Viewport; - public graphicsCapabilities: GraphicsCapabilities; + public graphicsCapabilities: GraphicsCapabilities; - constructor(){ - this.graphicsCapabilities = new GraphicsCapabilities(); - this.graphicsCapabilities.initialize(this); + constructor(){ + this.graphicsCapabilities = new GraphicsCapabilities(); + this.graphicsCapabilities.initialize(this); + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/PostProcessing/PostProcessor.ts b/source/src/Graphics/PostProcessing/PostProcessor.ts index 41202f5a..c1a3fce9 100644 --- a/source/src/Graphics/PostProcessing/PostProcessor.ts +++ b/source/src/Graphics/PostProcessing/PostProcessor.ts @@ -1,58 +1,60 @@ -class PostProcessor { - public enabled: boolean; - public effect: egret.Filter; - public scene: Scene; - public shape: egret.Shape; +module es { + export class PostProcessor { + public enabled: boolean; + public effect: egret.Filter; + public scene: Scene; + public shape: egret.Shape; - public static default_vert = "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - "attribute vec2 aColor;\n" + - - "uniform vec2 projectionVector;\n" + - //"uniform vec2 offsetVector;\n" + + public static default_vert = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + "attribute vec2 aColor;\n" + - "varying vec2 vTextureCoord;\n" + - "varying vec4 vColor;\n" + + "uniform vec2 projectionVector;\n" + + //"uniform vec2 offsetVector;\n" + - "const vec2 center = vec2(-1.0, 1.0);\n" + + "varying vec2 vTextureCoord;\n" + + "varying vec4 vColor;\n" + - "void main(void) {\n" + - "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - "vTextureCoord = aTextureCoord;\n" + - "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + - "}"; + "const vec2 center = vec2(-1.0, 1.0);\n" + - constructor(effect: egret.Filter = null){ - this.enabled = true; - this.effect = effect; - } + "void main(void) {\n" + + "gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + "vTextureCoord = aTextureCoord;\n" + + "vColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n" + + "}"; - public onAddedToScene(scene: Scene){ - this.scene = scene; - this.shape = new egret.Shape(); - this.shape.graphics.beginFill(0xFFFFFF, 1); - this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this.shape.graphics.endFill(); - scene.addChild(this.shape); - } - - public process(){ - this.drawFullscreenQuad(); - } - - public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){} - - protected drawFullscreenQuad(){ - this.scene.filters = [this.effect]; - // this.shape.filters = [this.effect]; - } - - public unload(){ - if (this.effect){ - this.effect = null; + constructor(effect: egret.Filter = null){ + this.enabled = true; + this.effect = effect; } - this.scene.removeChild(this.shape); - this.scene = null; + public onAddedToScene(scene: Scene){ + this.scene = scene; + this.shape = new egret.Shape(); + this.shape.graphics.beginFill(0xFFFFFF, 1); + this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this.shape.graphics.endFill(); + scene.addChild(this.shape); + } + + public process(){ + this.drawFullscreenQuad(); + } + + public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){} + + protected drawFullscreenQuad(){ + this.scene.filters = [this.effect]; + // this.shape.filters = [this.effect]; + } + + public unload(){ + if (this.effect){ + this.effect = null; + } + + this.scene.removeChild(this.shape); + this.scene = null; + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/PostProcessing/PostProcessors/GaussianBlurPostProcessor.ts b/source/src/Graphics/PostProcessing/PostProcessors/GaussianBlurPostProcessor.ts index 3030b81f..dc6d02d2 100644 --- a/source/src/Graphics/PostProcessing/PostProcessors/GaussianBlurPostProcessor.ts +++ b/source/src/Graphics/PostProcessing/PostProcessors/GaussianBlurPostProcessor.ts @@ -1,6 +1,8 @@ -class GaussianBlurPostProcessor extends PostProcessor { - public onAddedToScene(scene: Scene){ - super.onAddedToScene(scene); - this.effect = new GaussianBlurEffect(); +module es { + export class GaussianBlurPostProcessor extends PostProcessor { + public onAddedToScene(scene: Scene){ + super.onAddedToScene(scene); + this.effect = new GaussianBlurEffect(); + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Renderers/DefaultRenderer.ts b/source/src/Graphics/Renderers/DefaultRenderer.ts index dd18bd8e..67fa419b 100644 --- a/source/src/Graphics/Renderers/DefaultRenderer.ts +++ b/source/src/Graphics/Renderers/DefaultRenderer.ts @@ -1,13 +1,15 @@ /// -class DefaultRenderer extends Renderer { - public render(scene: Scene) { - let cam = this.camera ? this.camera : scene.camera; - this.beginRender(cam); +module es { + export class DefaultRenderer extends Renderer { + public render(scene: Scene) { + let cam = this.camera ? this.camera : scene.camera; + this.beginRender(cam); - for (let i = 0; i < scene.renderableComponents.count; i++){ - let renderable = scene.renderableComponents.buffer[i]; - if (renderable.enabled && renderable.isVisibleFromCamera(cam)) - this.renderAfterStateCheck(renderable, cam); + for (let i = 0; i < scene.renderableComponents.count; i++){ + let renderable = scene.renderableComponents.buffer[i]; + if (renderable.enabled && renderable.isVisibleFromCamera(cam)) + this.renderAfterStateCheck(renderable, cam); + } } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts b/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts index 0ae9af42..d8567650 100644 --- a/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts +++ b/source/src/Graphics/Renderers/PolygonLight/PolyLight.ts @@ -1,46 +1,48 @@ -class PolyLight extends RenderableComponent { - public power: number; - protected _radius: number; - private _lightEffect; - private _indices: number[] = []; +module es { + export class PolyLight extends RenderableComponent { + public power: number; + protected _radius: number; + private _lightEffect; + private _indices: number[] = []; - public get radius(){ - return this._radius; - } - public set radius(value: number){ - this.setRadius(value); - } + public get radius(){ + return this._radius; + } + public set radius(value: number){ + this.setRadius(value); + } - constructor(radius: number, color: number, power: number){ - super(); + constructor(radius: number, color: number, power: number){ + super(); - this.radius = radius; - this.power = power; - this.color = color; - this.computeTriangleIndices(); - } + this.radius = radius; + this.power = power; + this.color = color; + this.computeTriangleIndices(); + } - private computeTriangleIndices(totalTris: number = 20){ - this._indices.length = 0; + private computeTriangleIndices(totalTris: number = 20){ + this._indices.length = 0; + + for (let i = 0; i < totalTris; i += 2){ + this._indices.push(0); + this._indices.push(i + 2); + this._indices.push(i + 1); + } + } + + public setRadius(radius: number){ + if (radius != this._radius){ + this._radius = radius; + this._areBoundsDirty = true; + } + } + + public render(camera: Camera) { + } + + public reset(){ - for (let i = 0; i < totalTris; i += 2){ - this._indices.push(0); - this._indices.push(i + 2); - this._indices.push(i + 1); } } - - public setRadius(radius: number){ - if (radius != this._radius){ - this._radius = radius; - this._areBoundsDirty = true; - } - } - - public render(camera: Camera) { - } - - public reset(){ - - } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Renderers/Renderer.ts b/source/src/Graphics/Renderers/Renderer.ts index 86b5afec..6859059b 100644 --- a/source/src/Graphics/Renderers/Renderer.ts +++ b/source/src/Graphics/Renderers/Renderer.ts @@ -1,38 +1,40 @@ -/** - * 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用 - */ -abstract class Renderer { - /** - * 渲染器用于渲染的摄像机(实际上是用于剔除的变换矩阵和边界) - * 不是必须的 - * Renderer子类可以选择调用beginRender时使用的摄像头 - */ - public camera: Camera; - +module es { /** - * 当渲染器被添加到场景时调用 - * @param scene + * 渲染器被添加到场景中并处理所有对RenderableComponent的实际调用 */ - public onAddedToScene(scene: Scene){} + export abstract class Renderer { + /** + * 渲染器用于渲染的摄像机(实际上是用于剔除的变换矩阵和边界) + * 不是必须的 + * Renderer子类可以选择调用beginRender时使用的摄像头 + */ + public camera: Camera; - protected beginRender(cam: Camera){ - + /** + * 当渲染器被添加到场景时调用 + * @param scene + */ + public onAddedToScene(scene: Scene){} + + protected beginRender(cam: Camera){ + + } + + /** + * + * @param scene + */ + public abstract render(scene: Scene); + + public unload(){ } + + /** + * + * @param renderable + * @param cam + */ + protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){ + renderable.render(cam); + } } - - /** - * - * @param scene - */ - public abstract render(scene: Scene); - - public unload(){ } - - /** - * - * @param renderable - * @param cam - */ - protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){ - renderable.render(cam); - } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Renderers/ScreenSpaceRenderer.ts b/source/src/Graphics/Renderers/ScreenSpaceRenderer.ts index dbf7da35..0fbe20c0 100644 --- a/source/src/Graphics/Renderers/ScreenSpaceRenderer.ts +++ b/source/src/Graphics/Renderers/ScreenSpaceRenderer.ts @@ -1,7 +1,9 @@ -/** - * 渲染器使用自己的不移动的摄像机进行渲染。 - */ -class ScreenSpaceRenderer extends Renderer { - public render(scene: Scene) { +module es { + /** + * 渲染器使用自己的不移动的摄像机进行渲染。 + */ + export class ScreenSpaceRenderer extends Renderer { + public render(scene: Scene) { + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Transitions/FadeTransition.ts b/source/src/Graphics/Transitions/FadeTransition.ts index 76d44cc5..a7878efa 100644 --- a/source/src/Graphics/Transitions/FadeTransition.ts +++ b/source/src/Graphics/Transitions/FadeTransition.ts @@ -1,38 +1,40 @@ /// -class FadeTransition extends SceneTransition { - public fadeToColor: number = 0x000000; - public fadeOutDuration = 0.4; - public fadeEaseType: Function = egret.Ease.quadInOut; - public delayBeforeFadeInDuration = 0.1; - private _mask: egret.Shape; - private _alpha: number = 0; +module es { + export class FadeTransition extends SceneTransition { + public fadeToColor: number = 0x000000; + public fadeOutDuration = 0.4; + public fadeEaseType: Function = egret.Ease.quadInOut; + public delayBeforeFadeInDuration = 0.1; + private _mask: egret.Shape; + private _alpha: number = 0; - constructor(sceneLoadAction: Function) { - super(sceneLoadAction); - this._mask = new egret.Shape(); - } + constructor(sceneLoadAction: Function) { + super(sceneLoadAction); + this._mask = new egret.Shape(); + } - public async onBeginTransition() { - this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this._mask.graphics.endFill(); - SceneManager.stage.addChild(this._mask); + public async onBeginTransition() { + this._mask.graphics.beginFill(this.fadeToColor, 1); + this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + SceneManager.stage.addChild(this._mask); - egret.Tween.get(this).to({ _alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType) - .call(async () => { - await this.loadNextScene(); - }).wait(this.delayBeforeFadeInDuration).call(() => { + egret.Tween.get(this).to({ _alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType) + .call(async () => { + await this.loadNextScene(); + }).wait(this.delayBeforeFadeInDuration).call(() => { egret.Tween.get(this).to({ _alpha: 0 }, this.fadeOutDuration * 1000, this.fadeEaseType).call(() => { this.transitionComplete(); SceneManager.stage.removeChild(this._mask); }); }); - } + } - public render(){ - this._mask.graphics.clear(); - this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this._mask.graphics.endFill(); + public render(){ + this._mask.graphics.clear(); + this._mask.graphics.beginFill(this.fadeToColor, this._alpha); + this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Transitions/SceneTransition.ts b/source/src/Graphics/Transitions/SceneTransition.ts index 1fa8c5a8..620a8264 100644 --- a/source/src/Graphics/Transitions/SceneTransition.ts +++ b/source/src/Graphics/Transitions/SceneTransition.ts @@ -1,75 +1,77 @@ -/** - * SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡 - */ -abstract class SceneTransition { - private _hasPreviousSceneRender: boolean; - /** 是否加载新场景的标志 */ - public loadsNewScene: boolean; - /** - * 将此用于两个部分的转换。例如,淡出会先淡出到黑色,然后当isNewSceneLoaded为true,它会淡出。 - * 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。 +module es { + /** + * SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡 */ - public isNewSceneLoaded: boolean; - /** 返回新加载场景的函数 */ - protected sceneLoadAction: Function; - /** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */ - public onScreenObscured: Function; - /** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */ - public onTransitionCompleted: Function; + export abstract class SceneTransition { + private _hasPreviousSceneRender: boolean; + /** 是否加载新场景的标志 */ + public loadsNewScene: boolean; + /** + * 将此用于两个部分的转换。例如,淡出会先淡出到黑色,然后当isNewSceneLoaded为true,它会淡出。 + * 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。 + */ + public isNewSceneLoaded: boolean; + /** 返回新加载场景的函数 */ + protected sceneLoadAction: Function; + /** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */ + public onScreenObscured: Function; + /** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */ + public onTransitionCompleted: Function; - public get hasPreviousSceneRender(){ - if (!this._hasPreviousSceneRender){ - this._hasPreviousSceneRender = true; - return false; + public get hasPreviousSceneRender(){ + if (!this._hasPreviousSceneRender){ + this._hasPreviousSceneRender = true; + return false; + } + + return true; } - return true; - } - - constructor(sceneLoadAction: Function) { - this.sceneLoadAction = sceneLoadAction; - this.loadsNewScene = sceneLoadAction != null; - } - - public preRender() { } - - public render() { - - } - - public async onBeginTransition() { - await this.loadNextScene(); - this.transitionComplete(); - } - - protected transitionComplete() { - SceneManager.sceneTransition = null; - - if (this.onTransitionCompleted) { - this.onTransitionCompleted(); + constructor(sceneLoadAction: Function) { + this.sceneLoadAction = sceneLoadAction; + this.loadsNewScene = sceneLoadAction != null; } - } - protected async loadNextScene() { - if (this.onScreenObscured) - this.onScreenObscured(); + public preRender() { } - if (!this.loadsNewScene) { + public render() { + + } + + public async onBeginTransition() { + await this.loadNextScene(); + this.transitionComplete(); + } + + protected transitionComplete() { + SceneManager.sceneTransition = null; + + if (this.onTransitionCompleted) { + this.onTransitionCompleted(); + } + } + + protected async loadNextScene() { + if (this.onScreenObscured) + this.onScreenObscured(); + + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + } + + SceneManager.scene = await this.sceneLoadAction(); this.isNewSceneLoaded = true; } - SceneManager.scene = await this.sceneLoadAction(); - this.isNewSceneLoaded = true; - } + public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise{ + return new Promise((resolve)=>{ + let start = reverseDirection ? 1 : 0; + let end = reverseDirection ? 0 : 1; - public tickEffectProgressProperty(filter: egret.CustomFilter, duration: number, easeType: Function, reverseDirection = false): Promise{ - return new Promise((resolve)=>{ - let start = reverseDirection ? 1 : 0; - let end = reverseDirection ? 0 : 1; - - egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(()=>{ - resolve(); + egret.Tween.get(filter.uniforms).set({_progress: start}).to({_progress: end}, duration * 1000, easeType).call(()=>{ + resolve(); + }); }); - }); + } } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Transitions/WindTransition.ts b/source/src/Graphics/Transitions/WindTransition.ts index 3bf540f4..4fe72e54 100644 --- a/source/src/Graphics/Transitions/WindTransition.ts +++ b/source/src/Graphics/Transitions/WindTransition.ts @@ -1,65 +1,67 @@ -class WindTransition extends SceneTransition { - private _mask: egret.Shape; - private _windEffect: egret.CustomFilter; +module es { + export class WindTransition extends SceneTransition { + private _mask: egret.Shape; + private _windEffect: egret.CustomFilter; - public duration = 1; - public set windSegments(value: number) { - this._windEffect.uniforms._windSegments = value; + public duration = 1; + public set windSegments(value: number) { + this._windEffect.uniforms._windSegments = value; + } + public set size(value: number) { + this._windEffect.uniforms._size = value; + } + public easeType = egret.Ease.quadOut; + constructor(sceneLoadAction: Function) { + super(sceneLoadAction); + + let vertexSrc = "attribute vec2 aVertexPosition;\n" + + "attribute vec2 aTextureCoord;\n" + + + "uniform vec2 projectionVector;\n" + + + "varying vec2 vTextureCoord;\n" + + + "const vec2 center = vec2(-1.0, 1.0);\n" + + + "void main(void) {\n" + + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + + " vTextureCoord = aTextureCoord;\n" + + "}"; + let fragmentSrc = "precision lowp float;\n" + + "varying vec2 vTextureCoord;\n" + + "uniform sampler2D uSampler;\n" + + "uniform float _progress;\n" + + "uniform float _size;\n" + + "uniform float _windSegments;\n" + + + "void main(void) {\n" + + "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + + "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + + "float r = x - floor(x);\n" + + "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + + "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + + "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + + "}"; + + this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { + _progress: 0, + _size: 0.3, + _windSegments: 100 + }); + + this._mask = new egret.Shape(); + this._mask.graphics.beginFill(0xFFFFFF, 1); + this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.endFill(); + this._mask.filters = [this._windEffect]; + SceneManager.stage.addChild(this._mask); + } + + public async onBeginTransition() { + this.loadNextScene(); + await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType); + this.transitionComplete(); + SceneManager.stage.removeChild(this._mask); + } } - public set size(value: number) { - this._windEffect.uniforms._size = value; - } - public easeType = egret.Ease.quadOut; - constructor(sceneLoadAction: Function) { - super(sceneLoadAction); - - let vertexSrc = "attribute vec2 aVertexPosition;\n" + - "attribute vec2 aTextureCoord;\n" + - - "uniform vec2 projectionVector;\n" + - - "varying vec2 vTextureCoord;\n" + - - "const vec2 center = vec2(-1.0, 1.0);\n" + - - "void main(void) {\n" + - " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + - " vTextureCoord = aTextureCoord;\n" + - "}"; - let fragmentSrc = "precision lowp float;\n" + - "varying vec2 vTextureCoord;\n" + - "uniform sampler2D uSampler;\n" + - "uniform float _progress;\n" + - "uniform float _size;\n" + - "uniform float _windSegments;\n" + - - "void main(void) {\n" + - "vec2 co = floor(vec2(0.0, vTextureCoord.y * _windSegments));\n" + - "float x = sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453;\n" + - "float r = x - floor(x);\n" + - "float m = smoothstep(0.0, -_size, vTextureCoord.x * (1.0 - _size) + _size * r - (_progress * (1.0 + _size)));\n" + - "vec4 fg = texture2D(uSampler, vTextureCoord);\n" + - "gl_FragColor = mix(fg, vec4(0, 0, 0, 0), m);\n" + - "}"; - - this._windEffect = new egret.CustomFilter(vertexSrc, fragmentSrc, { - _progress: 0, - _size: 0.3, - _windSegments: 100 - }); - - this._mask = new egret.Shape(); - this._mask.graphics.beginFill(0xFFFFFF, 1); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this._mask.graphics.endFill(); - this._mask.filters = [this._windEffect]; - SceneManager.stage.addChild(this._mask); - } - - public async onBeginTransition() { - this.loadNextScene(); - await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType); - this.transitionComplete(); - SceneManager.stage.removeChild(this._mask); - } -} \ No newline at end of file +} diff --git a/source/src/Graphics/Viewport.ts b/source/src/Graphics/Viewport.ts index 38ebef3f..182b4223 100644 --- a/source/src/Graphics/Viewport.ts +++ b/source/src/Graphics/Viewport.ts @@ -1,34 +1,36 @@ -class Viewport { - private _x: number; - private _y: number; - private _width: number; - private _height: number; - private _minDepth: number; - private _maxDepth: number; - - public get aspectRatio(){ - if ((this._height != 0) && (this._width != 0)) - return (this._width / this._height); - return 0; - } +module es { + export class Viewport { + private _x: number; + private _y: number; + private _width: number; + private _height: number; + private _minDepth: number; + private _maxDepth: number; - public get bounds(){ - return new Rectangle(this._x, this._y, this._width, this._height); - } - public set bounds(value: Rectangle){ - this._x = value.x; - this._y = value.y; - this._width = value.width; - this._height = value.height; - } + public get aspectRatio(){ + if ((this._height != 0) && (this._width != 0)) + return (this._width / this._height); + return 0; + } + + public get bounds(){ + return new Rectangle(this._x, this._y, this._width, this._height); + } + public set bounds(value: Rectangle){ + this._x = value.x; + this._y = value.y; + this._width = value.width; + this._height = value.height; + } + + constructor(x: number, y: number, width: number, height: number){ + this._x = x; + this._y = y; + this._width = width; + this._height = height; + this._minDepth = 0; + this._maxDepth = 1; + } - constructor(x: number, y: number, width: number, height: number){ - this._x = x; - this._y = y; - this._width = width; - this._height = height; - this._minDepth = 0; - this._maxDepth = 1; } - -} \ No newline at end of file +} diff --git a/source/src/Math/Bezier.ts b/source/src/Math/Bezier.ts index 53668d82..e6a4fbe1 100644 --- a/source/src/Math/Bezier.ts +++ b/source/src/Math/Bezier.ts @@ -1,121 +1,123 @@ -/** 贝塞尔帮助类 */ -class Bezier { - /** - * 二次贝塞尔曲线 - * @param p0 - * @param p1 - * @param p2 - * @param t - */ - public static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2 { - t = MathHelper.clamp01(t); - let oneMinusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMinusT * oneMinusT), p0), - Vector2.multiply(new Vector2(2 * oneMinusT * t), p1)), Vector2.multiply(new Vector2(t * t), p2)); - } - - /** - * 得到二次贝塞尔函数的一阶导数 - * @param p0 - * @param p1 - * @param p2 - * @param t - */ - public static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number) { - return Vector2.add(Vector2.multiply(new Vector2(2 * (1 - t)), Vector2.subtract(p1, p0)), - Vector2.multiply(new Vector2(2 * t), Vector2.subtract(p2, p1))); - } - - /** - * 得到一个三次贝塞尔函数的一阶导数 - * @param start - * @param firstControlPoint - * @param secondControlPoint - * @param end - * @param t - */ - public static getFirstDerivativeThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, - end: Vector2, t: number) { - t = MathHelper.clamp01(t); - let oneMunusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT), Vector2.subtract(firstControlPoint, start)), - Vector2.multiply(new Vector2(6 * oneMunusT * t), Vector2.subtract(secondControlPoint, firstControlPoint))), - Vector2.multiply(new Vector2(3 * t * t), Vector2.subtract(end, secondControlPoint))); - } - - /** - * 计算一个三次贝塞尔 - * @param start - * @param firstControlPoint - * @param secondControlPoint - * @param end - * @param t - */ - public static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, - end: Vector2, t: number) { - t = MathHelper.clamp01(t); - let oneMunusT = 1 - t; - return Vector2.add(Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMunusT * oneMunusT * oneMunusT), start), - Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT * t), firstControlPoint)), - Vector2.multiply(new Vector2(3 * oneMunusT * t * t), secondControlPoint)), - Vector2.multiply(new Vector2(t * t * t), end)); - } - - /** - * 递归地细分bezier曲线,直到满足距离校正 - * 在这种算法中,平面切片的点要比曲面切片少。返回完成后应返回到ListPool的合并列表。 - * @param start - * @param firstCtrlPoint - * @param secondCtrlPoint - * @param end - * @param distanceTolerance - */ - public static getOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, - end: Vector2, distanceTolerance: number = 1) { - let points = ListPool.obtain(); - points.push(start); - this.recursiveGetOptimizedDrawingPoints(start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance); - points.push(end); - - return points; - } - - /** - * 递归地细分bezier曲线,直到满足距离校正。在这种算法中,平面切片的点要比曲面切片少。 - * @param start - * @param firstCtrlPoint - * @param secondCtrlPoint - * @param end - * @param points - * @param distanceTolerance - */ - private static recursiveGetOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, - end: Vector2, points: Vector2[], distanceTolerance: number) { - // 计算线段的所有中点 - let pt12 = Vector2.divide(Vector2.add(start, firstCtrlPoint), new Vector2(2)); - let pt23 = Vector2.divide(Vector2.add(firstCtrlPoint, secondCtrlPoint), new Vector2(2)); - let pt34 = Vector2.divide(Vector2.add(secondCtrlPoint, end), new Vector2(2)); - - // 计算新半直线的中点 - let pt123 = Vector2.divide(Vector2.add(pt12, pt23), new Vector2(2)); - let pt234 = Vector2.divide(Vector2.add(pt23, pt34), new Vector2(2)); - - // 最后再细分最后两个中点。如果我们满足我们的距离公差,这将是我们使用的最后一点。 - let pt1234 = Vector2.divide(Vector2.add(pt123, pt234), new Vector2(2)); - - // 试着用一条直线来近似整个三次曲线 - let deltaLine = Vector2.subtract(end, start); - - let d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); - let d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); - - if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) { - points.push(pt1234); - return; +module es { + /** 贝塞尔帮助类 */ + export class Bezier { + /** + * 二次贝塞尔曲线 + * @param p0 + * @param p1 + * @param p2 + * @param t + */ + public static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2 { + t = MathHelper.clamp01(t); + let oneMinusT = 1 - t; + return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMinusT * oneMinusT), p0), + Vector2.multiply(new Vector2(2 * oneMinusT * t), p1)), Vector2.multiply(new Vector2(t * t), p2)); } - // 继续细分 - this.recursiveGetOptimizedDrawingPoints(start, pt12, pt123, pt1234, points, distanceTolerance); - this.recursiveGetOptimizedDrawingPoints(pt1234, pt234, pt34, end, points, distanceTolerance); + /** + * 得到二次贝塞尔函数的一阶导数 + * @param p0 + * @param p1 + * @param p2 + * @param t + */ + public static getFirstDerivative(p0: Vector2, p1: Vector2, p2: Vector2, t: number) { + return Vector2.add(Vector2.multiply(new Vector2(2 * (1 - t)), Vector2.subtract(p1, p0)), + Vector2.multiply(new Vector2(2 * t), Vector2.subtract(p2, p1))); + } + + /** + * 得到一个三次贝塞尔函数的一阶导数 + * @param start + * @param firstControlPoint + * @param secondControlPoint + * @param end + * @param t + */ + public static getFirstDerivativeThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, + end: Vector2, t: number) { + t = MathHelper.clamp01(t); + let oneMunusT = 1 - t; + return Vector2.add(Vector2.add(Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT), Vector2.subtract(firstControlPoint, start)), + Vector2.multiply(new Vector2(6 * oneMunusT * t), Vector2.subtract(secondControlPoint, firstControlPoint))), + Vector2.multiply(new Vector2(3 * t * t), Vector2.subtract(end, secondControlPoint))); + } + + /** + * 计算一个三次贝塞尔 + * @param start + * @param firstControlPoint + * @param secondControlPoint + * @param end + * @param t + */ + public static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, + end: Vector2, t: number) { + t = MathHelper.clamp01(t); + let oneMunusT = 1 - t; + return Vector2.add(Vector2.add(Vector2.add(Vector2.multiply(new Vector2(oneMunusT * oneMunusT * oneMunusT), start), + Vector2.multiply(new Vector2(3 * oneMunusT * oneMunusT * t), firstControlPoint)), + Vector2.multiply(new Vector2(3 * oneMunusT * t * t), secondControlPoint)), + Vector2.multiply(new Vector2(t * t * t), end)); + } + + /** + * 递归地细分bezier曲线,直到满足距离校正 + * 在这种算法中,平面切片的点要比曲面切片少。返回完成后应返回到ListPool的合并列表。 + * @param start + * @param firstCtrlPoint + * @param secondCtrlPoint + * @param end + * @param distanceTolerance + */ + public static getOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, + end: Vector2, distanceTolerance: number = 1) { + let points = ListPool.obtain(); + points.push(start); + this.recursiveGetOptimizedDrawingPoints(start, firstCtrlPoint, secondCtrlPoint, end, points, distanceTolerance); + points.push(end); + + return points; + } + + /** + * 递归地细分bezier曲线,直到满足距离校正。在这种算法中,平面切片的点要比曲面切片少。 + * @param start + * @param firstCtrlPoint + * @param secondCtrlPoint + * @param end + * @param points + * @param distanceTolerance + */ + private static recursiveGetOptimizedDrawingPoints(start: Vector2, firstCtrlPoint: Vector2, secondCtrlPoint: Vector2, + end: Vector2, points: Vector2[], distanceTolerance: number) { + // 计算线段的所有中点 + let pt12 = Vector2.divide(Vector2.add(start, firstCtrlPoint), new Vector2(2)); + let pt23 = Vector2.divide(Vector2.add(firstCtrlPoint, secondCtrlPoint), new Vector2(2)); + let pt34 = Vector2.divide(Vector2.add(secondCtrlPoint, end), new Vector2(2)); + + // 计算新半直线的中点 + let pt123 = Vector2.divide(Vector2.add(pt12, pt23), new Vector2(2)); + let pt234 = Vector2.divide(Vector2.add(pt23, pt34), new Vector2(2)); + + // 最后再细分最后两个中点。如果我们满足我们的距离公差,这将是我们使用的最后一点。 + let pt1234 = Vector2.divide(Vector2.add(pt123, pt234), new Vector2(2)); + + // 试着用一条直线来近似整个三次曲线 + let deltaLine = Vector2.subtract(end, start); + + let d2 = Math.abs(((firstCtrlPoint.x, end.x) * deltaLine.y - (firstCtrlPoint.y - end.y) * deltaLine.x)); + let d3 = Math.abs(((secondCtrlPoint.x - end.x) * deltaLine.y - (secondCtrlPoint.y - end.y) * deltaLine.x)); + + if ((d2 + d3) * (d2 + d3) < distanceTolerance * (deltaLine.x * deltaLine.x + deltaLine.y * deltaLine.y)) { + points.push(pt1234); + return; + } + + // 继续细分 + this.recursiveGetOptimizedDrawingPoints(start, pt12, pt123, pt1234, points, distanceTolerance); + this.recursiveGetOptimizedDrawingPoints(pt1234, pt234, pt34, end, points, distanceTolerance); + } } -} \ No newline at end of file +} diff --git a/source/src/Math/Flags.ts b/source/src/Math/Flags.ts index ab415c81..f83ed4b5 100644 --- a/source/src/Math/Flags.ts +++ b/source/src/Math/Flags.ts @@ -1,62 +1,64 @@ -/** - * 帮助处理位掩码的实用程序类 - * 除了isFlagSet之外,所有方法都期望flag参数是一个非移位的标志 - * 允许您使用普通的(0、1、2、3等)来设置/取消您的标记 - */ -class Flags { +module es { /** - * 检查位标志是否已在数值中设置 - * 检查期望标志是否已经移位 - * @param self - * @param flag + * 帮助处理位掩码的实用程序类 + * 除了isFlagSet之外,所有方法都期望flag参数是一个非移位的标志 + * 允许您使用普通的(0、1、2、3等)来设置/取消您的标记 */ - public static isFlagSet(self: number, flag: number): boolean{ - return (self & flag) != 0; - } + export class Flags { + /** + * 检查位标志是否已在数值中设置 + * 检查期望标志是否已经移位 + * @param self + * @param flag + */ + public static isFlagSet(self: number, flag: number): boolean{ + return (self & flag) != 0; + } - /** - * 检查位标志是否在数值中设置 - * @param self - * @param flag - */ - public static isUnshiftedFlagSet(self: number, flag: number): boolean{ - flag = 1 << flag; - return (self & flag) != 0; - } + /** + * 检查位标志是否在数值中设置 + * @param self + * @param flag + */ + public static isUnshiftedFlagSet(self: number, flag: number): boolean{ + flag = 1 << flag; + return (self & flag) != 0; + } - /** - * 设置数值标志位,移除所有已经设置的标志 - * @param self - * @param flag - */ - public static setFlagExclusive(self: number, flag: number){ - return 1 << flag; - } + /** + * 设置数值标志位,移除所有已经设置的标志 + * @param self + * @param flag + */ + public static setFlagExclusive(self: number, flag: number){ + return 1 << flag; + } - /** - * 设置标志位 - * @param self - * @param flag - */ - public static setFlag(self: number, flag: number){ - return (self | 1 << flag); - } + /** + * 设置标志位 + * @param self + * @param flag + */ + public static setFlag(self: number, flag: number){ + return (self | 1 << flag); + } - /** - * 取消标志位 - * @param self - * @param flag - */ - public static unsetFlag(self: number, flag: number){ - flag = 1 << flag; - return (self & (~flag)); - } + /** + * 取消标志位 + * @param self + * @param flag + */ + public static unsetFlag(self: number, flag: number){ + flag = 1 << flag; + return (self & (~flag)); + } - /** - * 反转数值集合位 - * @param self - */ - public static invertFlags(self: number){ - return ~self; + /** + * 反转数值集合位 + * @param self + */ + public static invertFlags(self: number){ + return ~self; + } } -} \ No newline at end of file +} diff --git a/source/src/Math/MathHelper.ts b/source/src/Math/MathHelper.ts index 0c37c500..24186325 100644 --- a/source/src/Math/MathHelper.ts +++ b/source/src/Math/MathHelper.ts @@ -1,78 +1,80 @@ -class MathHelper { - public static readonly Epsilon: number = 0.00001; - public static readonly Rad2Deg = 57.29578; - public static readonly Deg2Rad = 0.0174532924; +module es { + export class MathHelper { + public static readonly Epsilon: number = 0.00001; + public static readonly Rad2Deg = 57.29578; + public static readonly Deg2Rad = 0.0174532924; - /** - * 将弧度转换成角度。 - * @param radians 用弧度表示的角 - */ - public static toDegrees(radians: number){ - return radians * 57.295779513082320876798154814105; + /** + * 将弧度转换成角度。 + * @param radians 用弧度表示的角 + */ + public static toDegrees(radians: number){ + return radians * 57.295779513082320876798154814105; + } + + /** + * 将角度转换为弧度 + * @param degrees + */ + public static toRadians(degrees: number){ + return degrees * 0.017453292519943295769236907684886; + } + + /** + * mapps值(在leftMin - leftMax范围内)到rightMin - rightMax范围内的值 + * @param value + * @param leftMin + * @param leftMax + * @param rightMin + * @param rightMax + */ + public static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number){ + return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); + } + + public static lerp(value1: number, value2: number, amount: number){ + return value1 + (value2 - value1) * amount; + } + + public static clamp(value: number, min: number, max: number){ + if (value < min) + return min; + + if (value > max) + return max; + + return value; + } + + public static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number){ + let radians = MathHelper.toRadians(angleInDegrees); + return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); + } + + /** + * 如果值为偶数,返回true + * @param value + */ + public static isEven(value: number){ + return value % 2 == 0; + } + + /** + * 数值限定在0-1之间 + * @param value + */ + public static clamp01(value: number){ + if (value < 0) + return 0; + + if (value > 1) + return 1; + + return value; + } + + public static angleBetweenVectors(from: Vector2, to: Vector2){ + return Math.atan2(to.y - from.y, to.x - from.x); + } } - - /** - * 将角度转换为弧度 - * @param degrees - */ - public static toRadians(degrees: number){ - return degrees * 0.017453292519943295769236907684886; - } - - /** - * mapps值(在leftMin - leftMax范围内)到rightMin - rightMax范围内的值 - * @param value - * @param leftMin - * @param leftMax - * @param rightMin - * @param rightMax - */ - public static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number){ - return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); - } - - public static lerp(value1: number, value2: number, amount: number){ - return value1 + (value2 - value1) * amount; - } - - public static clamp(value: number, min: number, max: number){ - if (value < min) - return min; - - if (value > max) - return max; - - return value; - } - - public static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number){ - let radians = MathHelper.toRadians(angleInDegrees); - return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y); - } - - /** - * 如果值为偶数,返回true - * @param value - */ - public static isEven(value: number){ - return value % 2 == 0; - } - - /** - * 数值限定在0-1之间 - * @param value - */ - public static clamp01(value: number){ - if (value < 0) - return 0; - - if (value > 1) - return 1; - - return value; - } - - public static angleBetweenVectors(from: Vector2, to: Vector2){ - return Math.atan2(to.y - from.y, to.x - from.x); - } -} \ No newline at end of file +} diff --git a/source/src/Math/Matrix2D.ts b/source/src/Math/Matrix2D.ts index 41794194..9b1e69e7 100644 --- a/source/src/Math/Matrix2D.ts +++ b/source/src/Math/Matrix2D.ts @@ -1,217 +1,219 @@ -/** - * 表示右手3 * 3的浮点矩阵,可以存储平移、缩放和旋转信息。 - */ -class Matrix2D { - public m11: number = 0; - public m12: number = 0; - - public m21: number = 0; - public m22: number = 0; - - public m31: number = 0; - public m32: number = 0; - - private static _identity: Matrix2D = new Matrix2D(1, 0, 0, 1, 0, 0); - +module es { /** - * 单位矩阵 + * 表示右手3 * 3的浮点矩阵,可以存储平移、缩放和旋转信息。 */ - public static get identity(){ - return Matrix2D._identity; + export class Matrix2D { + public m11: number = 0; + public m12: number = 0; + + public m21: number = 0; + public m22: number = 0; + + public m31: number = 0; + public m32: number = 0; + + private static _identity: Matrix2D = new Matrix2D(1, 0, 0, 1, 0, 0); + + /** + * 单位矩阵 + */ + public static get identity(){ + return Matrix2D._identity; + } + + constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number){ + this.m11 = m11 ? m11 : 1; + this.m12 = m12 ? m12 : 0; + + this.m21 = m21 ? m21 : 0; + this.m22 = m22 ? m22 : 1; + + this.m31 = m31 ? m31 : 0; + this.m32 = m32 ? m32 : 0; + } + + /** 存储在这个矩阵中的位置 */ + public get translation(){ + return new Vector2(this.m31, this.m32); + } + + public set translation(value: Vector2){ + this.m31 = value.x; + this.m32 = value.y; + } + + /** 以弧度表示的旋转存储在这个矩阵中 */ + public get rotation(){ + return Math.atan2(this.m21, this.m11); + } + + public set rotation(value: number){ + let val1 = Math.cos(value); + let val2 = Math.sin(value); + + this.m11 = val1; + this.m12 = val2; + this.m21 = -val2; + this.m22 = val1; + } + + /** + * 以度为单位的旋转存储在这个矩阵中 + */ + public get rotationDegrees(){ + return MathHelper.toDegrees(this.rotation); + } + + public set rotationDegrees(value: number){ + this.rotation = MathHelper.toRadians(value); + } + + public get scale(){ + return new Vector2(this.m11, this.m22); + } + + public set scale(value: Vector2){ + this.m11 = value.x; + this.m12 = value.y; + } + + /** + * 创建一个新的matrix, 它包含两个矩阵的和。 + * @param matrix1 + * @param matrix2 + */ + public static add(matrix1: Matrix2D, matrix2: Matrix2D){ + matrix1.m11 += matrix2.m11; + matrix1.m12 += matrix2.m12; + + matrix1.m21 += matrix2.m21; + matrix1.m22 += matrix2.m22; + + matrix1.m31 += matrix2.m31; + matrix1.m32 += matrix2.m32; + + return matrix1; + } + + public static divide(matrix1: Matrix2D, matrix2: Matrix2D){ + matrix1.m11 /= matrix2.m11; + matrix1.m12 /= matrix2.m12; + + matrix1.m21 /= matrix2.m21; + matrix1.m22 /= matrix2.m22; + + matrix1.m31 /= matrix2.m31; + matrix1.m32 /= matrix2.m32; + + return matrix1; + } + + public static multiply(matrix1: Matrix2D, matrix2: Matrix2D){ + let result = new Matrix2D(); + + let m11 = ( matrix1.m11 * matrix2.m11 ) + ( matrix1.m12 * matrix2.m21 ); + let m12 = ( matrix1.m11 * matrix2.m12 ) + ( matrix1.m12 * matrix2.m22 ); + + let m21 = ( matrix1.m21 * matrix2.m11 ) + ( matrix1.m22 * matrix2.m21 ); + let m22 = ( matrix1.m21 * matrix2.m12 ) + ( matrix1.m22 * matrix2.m22 ); + + let m31 = ( matrix1.m31 * matrix2.m11 ) + ( matrix1.m32 * matrix2.m21 ) + matrix2.m31; + let m32 = ( matrix1.m31 * matrix2.m12 ) + ( matrix1.m32 * matrix2.m22 ) + matrix2.m32; + + result.m11 = m11; + result.m12 = m12; + + result.m21 = m21; + result.m22 = m22; + + result.m31 = m31; + result.m32 = m32; + + return result; + } + + public static multiplyTranslation(matrix: Matrix2D, x: number, y: number){ + let trans = Matrix2D.createTranslation(x, y); + return Matrix2D.multiply(matrix, trans); + } + + public determinant(){ + return this.m11 * this.m22 - this.m12 * this.m21; + } + + public static invert(matrix: Matrix2D, result: Matrix2D = new Matrix2D()){ + let det = 1 / matrix.determinant(); + + result.m11 = matrix.m22 * det; + result.m12 = -matrix.m12 * det; + + result.m21 = -matrix.m21 * det; + result.m22 = matrix.m11 * det; + + result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; + result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; + + return result; + } + + /** + * 创建一个新的tranlation + * @param xPosition + * @param yPosition + */ + public static createTranslation(xPosition: number, yPosition: number){ + let result = new Matrix2D(); + + result.m11 = 1; + result.m12 = 0; + + result.m21 = 0; + result.m22 = 1; + + result.m31 = xPosition; + result.m32 = yPosition; + + return result; + } + + /** + * 根据position 创建一个translation + * @param position + */ + public static createTranslationVector(position: Vector2){ + return this.createTranslation(position.x, position.y); + } + + public static createRotation(radians: number, result?: Matrix2D){ + result = new Matrix2D(); + + let val1 = Math.cos(radians); + let val2 = Math.sin(radians); + + result.m11 = val1; + result.m12 = val2; + result.m21 = -val2; + result.m22 = val1; + + return result; + } + + public static createScale(xScale: number, yScale: number, result: Matrix2D = new Matrix2D()){ + result.m11 = xScale; + result.m12 = 0; + + result.m21 = 0; + result.m22 = yScale; + + result.m31 = 0; + result.m32 = 0; + + return result; + } + + public toEgretMatrix(): egret.Matrix{ + let matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); + return matrix; + } } - - constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number){ - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; - } - - /** 存储在这个矩阵中的位置 */ - public get translation(){ - return new Vector2(this.m31, this.m32); - } - - public set translation(value: Vector2){ - this.m31 = value.x; - this.m32 = value.y; - } - - /** 以弧度表示的旋转存储在这个矩阵中 */ - public get rotation(){ - return Math.atan2(this.m21, this.m11); - } - - public set rotation(value: number){ - let val1 = Math.cos(value); - let val2 = Math.sin(value); - - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; - } - - /** - * 以度为单位的旋转存储在这个矩阵中 - */ - public get rotationDegrees(){ - return MathHelper.toDegrees(this.rotation); - } - - public set rotationDegrees(value: number){ - this.rotation = MathHelper.toRadians(value); - } - - public get scale(){ - return new Vector2(this.m11, this.m22); - } - - public set scale(value: Vector2){ - this.m11 = value.x; - this.m12 = value.y; - } - - /** - * 创建一个新的matrix, 它包含两个矩阵的和。 - * @param matrix1 - * @param matrix2 - */ - public static add(matrix1: Matrix2D, matrix2: Matrix2D){ - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; - - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; - - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; - - return matrix1; - } - - public static divide(matrix1: Matrix2D, matrix2: Matrix2D){ - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; - - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; - - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; - - return matrix1; - } - - public static multiply(matrix1: Matrix2D, matrix2: Matrix2D){ - let result = new Matrix2D(); - - let m11 = ( matrix1.m11 * matrix2.m11 ) + ( matrix1.m12 * matrix2.m21 ); - let m12 = ( matrix1.m11 * matrix2.m12 ) + ( matrix1.m12 * matrix2.m22 ); - - let m21 = ( matrix1.m21 * matrix2.m11 ) + ( matrix1.m22 * matrix2.m21 ); - let m22 = ( matrix1.m21 * matrix2.m12 ) + ( matrix1.m22 * matrix2.m22 ); - - let m31 = ( matrix1.m31 * matrix2.m11 ) + ( matrix1.m32 * matrix2.m21 ) + matrix2.m31; - let m32 = ( matrix1.m31 * matrix2.m12 ) + ( matrix1.m32 * matrix2.m22 ) + matrix2.m32; - - result.m11 = m11; - result.m12 = m12; - - result.m21 = m21; - result.m22 = m22; - - result.m31 = m31; - result.m32 = m32; - - return result; - } - - public static multiplyTranslation(matrix: Matrix2D, x: number, y: number){ - let trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); - } - - public determinant(){ - return this.m11 * this.m22 - this.m12 * this.m21; - } - - public static invert(matrix: Matrix2D, result: Matrix2D = new Matrix2D()){ - let det = 1 / matrix.determinant(); - - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - - return result; - } - - /** - * 创建一个新的tranlation - * @param xPosition - * @param yPosition - */ - public static createTranslation(xPosition: number, yPosition: number){ - let result = new Matrix2D(); - - result.m11 = 1; - result.m12 = 0; - - result.m21 = 0; - result.m22 = 1; - - result.m31 = xPosition; - result.m32 = yPosition; - - return result; - } - - /** - * 根据position 创建一个translation - * @param position - */ - public static createTranslationVector(position: Vector2){ - return this.createTranslation(position.x, position.y); - } - - public static createRotation(radians: number, result?: Matrix2D){ - result = new Matrix2D(); - - let val1 = Math.cos(radians); - let val2 = Math.sin(radians); - - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - - return result; - } - - public static createScale(xScale: number, yScale: number, result: Matrix2D = new Matrix2D()){ - result.m11 = xScale; - result.m12 = 0; - - result.m21 = 0; - result.m22 = yScale; - - result.m31 = 0; - result.m32 = 0; - - return result; - } - - public toEgretMatrix(): egret.Matrix{ - let matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); - return matrix; - } -} \ No newline at end of file +} diff --git a/source/src/Math/Rectangle.ts b/source/src/Math/Rectangle.ts index 694b553a..22e368e4 100644 --- a/source/src/Math/Rectangle.ts +++ b/source/src/Math/Rectangle.ts @@ -1,183 +1,185 @@ -class Rectangle extends egret.Rectangle { - /** - * 获取矩形的最大点,即右下角 - */ - public get max() { - return new Vector2(this.right, this.bottom); - } +module es { + export class Rectangle extends egret.Rectangle { + /** + * 获取矩形的最大点,即右下角 + */ + public get max() { + return new Vector2(this.right, this.bottom); + } - /** 中心点坐标 */ - public get center() { - return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); - } + /** 中心点坐标 */ + public get center() { + return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2)); + } - /** 左上角的坐标 */ - public get location() { - return new Vector2(this.x, this.y); - } - /** 左上角的坐标 */ - public set location(value: Vector2) { - this.x = value.x; - this.y = value.y; - } + /** 左上角的坐标 */ + public get location() { + return new Vector2(this.x, this.y); + } + /** 左上角的坐标 */ + public set location(value: Vector2) { + this.x = value.x; + this.y = value.y; + } - public get size() { - return new Vector2(this.width, this.height); - } + public get size() { + return new Vector2(this.width, this.height); + } - public set size(value: Vector2) { - this.width = value.x; - this.height = value.y; - } + public set size(value: Vector2) { + this.width = value.x; + this.height = value.y; + } - /** - * 是否与另一个矩形相交 - * @param value - */ - public intersects(value: egret.Rectangle) { - return value.left < this.right && - this.left < value.right && - value.top < this.bottom && - this.top < value.bottom; - } + /** + * 是否与另一个矩形相交 + * @param value + */ + public intersects(value: egret.Rectangle) { + return value.left < this.right && + this.left < value.right && + value.top < this.bottom && + this.top < value.bottom; + } - /** - * 获取所提供的矩形是否在此矩形的边界内 - * @param value - */ - public containsRect(value: Rectangle) { - return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && - (this.y <= value.y)) && - (value.y < (this.y + this.height))); - } + /** + * 获取所提供的矩形是否在此矩形的边界内 + * @param value + */ + public containsRect(value: Rectangle) { + return ((((this.x <= value.x) && (value.x < (this.x + this.width))) && + (this.y <= value.y)) && + (value.y < (this.y + this.height))); + } - public getHalfSize() { - return new Vector2(this.width * 0.5, this.height * 0.5); - } + public getHalfSize() { + return new Vector2(this.width * 0.5, this.height * 0.5); + } - /** - * 创建一个矩形的最小/最大点(左上角,右下角的点) - * @param minX - * @param minY - * @param maxX - * @param maxY - */ - public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) { - return new Rectangle(minX, minY, maxX - minX, maxY - minY); - } + /** + * 创建一个矩形的最小/最大点(左上角,右下角的点) + * @param minX + * @param minY + * @param maxX + * @param maxY + */ + public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) { + return new Rectangle(minX, minY, maxX - minX, maxY - minY); + } - /** - * 获取矩形边界上与给定点最近的点 - * @param point - */ - public getClosestPointOnRectangleBorderToPoint(point: Vector2): { res: Vector2, edgeNormal: Vector2 } { - let edgeNormal = Vector2.zero; + /** + * 获取矩形边界上与给定点最近的点 + * @param point + */ + public getClosestPointOnRectangleBorderToPoint(point: Vector2): { res: Vector2, edgeNormal: Vector2 } { + let edgeNormal = Vector2.zero; - // 对于每个轴,如果点在盒子外面 - let res = new Vector2(); - res.x = MathHelper.clamp(point.x, this.left, this.right); - res.y = MathHelper.clamp(point.y, this.top, this.bottom); + // 对于每个轴,如果点在盒子外面 + let res = new Vector2(); + res.x = MathHelper.clamp(point.x, this.left, this.right); + res.y = MathHelper.clamp(point.y, this.top, this.bottom); - // 如果点在矩形内,我们需要推res到边界,因为它将在矩形内 - if (this.contains(res.x, res.y)) { - let dl = res.x - this.left; - let dr = this.right - res.x; - let dt = res.y - this.top; - let db = this.bottom - res.y; + // 如果点在矩形内,我们需要推res到边界,因为它将在矩形内 + if (this.contains(res.x, res.y)) { + let dl = res.x - this.left; + let dr = this.right - res.x; + let dt = res.y - this.top; + let db = this.bottom - res.y; - let min = Math.min(dl, dr, dt, db); - if (min == dt) { - res.y = this.top; - edgeNormal.y = -1; - } else if (min == db) { - res.y = this.bottom; - edgeNormal.y = 1; - } else if (min == dl) { - res.x = this.left; - edgeNormal.x = -1; + let min = Math.min(dl, dr, dt, db); + if (min == dt) { + res.y = this.top; + edgeNormal.y = -1; + } else if (min == db) { + res.y = this.bottom; + edgeNormal.y = 1; + } else if (min == dl) { + res.x = this.left; + edgeNormal.x = -1; + } else { + res.x = this.right; + edgeNormal.x = 1; + } } else { - res.x = this.right; - edgeNormal.x = 1; + if (res.x == this.left) edgeNormal.x = -1; + if (res.x == this.right) edgeNormal.x = 1; + if (res.y == this.top) edgeNormal.y = -1; + if (res.y == this.bottom) edgeNormal.y = 1; } - } else { - if (res.x == this.left) edgeNormal.x = -1; - if (res.x == this.right) edgeNormal.x = 1; - if (res.y == this.top) edgeNormal.y = -1; - if (res.y == this.bottom) edgeNormal.y = 1; + + return { res: res, edgeNormal: edgeNormal }; } - return { res: res, edgeNormal: edgeNormal }; - } + /** + * + */ + public getClosestPointOnBoundsToOrigin() { + let max = this.max; + let minDist = Math.abs(this.location.x); + let boundsPoint = new Vector2(this.location.x, 0); - /** - * - */ - public getClosestPointOnBoundsToOrigin() { - let max = this.max; - let minDist = Math.abs(this.location.x); - let boundsPoint = new Vector2(this.location.x, 0); + if (Math.abs(max.x) < minDist) { + minDist = Math.abs(max.x); + boundsPoint.x = max.x; + boundsPoint.y = 0; + } - if (Math.abs(max.x) < minDist) { - minDist = Math.abs(max.x); - boundsPoint.x = max.x; - boundsPoint.y = 0; + if (Math.abs(max.y) < minDist) { + minDist = Math.abs(max.y); + boundsPoint.x = 0; + boundsPoint.y = max.y; + } + + if (Math.abs(this.location.y) < minDist) { + minDist = Math.abs(this.location.y); + boundsPoint.x = 0; + boundsPoint.y = this.location.y; + } + + return boundsPoint; } - if (Math.abs(max.y) < minDist) { - minDist = Math.abs(max.y); - boundsPoint.x = 0; - boundsPoint.y = max.y; + public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number){ + this.x = parentPosition.x + position.x - origin.x * scale.x; + this.y = parentPosition.y + position.y - origin.y * scale.y; + this.width = width * scale.x; + this.height = height * scale.y; } - if (Math.abs(this.location.y) < minDist) { - minDist = Math.abs(this.location.y); - boundsPoint.x = 0; - boundsPoint.y = this.location.y; + /** + * 将egret矩形转化为Rectangle + * @param rect + */ + public setEgretRect(rect: egret.Rectangle): Rectangle{ + this.x = rect.x; + this.y = rect.y; + this.width = rect.width; + this.height = rect.height; + return this; } - return boundsPoint; - } + /** + * 给定多边形的点,计算边界 + * @param points + */ + public static rectEncompassingPoints(points: Vector2[]) { + // 我们需要求出x/y的最小值/最大值 + let minX = Number.POSITIVE_INFINITY; + let minY = Number.POSITIVE_INFINITY; + let maxX = Number.NEGATIVE_INFINITY; + let maxY = Number.NEGATIVE_INFINITY; - public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number){ - this.x = parentPosition.x + position.x - origin.x * scale.x; - this.y = parentPosition.y + position.y - origin.y * scale.y; - this.width = width * scale.x; - this.height = height * scale.y; - } + for (let i = 0; i < points.length; i++) { + let pt = points[i]; - /** - * 将egret矩形转化为Rectangle - * @param rect - */ - public setEgretRect(rect: egret.Rectangle): Rectangle{ - this.x = rect.x; - this.y = rect.y; - this.width = rect.width; - this.height = rect.height; - return this; - } - - /** - * 给定多边形的点,计算边界 - * @param points - */ - public static rectEncompassingPoints(points: Vector2[]) { - // 我们需要求出x/y的最小值/最大值 - let minX = Number.POSITIVE_INFINITY; - let minY = Number.POSITIVE_INFINITY; - let maxX = Number.NEGATIVE_INFINITY; - let maxY = Number.NEGATIVE_INFINITY; + if (pt.x < minX) minX = pt.x; + if (pt.x > maxX) maxX = pt.x; - for (let i = 0; i < points.length; i++) { - let pt = points[i]; + if (pt.y < minY) minY = pt.y; + if (pt.y > maxY) maxY = pt.y; + } - if (pt.x < minX) minX = pt.x; - if (pt.x > maxX) maxX = pt.x; - - if (pt.y < minY) minY = pt.y; - if (pt.y > maxY) maxY = pt.y; + return this.fromMinMax(minX, minY, maxX, maxY); } - - return this.fromMinMax(minX, minY, maxX, maxY); } -} \ No newline at end of file +} diff --git a/source/src/Math/Vector2.ts b/source/src/Math/Vector2.ts index 9529ac41..13dbe2aa 100644 --- a/source/src/Math/Vector2.ts +++ b/source/src/Math/Vector2.ts @@ -1,183 +1,185 @@ -/** 2d 向量 */ -class Vector2 { - public x: number = 0; - public y: number = 0; +module es { + /** 2d 向量 */ + export class Vector2 { + public x: number = 0; + public y: number = 0; - private static readonly unitYVector = new Vector2(0, 1); - private static readonly unitXVector = new Vector2(1, 0); - private static readonly unitVector2 = new Vector2(1, 1); - private static readonly zeroVector2 = new Vector2(0, 0); - public static get zero(){ - return Vector2.zeroVector2; + private static readonly unitYVector = new Vector2(0, 1); + private static readonly unitXVector = new Vector2(1, 0); + private static readonly unitVector2 = new Vector2(1, 1); + private static readonly zeroVector2 = new Vector2(0, 0); + public static get zero(){ + return Vector2.zeroVector2; + } + + public static get one(){ + return Vector2.unitVector2; + } + + public static get unitX(){ + return Vector2.unitXVector; + } + + public static get unitY(){ + return Vector2.unitYVector; + } + + /** + * 从两个值构造一个带有X和Y的二维向量。 + * @param x 二维空间中的x坐标 + * @param y 二维空间的y坐标 + */ + constructor(x? : number, y?: number){ + this.x = x ? x : 0; + this.y = y ? y : this.x; + } + + /** + * + * @param value1 + * @param value2 + */ + public static add(value1: Vector2, value2: Vector2){ + let result: Vector2 = new Vector2(0, 0); + result.x = value1.x + value2.x; + result.y = value1.y + value2.y; + return result; + } + + /** + * + * @param value1 + * @param value2 + */ + public static divide(value1: Vector2, value2: Vector2){ + let result: Vector2 = new Vector2(0, 0); + result.x = value1.x / value2.x; + result.y = value1.y / value2.y; + return result; + } + + /** + * + * @param value1 + * @param value2 + */ + public static multiply(value1: Vector2, value2: Vector2){ + let result: Vector2 = new Vector2(0, 0); + result.x = value1.x * value2.x; + result.y = value1.y * value2.y; + return result; + } + + /** + * + * @param value1 + * @param value2 + */ + public static subtract(value1: Vector2, value2: Vector2){ + let result: Vector2 = new Vector2(0, 0); + result.x = value1.x - value2.x; + result.y = value1.y - value2.y; + return result; + } + + /** 变成一个方向相同的单位向量 */ + public normalize(){ + let val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); + this.x *= val; + this.y *= val; + } + + /** 返回它的长度 */ + public length(){ + return Math.sqrt((this.x * this.x) + (this.y * this.y)); + } + + /** 对x和y值四舍五入 */ + public round(): Vector2{ + return new Vector2(Math.round(this.x), Math.round(this.y)); + } + + /** + * 创建一个新的Vector2 + * 它包含来自另一个向量的标准化值。 + * @param value + */ + public static normalize(value: Vector2){ + let val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); + value.x *= val; + value.y *= val; + return value; + } + + /** + * 返回两个向量的点积 + * @param value1 + * @param value2 + */ + public static dot(value1: Vector2, value2: Vector2): number{ + return (value1.x * value2.x) + (value1.y * value2.y); + } + + /** + * 返回两个向量之间距离的平方 + * @param value1 + * @param value2 + */ + public static distanceSquared(value1: Vector2, value2: Vector2){ + let v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return (v1 * v1) + (v2 * v2); + } + + /** + * + * @param value1 + * @param min + * @param max + */ + public static clamp(value1: Vector2, min: Vector2, max: Vector2){ + return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), + MathHelper.clamp(value1.y, min.y, max.y)); + } + + /** + * 包含指定向量的线性插值 + * @param value1 第一个向量 + * @param value2 第二个向量 + * @param amount 权重值(0.0到1.0之间) + */ + public static lerp(value1: Vector2, value2: Vector2, amount: number){ + return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount)); + } + + /** + * + * @param position + * @param matrix + */ + public static transform(position: Vector2, matrix: Matrix2D){ + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + } + + /** + * 返回两个向量之间的距离 + * @param value1 + * @param value2 + */ + public static distance(value1: Vector2, value2: Vector2){ + let v1 = value1.x - value2.x, v2 = value1.y - value2.y; + return Math.sqrt((v1 * v1) + (v2 * v2)); + } + + /** + * 矢量反演的结果 + * @param value + */ + public static negate(value: Vector2){ + let result: Vector2 = new Vector2(); + result.x = -value.x; + result.y = -value.y; + + return result; + } } - - public static get one(){ - return Vector2.unitVector2; - } - - public static get unitX(){ - return Vector2.unitXVector; - } - - public static get unitY(){ - return Vector2.unitYVector; - } - - /** - * 从两个值构造一个带有X和Y的二维向量。 - * @param x 二维空间中的x坐标 - * @param y 二维空间的y坐标 - */ - constructor(x? : number, y?: number){ - this.x = x ? x : 0; - this.y = y ? y : this.x; - } - - /** - * - * @param value1 - * @param value2 - */ - public static add(value1: Vector2, value2: Vector2){ - let result: Vector2 = new Vector2(0, 0); - result.x = value1.x + value2.x; - result.y = value1.y + value2.y; - return result; - } - - /** - * - * @param value1 - * @param value2 - */ - public static divide(value1: Vector2, value2: Vector2){ - let result: Vector2 = new Vector2(0, 0); - result.x = value1.x / value2.x; - result.y = value1.y / value2.y; - return result; - } - - /** - * - * @param value1 - * @param value2 - */ - public static multiply(value1: Vector2, value2: Vector2){ - let result: Vector2 = new Vector2(0, 0); - result.x = value1.x * value2.x; - result.y = value1.y * value2.y; - return result; - } - - /** - * - * @param value1 - * @param value2 - */ - public static subtract(value1: Vector2, value2: Vector2){ - let result: Vector2 = new Vector2(0, 0); - result.x = value1.x - value2.x; - result.y = value1.y - value2.y; - return result; - } - - /** 变成一个方向相同的单位向量 */ - public normalize(){ - let val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y)); - this.x *= val; - this.y *= val; - } - - /** 返回它的长度 */ - public length(){ - return Math.sqrt((this.x * this.x) + (this.y * this.y)); - } - - /** 对x和y值四舍五入 */ - public round(): Vector2{ - return new Vector2(Math.round(this.x), Math.round(this.y)); - } - - /** - * 创建一个新的Vector2 - * 它包含来自另一个向量的标准化值。 - * @param value - */ - public static normalize(value: Vector2){ - let val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y)); - value.x *= val; - value.y *= val; - return value; - } - - /** - * 返回两个向量的点积 - * @param value1 - * @param value2 - */ - public static dot(value1: Vector2, value2: Vector2): number{ - return (value1.x * value2.x) + (value1.y * value2.y); - } - - /** - * 返回两个向量之间距离的平方 - * @param value1 - * @param value2 - */ - public static distanceSquared(value1: Vector2, value2: Vector2){ - let v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return (v1 * v1) + (v2 * v2); - } - - /** - * - * @param value1 - * @param min - * @param max - */ - public static clamp(value1: Vector2, min: Vector2, max: Vector2){ - return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), - MathHelper.clamp(value1.y, min.y, max.y)); - } - - /** - * 包含指定向量的线性插值 - * @param value1 第一个向量 - * @param value2 第二个向量 - * @param amount 权重值(0.0到1.0之间) - */ - public static lerp(value1: Vector2, value2: Vector2, amount: number){ - return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount)); - } - - /** - * - * @param position - * @param matrix - */ - public static transform(position: Vector2, matrix: Matrix2D){ - return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); - } - - /** - * 返回两个向量之间的距离 - * @param value1 - * @param value2 - */ - public static distance(value1: Vector2, value2: Vector2){ - let v1 = value1.x - value2.x, v2 = value1.y - value2.y; - return Math.sqrt((v1 * v1) + (v2 * v2)); - } - - /** - * 矢量反演的结果 - * @param value - */ - public static negate(value: Vector2){ - let result: Vector2 = new Vector2(); - result.x = -value.x; - result.y = -value.y; - - return result; - } -} \ No newline at end of file +} diff --git a/source/src/Math/Vector3.ts b/source/src/Math/Vector3.ts index 7ef18989..72f627c7 100644 --- a/source/src/Math/Vector3.ts +++ b/source/src/Math/Vector3.ts @@ -1,11 +1,13 @@ -class Vector3 { - public x: number; - public y: number; - public z: number; +module es { + export class Vector3 { + public x: number; + public y: number; + public z: number; - constructor(x: number, y: number, z: number){ - this.x = x; - this.y = y; - this.z = z; + constructor(x: number, y: number, z: number){ + this.x = x; + this.y = y; + this.z = z; + } } -} \ No newline at end of file +} diff --git a/source/src/Physics/ColliderTriggerHelper.ts b/source/src/Physics/ColliderTriggerHelper.ts index 303c678d..c4a5de78 100644 --- a/source/src/Physics/ColliderTriggerHelper.ts +++ b/source/src/Physics/ColliderTriggerHelper.ts @@ -1,101 +1,105 @@ -/** 移动器使用的帮助器类,用于管理触发器碰撞器交互并调用itriggerlistener。 */ -class ColliderTriggerHelper { - private _entity: Entity; - /** 存储当前帧中发生的所有活动交集对 */ - private _activeTriggerIntersections: Pair[] = []; - /** 存储前一帧的交叉对,以便我们可以在移动该帧后检测出口 */ - private _previousTriggerIntersections: Pair[] = []; - private _tempTriggerList: ITriggerListener[] = []; - - constructor(entity: Entity) { - this._entity = entity; - } - +module es { /** - * 实体被移动后,应该调用更新。它会处理碰撞器重叠的任何itriggerlistener。 + * 移动器使用的帮助器类,用于管理触发器碰撞器交互并调用itriggerlistener */ - public update() { - let colliders = this._entity.getComponents(Collider); - for (let i = 0; i < colliders.length; i++) { - let collider = colliders[i]; + export class ColliderTriggerHelper { + private _entity: Entity; + /** 存储当前帧中发生的所有活动交集对 */ + private _activeTriggerIntersections: Pair[] = []; + /** 存储前一帧的交叉对,以便我们可以在移动该帧后检测出口 */ + private _previousTriggerIntersections: Pair[] = []; + private _tempTriggerList: ITriggerListener[] = []; - let boxcastResult = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); - collider.bounds = boxcastResult.rect; - let neighbors = boxcastResult.colliders; - for (let j = 0; j < neighbors.length; j++) { - let neighbor = neighbors[j]; - if (!collider.isTrigger && !neighbor.isTrigger) - continue; + constructor(entity: Entity) { + this._entity = entity; + } - if (collider.overlaps(neighbor)) { - let pair = new Pair(collider, neighbor); - let shouldReportTriggerEvent = this._activeTriggerIntersections.findIndex(value => { - return value.first == pair.first && value.second == pair.second; - }) == -1 && this._previousTriggerIntersections.findIndex(value => { - return value.first == pair.first && value.second == pair.second; - }) == -1; + /** + * 实体被移动后,应该调用更新。它会处理碰撞器重叠的任何itriggerlistener。 + */ + public update() { + let colliders = this._entity.getComponents(Collider); + for (let i = 0; i < colliders.length; i++) { + let collider = colliders[i]; - if (shouldReportTriggerEvent) - this.notifyTriggerListeners(pair, true); + let boxcastResult = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); + collider.bounds = boxcastResult.rect; + let neighbors = boxcastResult.colliders; + for (let j = 0; j < neighbors.length; j++) { + let neighbor = neighbors[j]; + if (!collider.isTrigger && !neighbor.isTrigger) + continue; - if (!this._activeTriggerIntersections.contains(pair)) - this._activeTriggerIntersections.push(pair); + if (collider.overlaps(neighbor)) { + let pair = new Pair(collider, neighbor); + let shouldReportTriggerEvent = this._activeTriggerIntersections.findIndex(value => { + return value.first == pair.first && value.second == pair.second; + }) == -1 && this._previousTriggerIntersections.findIndex(value => { + return value.first == pair.first && value.second == pair.second; + }) == -1; + + if (shouldReportTriggerEvent) + this.notifyTriggerListeners(pair, true); + + if (!this._activeTriggerIntersections.contains(pair)) + this._activeTriggerIntersections.push(pair); + } } } + + ListPool.free(colliders); + + this.checkForExitedColliders(); } - ListPool.free(colliders); + private checkForExitedColliders(){ + for (let i = 0; i < this._activeTriggerIntersections.length; i ++){ + let index = this._previousTriggerIntersections.findIndex(value => { + if (value.first == this._activeTriggerIntersections[i].first && value.second == this._activeTriggerIntersections[i].second) + return true; - this.checkForExitedColliders(); - } - - private checkForExitedColliders(){ - for (let i = 0; i < this._activeTriggerIntersections.length; i ++){ - let index = this._previousTriggerIntersections.findIndex(value => { - if (value.first == this._activeTriggerIntersections[i].first && value.second == this._activeTriggerIntersections[i].second) - return true; - - return false; - }); - if (index != -1) - this._previousTriggerIntersections.removeAt(index); - } - - for (let i = 0; i < this._previousTriggerIntersections.length; i ++){ - this.notifyTriggerListeners(this._previousTriggerIntersections[i], false) - } - this._previousTriggerIntersections.length = 0; - for (let i = 0; i < this._activeTriggerIntersections.length; i ++){ - if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])){ - this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); - } - } - this._activeTriggerIntersections.length = 0; - } - - private notifyTriggerListeners(collisionPair: Pair, isEntering: boolean) { - collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (let i = 0; i < this._tempTriggerList.length; i ++){ - if (isEntering){ - this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); - } else { - this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); + return false; + }); + if (index != -1) + this._previousTriggerIntersections.removeAt(index); } - this._tempTriggerList.length = 0; + for (let i = 0; i < this._previousTriggerIntersections.length; i ++){ + this.notifyTriggerListeners(this._previousTriggerIntersections[i], false) + } + this._previousTriggerIntersections.length = 0; + for (let i = 0; i < this._activeTriggerIntersections.length; i ++){ + if (!this._previousTriggerIntersections.contains(this._activeTriggerIntersections[i])){ + this._previousTriggerIntersections.push(this._activeTriggerIntersections[i]); + } + } + this._activeTriggerIntersections.length = 0; + } - if (collisionPair.second.entity){ - collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); - for (let i = 0; i < this._tempTriggerList.length; i ++){ - if (isEntering){ - this._tempTriggerList[i].onTriggerEnter(collisionPair.first, collisionPair.second); - } else { - this._tempTriggerList[i].onTriggerExit(collisionPair.first, collisionPair.second); - } + private notifyTriggerListeners(collisionPair: Pair, isEntering: boolean) { + collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (let i = 0; i < this._tempTriggerList.length; i ++){ + if (isEntering){ + this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first); + } else { + this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first); } this._tempTriggerList.length = 0; + + if (collisionPair.second.entity){ + collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList); + for (let i = 0; i < this._tempTriggerList.length; i ++){ + if (isEntering){ + this._tempTriggerList[i].onTriggerEnter(collisionPair.first, collisionPair.second); + } else { + this._tempTriggerList[i].onTriggerExit(collisionPair.first, collisionPair.second); + } + } + + this._tempTriggerList.length = 0; + } } } } -} \ No newline at end of file +} diff --git a/source/src/Physics/Collision.ts b/source/src/Physics/Collision.ts index eed7f5b5..06b14bf5 100644 --- a/source/src/Physics/Collision.ts +++ b/source/src/Physics/Collision.ts @@ -1,168 +1,170 @@ -enum PointSectors { - center = 0, - top = 1, - bottom = 2, - topLeft = 9, - topRight = 5, - left = 8, - right = 4, - bottomLeft = 10, - bottomRight = 6 -} - -class Collisions { - public static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean { - let b = Vector2.subtract(a2, a1); - let d = Vector2.subtract(b2, b1); - let bDotDPerp = b.x * d.y - b.y * d.x; - - // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 - if (bDotDPerp == 0) - return false; - - let c = Vector2.subtract(b1, a1); - let t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) - return false; - - let u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) - return false; - - return true; +module es { + export enum PointSectors { + center = 0, + top = 1, + bottom = 2, + topLeft = 9, + topRight = 5, + left = 8, + right = 4, + bottomLeft = 10, + bottomRight = 6 } - public static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2 { - let intersection = new Vector2(0, 0); + export class Collisions { + public static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean { + let b = Vector2.subtract(a2, a1); + let d = Vector2.subtract(b2, b1); + let bDotDPerp = b.x * d.y - b.y * d.x; - let b = Vector2.subtract(a2, a1); - let d = Vector2.subtract(b2, b1); - let bDotDPerp = b.x * d.y - b.y * d.x; + // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 + if (bDotDPerp == 0) + return false; - // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 - if (bDotDPerp == 0) - return intersection; + let c = Vector2.subtract(b1, a1); + let t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return false; - let c = Vector2.subtract(b1, a1); - let t = (c.x * d.y - c.y * d.x) / bDotDPerp; - if (t < 0 || t > 1) - return intersection; + let u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return false; - let u = (c.x * b.y - c.y * b.x) / bDotDPerp; - if (u < 0 || u > 1) - return intersection; - - intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); - - return intersection; - } - - public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2) { - let v = Vector2.subtract(lineB, lineA); - let w = Vector2.subtract(closestTo, lineA); - let t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); - - return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); - } - - public static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean { - return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); - } - - public static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean { - return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; - } - - public static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean { - return Vector2.distanceSquared(circleCenter, point) < radius * radius; - } - - public static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean { - let ew = rect.width * 0.5; - let eh = rect.height * 0.5; - let vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); - let vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); - - return vx * vx + vy * vy < cRadius * cRadius; - } - - public static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2){ - let fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); - let toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); - - if (fromSector == PointSectors.center || toSector == PointSectors.center){ return true; - } else if((fromSector & toSector) != 0){ - return false; - } else{ - let both = fromSector | toSector; - // 线对边进行检查 - let edgeFrom: Vector2; - let edgeTo: Vector2; - - if ((both & PointSectors.top) != 0){ - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; - } - - if ((both & PointSectors.bottom) != 0){ - edgeFrom = new Vector2(rect.x, rect.y + rect.height); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; - } - - if ((both & PointSectors.left) != 0){ - edgeFrom = new Vector2(rect.x, rect.y); - edgeTo = new Vector2(rect.x, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; - } - - if ((both & PointSectors.right) != 0){ - edgeFrom = new Vector2(rect.x + rect.width, rect.y); - edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); - if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) - return true; - } } - return false; + public static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2 { + let intersection = new Vector2(0, 0); + + let b = Vector2.subtract(a2, a1); + let d = Vector2.subtract(b2, b1); + let bDotDPerp = b.x * d.y - b.y * d.x; + + // 如果b*d = 0,表示这两条直线平行,因此有无穷个交点 + if (bDotDPerp == 0) + return intersection; + + let c = Vector2.subtract(b1, a1); + let t = (c.x * d.y - c.y * d.x) / bDotDPerp; + if (t < 0 || t > 1) + return intersection; + + let u = (c.x * b.y - c.y * b.x) / bDotDPerp; + if (u < 0 || u > 1) + return intersection; + + intersection = Vector2.add(a1, new Vector2(t * b.x, t * b.y)); + + return intersection; + } + + public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2) { + let v = Vector2.subtract(lineB, lineA); + let w = Vector2.subtract(closestTo, lineA); + let t = Vector2.dot(w, v) / Vector2.dot(v, v); + t = MathHelper.clamp(t, 0, 1); + + return Vector2.add(lineA, new Vector2(v.x * t, v.y * t)); + } + + public static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean { + return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2); + } + + public static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean { + return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius; + } + + public static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean { + return Vector2.distanceSquared(circleCenter, point) < radius * radius; + } + + public static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean { + let ew = rect.width * 0.5; + let eh = rect.height * 0.5; + let vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew); + let vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh); + + return vx * vx + vy * vy < cRadius * cRadius; + } + + public static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2){ + let fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom); + let toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo); + + if (fromSector == PointSectors.center || toSector == PointSectors.center){ + return true; + } else if((fromSector & toSector) != 0){ + return false; + } else{ + let both = fromSector | toSector; + // 线对边进行检查 + let edgeFrom: Vector2; + let edgeTo: Vector2; + + if ((both & PointSectors.top) != 0){ + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x + rect.width, rect.y); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + + if ((both & PointSectors.bottom) != 0){ + edgeFrom = new Vector2(rect.x, rect.y + rect.height); + edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + + if ((both & PointSectors.left) != 0){ + edgeFrom = new Vector2(rect.x, rect.y); + edgeTo = new Vector2(rect.x, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + + if ((both & PointSectors.right) != 0){ + edgeFrom = new Vector2(rect.x + rect.width, rect.y); + edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height); + if (this.isLineToLine(edgeFrom, edgeTo, lineFrom, lineTo)) + return true; + } + } + + return false; + } + + public static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2) { + return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; + } + + /** + * 位标志和帮助使用Cohen–Sutherland算法 + * + * 位标志: + * 1001 1000 1010 + * 0001 0000 0010 + * 0101 0100 0110 + * @param rX + * @param rY + * @param rW + * @param rH + * @param point + */ + public static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors { + let sector = PointSectors.center; + + if (point.x < rX) + sector |= PointSectors.left; + else if (point.x >= rX + rW) + sector |= PointSectors.right; + + if (point.y < rY) + sector |= PointSectors.top; + else if (point.y >= rY + rH) + sector |= PointSectors.bottom; + + return sector; + } } - - public static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2) { - return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH; - } - - /** - * 位标志和帮助使用Cohen–Sutherland算法 - * - * 位标志: - * 1001 1000 1010 - * 0001 0000 0010 - * 0101 0100 0110 - * @param rX - * @param rY - * @param rW - * @param rH - * @param point - */ - public static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors { - let sector = PointSectors.center; - - if (point.x < rX) - sector |= PointSectors.left; - else if (point.x >= rX + rW) - sector |= PointSectors.right; - - if (point.y < rY) - sector |= PointSectors.top; - else if (point.y >= rY + rH) - sector |= PointSectors.bottom; - - return sector; - } -} \ No newline at end of file +} diff --git a/source/src/Physics/Physics.ts b/source/src/Physics/Physics.ts index 08757b42..57be0921 100644 --- a/source/src/Physics/Physics.ts +++ b/source/src/Physics/Physics.ts @@ -1,64 +1,66 @@ -class Physics { - private static _spatialHash: SpatialHash; - /** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */ - public static spatialHashCellSize = 100; - /** 接受layerMask的所有方法的默认值 */ - public static readonly allLayers: number = -1; +module es { + export class Physics { + private static _spatialHash: SpatialHash; + /** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */ + public static spatialHashCellSize = 100; + /** 接受layerMask的所有方法的默认值 */ + public static readonly allLayers: number = -1; - public static reset(){ - this._spatialHash = new SpatialHash(this.spatialHashCellSize); - } + public static reset(){ + this._spatialHash = new SpatialHash(this.spatialHashCellSize); + } - /** - * 从SpatialHash中移除所有碰撞器 - */ - public static clear(){ - this._spatialHash.clear(); - } + /** + * 从SpatialHash中移除所有碰撞器 + */ + public static clear(){ + this._spatialHash.clear(); + } - public static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask = -1){ - return this._spatialHash.overlapCircle(center, randius, results, layerMask); - } + public static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask = -1){ + return this._spatialHash.overlapCircle(center, randius, results, layerMask); + } - public static boxcastBroadphase(rect: Rectangle, layerMask: number = this.allLayers){ - let boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); - return {colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds}; - } + public static boxcastBroadphase(rect: Rectangle, layerMask: number = this.allLayers){ + let boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); + return {colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds}; + } - public static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask = this.allLayers){ - return this._spatialHash.aabbBroadphase(rect, collider, layerMask); - } + public static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask = this.allLayers){ + return this._spatialHash.aabbBroadphase(rect, collider, layerMask); + } - /** - * 将对撞机添加到物理系统中 - * @param collider - */ - public static addCollider(collider: Collider){ - Physics._spatialHash.register(collider); - } + /** + * 将对撞机添加到物理系统中 + * @param collider + */ + public static addCollider(collider: Collider){ + Physics._spatialHash.register(collider); + } - /** - * 从物理系统中移除对撞机 - * @param collider - */ - public static removeCollider(collider: Collider){ - Physics._spatialHash.remove(collider); - } + /** + * 从物理系统中移除对撞机 + * @param collider + */ + public static removeCollider(collider: Collider){ + Physics._spatialHash.remove(collider); + } - /** - * 更新物理系统中对撞机的位置。这实际上只是移除然后重新添加带有新边界的碰撞器 - * @param collider - */ - public static updateCollider(collider: Collider){ - this._spatialHash.remove(collider); - this._spatialHash.register(collider); - } + /** + * 更新物理系统中对撞机的位置。这实际上只是移除然后重新添加带有新边界的碰撞器 + * @param collider + */ + public static updateCollider(collider: Collider){ + this._spatialHash.remove(collider); + this._spatialHash.register(collider); + } - /** - * debug绘制空间散列的内容 - * @param secondsToDisplay - */ - public static debugDraw(secondsToDisplay){ - this._spatialHash.debugDraw(secondsToDisplay, 2); + /** + * debug绘制空间散列的内容 + * @param secondsToDisplay + */ + public static debugDraw(secondsToDisplay){ + this._spatialHash.debugDraw(secondsToDisplay, 2); + } } -} \ No newline at end of file +} diff --git a/source/src/Physics/Shapes/CollisionResult.ts b/source/src/Physics/Shapes/CollisionResult.ts index 3593068c..50a78dcc 100644 --- a/source/src/Physics/Shapes/CollisionResult.ts +++ b/source/src/Physics/Shapes/CollisionResult.ts @@ -1,11 +1,13 @@ -class CollisionResult { - public collider: Collider; - public minimumTranslationVector: Vector2 = Vector2.zero; - public normal: Vector2 = Vector2.zero; - public point: Vector2 = Vector2.zero; +module es { + export class CollisionResult { + public collider: Collider; + public minimumTranslationVector: Vector2 = Vector2.zero; + public normal: Vector2 = Vector2.zero; + public point: Vector2 = Vector2.zero; - public invertResult(){ - this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector); - this.normal = Vector2.negate(this.normal); + public invertResult(){ + this.minimumTranslationVector = Vector2.negate(this.minimumTranslationVector); + this.normal = Vector2.negate(this.normal); + } } -} \ No newline at end of file +} diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts index 4f55d338..fd6e5659 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts @@ -1,302 +1,304 @@ -class ShapeCollisions { - /** - * 检查两个多边形之间的碰撞 - * @param first - * @param second - */ - public static polygonToPolygon(first: Polygon, second: Polygon) { - let result = new CollisionResult(); - let isIntersecting = true; +module es { + export class ShapeCollisions { + /** + * 检查两个多边形之间的碰撞 + * @param first + * @param second + */ + public static polygonToPolygon(first: Polygon, second: Polygon) { + let result = new CollisionResult(); + let isIntersecting = true; - let firstEdges = first.edgeNormals; - let secondEdges = second.edgeNormals; - let minIntervalDistance = Number.POSITIVE_INFINITY; - let translationAxis = new Vector2(); - let polygonOffset = Vector2.subtract(first.position, second.position); - let axis: Vector2; + let firstEdges = first.edgeNormals; + let secondEdges = second.edgeNormals; + let minIntervalDistance = Number.POSITIVE_INFINITY; + let translationAxis = new Vector2(); + let polygonOffset = Vector2.subtract(first.position, second.position); + let axis: Vector2; - // 循环穿过两个多边形的所有边 - for (let edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { - // 1. 找出当前多边形是否相交 - // 多边形的归一化轴垂直于缓存给我们的当前边 - if (edgeIndex < firstEdges.length) { - axis = firstEdges[edgeIndex]; - } else { - axis = secondEdges[edgeIndex - firstEdges.length]; + // 循环穿过两个多边形的所有边 + for (let edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) { + // 1. 找出当前多边形是否相交 + // 多边形的归一化轴垂直于缓存给我们的当前边 + if (edgeIndex < firstEdges.length) { + axis = firstEdges[edgeIndex]; + } else { + axis = secondEdges[edgeIndex - firstEdges.length]; + } + + // 求多边形在当前轴上的投影 + let minA = 0; + let minB = 0; + let maxA = 0; + let maxB = 0; + let intervalDist = 0; + let ta = this.getInterval(axis, first, minA, maxA); + minA = ta.min; + minB = ta.max; + let tb = this.getInterval(axis, second, minB, maxB); + minB = tb.min; + maxB = tb.max; + + // 将区间设为第二个多边形的空间。由轴上投影的位置差偏移。 + let relativeIntervalOffset = Vector2.dot(polygonOffset, axis); + minA += relativeIntervalOffset; + maxA += relativeIntervalOffset; + + // 检查多边形投影是否正在相交 + intervalDist = this.intervalDistance(minA, maxA, minB, maxB); + if (intervalDist > 0) + isIntersecting = false; + + // 对于多对多数据类型转换,添加一个Vector2?参数称为deltaMovement。为了提高速度,我们这里不使用它 + // TODO: 现在找出多边形是否会相交。只要检查速度就行了 + + // 如果多边形不相交,也不会相交,退出循环 + if (!isIntersecting) + return null; + + // 检查当前间隔距离是否为最小值。如果是,则存储间隔距离和当前距离。这将用于计算最小平移向量 + intervalDist = Math.abs(intervalDist); + if (intervalDist < minIntervalDistance) { + minIntervalDistance = intervalDist; + translationAxis = axis; + + if (Vector2.dot(translationAxis, polygonOffset) < 0) + translationAxis = new Vector2(-translationAxis); + } } - // 求多边形在当前轴上的投影 - let minA = 0; - let minB = 0; - let maxA = 0; - let maxB = 0; - let intervalDist = 0; - let ta = this.getInterval(axis, first, minA, maxA); - minA = ta.min; - minB = ta.max; - let tb = this.getInterval(axis, second, minB, maxB); - minB = tb.min; - maxB = tb.max; - - // 将区间设为第二个多边形的空间。由轴上投影的位置差偏移。 - let relativeIntervalOffset = Vector2.dot(polygonOffset, axis); - minA += relativeIntervalOffset; - maxA += relativeIntervalOffset; - - // 检查多边形投影是否正在相交 - intervalDist = this.intervalDistance(minA, maxA, minB, maxB); - if (intervalDist > 0) - isIntersecting = false; - - // 对于多对多数据类型转换,添加一个Vector2?参数称为deltaMovement。为了提高速度,我们这里不使用它 - // TODO: 现在找出多边形是否会相交。只要检查速度就行了 - - // 如果多边形不相交,也不会相交,退出循环 - if (!isIntersecting) - return null; - - // 检查当前间隔距离是否为最小值。如果是,则存储间隔距离和当前距离。这将用于计算最小平移向量 - intervalDist = Math.abs(intervalDist); - if (intervalDist < minIntervalDistance) { - minIntervalDistance = intervalDist; - translationAxis = axis; - - if (Vector2.dot(translationAxis, polygonOffset) < 0) - translationAxis = new Vector2(-translationAxis); - } - } - - // 利用最小平移向量对多边形进行推入。 - result.normal = translationAxis; - result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance)); - - return result; - } - - /** - * 计算[minA, maxA]和[minB, maxB]之间的距离。如果间隔重叠,距离是负的 - * @param minA - * @param maxA - * @param minB - * @param maxB - */ - public static intervalDistance(minA: number, maxA: number, minB: number, maxB) { - if (minA < minB) - return minB - maxA; - - return minA - minB; - } - - /** - * 计算一个多边形在一个轴上的投影,并返回一个[min,max]区间 - * @param axis - * @param polygon - * @param min - * @param max - */ - public static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number) { - let dot = Vector2.dot(polygon.points[0], axis); - min = max = dot; - - for (let i = 1; i < polygon.points.length; i++) { - dot = Vector2.dot(polygon.points[i], axis); - if (dot < min) { - min = dot; - } else if (dot > max) { - max = dot; - } - } - - return { min: min, max: max }; - } - - /** - * - * @param circle - * @param polygon - */ - public static circleToPolygon(circle: Circle, polygon: Polygon) { - let result = new CollisionResult(); - - let poly2Circle = Vector2.subtract(circle.position, polygon.position); - - let gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); - let closestPoint: Vector2 = gpp.closestPoint; - let distanceSquared: number = gpp.distanceSquared; - result.normal = gpp.edgeNormal; - - let circleCenterInsidePoly = polygon.containsPoint(circle.position); - if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) - return null; - - let mtv: Vector2; - if (circleCenterInsidePoly) { - mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared) - circle.radius)); - } else { - if (distanceSquared == 0) { - mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); - } else { - let distance = Math.sqrt(distanceSquared); - mtv = Vector2.multiply(new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), new Vector2((circle.radius - distanceSquared) / distance)); - } - } - - result.minimumTranslationVector = mtv; - result.point = Vector2.add(closestPoint, polygon.position); - - return result; - } - - /** - * 适用于圆心在方框内以及只与方框外圆心重叠的圆。 - * @param circle - * @param box - */ - public static circleToBox(circle: Circle, box: Box): CollisionResult { - let result = new CollisionResult(); - let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; - - if (box.containsPoint(circle.position)) { - result.point = closestPointOnBounds; - - let safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); - result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); + // 利用最小平移向量对多边形进行推入。 + result.normal = translationAxis; + result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance)); return result; } - let sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); - if (sqrDistance == 0) { - result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius)); - } else if (sqrDistance <= circle.radius * circle.radius) { - result.normal = Vector2.subtract(circle.position, closestPointOnBounds); - let depth = result.normal.length() - circle.radius; - result.normal = Vector2Ext.normalize(result.normal); - result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); + /** + * 计算[minA, maxA]和[minB, maxB]之间的距离。如果间隔重叠,距离是负的 + * @param minA + * @param maxA + * @param minB + * @param maxB + */ + public static intervalDistance(minA: number, maxA: number, minB: number, maxB) { + if (minA < minB) + return minB - maxA; - return result; + return minA - minB; } - return null; - } + /** + * 计算一个多边形在一个轴上的投影,并返回一个[min,max]区间 + * @param axis + * @param polygon + * @param min + * @param max + */ + public static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number) { + let dot = Vector2.dot(polygon.points[0], axis); + min = max = dot; - /** - * - * @param point - * @param circle - */ - public static pointToCircle(point: Vector2, circle: Circle) { - let result = new CollisionResult(); + for (let i = 1; i < polygon.points.length; i++) { + dot = Vector2.dot(polygon.points[i], axis); + if (dot < min) { + min = dot; + } else if (dot > max) { + max = dot; + } + } - let distanceSquared = Vector2.distanceSquared(point, circle.position); - let sumOfRadii = 1 + circle.radius; - let collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided) { - result.normal = Vector2.normalize(Vector2.subtract(point, circle.position)); - let depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal); - result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius))); - - return result; + return { min: min, max: max }; } - return null; - } + /** + * + * @param circle + * @param polygon + */ + public static circleToPolygon(circle: Circle, polygon: Polygon) { + let result = new CollisionResult(); - /** - * - * @param lineA - * @param lineB - * @param closestTo - */ - public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2) { - let v = Vector2.subtract(lineB, lineA); - let w = Vector2.subtract(closestTo, lineA); - let t = Vector2.dot(w, v) / Vector2.dot(v, v); - t = MathHelper.clamp(t, 0, 1); + let poly2Circle = Vector2.subtract(circle.position, polygon.position); - return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); - } - - /** - * - * @param point - * @param poly - */ - public static pointToPoly(point: Vector2, poly: Polygon) { - let result = new CollisionResult(); - - if (poly.containsPoint(point)) { - let distanceSquared: number; - let gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position)); - let closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; + let gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); + let closestPoint: Vector2 = gpp.closestPoint; + let distanceSquared: number = gpp.distanceSquared; result.normal = gpp.edgeNormal; - result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); - result.point = Vector2.add(closestPoint, poly.position); - - return result; - } - - return null; - } - - /** - * - * @param first - * @param second - */ - public static circleToCircle(first: Circle, second: Circle){ - let result = new CollisionResult(); - - let distanceSquared = Vector2.distanceSquared(first.position, second.position); - let sumOfRadii = first.radius + second.radius; - let collided = distanceSquared < sumOfRadii * sumOfRadii; - if (collided){ - result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position)); - let depth = sumOfRadii - Math.sqrt(distanceSquared); - result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal); - result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius))); - - return result; - } - - return null; - } - - /** - * - * @param first - * @param second - */ - public static boxToBox(first: Box, second: Box){ - let result = new CollisionResult(); - - let minkowskiDiff = this.minkowskiDifference(first, second); - if (minkowskiDiff.contains(0, 0)){ - // 计算MTV。如果它是零,我们就可以称它为非碰撞 - result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); - - if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) + let circleCenterInsidePoly = polygon.containsPoint(circle.position); + if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) return null; - - result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); - result.normal.normalize(); + + let mtv: Vector2; + if (circleCenterInsidePoly) { + mtv = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared) - circle.radius)); + } else { + if (distanceSquared == 0) { + mtv = Vector2.multiply(result.normal, new Vector2(circle.radius)); + } else { + let distance = Math.sqrt(distanceSquared); + mtv = Vector2.multiply(new Vector2(-Vector2.subtract(poly2Circle, closestPoint)), new Vector2((circle.radius - distanceSquared) / distance)); + } + } + + result.minimumTranslationVector = mtv; + result.point = Vector2.add(closestPoint, polygon.position); return result; } - return null; - } + /** + * 适用于圆心在方框内以及只与方框外圆心重叠的圆。 + * @param circle + * @param box + */ + public static circleToBox(circle: Circle, box: Box): CollisionResult { + let result = new CollisionResult(); + let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; - private static minkowskiDifference(first: Box, second: Box){ - // 我们需要第一个框的左上角 - // 碰撞器只会修改运动的位置所以我们需要用位置来计算出运动是什么。 - let positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, Vector2.divide(first.bounds.size, new Vector2(2)))); - let topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max); - let fullSize = Vector2.add(first.bounds.size, second.bounds.size); + if (box.containsPoint(circle.position)) { + result.point = closestPointOnBounds; - return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y) + let safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); + result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); + + return result; + } + + let sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); + if (sqrDistance == 0) { + result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius)); + } else if (sqrDistance <= circle.radius * circle.radius) { + result.normal = Vector2.subtract(circle.position, closestPointOnBounds); + let depth = result.normal.length() - circle.radius; + result.normal = Vector2Ext.normalize(result.normal); + result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); + + return result; + } + + return null; + } + + /** + * + * @param point + * @param circle + */ + public static pointToCircle(point: Vector2, circle: Circle) { + let result = new CollisionResult(); + + let distanceSquared = Vector2.distanceSquared(point, circle.position); + let sumOfRadii = 1 + circle.radius; + let collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided) { + result.normal = Vector2.normalize(Vector2.subtract(point, circle.position)); + let depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal); + result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius))); + + return result; + } + + return null; + } + + /** + * + * @param lineA + * @param lineB + * @param closestTo + */ + public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2) { + let v = Vector2.subtract(lineB, lineA); + let w = Vector2.subtract(closestTo, lineA); + let t = Vector2.dot(w, v) / Vector2.dot(v, v); + t = MathHelper.clamp(t, 0, 1); + + return Vector2.add(lineA, Vector2.multiply(v, new Vector2(t, t))); + } + + /** + * + * @param point + * @param poly + */ + public static pointToPoly(point: Vector2, poly: Polygon) { + let result = new CollisionResult(); + + if (poly.containsPoint(point)) { + let distanceSquared: number; + let gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position)); + let closestPoint = gpp.closestPoint; + distanceSquared = gpp.distanceSquared; + result.normal = gpp.edgeNormal; + + result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); + result.point = Vector2.add(closestPoint, poly.position); + + return result; + } + + return null; + } + + /** + * + * @param first + * @param second + */ + public static circleToCircle(first: Circle, second: Circle){ + let result = new CollisionResult(); + + let distanceSquared = Vector2.distanceSquared(first.position, second.position); + let sumOfRadii = first.radius + second.radius; + let collided = distanceSquared < sumOfRadii * sumOfRadii; + if (collided){ + result.normal = Vector2.normalize(Vector2.subtract(first.position, second.position)); + let depth = sumOfRadii - Math.sqrt(distanceSquared); + result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal); + result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius))); + + return result; + } + + return null; + } + + /** + * + * @param first + * @param second + */ + public static boxToBox(first: Box, second: Box){ + let result = new CollisionResult(); + + let minkowskiDiff = this.minkowskiDifference(first, second); + if (minkowskiDiff.contains(0, 0)){ + // 计算MTV。如果它是零,我们就可以称它为非碰撞 + result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); + + if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) + return null; + + result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); + result.normal.normalize(); + + return result; + } + + return null; + } + + private static minkowskiDifference(first: Box, second: Box){ + // 我们需要第一个框的左上角 + // 碰撞器只会修改运动的位置所以我们需要用位置来计算出运动是什么。 + let positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, Vector2.divide(first.bounds.size, new Vector2(2)))); + let topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max); + let fullSize = Vector2.add(first.bounds.size, second.bounds.size); + + return new Rectangle(topLeft.x, topLeft.y, fullSize.x, fullSize.y) + } } -} \ No newline at end of file +} diff --git a/source/src/Utils/Analysis/Layout.ts b/source/src/Utils/Analysis/Layout.ts index c6181014..d11b611f 100644 --- a/source/src/Utils/Analysis/Layout.ts +++ b/source/src/Utils/Analysis/Layout.ts @@ -1,69 +1,71 @@ -/** - * 支持标题安全区的布局类。 - */ -class Layout { - public clientArea: Rectangle; - public safeArea: Rectangle; +module es { + /** + * 支持标题安全区的布局类。 + */ + export class Layout { + public clientArea: Rectangle; + public safeArea: Rectangle; - constructor(){ - this.clientArea = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); - this.safeArea = this.clientArea; + constructor(){ + this.clientArea = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this.safeArea = this.clientArea; + } + + public place(size: Vector2, horizontalMargin: number, verticalMargine: number, alignment: Alignment){ + let rc = new Rectangle(0, 0, size.x, size.y); + if ((alignment & Alignment.left) != 0){ + rc.x = this.clientArea.x + (this.clientArea.width * horizontalMargin); + }else if((alignment & Alignment.right) != 0){ + rc.x = this.clientArea.x + (this.clientArea.width * (1 - horizontalMargin)) - rc.width; + } else if((alignment & Alignment.horizontalCenter) != 0){ + rc.x = this.clientArea.x + (this.clientArea.width - rc.width) / 2 + (horizontalMargin * this.clientArea.width); + }else{ + + } + + if ((alignment & Alignment.top) != 0){ + rc.y = this.clientArea.y + (this.clientArea.height * verticalMargine); + }else if((alignment & Alignment.bottom) != 0){ + rc.y = this.clientArea.y + (this.clientArea.height * (1 - verticalMargine)) - rc.height; + } else if((alignment & Alignment.verticalCenter) != 0){ + rc.y = this.clientArea.y + (this.clientArea.height - rc.height) / 2 + (verticalMargine * this.clientArea.height); + }else{ + + } + + // 确保布局区域在安全区域内。 + if (rc.left < this.safeArea.left) + rc.x = this.safeArea.left; + + if (rc.right > this.safeArea.right) + rc.x = this.safeArea.right - rc.width; + + if (rc.top < this.safeArea.top) + rc.y = this.safeArea.top; + + if (rc.bottom > this.safeArea.bottom) + rc.y = this.safeArea.bottom - rc.height; + + return rc; + } } - public place(size: Vector2, horizontalMargin: number, verticalMargine: number, alignment: Alignment){ - let rc = new Rectangle(0, 0, size.x, size.y); - if ((alignment & Alignment.left) != 0){ - rc.x = this.clientArea.x + (this.clientArea.width * horizontalMargin); - }else if((alignment & Alignment.right) != 0){ - rc.x = this.clientArea.x + (this.clientArea.width * (1 - horizontalMargin)) - rc.width; - } else if((alignment & Alignment.horizontalCenter) != 0){ - rc.x = this.clientArea.x + (this.clientArea.width - rc.width) / 2 + (horizontalMargin * this.clientArea.width); - }else{ - - } - - if ((alignment & Alignment.top) != 0){ - rc.y = this.clientArea.y + (this.clientArea.height * verticalMargine); - }else if((alignment & Alignment.bottom) != 0){ - rc.y = this.clientArea.y + (this.clientArea.height * (1 - verticalMargine)) - rc.height; - } else if((alignment & Alignment.verticalCenter) != 0){ - rc.y = this.clientArea.y + (this.clientArea.height - rc.height) / 2 + (verticalMargine * this.clientArea.height); - }else{ - - } - - // 确保布局区域在安全区域内。 - if (rc.left < this.safeArea.left) - rc.x = this.safeArea.left; - - if (rc.right > this.safeArea.right) - rc.x = this.safeArea.right - rc.width; - - if (rc.top < this.safeArea.top) - rc.y = this.safeArea.top; - - if (rc.bottom > this.safeArea.bottom) - rc.y = this.safeArea.bottom - rc.height; - - return rc; + export enum Alignment { + none = 0, + left = 1, + right = 2, + horizontalCenter = 4, + top = 8, + bottom = 16, + verticalCenter = 32, + topLeft = top | left, + topRight = top | right, + topCenter = top | horizontalCenter, + bottomLeft = bottom | left, + bottomRight = bottom | right, + bottomCenter = bottom | horizontalCenter, + centerLeft = verticalCenter | left, + centerRight = verticalCenter | right, + center = verticalCenter | horizontalCenter } } - -enum Alignment { - none = 0, - left = 1, - right = 2, - horizontalCenter = 4, - top = 8, - bottom = 16, - verticalCenter = 32, - topLeft = top | left, - topRight = top | right, - topCenter = top | horizontalCenter, - bottomLeft = bottom | left, - bottomRight = bottom | right, - bottomCenter = bottom | horizontalCenter, - centerLeft = verticalCenter | left, - centerRight = verticalCenter | right, - center = verticalCenter | horizontalCenter -} \ No newline at end of file diff --git a/source/src/Utils/Analysis/TimeRuler.ts b/source/src/Utils/Analysis/TimeRuler.ts index b4ca2e78..846043aa 100644 --- a/source/src/Utils/Analysis/TimeRuler.ts +++ b/source/src/Utils/Analysis/TimeRuler.ts @@ -1,349 +1,351 @@ -/** - * 通过使用这个类,您可以直观地找到瓶颈和基本的CPU使用情况。 - */ -class TimeRuler { - /** 最大条数 8 */ - public static readonly maxBars = 8; - /** */ - public static readonly maxSamples = 256; - /** 每条的最大嵌套调用 */ - public static readonly maxNestCall = 32; - /** 条的高度(以像素为单位) */ - public static readonly barHeight = 8; - /** 最大显示帧 */ - public static readonly maxSampleFrames = 4; - /** 持续时间(帧数)为采取抓拍日志。 */ - public static readonly logSnapDuration = 120; - public static readonly barPadding = 2; - public static readonly autoAdjustDelay = 30; - public static Instance: TimeRuler; - private _frameKey = 'frame'; - private _logKey = 'log'; - - /** 每帧的日志 */ - private _logs: FrameLog[]; - /** 当前显示帧计数 */ - private sampleFrames: number; - /** 获取/设置目标样本帧。 */ - public targetSampleFrames: number; - /** 获取/设置计时器标尺宽度。 */ - public width: number; - public enabled: true; - /** TimerRuler画的位置。 */ - private _position: Vector2; - /** 上一帧日志 */ - private _prevLog: FrameLog; - /** 当前帧日志 */ - private _curLog: FrameLog; - /** 当前帧数量 */ - private frameCount: number; - /** */ - private markers: MarkerInfo[] = []; - /** 秒表用来测量时间。 */ - private stopwacth: stopwatch.Stopwatch = new stopwatch.Stopwatch(); - /** 从标记名映射到标记id的字典。 */ - private _markerNameToIdMap: Map = new Map(); +module es { /** - * 你想在游戏开始时调用StartFrame更新方法。 - * 当游戏在固定时间步进模式下运行缓慢时,更新会多次调用。 - * 在这种情况下,我们应该忽略StartFrame调用。 - * 为此,我们只需一直跟踪StartFrame调用的次数,直到Draw被调用。 + * 通过使用这个类,您可以直观地找到瓶颈和基本的CPU使用情况。 */ - private _updateCount: number; - /** */ - public showLog = false; - private _frameAdjust: number; + export class TimeRuler { + /** 最大条数 8 */ + public static readonly maxBars = 8; + /** */ + public static readonly maxSamples = 256; + /** 每条的最大嵌套调用 */ + public static readonly maxNestCall = 32; + /** 条的高度(以像素为单位) */ + public static readonly barHeight = 8; + /** 最大显示帧 */ + public static readonly maxSampleFrames = 4; + /** 持续时间(帧数)为采取抓拍日志。 */ + public static readonly logSnapDuration = 120; + public static readonly barPadding = 2; + public static readonly autoAdjustDelay = 30; + public static Instance: TimeRuler; + private _frameKey = 'frame'; + private _logKey = 'log'; - constructor() { - TimeRuler.Instance = this; - this._logs = new Array(2); - for (let i = 0; i < this._logs.length; ++i) - this._logs[i] = new FrameLog(); + /** 每帧的日志 */ + private _logs: FrameLog[]; + /** 当前显示帧计数 */ + private sampleFrames: number; + /** 获取/设置目标样本帧。 */ + public targetSampleFrames: number; + /** 获取/设置计时器标尺宽度。 */ + public width: number; + public enabled: true; + /** TimerRuler画的位置。 */ + private _position: Vector2; + /** 上一帧日志 */ + private _prevLog: FrameLog; + /** 当前帧日志 */ + private _curLog: FrameLog; + /** 当前帧数量 */ + private frameCount: number; + /** */ + private markers: MarkerInfo[] = []; + /** 秒表用来测量时间。 */ + private stopwacth: stopwatch.Stopwatch = new stopwatch.Stopwatch(); + /** 从标记名映射到标记id的字典。 */ + private _markerNameToIdMap: Map = new Map(); + /** + * 你想在游戏开始时调用StartFrame更新方法。 + * 当游戏在固定时间步进模式下运行缓慢时,更新会多次调用。 + * 在这种情况下,我们应该忽略StartFrame调用。 + * 为此,我们只需一直跟踪StartFrame调用的次数,直到Draw被调用。 + */ + private _updateCount: number; + /** */ + public showLog = false; + private _frameAdjust: number; - this.sampleFrames = this.targetSampleFrames = 1; - this.width = SceneManager.stage.stageWidth * 0.8; - this.onGraphicsDeviceReset(); - } + constructor() { + TimeRuler.Instance = this; + this._logs = new Array(2); + for (let i = 0; i < this._logs.length; ++i) + this._logs[i] = new FrameLog(); - private onGraphicsDeviceReset() { - let layout = new Layout(); - this._position = layout.place(new Vector2(this.width, TimeRuler.barHeight), 0, 0.01, Alignment.bottomCenter).location; - } + this.sampleFrames = this.targetSampleFrames = 1; + this.width = SceneManager.stage.stageWidth * 0.8; + this.onGraphicsDeviceReset(); + } - /** - * - */ - public startFrame() { - // 当这个方法被多次调用时,我们跳过重置帧。 - let lock = new LockUtils(this._frameKey); - lock.lock().then(() => { - this._updateCount = parseInt(egret.localStorage.getItem(this._frameKey), 10); - if (isNaN(this._updateCount)) - this._updateCount = 0; - let count = this._updateCount; - count += 1; - egret.localStorage.setItem(this._frameKey, count.toString()); - if (this.enabled && (1 < count && count < TimeRuler.maxSampleFrames)) - return; + private onGraphicsDeviceReset() { + let layout = new Layout(); + this._position = layout.place(new Vector2(this.width, TimeRuler.barHeight), 0, 0.01, Alignment.bottomCenter).location; + } - // 更新当前帧日志。 - this._prevLog = this._logs[this.frameCount++ & 0x1]; - this._curLog = this._logs[this.frameCount & 0x1]; + /** + * + */ + public startFrame() { + // 当这个方法被多次调用时,我们跳过重置帧。 + let lock = new LockUtils(this._frameKey); + lock.lock().then(() => { + this._updateCount = parseInt(egret.localStorage.getItem(this._frameKey), 10); + if (isNaN(this._updateCount)) + this._updateCount = 0; + let count = this._updateCount; + count += 1; + egret.localStorage.setItem(this._frameKey, count.toString()); + if (this.enabled && (1 < count && count < TimeRuler.maxSampleFrames)) + return; - let endFrameTime = this.stopwacth.getTime(); - // 更新标记并创建日志。 - for (let barIndex = 0; barIndex < this._prevLog.bars.length; ++barIndex) { - let prevBar = this._prevLog.bars[barIndex]; - let nextBar = this._curLog.bars[barIndex]; + // 更新当前帧日志。 + this._prevLog = this._logs[this.frameCount++ & 0x1]; + this._curLog = this._logs[this.frameCount & 0x1]; - // 重新打开在前一帧中没有调用结束标记的标记。 - for (let nest = 0; nest < prevBar.nestCount; ++nest) { - let markerIdx = prevBar.markerNests[nest]; - prevBar.markers[markerIdx].endTime = endFrameTime; - nextBar.markerNests[nest] = nest; - nextBar.markers[nest].markerId = prevBar.markers[markerIdx].markerId; - nextBar.markers[nest].beginTime = 0; - nextBar.markers[nest].endTime = -1; - nextBar.markers[nest].color = prevBar.markers[markerIdx].color; - } + let endFrameTime = this.stopwacth.getTime(); + // 更新标记并创建日志。 + for (let barIndex = 0; barIndex < this._prevLog.bars.length; ++barIndex) { + let prevBar = this._prevLog.bars[barIndex]; + let nextBar = this._curLog.bars[barIndex]; - // 更新日志标记 - for (let markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) { - let duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime; - let markerId = prevBar.markers[markerIdx].markerId; - let m = this.markers[markerId]; + // 重新打开在前一帧中没有调用结束标记的标记。 + for (let nest = 0; nest < prevBar.nestCount; ++nest) { + let markerIdx = prevBar.markerNests[nest]; + prevBar.markers[markerIdx].endTime = endFrameTime; + nextBar.markerNests[nest] = nest; + nextBar.markers[nest].markerId = prevBar.markers[markerIdx].markerId; + nextBar.markers[nest].beginTime = 0; + nextBar.markers[nest].endTime = -1; + nextBar.markers[nest].color = prevBar.markers[markerIdx].color; + } - m.logs[barIndex].color = prevBar.markers[markerIdx].color; - if (!m.logs[barIndex].initialized) { - m.logs[barIndex].min = duration; - m.logs[barIndex].max = duration; - m.logs[barIndex].avg = duration; - m.logs[barIndex].initialized = true; - } else { - m.logs[barIndex].min = Math.min(m.logs[barIndex].min, duration); - m.logs[barIndex].max = Math.min(m.logs[barIndex].max, duration); - m.logs[barIndex].avg += duration; - m.logs[barIndex].avg *= 0.5; + // 更新日志标记 + for (let markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) { + let duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime; + let markerId = prevBar.markers[markerIdx].markerId; + let m = this.markers[markerId]; - if (m.logs[barIndex].samples++ >= TimeRuler.logSnapDuration) { - m.logs[barIndex].snapMin = m.logs[barIndex].min; - m.logs[barIndex].snapMax = m.logs[barIndex].max; - m.logs[barIndex].snapAvg = m.logs[barIndex].avg; - m.logs[barIndex].samples = 0; + m.logs[barIndex].color = prevBar.markers[markerIdx].color; + if (!m.logs[barIndex].initialized) { + m.logs[barIndex].min = duration; + m.logs[barIndex].max = duration; + m.logs[barIndex].avg = duration; + m.logs[barIndex].initialized = true; + } else { + m.logs[barIndex].min = Math.min(m.logs[barIndex].min, duration); + m.logs[barIndex].max = Math.min(m.logs[barIndex].max, duration); + m.logs[barIndex].avg += duration; + m.logs[barIndex].avg *= 0.5; + + if (m.logs[barIndex].samples++ >= TimeRuler.logSnapDuration) { + m.logs[barIndex].snapMin = m.logs[barIndex].min; + m.logs[barIndex].snapMax = m.logs[barIndex].max; + m.logs[barIndex].snapAvg = m.logs[barIndex].avg; + m.logs[barIndex].samples = 0; + } } } + + nextBar.markCount = prevBar.nestCount; + nextBar.nestCount = prevBar.nestCount; } - nextBar.markCount = prevBar.nestCount; - nextBar.nestCount = prevBar.nestCount; - } - - this.stopwacth.reset(); - this.stopwacth.start(); - }); - } - - /** - * 开始测量时间。 - * @param markerName - * @param color - */ - public beginMark(markerName: string, color: number, barIndex: number = 0) { - let lock = new LockUtils(this._frameKey); - lock.lock().then(() => { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) - throw new Error("barIndex argument out of range"); - - let bar = this._curLog.bars[barIndex]; - if (bar.markCount >= TimeRuler.maxSamples) { - throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count"); - } - - if (bar.nestCount >= TimeRuler.maxNestCall) { - throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); - } - - // 获取注册的标记 - let markerId = this._markerNameToIdMap.get(markerName); - if (isNaN(markerId)) { - // 如果此标记未注册,则注册此标记。 - markerId = this.markers.length; - this._markerNameToIdMap.set(markerName, markerId); - } - - bar.markerNests[bar.nestCount++] = bar.markCount; - bar.markers[bar.markCount].markerId = markerId; - bar.markers[bar.markCount].color = color; - bar.markers[bar.markCount].beginTime = this.stopwacth.getTime(); - bar.markers[bar.markCount].endTime = -1; - }); - } - - /** - * - * @param markerName - * @param barIndex - */ - public endMark(markerName: string, barIndex: number = 0) { - let lock = new LockUtils(this._frameKey); - lock.lock().then(() => { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) - throw new Error("barIndex argument out of range"); - - let bar = this._curLog.bars[barIndex]; - if (bar.nestCount <= 0) { - throw new Error("call beginMark method before calling endMark method"); - } - - let markerId = this._markerNameToIdMap.get(markerName); - if (isNaN(markerId)) { - throw new Error(`Marker ${markerName} is not registered. Make sure you specifed same name as you used for beginMark method`); - } - - let markerIdx = bar.markerNests[--bar.nestCount]; - if (bar.markers[markerIdx].markerId != markerId) { - throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B)."); - } - - bar.markers[markerIdx].endTime = this.stopwacth.getTime(); - }); - } - - /** - * 获取给定bar索引和标记名称的平均时间。 - * @param barIndex - * @param markerName - */ - public getAverageTime(barIndex: number, markerName: string) { - if (barIndex < 0 || barIndex >= TimeRuler.maxBars) { - throw new Error("barIndex argument out of range"); - } - let result = 0; - let markerId = this._markerNameToIdMap.get(markerName); - if (markerId) { - result = this.markers[markerId].logs[barIndex].avg; - } - - return result; - } - - /** - * - */ - public resetLog() { - let lock = new LockUtils(this._logKey); - lock.lock().then(() => { - let count = parseInt(egret.localStorage.getItem(this._logKey), 10); - count += 1; - egret.localStorage.setItem(this._logKey, count.toString()); - this.markers.forEach(markerInfo => { - for (let i = 0; i < markerInfo.logs.length; ++i){ - markerInfo.logs[i].initialized = false; - markerInfo.logs[i].snapMin = 0; - markerInfo.logs[i].snapMax = 0; - markerInfo.logs[i].snapAvg = 0; - - markerInfo.logs[i].min = 0; - markerInfo.logs[i].max = 0; - markerInfo.logs[i].avg = 0; - - markerInfo.logs[i].samples = 0; - } + this.stopwacth.reset(); + this.stopwacth.start(); }); - }); - } + } - public render(position: Vector2 = this._position, width: number = this.width){ - egret.localStorage.setItem(this._frameKey, "0"); + /** + * 开始测量时间。 + * @param markerName + * @param color + */ + public beginMark(markerName: string, color: number, barIndex: number = 0) { + let lock = new LockUtils(this._frameKey); + lock.lock().then(() => { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + throw new Error("barIndex argument out of range"); - if (!this.showLog) - return; + let bar = this._curLog.bars[barIndex]; + if (bar.markCount >= TimeRuler.maxSamples) { + throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count"); + } - let height = 0; - let maxTime = 0; - this._prevLog.bars.forEach(bar => { - if (bar.markCount > 0){ - height += TimeRuler.barHeight + TimeRuler.barPadding * 2; - maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime); + if (bar.nestCount >= TimeRuler.maxNestCall) { + throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls"); + } + + // 获取注册的标记 + let markerId = this._markerNameToIdMap.get(markerName); + if (isNaN(markerId)) { + // 如果此标记未注册,则注册此标记。 + markerId = this.markers.length; + this._markerNameToIdMap.set(markerName, markerId); + } + + bar.markerNests[bar.nestCount++] = bar.markCount; + bar.markers[bar.markCount].markerId = markerId; + bar.markers[bar.markCount].color = color; + bar.markers[bar.markCount].beginTime = this.stopwacth.getTime(); + bar.markers[bar.markCount].endTime = -1; + }); + } + + /** + * + * @param markerName + * @param barIndex + */ + public endMark(markerName: string, barIndex: number = 0) { + let lock = new LockUtils(this._frameKey); + lock.lock().then(() => { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) + throw new Error("barIndex argument out of range"); + + let bar = this._curLog.bars[barIndex]; + if (bar.nestCount <= 0) { + throw new Error("call beginMark method before calling endMark method"); + } + + let markerId = this._markerNameToIdMap.get(markerName); + if (isNaN(markerId)) { + throw new Error(`Marker ${markerName} is not registered. Make sure you specifed same name as you used for beginMark method`); + } + + let markerIdx = bar.markerNests[--bar.nestCount]; + if (bar.markers[markerIdx].markerId != markerId) { + throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B)."); + } + + bar.markers[markerIdx].endTime = this.stopwacth.getTime(); + }); + } + + /** + * 获取给定bar索引和标记名称的平均时间。 + * @param barIndex + * @param markerName + */ + public getAverageTime(barIndex: number, markerName: string) { + if (barIndex < 0 || barIndex >= TimeRuler.maxBars) { + throw new Error("barIndex argument out of range"); + } + let result = 0; + let markerId = this._markerNameToIdMap.get(markerName); + if (markerId) { + result = this.markers[markerId].logs[barIndex].avg; } - }) - const frameSpan = 1 / 60 * 1000; - let sampleSpan = this.sampleFrames * frameSpan; - - if (maxTime > sampleSpan){ - this._frameAdjust = Math.max(0, this._frameAdjust) + 1; - }else{ - this._frameAdjust = Math.min(0, this._frameAdjust) - 1; + return result; } - if (Math.max(this._frameAdjust) > TimeRuler.autoAdjustDelay){ - this.sampleFrames = Math.min(TimeRuler.maxSampleFrames, this.sampleFrames); - this.sampleFrames = Math.max(this.targetSampleFrames, (maxTime / frameSpan) + 1); + /** + * + */ + public resetLog() { + let lock = new LockUtils(this._logKey); + lock.lock().then(() => { + let count = parseInt(egret.localStorage.getItem(this._logKey), 10); + count += 1; + egret.localStorage.setItem(this._logKey, count.toString()); + this.markers.forEach(markerInfo => { + for (let i = 0; i < markerInfo.logs.length; ++i){ + markerInfo.logs[i].initialized = false; + markerInfo.logs[i].snapMin = 0; + markerInfo.logs[i].snapMax = 0; + markerInfo.logs[i].snapAvg = 0; - this._frameAdjust = 0; + markerInfo.logs[i].min = 0; + markerInfo.logs[i].max = 0; + markerInfo.logs[i].avg = 0; + + markerInfo.logs[i].samples = 0; + } + }); + }); } - let msToPs = width / sampleSpan; - let startY = position.y - (height - TimeRuler.barHeight); - let y = startY; + public render(position: Vector2 = this._position, width: number = this.width){ + egret.localStorage.setItem(this._frameKey, "0"); - // TODO: draw + if (!this.showLog) + return; + + let height = 0; + let maxTime = 0; + this._prevLog.bars.forEach(bar => { + if (bar.markCount > 0){ + height += TimeRuler.barHeight + TimeRuler.barPadding * 2; + maxTime = Math.max(maxTime, bar.markers[bar.markCount - 1].endTime); + } + }) + + const frameSpan = 1 / 60 * 1000; + let sampleSpan = this.sampleFrames * frameSpan; + + if (maxTime > sampleSpan){ + this._frameAdjust = Math.max(0, this._frameAdjust) + 1; + }else{ + this._frameAdjust = Math.min(0, this._frameAdjust) - 1; + } + + if (Math.max(this._frameAdjust) > TimeRuler.autoAdjustDelay){ + this.sampleFrames = Math.min(TimeRuler.maxSampleFrames, this.sampleFrames); + this.sampleFrames = Math.max(this.targetSampleFrames, (maxTime / frameSpan) + 1); + + this._frameAdjust = 0; + } + + let msToPs = width / sampleSpan; + let startY = position.y - (height - TimeRuler.barHeight); + let y = startY; + + // TODO: draw + } + } + + /** + * 日志信息 + */ + export class FrameLog { + public bars: MarkerCollection[]; + + constructor() { + this.bars = new Array(TimeRuler.maxBars); + this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); + } + } + + /** + * 标记的集合 + */ + export class MarkerCollection { + public markers: Marker[] = new Array(TimeRuler.maxSamples); + public markCount: number = 0; + public markerNests: number[] = new Array(TimeRuler.maxNestCall); + public nestCount: number = 0; + + constructor(){ + this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); + this.markerNests.fill(0, 0, TimeRuler.maxNestCall); + } + } + + export class Marker { + public markerId: number = 0; + public beginTime: number = 0; + public endTime: number = 0; + public color: number = 0x000000; + } + + export class MarkerInfo { + public name: string; + public logs: MarkerLog[] = new Array(TimeRuler.maxBars); + + constructor(name) { + this.name = name; + this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); + } + } + + export class MarkerLog { + public snapMin: number = 0; + public snapMax: number = 0; + public snapAvg: number = 0; + public min: number = 0; + public max: number = 0; + public avg: number = 0; + public samples: number = 0; + public color: number = 0x000000; + public initialized: boolean = false; } } - -/** - * 日志信息 - */ -class FrameLog { - public bars: MarkerCollection[]; - - constructor() { - this.bars = new Array(TimeRuler.maxBars); - this.bars.fill(new MarkerCollection(), 0, TimeRuler.maxBars); - } -} - -/** - * 标记的集合 - */ -class MarkerCollection { - public markers: Marker[] = new Array(TimeRuler.maxSamples); - public markCount: number = 0; - public markerNests: number[] = new Array(TimeRuler.maxNestCall); - public nestCount: number = 0; - - constructor(){ - this.markers.fill(new Marker(), 0, TimeRuler.maxSamples); - this.markerNests.fill(0, 0, TimeRuler.maxNestCall); - } -} - -class Marker { - public markerId: number = 0; - public beginTime: number = 0; - public endTime: number = 0; - public color: number = 0x000000; -} - -class MarkerInfo { - public name: string; - public logs: MarkerLog[] = new Array(TimeRuler.maxBars); - - constructor(name) { - this.name = name; - this.logs.fill(new MarkerLog(), 0, TimeRuler.maxBars); - } -} - -class MarkerLog { - public snapMin: number = 0; - public snapMax: number = 0; - public snapAvg: number = 0; - public min: number = 0; - public max: number = 0; - public avg: number = 0; - public samples: number = 0; - public color: number = 0x000000; - public initialized: boolean = false; -} \ No newline at end of file diff --git a/source/src/Utils/ContentManager.ts b/source/src/Utils/ContentManager.ts index 9d651295..4d80348e 100644 --- a/source/src/Utils/ContentManager.ts +++ b/source/src/Utils/ContentManager.ts @@ -1,41 +1,43 @@ -class ContentManager { - protected loadedAssets: Map = new Map(); +module es { + export class ContentManager { + protected loadedAssets: Map = new Map(); - /** 异步加载资源 */ - public loadRes(name: string, local: boolean = true): Promise { - return new Promise((resolve, reject) => { - let res = this.loadedAssets.get(name); - if (res) { - resolve(res); - return; - } + /** 异步加载资源 */ + public loadRes(name: string, local: boolean = true): Promise { + return new Promise((resolve, reject) => { + let res = this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } - if (local) { - RES.getResAsync(name).then((data) => { - this.loadedAssets.set(name, data); - resolve(data); - }).catch((err) => { - console.error("资源加载错误:", name, err); - reject(err); - }); - } else { - RES.getResByUrl(name).then((data) => { - this.loadedAssets.set(name, data); - resolve(data); - }).catch((err) => { - console.error("资源加载错误:", name, err); - reject(err); - }); - } - }); + if (local) { + RES.getResAsync(name).then((data) => { + this.loadedAssets.set(name, data); + resolve(data); + }).catch((err) => { + console.error("资源加载错误:", name, err); + reject(err); + }); + } else { + RES.getResByUrl(name).then((data) => { + this.loadedAssets.set(name, data); + resolve(data); + }).catch((err) => { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }); + } + + public dispose() { + this.loadedAssets.forEach(value => { + let assetsToRemove = value; + assetsToRemove.dispose(); + }); + + this.loadedAssets.clear(); + } } - - public dispose() { - this.loadedAssets.forEach(value => { - let assetsToRemove = value; - assetsToRemove.dispose(); - }); - - this.loadedAssets.clear(); - } -} \ No newline at end of file +} diff --git a/source/src/Utils/DrawUtils.ts b/source/src/Utils/DrawUtils.ts index 54be26fd..2ae27506 100644 --- a/source/src/Utils/DrawUtils.ts +++ b/source/src/Utils/DrawUtils.ts @@ -1,59 +1,61 @@ -/** 各种辅助方法来辅助绘图 */ -class DrawUtils { - public static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness: number = 1){ - this.drawLineAngle(shape, start, MathHelper.angleBetweenVectors(start, end), Vector2.distance(start, end), color, thickness); - } - - public static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness = 1){ - shape.graphics.beginFill(color); - shape.graphics.drawRect(start.x, start.y, 1, 1); - shape.graphics.endFill(); - - shape.scaleX = length; - shape.scaleY = thickness; - shape.$anchorOffsetX = 0; - shape.$anchorOffsetY = 0; - shape.rotation = radians; - } - - public static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness = 1){ - this.drawHollowRectR(shape, rect.x, rect.y, rect.width, rect.height, color, thickness); - } - - public static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness = 1){ - let tl = new Vector2(x, y).round(); - let tr = new Vector2(x + width, y).round(); - let br = new Vector2(x + width, y + height).round(); - let bl = new Vector2(x, y + height).round(); - - this.drawLine(shape, tl, tr, color, thickness); - this.drawLine(shape, tr, br, color, thickness); - this.drawLine(shape, br, bl, color, thickness); - this.drawLine(shape, bl, tl, color, thickness); - } - - public static drawPixel(shape: egret.Shape, position: Vector2, color: number, size: number = 1){ - let destRect = new Rectangle(position.x, position.y, size, size); - if (size != 1){ - destRect.x -= size * 0.5; - destRect.y -= size * 0.5; +module es { + /** 各种辅助方法来辅助绘图 */ + export class DrawUtils { + public static drawLine(shape: egret.Shape, start: Vector2, end: Vector2, color: number, thickness: number = 1){ + this.drawLineAngle(shape, start, MathHelper.angleBetweenVectors(start, end), Vector2.distance(start, end), color, thickness); } - shape.graphics.beginFill(color); - shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height); - shape.graphics.endFill(); - } + public static drawLineAngle(shape: egret.Shape, start: Vector2, radians: number, length: number, color: number, thickness = 1){ + shape.graphics.beginFill(color); + shape.graphics.drawRect(start.x, start.y, 1, 1); + shape.graphics.endFill(); - public static getColorMatrix(color: number): egret.ColorMatrixFilter{ - let colorMatrix = [ - 1, 0, 0, 0, 0, - 0, 1, 0, 0, 0, - 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0 - ]; - colorMatrix[0] = Math.floor(color / 256 / 256) / 255; - colorMatrix[6] = Math.floor(color / 256 % 256) / 255; - colorMatrix[12] = color % 256 / 255; - return new egret.ColorMatrixFilter(colorMatrix); + shape.scaleX = length; + shape.scaleY = thickness; + shape.$anchorOffsetX = 0; + shape.$anchorOffsetY = 0; + shape.rotation = radians; + } + + public static drawHollowRect(shape: egret.Shape, rect: Rectangle, color: number, thickness = 1){ + this.drawHollowRectR(shape, rect.x, rect.y, rect.width, rect.height, color, thickness); + } + + public static drawHollowRectR(shape: egret.Shape, x: number, y: number, width: number, height: number, color: number, thickness = 1){ + let tl = new Vector2(x, y).round(); + let tr = new Vector2(x + width, y).round(); + let br = new Vector2(x + width, y + height).round(); + let bl = new Vector2(x, y + height).round(); + + this.drawLine(shape, tl, tr, color, thickness); + this.drawLine(shape, tr, br, color, thickness); + this.drawLine(shape, br, bl, color, thickness); + this.drawLine(shape, bl, tl, color, thickness); + } + + public static drawPixel(shape: egret.Shape, position: Vector2, color: number, size: number = 1){ + let destRect = new Rectangle(position.x, position.y, size, size); + if (size != 1){ + destRect.x -= size * 0.5; + destRect.y -= size * 0.5; + } + + shape.graphics.beginFill(color); + shape.graphics.drawRect(destRect.x, destRect.y, destRect.width, destRect.height); + shape.graphics.endFill(); + } + + public static getColorMatrix(color: number): egret.ColorMatrixFilter{ + let colorMatrix = [ + 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 + ]; + colorMatrix[0] = Math.floor(color / 256 / 256) / 255; + colorMatrix[6] = Math.floor(color / 256 % 256) / 255; + colorMatrix[12] = color % 256 / 255; + return new egret.ColorMatrixFilter(colorMatrix); + } } -} \ No newline at end of file +} diff --git a/source/src/Utils/Emitter.ts b/source/src/Utils/Emitter.ts index a9c91edf..521aa9b8 100644 --- a/source/src/Utils/Emitter.ts +++ b/source/src/Utils/Emitter.ts @@ -1,68 +1,69 @@ -/** - * 用于事件管理 - */ -class Emitter { - private _messageTable: Map; - - constructor(){ - this._messageTable = new Map(); - } - +module es { /** - * 开始监听项 - * @param eventType 监听类型 - * @param handler 监听函数 - * @param context 监听上下文 + * 用于包装事件的一个小类 */ - public addObserver(eventType: T, handler: Function, context: any){ - let list: FuncPack[] = this._messageTable.get(eventType); - if (!list){ - list = []; - this._messageTable.set(eventType, list); + export class FuncPack { + /** 函数 */ + public func: Function; + /** 上下文 */ + public context: any; + + constructor(func: Function, context: any){ + this.func = func; + this.context = context; + } + } + /** + * 用于事件管理 + */ + export class Emitter { + private _messageTable: Map; + + constructor(){ + this._messageTable = new Map(); } - if (list.contains(handler)) - console.warn("您试图添加相同的观察者两次"); - list.push(new FuncPack(handler, context)); - } + /** + * 开始监听项 + * @param eventType 监听类型 + * @param handler 监听函数 + * @param context 监听上下文 + */ + public addObserver(eventType: T, handler: Function, context: any){ + let list: FuncPack[] = this._messageTable.get(eventType); + if (!list){ + list = []; + this._messageTable.set(eventType, list); + } - /** - * 移除监听项 - * @param eventType 事件类型 - * @param handler 事件函数 - */ - public removeObserver(eventType: T, handler: Function){ - let messageData = this._messageTable.get(eventType); - let index = messageData.findIndex(data => data.func == handler); - if (index != -1) - messageData.removeAt(index); - } + if (list.contains(handler)) + console.warn("您试图添加相同的观察者两次"); + list.push(new FuncPack(handler, context)); + } - /** - * 触发该事件 - * @param eventType 事件类型 - * @param data 事件数据 - */ - public emit(eventType: T, data?: any){ - let list: FuncPack[] = this._messageTable.get(eventType); - if (list){ - for (let i = list.length - 1; i >= 0; i --) - list[i].func.call(list[i].context, data); + /** + * 移除监听项 + * @param eventType 事件类型 + * @param handler 事件函数 + */ + public removeObserver(eventType: T, handler: Function){ + let messageData = this._messageTable.get(eventType); + let index = messageData.findIndex(data => data.func == handler); + if (index != -1) + messageData.removeAt(index); + } + + /** + * 触发该事件 + * @param eventType 事件类型 + * @param data 事件数据 + */ + public emit(eventType: T, data?: any){ + let list: FuncPack[] = this._messageTable.get(eventType); + if (list){ + for (let i = list.length - 1; i >= 0; i --) + list[i].func.call(list[i].context, data); + } } } } - -/** - * 用于包装事件的一个小类 - */ -class FuncPack { - /** 函数 */ - public func: Function; - /** 上下文 */ - public context: any; - - constructor(func: Function, context: any){ - this.func = func; - this.context = context; - } -} \ No newline at end of file diff --git a/source/src/Utils/GlobalManager.ts b/source/src/Utils/GlobalManager.ts index 1e48ee99..e962b6c3 100644 --- a/source/src/Utils/GlobalManager.ts +++ b/source/src/Utils/GlobalManager.ts @@ -1,46 +1,48 @@ -class GlobalManager { - public static globalManagers: GlobalManager[] = []; - private _enabled: boolean; +module es { + export class GlobalManager { + public static globalManagers: GlobalManager[] = []; + private _enabled: boolean; - public get enabled(){ - return this._enabled; - } - public set enabled(value: boolean){ - this.setEnabled(value); - } - public setEnabled(isEnabled: boolean){ - if (this._enabled != isEnabled){ - this._enabled = isEnabled; - if (this._enabled){ - this.onEnabled(); - } else { - this.onDisabled(); + public get enabled(){ + return this._enabled; + } + public set enabled(value: boolean){ + this.setEnabled(value); + } + public setEnabled(isEnabled: boolean){ + if (this._enabled != isEnabled){ + this._enabled = isEnabled; + if (this._enabled){ + this.onEnabled(); + } else { + this.onDisabled(); + } } } - } - public onEnabled(){} + public onEnabled(){} - public onDisabled(){} + public onDisabled(){} - public update(){} + public update(){} - public static registerGlobalManager(manager: GlobalManager){ - this.globalManagers.push(manager); - manager.enabled = true; - } - - public static unregisterGlobalManager(manager: GlobalManager){ - this.globalManagers.remove(manager); - manager.enabled = false; - } - - public static getGlobalManager(type){ - for (let i = 0; i < this.globalManagers.length; i ++){ - if (this.globalManagers[i] instanceof type) - return this.globalManagers[i] as T; + public static registerGlobalManager(manager: GlobalManager){ + this.globalManagers.push(manager); + manager.enabled = true; } - return null; + public static unregisterGlobalManager(manager: GlobalManager){ + this.globalManagers.remove(manager); + manager.enabled = false; + } + + public static getGlobalManager(type){ + for (let i = 0; i < this.globalManagers.length; i ++){ + if (this.globalManagers[i] instanceof type) + return this.globalManagers[i] as T; + } + + return null; + } } -} \ No newline at end of file +} diff --git a/source/src/Utils/Input.ts b/source/src/Utils/Input.ts index 09d961f9..a66e9493 100644 --- a/source/src/Utils/Input.ts +++ b/source/src/Utils/Input.ts @@ -1,147 +1,149 @@ -class TouchState { - public x = 0; - public y = 0; - public touchPoint: number = -1; - public touchDown: boolean = false; - public get position(){ - return new Vector2(this.x, this.y); - } - - public reset(){ - this.x = 0; - this.y = 0; - this.touchDown = false; - this.touchPoint = -1; - } -} - -class Input { - private static _init: boolean = false; - private static _stage: egret.Stage; - private static _previousTouchState: TouchState = new TouchState(); - private static _gameTouchs: TouchState[] = []; - private static _resolutionOffset: Vector2 = new Vector2(); - private static _resolutionScale: Vector2 = Vector2.one; - private static _touchIndex: number = 0; - private static _totalTouchCount: number = 0; - /** 返回第一个触摸点的坐标 */ - public static get touchPosition(){ - if (!this._gameTouchs[0]) - return Vector2.zero; - return this._gameTouchs[0].position; - } - /** 获取最大触摸数 */ - public static get maxSupportedTouch(){ - return this._stage.maxTouches; - } - /** - * 设置最大触摸数 - */ - public static set maxSupportedTouch(value: number){ - this._stage.maxTouches = value; - this.initTouchCache(); - } - /** 获取缩放值 默认为1 */ - public static get resolutionScale(){ - return this._resolutionScale; - } - /** 当前触摸点数量 */ - public static get totalTouchCount(){ - return this._totalTouchCount; - } - /** - * 触摸列表 存放最大个数量触摸点信息 - * 可通过判断touchPoint是否为-1 来确定是否为有触摸 - * 通过判断touchDown 判断触摸点是否有按下 - */ - public static get gameTouchs(){ - return this._gameTouchs; - } - - /** 获取第一个触摸点距离上次距离的增量 */ - public static get touchPositionDelta(){ - let delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position); - if (delta.length() > 0){ - this.setpreviousTouchState(this._gameTouchs[0]); +module es { + export class TouchState { + public x = 0; + public y = 0; + public touchPoint: number = -1; + public touchDown: boolean = false; + public get position(){ + return new Vector2(this.x, this.y); } - return delta; - } - public static initialize(stage: egret.Stage){ - if (this._init) - return; - - this._init = true; - this._stage = stage; - this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); - - this.initTouchCache(); - } - - private static initTouchCache(){ - this._totalTouchCount = 0; - this._touchIndex = 0; - this._gameTouchs.length = 0; - for (let i = 0; i < this.maxSupportedTouch; i ++){ - this._gameTouchs.push(new TouchState()); + public reset(){ + this.x = 0; + this.y = 0; + this.touchDown = false; + this.touchPoint = -1; } } - private static touchBegin(evt: egret.TouchEvent){ - if (this._touchIndex < this.maxSupportedTouch){ - this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; - this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; - this._gameTouchs[this._touchIndex].x = evt.stageX; - this._gameTouchs[this._touchIndex].y = evt.stageY; - if (this._touchIndex == 0){ + export class Input { + private static _init: boolean = false; + private static _stage: egret.Stage; + private static _previousTouchState: TouchState = new TouchState(); + private static _gameTouchs: TouchState[] = []; + private static _resolutionOffset: Vector2 = new Vector2(); + private static _resolutionScale: Vector2 = Vector2.one; + private static _touchIndex: number = 0; + private static _totalTouchCount: number = 0; + /** 返回第一个触摸点的坐标 */ + public static get touchPosition(){ + if (!this._gameTouchs[0]) + return Vector2.zero; + return this._gameTouchs[0].position; + } + /** 获取最大触摸数 */ + public static get maxSupportedTouch(){ + return this._stage.maxTouches; + } + /** + * 设置最大触摸数 + */ + public static set maxSupportedTouch(value: number){ + this._stage.maxTouches = value; + this.initTouchCache(); + } + /** 获取缩放值 默认为1 */ + public static get resolutionScale(){ + return this._resolutionScale; + } + /** 当前触摸点数量 */ + public static get totalTouchCount(){ + return this._totalTouchCount; + } + /** + * 触摸列表 存放最大个数量触摸点信息 + * 可通过判断touchPoint是否为-1 来确定是否为有触摸 + * 通过判断touchDown 判断触摸点是否有按下 + */ + public static get gameTouchs(){ + return this._gameTouchs; + } + + /** 获取第一个触摸点距离上次距离的增量 */ + public static get touchPositionDelta(){ + let delta = Vector2.subtract(this.touchPosition, this._previousTouchState.position); + if (delta.length() > 0){ this.setpreviousTouchState(this._gameTouchs[0]); } - this._touchIndex ++; - this._totalTouchCount ++; - } - } - - private static touchMove(evt: egret.TouchEvent){ - if (evt.touchPointID == this._gameTouchs[0].touchPoint){ - this.setpreviousTouchState(this._gameTouchs[0]); + return delta; } - let touchIndex = this._gameTouchs.findIndex(touch => touch.touchPoint == evt.touchPointID); - if (touchIndex != -1){ - let touchData = this._gameTouchs[touchIndex]; - touchData.x = evt.stageX; - touchData.y = evt.stageY; - } - } + public static initialize(stage: egret.Stage){ + if (this._init) + return; - private static touchEnd(evt: egret.TouchEvent){ - let touchIndex = this._gameTouchs.findIndex(touch => touch.touchPoint == evt.touchPointID); - if (touchIndex != -1){ - let touchData = this._gameTouchs[touchIndex]; - touchData.reset(); - if (touchIndex == 0) - this._previousTouchState.reset(); - this._totalTouchCount --; - if (this.totalTouchCount == 0){ - this._touchIndex = 0; + this._init = true; + this._stage = stage; + this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); + + this.initTouchCache(); + } + + private static initTouchCache(){ + this._totalTouchCount = 0; + this._touchIndex = 0; + this._gameTouchs.length = 0; + for (let i = 0; i < this.maxSupportedTouch; i ++){ + this._gameTouchs.push(new TouchState()); } } - } - private static setpreviousTouchState(touchState: TouchState){ - this._previousTouchState = new TouchState(); - this._previousTouchState.x = touchState.position.x; - this._previousTouchState.y = touchState.position.y; - this._previousTouchState.touchPoint = touchState.touchPoint; - this._previousTouchState.touchDown = touchState.touchDown; - } + private static touchBegin(evt: egret.TouchEvent){ + if (this._touchIndex < this.maxSupportedTouch){ + this._gameTouchs[this._touchIndex].touchPoint = evt.touchPointID; + this._gameTouchs[this._touchIndex].touchDown = evt.touchDown; + this._gameTouchs[this._touchIndex].x = evt.stageX; + this._gameTouchs[this._touchIndex].y = evt.stageY; + if (this._touchIndex == 0){ + this.setpreviousTouchState(this._gameTouchs[0]); + } + this._touchIndex ++; + this._totalTouchCount ++; + } + } - public static scaledPosition(position: Vector2){ - let scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); - return Vector2.multiply(scaledPos, this.resolutionScale); + private static touchMove(evt: egret.TouchEvent){ + if (evt.touchPointID == this._gameTouchs[0].touchPoint){ + this.setpreviousTouchState(this._gameTouchs[0]); + } + + let touchIndex = this._gameTouchs.findIndex(touch => touch.touchPoint == evt.touchPointID); + if (touchIndex != -1){ + let touchData = this._gameTouchs[touchIndex]; + touchData.x = evt.stageX; + touchData.y = evt.stageY; + } + } + + private static touchEnd(evt: egret.TouchEvent){ + let touchIndex = this._gameTouchs.findIndex(touch => touch.touchPoint == evt.touchPointID); + if (touchIndex != -1){ + let touchData = this._gameTouchs[touchIndex]; + touchData.reset(); + if (touchIndex == 0) + this._previousTouchState.reset(); + this._totalTouchCount --; + if (this.totalTouchCount == 0){ + this._touchIndex = 0; + } + } + } + + private static setpreviousTouchState(touchState: TouchState){ + this._previousTouchState = new TouchState(); + this._previousTouchState.x = touchState.position.x; + this._previousTouchState.y = touchState.position.y; + this._previousTouchState.touchPoint = touchState.touchPoint; + this._previousTouchState.touchDown = touchState.touchDown; + } + + public static scaledPosition(position: Vector2){ + let scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y); + return Vector2.multiply(scaledPos, this.resolutionScale); + } } -} \ No newline at end of file +} diff --git a/source/src/Utils/ListPool.ts b/source/src/Utils/ListPool.ts index a208a76f..f40a6dc2 100644 --- a/source/src/Utils/ListPool.ts +++ b/source/src/Utils/ListPool.ts @@ -1,54 +1,56 @@ -/** - * 可以用于列表池的简单类 - */ -class ListPool { - private static readonly _objectQueue = []; - +module es { /** - * 预热缓存,使用最大的cacheCount对象填充缓存 - * @param cacheCount + * 可以用于列表池的简单类 */ - public static warmCache(cacheCount: number){ - cacheCount -= this._objectQueue.length; - if (cacheCount > 0){ - for (let i = 0; i < cacheCount; i ++){ - this._objectQueue.unshift([]); + export class ListPool { + private static readonly _objectQueue = []; + + /** + * 预热缓存,使用最大的cacheCount对象填充缓存 + * @param cacheCount + */ + public static warmCache(cacheCount: number){ + cacheCount -= this._objectQueue.length; + if (cacheCount > 0){ + for (let i = 0; i < cacheCount; i ++){ + this._objectQueue.unshift([]); + } } } - } - /** - * 将缓存修剪为cacheCount项目 - * @param cacheCount - */ - public static trimCache(cacheCount){ - while (cacheCount > this._objectQueue.length) - this._objectQueue.shift(); - } + /** + * 将缓存修剪为cacheCount项目 + * @param cacheCount + */ + public static trimCache(cacheCount){ + while (cacheCount > this._objectQueue.length) + this._objectQueue.shift(); + } - /** - * 清除缓存 - */ - public static clearCache(){ - this._objectQueue.length = 0; - } + /** + * 清除缓存 + */ + public static clearCache(){ + this._objectQueue.length = 0; + } - /** - * 如果可以的话,从堆栈中弹出一个项 - */ - public static obtain(): T[] { - if (this._objectQueue.length > 0) - return this._objectQueue.shift(); + /** + * 如果可以的话,从堆栈中弹出一个项 + */ + public static obtain(): T[] { + if (this._objectQueue.length > 0) + return this._objectQueue.shift(); - return []; - } + return []; + } - /** - * 将项推回堆栈 - * @param obj - */ - public static free(obj: Array){ - this._objectQueue.unshift(obj); - obj.length = 0; + /** + * 将项推回堆栈 + * @param obj + */ + public static free(obj: Array){ + this._objectQueue.unshift(obj); + obj.length = 0; + } } -} \ No newline at end of file +} diff --git a/source/src/Utils/Pair.ts b/source/src/Utils/Pair.ts index cc3cf6f2..f11e98bf 100644 --- a/source/src/Utils/Pair.ts +++ b/source/src/Utils/Pair.ts @@ -1,20 +1,22 @@ -/** - * 用于管理一对对象的简单DTO - */ -class Pair { - public first: T; - public second: T; +module es { + /** + * 用于管理一对对象的简单DTO + */ + export class Pair { + public first: T; + public second: T; - constructor(first: T, second: T){ - this.first = first; - this.second = second; - } + constructor(first: T, second: T){ + this.first = first; + this.second = second; + } - public clear(){ - this.first = this.second = null; - } + public clear(){ + this.first = this.second = null; + } - public equals(other: Pair){ - return this.first == other.first && this.second == other.second; + public equals(other: Pair){ + return this.first == other.first && this.second == other.second; + } } -} \ No newline at end of file +} diff --git a/source/src/Utils/RectangleExt.ts b/source/src/Utils/RectangleExt.ts index 4b83e05f..03eb3124 100644 --- a/source/src/Utils/RectangleExt.ts +++ b/source/src/Utils/RectangleExt.ts @@ -1,17 +1,19 @@ -class RectangleExt { - /** - * 计算两个矩形的并集。结果将是一个包含其他两个的矩形。 - * @param first - * @param point - */ - public static union(first: Rectangle, point: Vector2){ - let rect = new Rectangle(point.x, point.y, 0, 0); - // let rectResult = first.union(rect); - let result = new Rectangle(); - result.x = Math.min(first.x, rect.x); - result.y = Math.min(first.y, rect.y); - result.width = Math.max(first.right, rect.right) - result.x; - result.height = Math.max(first.bottom, result.bottom) - result.y; - return result; +module es { + export class RectangleExt { + /** + * 计算两个矩形的并集。结果将是一个包含其他两个的矩形。 + * @param first + * @param point + */ + public static union(first: Rectangle, point: Vector2){ + let rect = new Rectangle(point.x, point.y, 0, 0); + // let rectResult = first.union(rect); + let result = new Rectangle(); + result.x = Math.min(first.x, rect.x); + result.y = Math.min(first.y, rect.y); + result.width = Math.max(first.right, rect.right) - result.x; + result.height = Math.max(first.bottom, result.bottom) - result.y; + return result; + } } -} \ No newline at end of file +} diff --git a/source/src/Utils/Triangulator.ts b/source/src/Utils/Triangulator.ts index e283e4ce..2ec650c4 100644 --- a/source/src/Utils/Triangulator.ts +++ b/source/src/Utils/Triangulator.ts @@ -1,111 +1,113 @@ -/** - * 三角剖分 - */ -class Triangulator { - /** - * 最后一次三角调用中使用的点列表的三角形列表项的索引 - */ - public triangleIndices: number[] = []; - - private _triPrev: number[] = new Array(12); - private _triNext: number[] = new Array(12); - +module es { /** - * 计算一个三角形列表,该列表完全覆盖给定点集所包含的区域。如果点不是CCW,则将arePointsCCW参数传递为false - * @param points 定义封闭路径的点列表 - * @param arePointsCCW + * 三角剖分 */ - public triangulate(points: Vector2[], arePointsCCW: boolean = true){ - let count = points.length; + export class Triangulator { + /** + * 最后一次三角调用中使用的点列表的三角形列表项的索引 + */ + public triangleIndices: number[] = []; - // 设置前一个链接和下一个链接 - this.initialize(count); + private _triPrev: number[] = new Array(12); + private _triNext: number[] = new Array(12); - // 非三角的多边形断路器 - let iterations = 0; + /** + * 计算一个三角形列表,该列表完全覆盖给定点集所包含的区域。如果点不是CCW,则将arePointsCCW参数传递为false + * @param points 定义封闭路径的点列表 + * @param arePointsCCW + */ + public triangulate(points: Vector2[], arePointsCCW: boolean = true){ + let count = points.length; - // 从0开始 - let index = 0; + // 设置前一个链接和下一个链接 + this.initialize(count); - // 继续移除所有的三角形,直到只剩下一个三角形 - while (count > 3 && iterations < 500){ - iterations ++; + // 非三角的多边形断路器 + let iterations = 0; - let isEar = true; - let a = points[this._triPrev[index]]; - let b = points[index]; - let c = points[this._triNext[index]]; + // 从0开始 + let index = 0; - if (Vector2Ext.isTriangleCCW(a, b, c)){ - let k = this._triNext[this._triNext[index]]; - do { - if (Triangulator.testPointTriangle(points[k], a, b, c)){ - isEar = false; - break; - } + // 继续移除所有的三角形,直到只剩下一个三角形 + while (count > 3 && iterations < 500){ + iterations ++; - k = this._triNext[k]; - } while (k != this._triPrev[index]); - }else{ - isEar = false; + let isEar = true; + let a = points[this._triPrev[index]]; + let b = points[index]; + let c = points[this._triNext[index]]; + + if (Vector2Ext.isTriangleCCW(a, b, c)){ + let k = this._triNext[this._triNext[index]]; + do { + if (Triangulator.testPointTriangle(points[k], a, b, c)){ + isEar = false; + break; + } + + k = this._triNext[k]; + } while (k != this._triPrev[index]); + }else{ + isEar = false; + } + + if (isEar){ + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); + + // 删除vert通过重定向相邻vert的上一个和下一个链接,从而减少vertext计数 + this._triNext[this._triPrev[index]] = this._triNext[index]; + this._triPrev[this._triNext[index]] = this._triPrev[index]; + count --; + + // 接下来访问前一个vert + index = this._triPrev[index]; + }else{ + index = this._triNext[index]; + } } - if (isEar){ - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); + this.triangleIndices.push(this._triPrev[index]); + this.triangleIndices.push(index); + this.triangleIndices.push(this._triNext[index]); - // 删除vert通过重定向相邻vert的上一个和下一个链接,从而减少vertext计数 - this._triNext[this._triPrev[index]] = this._triNext[index]; - this._triPrev[this._triNext[index]] = this._triPrev[index]; - count --; + if (!arePointsCCW) + this.triangleIndices.reverse(); + } - // 接下来访问前一个vert - index = this._triPrev[index]; - }else{ - index = this._triNext[index]; + private initialize(count: number){ + this.triangleIndices.length = 0; + + if (this._triNext.length < count){ + this._triNext.reverse(); + this._triNext = new Array(Math.max(this._triNext.length * 2, count)); } + if (this._triPrev.length < count){ + this._triPrev.reverse(); + this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); + } + + for (let i = 0; i < count;i ++){ + this._triPrev[i] = i - 1; + this._triNext[i] = i + 1; + } + + this._triPrev[0] = count - 1; + this._triNext[count - 1] = 0; } - this.triangleIndices.push(this._triPrev[index]); - this.triangleIndices.push(index); - this.triangleIndices.push(this._triNext[index]); + public static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean{ + if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0) + return false; - if (!arePointsCCW) - this.triangleIndices.reverse(); - } + if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0) + return false; - private initialize(count: number){ - this.triangleIndices.length = 0; + if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0) + return false; - if (this._triNext.length < count){ - this._triNext.reverse(); - this._triNext = new Array(Math.max(this._triNext.length * 2, count)); - } - if (this._triPrev.length < count){ - this._triPrev.reverse(); - this._triPrev = new Array(Math.max(this._triPrev.length * 2, count)); + return true; } - - for (let i = 0; i < count;i ++){ - this._triPrev[i] = i - 1; - this._triNext[i] = i + 1; - } - - this._triPrev[0] = count - 1; - this._triNext[count - 1] = 0; } - - public static testPointTriangle(point: Vector2, a: Vector2, b: Vector2, c: Vector2): boolean{ - if (Vector2Ext.cross(Vector2.subtract(point, a), Vector2.subtract(b, a)) < 0) - return false; - - if (Vector2Ext.cross(Vector2.subtract(point, b), Vector2.subtract(c, b)) < 0) - return false; - - if (Vector2Ext.cross(Vector2.subtract(point, c), Vector2.subtract(a, c)) < 0) - return false; - - return true; - } -} \ No newline at end of file +} diff --git a/source/src/Utils/Vector2Ext.ts b/source/src/Utils/Vector2Ext.ts index 17789716..60ee6a4d 100644 --- a/source/src/Utils/Vector2Ext.ts +++ b/source/src/Utils/Vector2Ext.ts @@ -1,59 +1,60 @@ -class Vector2Ext { - /** - * 检查三角形是CCW还是CW - * @param a - * @param center - * @param c - */ - public static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2) { - return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; - } - - /** - * 计算二维伪叉乘点(Perp(u), v) - * @param u - * @param v - */ - public static cross(u: Vector2, v: Vector2) { - return u.y * v.x - u.x * v.y; - } - - /** - * 返回与传入向量垂直的向量 - * @param first - * @param second - */ - public static perpendicular(first: Vector2, second: Vector2) { - return new Vector2(-1 * (second.y - first.y), second.x - first.x); - } - - /** - * Vector2的临时解决方案 - * 标准化把向量弄乱了 - * @param vec - */ - public static normalize(vec: Vector2) { - let magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); - if (magnitude > MathHelper.Epsilon) { - vec = Vector2.divide(vec, new Vector2(magnitude)); - } else { - vec.x = vec.y = 0; +module es { + export class Vector2Ext { + /** + * 检查三角形是CCW还是CW + * @param a + * @param center + * @param c + */ + public static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2) { + return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; } - return vec; - } + /** + * 计算二维伪叉乘点(Perp(u), v) + * @param u + * @param v + */ + public static cross(u: Vector2, v: Vector2) { + return u.y * v.x - u.x * v.y; + } - /** - * 通过指定的矩阵对Vector2的数组中的向量应用变换,并将结果放置在另一个数组中。 - * @param sourceArray - * @param sourceIndex - * @param matrix - * @param destinationArray - * @param destinationIndex - * @param length - */ - public static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, - destinationArray: Vector2[], destinationIndex: number, length: number) { + /** + * 返回与传入向量垂直的向量 + * @param first + * @param second + */ + public static perpendicular(first: Vector2, second: Vector2) { + return new Vector2(-1 * (second.y - first.y), second.x - first.x); + } + + /** + * Vector2的临时解决方案 + * 标准化把向量弄乱了 + * @param vec + */ + public static normalize(vec: Vector2) { + let magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y)); + if (magnitude > MathHelper.Epsilon) { + vec = Vector2.divide(vec, new Vector2(magnitude)); + } else { + vec.x = vec.y = 0; + } + + return vec; + } + + /** + * 通过指定的矩阵对Vector2的数组中的向量应用变换,并将结果放置在另一个数组中。 + * @param sourceArray + * @param sourceIndex + * @param matrix + * @param destinationArray + * @param destinationIndex + * @param length + */ + public static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, + destinationArray: Vector2[], destinationIndex: number, length: number) { for (let i = 0; i < length; i ++){ let position = sourceArray[sourceIndex + i]; let destination = destinationArray[destinationIndex + i]; @@ -61,25 +62,26 @@ class Vector2Ext { destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; destinationArray[destinationIndex + i] = destination; } - } + } - public static transformR(position: Vector2, matrix: Matrix2D){ - let x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; - let y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; - return new Vector2(x, y); - } + public static transformR(position: Vector2, matrix: Matrix2D){ + let x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31; + let y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32; + return new Vector2(x, y); + } - /** - * 通过指定的矩阵对Vector2的数组中的所有向量应用变换,并将结果放到另一个数组中。 - * @param sourceArray - * @param matrix - * @param destinationArray - */ - public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) { - this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); - } + /** + * 通过指定的矩阵对Vector2的数组中的所有向量应用变换,并将结果放到另一个数组中。 + * @param sourceArray + * @param matrix + * @param destinationArray + */ + public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) { + this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length); + } - public static round(vec: Vector2){ - return new Vector2(Math.round(vec.x), Math.round(vec.y)); + public static round(vec: Vector2){ + return new Vector2(Math.round(vec.x), Math.round(vec.y)); + } } -} \ No newline at end of file +} From e61dd0c16bbd3d46a2fb4294ff4f3093bd6bcd74 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Thu, 23 Jul 2020 13:25:10 +0800 Subject: [PATCH 06/15] =?UTF-8?q?=E4=BC=98=E5=8C=96matrix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.d.ts | 66 ++- demo/libs/framework/framework.js | 401 ++++++++++++------ demo/libs/framework/framework.min.js | 2 +- source/bin/framework.d.ts | 66 ++- source/bin/framework.js | 401 ++++++++++++------ source/bin/framework.min.js | 2 +- source/src/ECS/Components/Camera.ts | 163 ++++++- .../Components/Physics/Colliders/Collider.ts | 48 ++- source/src/Math/Matrix2D.ts | 274 +++++------- source/src/Math/Vector2.ts | 40 ++ source/src/Physics/Shapes/Polygon.ts | 36 ++ source/src/Physics/Shapes/Shape.ts | 4 + 12 files changed, 1009 insertions(+), 494 deletions(-) diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index 6c72ef06..9f76bfa9 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -114,6 +114,10 @@ declare module es { static readonly unitX: Vector2; static readonly unitY: Vector2; constructor(x?: number, y?: number); + add(value: Vector2): Vector2; + divide(value: Vector2): Vector2; + multiply(value: Vector2): Vector2; + subtract(value: Vector2): this; static add(value1: Vector2, value2: Vector2): Vector2; static divide(value1: Vector2, value2: Vector2): Vector2; static multiply(value1: Vector2, value2: Vector2): Vector2; @@ -401,6 +405,12 @@ declare module es { lockOn = 0, cameraWindow = 1 } + class CameraInset { + left: number; + right: number; + top: number; + bottom: number; + } class Camera extends Component { position: Vector2; rotation: number; @@ -408,11 +418,20 @@ declare module es { minimumZoom: number; maximumZoom: number; readonly bounds: Rectangle; + readonly transformMatrix: Matrix2D; + readonly inverseTransformMatrix: Matrix2D; origin: Vector2; - private _zoom; - private _minimumZoom; - private _maximumZoom; - private _origin; + _zoom: any; + _minimumZoom: number; + _maximumZoom: number; + _bounds: Rectangle; + _inset: CameraInset; + _transformMatrix: Matrix2D; + _inverseTransformMatrix: Matrix2D; + _origin: Vector2; + _areMatrixedDirty: boolean; + _areBoundsDirty: boolean; + _isProjectionMatrixDirty: boolean; followLerp: number; deadzone: Rectangle; focusOffset: Vector2; @@ -425,13 +444,19 @@ declare module es { _worldSpaceDeadZone: Rectangle; constructor(targetEntity?: Entity, cameraStyle?: CameraStyle); onSceneSizeChanged(newWidth: number, newHeight: number): void; + protected updateMatrixes(): void; + setInset(left: number, right: number, top: number, bottom: number): Camera; setPosition(position: Vector2): this; setRotation(rotation: number): Camera; setZoom(zoom: number): Camera; setMinimumZoom(minZoom: number): Camera; setMaximumZoom(maxZoom: number): Camera; + onEntityTransformChanged(comp: transform.Component): void; zoomIn(deltaZoom: number): void; zoomOut(deltaZoom: number): void; + worldToScreenPoint(worldPosition: Vector2): Vector2; + screenToWorldPoint(screenPosition: Vector2): Vector2; + mouseToWorldPoint(): Vector2; onAddedToEntity(): void; update(): void; clampToMapSize(position: Vector2): Vector2; @@ -626,6 +651,8 @@ declare module es { _localOffsetLength: number; protected _isParentEntityAddedToScene: any; protected _isColliderRegistered: any; + _isPositionDirty: boolean; + _isRotationDirty: boolean; setLocalOffset(offset: Vector2): Collider; setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider; onAddedToEntity(): void; @@ -637,6 +664,7 @@ declare module es { unregisterColliderWithPhysicsSystem(): void; overlaps(other: Collider): any; collidesWith(collider: Collider, motion: Vector2): CollisionResult; + clone(): Component; } } declare module es { @@ -1079,31 +1107,24 @@ declare module es { } } declare module es { - class Matrix2D { + class Matrix2D extends egret.Matrix { m11: number; m12: number; m21: number; m22: number; m31: number; m32: number; - private static _identity; - static readonly identity: Matrix2D; - constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number); - translation: Vector2; - rotation: number; - rotationDegrees: number; - scale: Vector2; - static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static divide(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D; + static create(): Matrix2D; + identity(): Matrix2D; + translate(dx: number, dy: number): Matrix2D; + scale(sx: number, sy: number): Matrix2D; + rotate(angle: number): Matrix2D; + invert(): Matrix2D; + add(matrix: Matrix2D): Matrix2D; + substract(matrix: Matrix2D): Matrix2D; + divide(matrix: Matrix2D): Matrix2D; + multiply(matrix: Matrix2D): Matrix2D; determinant(): number; - static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D; - static createTranslation(xPosition: number, yPosition: number): Matrix2D; - static createTranslationVector(position: Vector2): Matrix2D; - static createRotation(radians: number, result?: Matrix2D): Matrix2D; - static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; - toEgretMatrix(): egret.Matrix; } } declare module es { @@ -1202,6 +1223,7 @@ declare module es { abstract pointCollidesWithShape(point: Vector2): CollisionResult; abstract overlaps(other: Shape): any; abstract collidesWithShape(other: Shape): CollisionResult; + clone(): Shape; } } declare module es { diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index c83321cc..8d58b667 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -660,6 +660,26 @@ var es; enumerable: true, configurable: true }); + Vector2.prototype.add = function (value) { + this.x += value.x; + this.y += value.y; + return this; + }; + Vector2.prototype.divide = function (value) { + this.x /= value.x; + this.y /= value.y; + return this; + }; + Vector2.prototype.multiply = function (value) { + this.x *= value.x; + this.y *= value.y; + return this; + }; + Vector2.prototype.subtract = function (value) { + this.x -= value.x; + this.y -= value.y; + return this; + }; Vector2.add = function (value1, value2) { var result = new Vector2(0, 0); result.x = value1.x + value2.x; @@ -1739,6 +1759,12 @@ var es; CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; })(CameraStyle = es.CameraStyle || (es.CameraStyle = {})); + var CameraInset = (function () { + function CameraInset() { + } + return CameraInset; + }()); + es.CameraInset = CameraInset; var Camera = (function (_super) { __extends(Camera, _super); function Camera(targetEntity, cameraStyle) { @@ -1747,7 +1773,12 @@ var es; var _this = _super.call(this) || this; _this._minimumZoom = 0.3; _this._maximumZoom = 3; + _this._transformMatrix = new es.Matrix2D().identity(); + _this._inverseTransformMatrix = new es.Matrix2D().identity(); _this._origin = es.Vector2.zero; + _this._areMatrixedDirty = true; + _this._areBoundsDirty = true; + _this._isProjectionMatrixDirty = true; _this.followLerp = 0.1; _this.deadzone = new es.Rectangle(); _this.focusOffset = new es.Vector2(); @@ -1816,7 +1847,48 @@ var es; }); Object.defineProperty(Camera.prototype, "bounds", { get: function () { - return new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + if (this._areMatrixedDirty) + this.updateMatrixes(); + if (this._areBoundsDirty) { + var topLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, this._inset.top)); + var bottomRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, es.SceneManager.stage.stageHeight - this._inset.bottom)); + if (this.entity.transform.rotation != 0) { + var topRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, this._inset.top)); + var bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, es.SceneManager.stage.stageHeight - this._inset.bottom)); + var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + this._bounds.location = new es.Vector2(minX, minY); + this._bounds.width = maxX - minX; + this._bounds.height = maxX - minY; + } + else { + this._bounds.location = topLeft; + this._bounds.width = bottomRight.x - topLeft.x; + this._bounds.height = bottomRight.y - topLeft.y; + } + this._areBoundsDirty = false; + } + return this._bounds; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "transformMatrix", { + get: function () { + if (this._areMatrixedDirty) + this.updateMatrixes(); + return this._transformMatrix; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "inverseTransformMatrix", { + get: function () { + if (this._areMatrixedDirty) + this.updateMatrixes(); + return this._inverseTransformMatrix; }, enumerable: true, configurable: true @@ -1828,6 +1900,7 @@ var es; set: function (value) { if (this._origin != value) { this._origin = value; + this._areMatrixedDirty = true; } }, enumerable: true, @@ -1838,6 +1911,34 @@ var es; this.origin = new es.Vector2(newWidth / 2, newHeight / 2); this.entity.transform.position = es.Vector2.add(this.entity.transform.position, es.Vector2.subtract(this._origin, oldOrigin)); }; + Camera.prototype.updateMatrixes = function () { + if (!this._areMatrixedDirty) + return; + var tempMat; + this._transformMatrix = es.Matrix2D.create().translate(-this.entity.transform.position.x, -this.entity.transform.position.y); + if (this._zoom != 1) { + tempMat = es.Matrix2D.create().scale(this._zoom, this._zoom); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + } + if (this.entity.transform.rotation != 0) { + tempMat = es.Matrix2D.create().rotate(this.entity.transform.rotation); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + } + tempMat = es.Matrix2D.create().translate(this._origin.x, this._origin.y); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + this._inverseTransformMatrix = this._transformMatrix.invert(); + this._areBoundsDirty = true; + this._areMatrixedDirty = false; + }; + Camera.prototype.setInset = function (left, right, top, bottom) { + this._inset = new CameraInset(); + this._inset.left = left; + this._inset.right = right; + this._inset.top = top; + this._inset.bottom = bottom; + this._areBoundsDirty = true; + return this; + }; Camera.prototype.setPosition = function (position) { this.entity.transform.setPosition(position.x, position.y); return this; @@ -1857,11 +1958,14 @@ var es; else { this._zoom = es.MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); } - es.SceneManager.scene.scaleX = this._zoom; - es.SceneManager.scene.scaleY = this._zoom; + this._areMatrixedDirty = true; return this; }; Camera.prototype.setMinimumZoom = function (minZoom) { + if (minZoom <= 0) { + console.error("minimumZoom must be greater than zero"); + return; + } if (this._zoom < minZoom) this._zoom = this.minimumZoom; this._minimumZoom = minZoom; @@ -1877,12 +1981,28 @@ var es; this._maximumZoom = maxZoom; return this; }; + Camera.prototype.onEntityTransformChanged = function (comp) { + this._areMatrixedDirty = true; + }; Camera.prototype.zoomIn = function (deltaZoom) { this.zoom += deltaZoom; }; Camera.prototype.zoomOut = function (deltaZoom) { this.zoom -= deltaZoom; }; + Camera.prototype.worldToScreenPoint = function (worldPosition) { + this.updateMatrixes(); + worldPosition = es.Vector2.transform(worldPosition, this._transformMatrix); + return worldPosition; + }; + Camera.prototype.screenToWorldPoint = function (screenPosition) { + this.updateMatrixes(); + screenPosition = es.Vector2.transform(screenPosition, this._inverseTransformMatrix); + return screenPosition; + }; + Camera.prototype.mouseToWorldPoint = function () { + return this.screenToWorldPoint(es.Input.touchPosition); + }; Camera.prototype.onAddedToEntity = function () { this.follow(this._targetEntity, this._cameraStyle); }; @@ -2560,6 +2680,8 @@ var es; _this.shouldColliderScaleAndRotateWithTransform = true; _this.registeredPhysicsBounds = new es.Rectangle(); _this._localOffset = es.Vector2.zero; + _this._isPositionDirty = true; + _this._isRotationDirty = true; return _this; } Object.defineProperty(Collider.prototype, "localOffset", { @@ -2590,7 +2712,10 @@ var es; }); Object.defineProperty(Collider.prototype, "bounds", { get: function () { - this.shape.recalculateBounds(this); + if (this._isPositionDirty || this._isRotationDirty) { + this.shape.recalculateBounds(this); + this._isPositionDirty = this._isRotationDirty = false; + } return this.shape.bounds; }, enumerable: true, @@ -2601,12 +2726,14 @@ var es; this.unregisterColliderWithPhysicsSystem(); this._localOffset = offset; this._localOffsetLength = this._localOffset.length(); + this._isPositionDirty = true; this.registerColliderWithPhysicsSystem(); } return this; }; Collider.prototype.setShouldColliderScaleAndRotateWithTransform = function (shouldColliderScaleAndRotationWithTransform) { this.shouldColliderScaleAndRotateWithTransform = shouldColliderScaleAndRotationWithTransform; + this._isPositionDirty = this._isRotationDirty = true; return this; }; Collider.prototype.onAddedToEntity = function () { @@ -2642,11 +2769,23 @@ var es; this._isParentEntityAddedToScene = false; }; Collider.prototype.onEntityTransformChanged = function (comp) { + switch (comp) { + case transform.Component.position: + this._isPositionDirty = true; + break; + case transform.Component.scale: + this._isPositionDirty = true; + break; + case transform.Component.rotation: + this._isRotationDirty = true; + break; + } if (this._isColliderRegistered) es.Physics.updateCollider(this); }; Collider.prototype.onEnabled = function () { this.registerColliderWithPhysicsSystem(); + this._isPositionDirty = this._isRotationDirty = true; }; Collider.prototype.onDisabled = function () { this.unregisterColliderWithPhysicsSystem(); @@ -2675,6 +2814,13 @@ var es; this.entity.position = oldPosition; return result; }; + Collider.prototype.clone = function () { + var collider = ObjectUtils.clone(this); + collider.entity = null; + if (this.shape) + collider.shape = this.shape.clone(); + return collider; + }; return Collider; }(es.Component)); es.Collider = Collider; @@ -4769,167 +4915,141 @@ var es; })(es || (es = {})); var es; (function (es) { - var Matrix2D = (function () { - function Matrix2D(m11, m12, m21, m22, m31, m32) { - this.m11 = 0; - this.m12 = 0; - this.m21 = 0; - this.m22 = 0; - this.m31 = 0; - this.m32 = 0; - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; + var Matrix2D = (function (_super) { + __extends(Matrix2D, _super); + function Matrix2D() { + return _super !== null && _super.apply(this, arguments) || this; } - Object.defineProperty(Matrix2D, "identity", { + Object.defineProperty(Matrix2D.prototype, "m11", { get: function () { - return Matrix2D._identity; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "translation", { - get: function () { - return new es.Vector2(this.m31, this.m32); + return this.a; }, set: function (value) { - this.m31 = value.x; - this.m32 = value.y; + this.a = value; }, enumerable: true, configurable: true }); - Object.defineProperty(Matrix2D.prototype, "rotation", { + Object.defineProperty(Matrix2D.prototype, "m12", { get: function () { - return Math.atan2(this.m21, this.m11); + return this.b; }, set: function (value) { - var val1 = Math.cos(value); - var val2 = Math.sin(value); - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; + this.b = value; }, enumerable: true, configurable: true }); - Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { + Object.defineProperty(Matrix2D.prototype, "m21", { get: function () { - return es.MathHelper.toDegrees(this.rotation); + return this.c; }, set: function (value) { - this.rotation = es.MathHelper.toRadians(value); + this.c = value; }, enumerable: true, configurable: true }); - Object.defineProperty(Matrix2D.prototype, "scale", { + Object.defineProperty(Matrix2D.prototype, "m22", { get: function () { - return new es.Vector2(this.m11, this.m22); + return this.d; }, set: function (value) { - this.m11 = value.x; - this.m12 = value.y; + this.d = value; }, enumerable: true, configurable: true }); - Matrix2D.add = function (matrix1, matrix2) { - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; - return matrix1; + Object.defineProperty(Matrix2D.prototype, "m31", { + get: function () { + return this.tx; + }, + set: function (value) { + this.tx = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "m32", { + get: function () { + return this.ty; + }, + set: function (value) { + this.ty = value; + }, + enumerable: true, + configurable: true + }); + Matrix2D.create = function () { + return egret.Matrix.create(); }; - Matrix2D.divide = function (matrix1, matrix2) { - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; - return matrix1; + Matrix2D.prototype.identity = function () { + _super.prototype.identity.call(this); + return this; }; - Matrix2D.multiply = function (matrix1, matrix2) { - var result = new Matrix2D(); - var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); - var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); - var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); - var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); - var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; - var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; - result.m11 = m11; - result.m12 = m12; - result.m21 = m21; - result.m22 = m22; - result.m31 = m31; - result.m32 = m32; - return result; + Matrix2D.prototype.translate = function (dx, dy) { + _super.prototype.translate.call(this, dx, dy); + return this; }; - Matrix2D.multiplyTranslation = function (matrix, x, y) { - var trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); + Matrix2D.prototype.scale = function (sx, sy) { + _super.prototype.scale.call(this, sx, sy); + return this; + }; + Matrix2D.prototype.rotate = function (angle) { + _super.prototype.rotate.call(this, angle); + return this; + }; + Matrix2D.prototype.invert = function () { + _super.prototype.invert.call(this); + return this; + }; + Matrix2D.prototype.add = function (matrix) { + this.m11 += matrix.m11; + this.m12 += matrix.m12; + this.m21 += matrix.m21; + this.m22 += matrix.m22; + this.m31 += matrix.m31; + this.m32 += matrix.m32; + return this; + }; + Matrix2D.prototype.substract = function (matrix) { + this.m11 -= matrix.m11; + this.m12 -= matrix.m12; + this.m21 -= matrix.m21; + this.m22 -= matrix.m22; + this.m31 -= matrix.m31; + this.m32 -= matrix.m32; + return this; + }; + Matrix2D.prototype.divide = function (matrix) { + this.m11 /= matrix.m11; + this.m12 /= matrix.m12; + this.m21 /= matrix.m21; + this.m22 /= matrix.m22; + this.m31 /= matrix.m31; + this.m32 /= matrix.m32; + return this; + }; + Matrix2D.prototype.multiply = function (matrix) { + var m11 = (this.m11 * matrix.m11) + (this.m12 * matrix.m21); + var m12 = (this.m11 * matrix.m12) + (this.m12 * matrix.m22); + var m21 = (this.m21 * matrix.m11) + (this.m22 * matrix.m21); + var m22 = (this.m21 * matrix.m12) + (this.m22 * matrix.m22); + var m31 = (this.m31 * matrix.m11) + (this.m32 * matrix.m21) + matrix.m31; + var m32 = (this.m31 * matrix.m12) + (this.m32 * matrix.m22) + matrix.m32; + this.m11 = m11; + this.m12 = m12; + this.m21 = m21; + this.m22 = m22; + this.m31 = m31; + this.m32 = m32; + return this; }; Matrix2D.prototype.determinant = function () { return this.m11 * this.m22 - this.m12 * this.m21; }; - Matrix2D.invert = function (matrix, result) { - if (result === void 0) { result = new Matrix2D(); } - var det = 1 / matrix.determinant(); - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - return result; - }; - Matrix2D.createTranslation = function (xPosition, yPosition) { - var result = new Matrix2D(); - result.m11 = 1; - result.m12 = 0; - result.m21 = 0; - result.m22 = 1; - result.m31 = xPosition; - result.m32 = yPosition; - return result; - }; - Matrix2D.createTranslationVector = function (position) { - return this.createTranslation(position.x, position.y); - }; - Matrix2D.createRotation = function (radians, result) { - result = new Matrix2D(); - var val1 = Math.cos(radians); - var val2 = Math.sin(radians); - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - return result; - }; - Matrix2D.createScale = function (xScale, yScale, result) { - if (result === void 0) { result = new Matrix2D(); } - result.m11 = xScale; - result.m12 = 0; - result.m21 = 0; - result.m22 = yScale; - result.m31 = 0; - result.m32 = 0; - return result; - }; - Matrix2D.prototype.toEgretMatrix = function () { - var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); - return matrix; - }; - Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); return Matrix2D; - }()); + }(egret.Matrix)); es.Matrix2D = Matrix2D; })(es || (es = {})); var es; @@ -5374,6 +5494,9 @@ var es; var Shape = (function () { function Shape() { } + Shape.prototype.clone = function () { + return ObjectUtils.clone(this); + }; return Shape; }()); es.Shape = Shape; @@ -5473,7 +5596,29 @@ var es; Polygon.prototype.recalculateBounds = function (collider) { this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotateWithTransform) { + var hasUnitScale = true; + var tempMat = void 0; + var combinedMatrix = es.Matrix2D.create().translate(-this._polygonCenter.x, -this._polygonCenter.y); + if (collider.entity.transform.scale != es.Vector2.zero) { + tempMat = es.Matrix2D.create().scale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); + combinedMatrix = combinedMatrix.multiply(tempMat); + hasUnitScale = false; + this.center = es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + } + if (collider.entity.transform.rotation != 0) { + tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation); + combinedMatrix = combinedMatrix.multiply(tempMat); + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x); + var offsetLength = hasUnitScale ? collider._localOffsetLength : + es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); + } + tempMat = es.Matrix2D.create().translate(this._polygonCenter.x, this._polygonCenter.y); + combinedMatrix = combinedMatrix.multiply(tempMat); + es.Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); this.isUnrotated = collider.entity.transform.rotation == 0; + if (collider._isRotationDirty) + this._areEdgeNormalsDirty = true; } this.position = es.Vector2.add(collider.entity.transform.position, this.center); this.bounds = es.Rectangle.rectEncompassingPoints(this.points); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 21b482eb..a9d330a4 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},i.prototype.zoomIn=function(t){this.zoom+=t},i.prototype.zoomOut=function(t){this.zoom-=t},i.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},i.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},i.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},i.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},i.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},i.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},i}(t.Component);t.Camera=n}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(e,"identity",{get:function(){return e._identity},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.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(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),e.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},e.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},e.multiply=function(t,n){var i=new e,r=t.m11*n.m11+t.m12*n.m21,o=t.m11*n.m12+t.m12*n.m22,s=t.m21*n.m11+t.m22*n.m21,a=t.m21*n.m12+t.m22*n.m22,c=t.m31*n.m11+t.m32*n.m21+n.m31,h=t.m31*n.m12+t.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},e.multiplyTranslation=function(t,n,i){var r=e.createTranslation(n,i);return e.multiply(t,r)},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.invert=function(t,n){void 0===n&&(n=new e);var i=1/t.determinant();return n.m11=t.m22*i,n.m12=-t.m12*i,n.m21=-t.m21*i,n.m22=t.m11*i,n.m31=(t.m32*t.m21-t.m31*t.m22)*i,n.m32=-(t.m32*t.m11-t.m31*t.m12)*i,n},e.createTranslation=function(t,n){var i=new e;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=t,i.m32=n,i},e.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},e.createRotation=function(t,n){n=new e;var i=Math.cos(t),r=Math.sin(t);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},e.createScale=function(t,n,i){return void 0===i&&(i=new e),i.m11=t,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},e.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},e._identity=new e(1,0,0,1,0,0),e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(){}}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 6c72ef06..9f76bfa9 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -114,6 +114,10 @@ declare module es { static readonly unitX: Vector2; static readonly unitY: Vector2; constructor(x?: number, y?: number); + add(value: Vector2): Vector2; + divide(value: Vector2): Vector2; + multiply(value: Vector2): Vector2; + subtract(value: Vector2): this; static add(value1: Vector2, value2: Vector2): Vector2; static divide(value1: Vector2, value2: Vector2): Vector2; static multiply(value1: Vector2, value2: Vector2): Vector2; @@ -401,6 +405,12 @@ declare module es { lockOn = 0, cameraWindow = 1 } + class CameraInset { + left: number; + right: number; + top: number; + bottom: number; + } class Camera extends Component { position: Vector2; rotation: number; @@ -408,11 +418,20 @@ declare module es { minimumZoom: number; maximumZoom: number; readonly bounds: Rectangle; + readonly transformMatrix: Matrix2D; + readonly inverseTransformMatrix: Matrix2D; origin: Vector2; - private _zoom; - private _minimumZoom; - private _maximumZoom; - private _origin; + _zoom: any; + _minimumZoom: number; + _maximumZoom: number; + _bounds: Rectangle; + _inset: CameraInset; + _transformMatrix: Matrix2D; + _inverseTransformMatrix: Matrix2D; + _origin: Vector2; + _areMatrixedDirty: boolean; + _areBoundsDirty: boolean; + _isProjectionMatrixDirty: boolean; followLerp: number; deadzone: Rectangle; focusOffset: Vector2; @@ -425,13 +444,19 @@ declare module es { _worldSpaceDeadZone: Rectangle; constructor(targetEntity?: Entity, cameraStyle?: CameraStyle); onSceneSizeChanged(newWidth: number, newHeight: number): void; + protected updateMatrixes(): void; + setInset(left: number, right: number, top: number, bottom: number): Camera; setPosition(position: Vector2): this; setRotation(rotation: number): Camera; setZoom(zoom: number): Camera; setMinimumZoom(minZoom: number): Camera; setMaximumZoom(maxZoom: number): Camera; + onEntityTransformChanged(comp: transform.Component): void; zoomIn(deltaZoom: number): void; zoomOut(deltaZoom: number): void; + worldToScreenPoint(worldPosition: Vector2): Vector2; + screenToWorldPoint(screenPosition: Vector2): Vector2; + mouseToWorldPoint(): Vector2; onAddedToEntity(): void; update(): void; clampToMapSize(position: Vector2): Vector2; @@ -626,6 +651,8 @@ declare module es { _localOffsetLength: number; protected _isParentEntityAddedToScene: any; protected _isColliderRegistered: any; + _isPositionDirty: boolean; + _isRotationDirty: boolean; setLocalOffset(offset: Vector2): Collider; setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider; onAddedToEntity(): void; @@ -637,6 +664,7 @@ declare module es { unregisterColliderWithPhysicsSystem(): void; overlaps(other: Collider): any; collidesWith(collider: Collider, motion: Vector2): CollisionResult; + clone(): Component; } } declare module es { @@ -1079,31 +1107,24 @@ declare module es { } } declare module es { - class Matrix2D { + class Matrix2D extends egret.Matrix { m11: number; m12: number; m21: number; m22: number; m31: number; m32: number; - private static _identity; - static readonly identity: Matrix2D; - constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number); - translation: Vector2; - rotation: number; - rotationDegrees: number; - scale: Vector2; - static add(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static divide(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiply(matrix1: Matrix2D, matrix2: Matrix2D): Matrix2D; - static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D; + static create(): Matrix2D; + identity(): Matrix2D; + translate(dx: number, dy: number): Matrix2D; + scale(sx: number, sy: number): Matrix2D; + rotate(angle: number): Matrix2D; + invert(): Matrix2D; + add(matrix: Matrix2D): Matrix2D; + substract(matrix: Matrix2D): Matrix2D; + divide(matrix: Matrix2D): Matrix2D; + multiply(matrix: Matrix2D): Matrix2D; determinant(): number; - static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D; - static createTranslation(xPosition: number, yPosition: number): Matrix2D; - static createTranslationVector(position: Vector2): Matrix2D; - static createRotation(radians: number, result?: Matrix2D): Matrix2D; - static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D; - toEgretMatrix(): egret.Matrix; } } declare module es { @@ -1202,6 +1223,7 @@ declare module es { abstract pointCollidesWithShape(point: Vector2): CollisionResult; abstract overlaps(other: Shape): any; abstract collidesWithShape(other: Shape): CollisionResult; + clone(): Shape; } } declare module es { diff --git a/source/bin/framework.js b/source/bin/framework.js index c83321cc..8d58b667 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -660,6 +660,26 @@ var es; enumerable: true, configurable: true }); + Vector2.prototype.add = function (value) { + this.x += value.x; + this.y += value.y; + return this; + }; + Vector2.prototype.divide = function (value) { + this.x /= value.x; + this.y /= value.y; + return this; + }; + Vector2.prototype.multiply = function (value) { + this.x *= value.x; + this.y *= value.y; + return this; + }; + Vector2.prototype.subtract = function (value) { + this.x -= value.x; + this.y -= value.y; + return this; + }; Vector2.add = function (value1, value2) { var result = new Vector2(0, 0); result.x = value1.x + value2.x; @@ -1739,6 +1759,12 @@ var es; CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn"; CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow"; })(CameraStyle = es.CameraStyle || (es.CameraStyle = {})); + var CameraInset = (function () { + function CameraInset() { + } + return CameraInset; + }()); + es.CameraInset = CameraInset; var Camera = (function (_super) { __extends(Camera, _super); function Camera(targetEntity, cameraStyle) { @@ -1747,7 +1773,12 @@ var es; var _this = _super.call(this) || this; _this._minimumZoom = 0.3; _this._maximumZoom = 3; + _this._transformMatrix = new es.Matrix2D().identity(); + _this._inverseTransformMatrix = new es.Matrix2D().identity(); _this._origin = es.Vector2.zero; + _this._areMatrixedDirty = true; + _this._areBoundsDirty = true; + _this._isProjectionMatrixDirty = true; _this.followLerp = 0.1; _this.deadzone = new es.Rectangle(); _this.focusOffset = new es.Vector2(); @@ -1816,7 +1847,48 @@ var es; }); Object.defineProperty(Camera.prototype, "bounds", { get: function () { - return new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + if (this._areMatrixedDirty) + this.updateMatrixes(); + if (this._areBoundsDirty) { + var topLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, this._inset.top)); + var bottomRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, es.SceneManager.stage.stageHeight - this._inset.bottom)); + if (this.entity.transform.rotation != 0) { + var topRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, this._inset.top)); + var bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, es.SceneManager.stage.stageHeight - this._inset.bottom)); + var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + this._bounds.location = new es.Vector2(minX, minY); + this._bounds.width = maxX - minX; + this._bounds.height = maxX - minY; + } + else { + this._bounds.location = topLeft; + this._bounds.width = bottomRight.x - topLeft.x; + this._bounds.height = bottomRight.y - topLeft.y; + } + this._areBoundsDirty = false; + } + return this._bounds; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "transformMatrix", { + get: function () { + if (this._areMatrixedDirty) + this.updateMatrixes(); + return this._transformMatrix; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Camera.prototype, "inverseTransformMatrix", { + get: function () { + if (this._areMatrixedDirty) + this.updateMatrixes(); + return this._inverseTransformMatrix; }, enumerable: true, configurable: true @@ -1828,6 +1900,7 @@ var es; set: function (value) { if (this._origin != value) { this._origin = value; + this._areMatrixedDirty = true; } }, enumerable: true, @@ -1838,6 +1911,34 @@ var es; this.origin = new es.Vector2(newWidth / 2, newHeight / 2); this.entity.transform.position = es.Vector2.add(this.entity.transform.position, es.Vector2.subtract(this._origin, oldOrigin)); }; + Camera.prototype.updateMatrixes = function () { + if (!this._areMatrixedDirty) + return; + var tempMat; + this._transformMatrix = es.Matrix2D.create().translate(-this.entity.transform.position.x, -this.entity.transform.position.y); + if (this._zoom != 1) { + tempMat = es.Matrix2D.create().scale(this._zoom, this._zoom); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + } + if (this.entity.transform.rotation != 0) { + tempMat = es.Matrix2D.create().rotate(this.entity.transform.rotation); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + } + tempMat = es.Matrix2D.create().translate(this._origin.x, this._origin.y); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + this._inverseTransformMatrix = this._transformMatrix.invert(); + this._areBoundsDirty = true; + this._areMatrixedDirty = false; + }; + Camera.prototype.setInset = function (left, right, top, bottom) { + this._inset = new CameraInset(); + this._inset.left = left; + this._inset.right = right; + this._inset.top = top; + this._inset.bottom = bottom; + this._areBoundsDirty = true; + return this; + }; Camera.prototype.setPosition = function (position) { this.entity.transform.setPosition(position.x, position.y); return this; @@ -1857,11 +1958,14 @@ var es; else { this._zoom = es.MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); } - es.SceneManager.scene.scaleX = this._zoom; - es.SceneManager.scene.scaleY = this._zoom; + this._areMatrixedDirty = true; return this; }; Camera.prototype.setMinimumZoom = function (minZoom) { + if (minZoom <= 0) { + console.error("minimumZoom must be greater than zero"); + return; + } if (this._zoom < minZoom) this._zoom = this.minimumZoom; this._minimumZoom = minZoom; @@ -1877,12 +1981,28 @@ var es; this._maximumZoom = maxZoom; return this; }; + Camera.prototype.onEntityTransformChanged = function (comp) { + this._areMatrixedDirty = true; + }; Camera.prototype.zoomIn = function (deltaZoom) { this.zoom += deltaZoom; }; Camera.prototype.zoomOut = function (deltaZoom) { this.zoom -= deltaZoom; }; + Camera.prototype.worldToScreenPoint = function (worldPosition) { + this.updateMatrixes(); + worldPosition = es.Vector2.transform(worldPosition, this._transformMatrix); + return worldPosition; + }; + Camera.prototype.screenToWorldPoint = function (screenPosition) { + this.updateMatrixes(); + screenPosition = es.Vector2.transform(screenPosition, this._inverseTransformMatrix); + return screenPosition; + }; + Camera.prototype.mouseToWorldPoint = function () { + return this.screenToWorldPoint(es.Input.touchPosition); + }; Camera.prototype.onAddedToEntity = function () { this.follow(this._targetEntity, this._cameraStyle); }; @@ -2560,6 +2680,8 @@ var es; _this.shouldColliderScaleAndRotateWithTransform = true; _this.registeredPhysicsBounds = new es.Rectangle(); _this._localOffset = es.Vector2.zero; + _this._isPositionDirty = true; + _this._isRotationDirty = true; return _this; } Object.defineProperty(Collider.prototype, "localOffset", { @@ -2590,7 +2712,10 @@ var es; }); Object.defineProperty(Collider.prototype, "bounds", { get: function () { - this.shape.recalculateBounds(this); + if (this._isPositionDirty || this._isRotationDirty) { + this.shape.recalculateBounds(this); + this._isPositionDirty = this._isRotationDirty = false; + } return this.shape.bounds; }, enumerable: true, @@ -2601,12 +2726,14 @@ var es; this.unregisterColliderWithPhysicsSystem(); this._localOffset = offset; this._localOffsetLength = this._localOffset.length(); + this._isPositionDirty = true; this.registerColliderWithPhysicsSystem(); } return this; }; Collider.prototype.setShouldColliderScaleAndRotateWithTransform = function (shouldColliderScaleAndRotationWithTransform) { this.shouldColliderScaleAndRotateWithTransform = shouldColliderScaleAndRotationWithTransform; + this._isPositionDirty = this._isRotationDirty = true; return this; }; Collider.prototype.onAddedToEntity = function () { @@ -2642,11 +2769,23 @@ var es; this._isParentEntityAddedToScene = false; }; Collider.prototype.onEntityTransformChanged = function (comp) { + switch (comp) { + case transform.Component.position: + this._isPositionDirty = true; + break; + case transform.Component.scale: + this._isPositionDirty = true; + break; + case transform.Component.rotation: + this._isRotationDirty = true; + break; + } if (this._isColliderRegistered) es.Physics.updateCollider(this); }; Collider.prototype.onEnabled = function () { this.registerColliderWithPhysicsSystem(); + this._isPositionDirty = this._isRotationDirty = true; }; Collider.prototype.onDisabled = function () { this.unregisterColliderWithPhysicsSystem(); @@ -2675,6 +2814,13 @@ var es; this.entity.position = oldPosition; return result; }; + Collider.prototype.clone = function () { + var collider = ObjectUtils.clone(this); + collider.entity = null; + if (this.shape) + collider.shape = this.shape.clone(); + return collider; + }; return Collider; }(es.Component)); es.Collider = Collider; @@ -4769,167 +4915,141 @@ var es; })(es || (es = {})); var es; (function (es) { - var Matrix2D = (function () { - function Matrix2D(m11, m12, m21, m22, m31, m32) { - this.m11 = 0; - this.m12 = 0; - this.m21 = 0; - this.m22 = 0; - this.m31 = 0; - this.m32 = 0; - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; + var Matrix2D = (function (_super) { + __extends(Matrix2D, _super); + function Matrix2D() { + return _super !== null && _super.apply(this, arguments) || this; } - Object.defineProperty(Matrix2D, "identity", { + Object.defineProperty(Matrix2D.prototype, "m11", { get: function () { - return Matrix2D._identity; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(Matrix2D.prototype, "translation", { - get: function () { - return new es.Vector2(this.m31, this.m32); + return this.a; }, set: function (value) { - this.m31 = value.x; - this.m32 = value.y; + this.a = value; }, enumerable: true, configurable: true }); - Object.defineProperty(Matrix2D.prototype, "rotation", { + Object.defineProperty(Matrix2D.prototype, "m12", { get: function () { - return Math.atan2(this.m21, this.m11); + return this.b; }, set: function (value) { - var val1 = Math.cos(value); - var val2 = Math.sin(value); - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; + this.b = value; }, enumerable: true, configurable: true }); - Object.defineProperty(Matrix2D.prototype, "rotationDegrees", { + Object.defineProperty(Matrix2D.prototype, "m21", { get: function () { - return es.MathHelper.toDegrees(this.rotation); + return this.c; }, set: function (value) { - this.rotation = es.MathHelper.toRadians(value); + this.c = value; }, enumerable: true, configurable: true }); - Object.defineProperty(Matrix2D.prototype, "scale", { + Object.defineProperty(Matrix2D.prototype, "m22", { get: function () { - return new es.Vector2(this.m11, this.m22); + return this.d; }, set: function (value) { - this.m11 = value.x; - this.m12 = value.y; + this.d = value; }, enumerable: true, configurable: true }); - Matrix2D.add = function (matrix1, matrix2) { - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; - return matrix1; + Object.defineProperty(Matrix2D.prototype, "m31", { + get: function () { + return this.tx; + }, + set: function (value) { + this.tx = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Matrix2D.prototype, "m32", { + get: function () { + return this.ty; + }, + set: function (value) { + this.ty = value; + }, + enumerable: true, + configurable: true + }); + Matrix2D.create = function () { + return egret.Matrix.create(); }; - Matrix2D.divide = function (matrix1, matrix2) { - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; - return matrix1; + Matrix2D.prototype.identity = function () { + _super.prototype.identity.call(this); + return this; }; - Matrix2D.multiply = function (matrix1, matrix2) { - var result = new Matrix2D(); - var m11 = (matrix1.m11 * matrix2.m11) + (matrix1.m12 * matrix2.m21); - var m12 = (matrix1.m11 * matrix2.m12) + (matrix1.m12 * matrix2.m22); - var m21 = (matrix1.m21 * matrix2.m11) + (matrix1.m22 * matrix2.m21); - var m22 = (matrix1.m21 * matrix2.m12) + (matrix1.m22 * matrix2.m22); - var m31 = (matrix1.m31 * matrix2.m11) + (matrix1.m32 * matrix2.m21) + matrix2.m31; - var m32 = (matrix1.m31 * matrix2.m12) + (matrix1.m32 * matrix2.m22) + matrix2.m32; - result.m11 = m11; - result.m12 = m12; - result.m21 = m21; - result.m22 = m22; - result.m31 = m31; - result.m32 = m32; - return result; + Matrix2D.prototype.translate = function (dx, dy) { + _super.prototype.translate.call(this, dx, dy); + return this; }; - Matrix2D.multiplyTranslation = function (matrix, x, y) { - var trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); + Matrix2D.prototype.scale = function (sx, sy) { + _super.prototype.scale.call(this, sx, sy); + return this; + }; + Matrix2D.prototype.rotate = function (angle) { + _super.prototype.rotate.call(this, angle); + return this; + }; + Matrix2D.prototype.invert = function () { + _super.prototype.invert.call(this); + return this; + }; + Matrix2D.prototype.add = function (matrix) { + this.m11 += matrix.m11; + this.m12 += matrix.m12; + this.m21 += matrix.m21; + this.m22 += matrix.m22; + this.m31 += matrix.m31; + this.m32 += matrix.m32; + return this; + }; + Matrix2D.prototype.substract = function (matrix) { + this.m11 -= matrix.m11; + this.m12 -= matrix.m12; + this.m21 -= matrix.m21; + this.m22 -= matrix.m22; + this.m31 -= matrix.m31; + this.m32 -= matrix.m32; + return this; + }; + Matrix2D.prototype.divide = function (matrix) { + this.m11 /= matrix.m11; + this.m12 /= matrix.m12; + this.m21 /= matrix.m21; + this.m22 /= matrix.m22; + this.m31 /= matrix.m31; + this.m32 /= matrix.m32; + return this; + }; + Matrix2D.prototype.multiply = function (matrix) { + var m11 = (this.m11 * matrix.m11) + (this.m12 * matrix.m21); + var m12 = (this.m11 * matrix.m12) + (this.m12 * matrix.m22); + var m21 = (this.m21 * matrix.m11) + (this.m22 * matrix.m21); + var m22 = (this.m21 * matrix.m12) + (this.m22 * matrix.m22); + var m31 = (this.m31 * matrix.m11) + (this.m32 * matrix.m21) + matrix.m31; + var m32 = (this.m31 * matrix.m12) + (this.m32 * matrix.m22) + matrix.m32; + this.m11 = m11; + this.m12 = m12; + this.m21 = m21; + this.m22 = m22; + this.m31 = m31; + this.m32 = m32; + return this; }; Matrix2D.prototype.determinant = function () { return this.m11 * this.m22 - this.m12 * this.m21; }; - Matrix2D.invert = function (matrix, result) { - if (result === void 0) { result = new Matrix2D(); } - var det = 1 / matrix.determinant(); - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - return result; - }; - Matrix2D.createTranslation = function (xPosition, yPosition) { - var result = new Matrix2D(); - result.m11 = 1; - result.m12 = 0; - result.m21 = 0; - result.m22 = 1; - result.m31 = xPosition; - result.m32 = yPosition; - return result; - }; - Matrix2D.createTranslationVector = function (position) { - return this.createTranslation(position.x, position.y); - }; - Matrix2D.createRotation = function (radians, result) { - result = new Matrix2D(); - var val1 = Math.cos(radians); - var val2 = Math.sin(radians); - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - return result; - }; - Matrix2D.createScale = function (xScale, yScale, result) { - if (result === void 0) { result = new Matrix2D(); } - result.m11 = xScale; - result.m12 = 0; - result.m21 = 0; - result.m22 = yScale; - result.m31 = 0; - result.m32 = 0; - return result; - }; - Matrix2D.prototype.toEgretMatrix = function () { - var matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); - return matrix; - }; - Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0); return Matrix2D; - }()); + }(egret.Matrix)); es.Matrix2D = Matrix2D; })(es || (es = {})); var es; @@ -5374,6 +5494,9 @@ var es; var Shape = (function () { function Shape() { } + Shape.prototype.clone = function () { + return ObjectUtils.clone(this); + }; return Shape; }()); es.Shape = Shape; @@ -5473,7 +5596,29 @@ var es; Polygon.prototype.recalculateBounds = function (collider) { this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotateWithTransform) { + var hasUnitScale = true; + var tempMat = void 0; + var combinedMatrix = es.Matrix2D.create().translate(-this._polygonCenter.x, -this._polygonCenter.y); + if (collider.entity.transform.scale != es.Vector2.zero) { + tempMat = es.Matrix2D.create().scale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); + combinedMatrix = combinedMatrix.multiply(tempMat); + hasUnitScale = false; + this.center = es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + } + if (collider.entity.transform.rotation != 0) { + tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation); + combinedMatrix = combinedMatrix.multiply(tempMat); + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x); + var offsetLength = hasUnitScale ? collider._localOffsetLength : + es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); + } + tempMat = es.Matrix2D.create().translate(this._polygonCenter.x, this._polygonCenter.y); + combinedMatrix = combinedMatrix.multiply(tempMat); + es.Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); this.isUnrotated = collider.entity.transform.rotation == 0; + if (collider._isRotationDirty) + this._areEdgeNormalsDirty = true; } this.position = es.Vector2.add(collider.entity.transform.position, this.center); this.bounds = es.Rectangle.rectEncompassingPoints(this.points); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 21b482eb..a9d330a4 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},i.prototype.zoomIn=function(t){this.zoom+=t},i.prototype.zoomOut=function(t){this.zoom-=t},i.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},i.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},i.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},i.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},i.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},i.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},i}(t.Component);t.Camera=n}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i,r,o){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=r||0,this.m32=o||0}return Object.defineProperty(e,"identity",{get:function(){return e._identity},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translation",{get:function(){return new t.Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.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(e.prototype,"rotationDegrees",{get:function(){return t.MathHelper.toDegrees(this.rotation)},set:function(e){this.rotation=t.MathHelper.toRadians(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new t.Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),e.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},e.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},e.multiply=function(t,n){var i=new e,r=t.m11*n.m11+t.m12*n.m21,o=t.m11*n.m12+t.m12*n.m22,s=t.m21*n.m11+t.m22*n.m21,a=t.m21*n.m12+t.m22*n.m22,c=t.m31*n.m11+t.m32*n.m21+n.m31,h=t.m31*n.m12+t.m32*n.m22+n.m32;return i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},e.multiplyTranslation=function(t,n,i){var r=e.createTranslation(n,i);return e.multiply(t,r)},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.invert=function(t,n){void 0===n&&(n=new e);var i=1/t.determinant();return n.m11=t.m22*i,n.m12=-t.m12*i,n.m21=-t.m21*i,n.m22=t.m11*i,n.m31=(t.m32*t.m21-t.m31*t.m22)*i,n.m32=-(t.m32*t.m11-t.m31*t.m12)*i,n},e.createTranslation=function(t,n){var i=new e;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=t,i.m32=n,i},e.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},e.createRotation=function(t,n){n=new e;var i=Math.cos(t),r=Math.sin(t);return n.m11=i,n.m12=r,n.m21=-r,n.m22=i,n},e.createScale=function(t,n,i){return void 0===i&&(i=new e),i.m11=t,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},e.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},e._identity=new e(1,0,0,1,0,0),e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){return function(){}}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Components/Camera.ts b/source/src/ECS/Components/Camera.ts index 49f0d259..6ab4bfad 100644 --- a/source/src/ECS/Components/Camera.ts +++ b/source/src/ECS/Components/Camera.ts @@ -4,6 +4,13 @@ module es { cameraWindow, } + export class CameraInset { + public left: number; + public right: number; + public top: number; + public bottom: number; + } + export class Camera extends Component { /** * 对entity.transform.position的快速访问 @@ -89,10 +96,61 @@ module es { } /** - * 相机的边框 + * 相机的世界-空间边界 */ public get bounds(){ - return new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + if (this._areMatrixedDirty) + this.updateMatrixes(); + + if (this._areBoundsDirty){ + // 旋转或非旋转的边界都需要左上角和右下角 + let topLeft = this.screenToWorldPoint(new Vector2(this._inset.left, this._inset.top)); + let bottomRight = this.screenToWorldPoint(new Vector2(SceneManager.stage.stageWidth - this._inset.right, + SceneManager.stage.stageHeight - this._inset.bottom)); + + if (this.entity.transform.rotation != 0){ + // 特别注意旋转的边界。我们需要找到绝对的最小/最大值并从中创建边界 + let topRight = this.screenToWorldPoint(new Vector2(SceneManager.stage.stageWidth - this._inset.right, + this._inset.top)); + let bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, + SceneManager.stage.stageHeight - this._inset.bottom)); + + let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); + let minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + let maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); + + this._bounds.location = new Vector2(minX, minY); + this._bounds.width = maxX - minX; + this._bounds.height = maxX - minY; + } else { + this._bounds.location = topLeft; + this._bounds.width = bottomRight.x - topLeft.x; + this._bounds.height = bottomRight.y - topLeft.y; + } + + this._areBoundsDirty = false; + } + + return this._bounds; + } + + /** + * 用于从世界坐标转换到屏幕 + */ + public get transformMatrix(): Matrix2D { + if (this._areMatrixedDirty) + this.updateMatrixes(); + return this._transformMatrix; + } + + /** + * 用于从屏幕坐标到世界的转换 + */ + public get inverseTransformMatrix(): Matrix2D { + if (this._areMatrixedDirty) + this.updateMatrixes(); + return this._inverseTransformMatrix; } public get origin() { @@ -102,13 +160,23 @@ module es { public set origin(value: Vector2) { if (this._origin != value) { this._origin = value; + this._areMatrixedDirty = true; } } - private _zoom; - private _minimumZoom = 0.3; - private _maximumZoom = 3; - private _origin: Vector2 = Vector2.zero; + public _zoom; + public _minimumZoom = 0.3; + public _maximumZoom = 3; + public _bounds: Rectangle; + public _inset: CameraInset; + public _transformMatrix: Matrix2D = new Matrix2D().identity(); + public _inverseTransformMatrix: Matrix2D = new Matrix2D().identity(); + public _origin: Vector2 = Vector2.zero; + + public _areMatrixedDirty: boolean = true; + public _areBoundsDirty: boolean = true; + public _isProjectionMatrixDirty = true; + /** * 如果相机模式为cameraWindow 则会进行缓动移动 * 该值为移动速度 @@ -158,6 +226,50 @@ module es { this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin)); } + protected updateMatrixes(){ + if (!this._areMatrixedDirty) + return; + + let tempMat: Matrix2D; + this._transformMatrix = Matrix2D.create().translate(-this.entity.transform.position.x, -this.entity.transform.position.y); + + if (this._zoom != 1){ + tempMat = Matrix2D.create().scale(this._zoom, this._zoom); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + } + + if (this.entity.transform.rotation != 0){ + tempMat = Matrix2D.create().rotate(this.entity.transform.rotation); + this._transformMatrix = this._transformMatrix.multiply(tempMat); + } + + tempMat = Matrix2D.create().translate(this._origin.x, this._origin.y); + this._transformMatrix =this._transformMatrix.multiply(tempMat); + + this._inverseTransformMatrix = this._transformMatrix.invert(); + + // 无论何时矩阵改变边界都是无效的 + this._areBoundsDirty = true; + this._areMatrixedDirty = false; + } + + /** + * 设置用于从视口边缘插入摄像机边界的量 + * @param left + * @param right + * @param top + * @param bottom + */ + public setInset(left: number, right: number, top: number, bottom: number): Camera { + this._inset = new CameraInset(); + this._inset.left = left; + this._inset.right = right; + this._inset.top = top; + this._inset.bottom = bottom; + this._areBoundsDirty = true; + return this; + } + /** * 对entity.transform.setPosition快速访问 * @param position @@ -190,9 +302,8 @@ module es { } else { this._zoom = MathHelper.map(newZoom, 0, 1, 1, this._maximumZoom); } + this._areMatrixedDirty = true; - SceneManager.scene.scaleX = this._zoom; - SceneManager.scene.scaleY = this._zoom; return this; } @@ -201,6 +312,11 @@ module es { * @param minZoom */ public setMinimumZoom(minZoom: number): Camera { + if (minZoom <= 0) { + console.error("minimumZoom must be greater than zero"); + return; + } + if (this._zoom < minZoom) this._zoom = this.minimumZoom; @@ -225,6 +341,10 @@ module es { return this; } + public onEntityTransformChanged(comp: transform.Component) { + this._areMatrixedDirty = true; + } + public zoomIn(deltaZoom: number) { this.zoom += deltaZoom; } @@ -233,6 +353,33 @@ module es { this.zoom -= deltaZoom; } + /** + * 将一个点从世界坐标转换到屏幕 + * @param worldPosition + */ + public worldToScreenPoint(worldPosition: Vector2): Vector2{ + this.updateMatrixes(); + worldPosition = Vector2.transform(worldPosition, this._transformMatrix); + return worldPosition; + } + + /** + * 将点从屏幕坐标转换为世界坐标 + * @param screenPosition + */ + public screenToWorldPoint(screenPosition: Vector2): Vector2{ + this.updateMatrixes(); + screenPosition = Vector2.transform(screenPosition, this._inverseTransformMatrix); + return screenPosition; + } + + /** + * 返回鼠标在世界空间中的位置 + */ + public mouseToWorldPoint(): Vector2{ + return this.screenToWorldPoint(Input.touchPosition); + } + public onAddedToEntity() { this.follow(this._targetEntity, this._cameraStyle); } diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index 5b482e79..e74088cc 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -4,11 +4,12 @@ module es { * 对撞机的基本形状 */ public shape: Shape; + /** * 将localOffset添加到实体。获取碰撞器几何图形的最终位置。 * 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转 */ - public get localOffset(): Vector2{ + public get localOffset(): Vector2 { return this._localOffset; } @@ -17,21 +18,21 @@ module es { * 允许向一个实体添加多个碰撞器并分别定位,还允许你设置缩放/旋转 * @param value */ - public set localOffset(value: Vector2){ + public set localOffset(value: Vector2) { this.setLocalOffset(value); } /** * 镖师碰撞器的绝对位置 */ - public get absolutePosition(): Vector2{ + public get absolutePosition(): Vector2 { return Vector2.add(this.entity.transform.position, this._localOffset); } /** * 封装变换。如果碰撞器没和实体一起旋转 则返回transform.rotation */ - public get rotation(): number{ + public get rotation(): number { if (this.shouldColliderScaleAndRotateWithTransform && this.entity) return this.entity.transform.rotation; @@ -58,7 +59,10 @@ module es { public shouldColliderScaleAndRotateWithTransform = true; public get bounds(): Rectangle { - this.shape.recalculateBounds(this); + if (this._isPositionDirty || this._isRotationDirty){ + this.shape.recalculateBounds(this); + this._isPositionDirty = this._isRotationDirty = false; + } return this.shape.bounds; } @@ -81,16 +85,20 @@ module es { */ protected _isColliderRegistered; + public _isPositionDirty: boolean = true; + public _isRotationDirty: boolean = true; + /** * 将localOffset添加到实体。获取碰撞器的最终位置。 * 这允许您向一个实体添加多个碰撞器并分别定位它们。 * @param offset */ - public setLocalOffset(offset: Vector2): Collider{ - if (this._localOffset != offset){ + public setLocalOffset(offset: Vector2): Collider { + if (this._localOffset != offset) { this.unregisterColliderWithPhysicsSystem(); this._localOffset = offset; this._localOffsetLength = this._localOffset.length(); + this._isPositionDirty = true; this.registerColliderWithPhysicsSystem(); } @@ -103,6 +111,7 @@ module es { */ public setShouldColliderScaleAndRotateWithTransform(shouldColliderScaleAndRotationWithTransform: boolean): Collider { this.shouldColliderScaleAndRotateWithTransform = shouldColliderScaleAndRotationWithTransform; + this._isPositionDirty = this._isRotationDirty = true; return this; } @@ -121,7 +130,7 @@ module es { let width = bounds.width / this.entity.scale.x; let height = bounds.height / this.entity.scale.y; // 圆碰撞器需要特别注意原点 - if (this instanceof CircleCollider){ + if (this instanceof CircleCollider) { let circleCollider = this as CircleCollider; circleCollider.radius = Math.max(width, height) * 0.5; } else { @@ -146,12 +155,25 @@ module es { } public onEntityTransformChanged(comp: transform.Component) { + switch (comp) { + case transform.Component.position: + this._isPositionDirty = true; + break; + case transform.Component.scale: + this._isPositionDirty = true; + break; + case transform.Component.rotation: + this._isRotationDirty = true; + break; + } + if (this._isColliderRegistered) Physics.updateCollider(this); } public onEnabled() { this.registerColliderWithPhysicsSystem(); + this._isPositionDirty = this._isRotationDirty = true; } public onDisabled() { @@ -206,5 +228,15 @@ module es { return result; } + + public clone(): Component{ + let collider = ObjectUtils.clone(this); + collider.entity = null; + + if (this.shape) + collider.shape = this.shape.clone(); + + return collider; + } } } diff --git a/source/src/Math/Matrix2D.ts b/source/src/Math/Matrix2D.ts index 9b1e69e7..f6d32cb6 100644 --- a/source/src/Math/Matrix2D.ts +++ b/source/src/Math/Matrix2D.ts @@ -2,218 +2,140 @@ module es { /** * 表示右手3 * 3的浮点矩阵,可以存储平移、缩放和旋转信息。 */ - export class Matrix2D { - public m11: number = 0; - public m12: number = 0; - - public m21: number = 0; - public m22: number = 0; - - public m31: number = 0; - public m32: number = 0; - - private static _identity: Matrix2D = new Matrix2D(1, 0, 0, 1, 0, 0); - - /** - * 单位矩阵 - */ - public static get identity(){ - return Matrix2D._identity; + export class Matrix2D extends egret.Matrix{ + public get m11(): number{ + return this.a; + } + public set m11(value: number){ + this.a = value; + } + public get m12(): number{ + return this.b; + } + public set m12(value: number){ + this.b = value; + } + public get m21(): number{ + return this.c; + } + public set m21(value: number){ + this.c = value; + } + public get m22(): number{ + return this.d; + } + public set m22(value: number){ + this.d = value; + } + public get m31(): number { + return this.tx; + } + public set m31(value: number){ + this.tx = value; + } + public get m32(): number{ + return this.ty; + } + public set m32(value: number){ + this.ty = value; } - constructor(m11?: number, m12?: number, m21?: number, m22?: number, m31?: number, m32?: number){ - this.m11 = m11 ? m11 : 1; - this.m12 = m12 ? m12 : 0; - - this.m21 = m21 ? m21 : 0; - this.m22 = m22 ? m22 : 1; - - this.m31 = m31 ? m31 : 0; - this.m32 = m32 ? m32 : 0; + public static create(): Matrix2D{ + return egret.Matrix.create() as Matrix2D; } - /** 存储在这个矩阵中的位置 */ - public get translation(){ - return new Vector2(this.m31, this.m32); + public identity(): Matrix2D{ + super.identity(); + return this; } - public set translation(value: Vector2){ - this.m31 = value.x; - this.m32 = value.y; + public translate(dx: number, dy: number): Matrix2D { + super.translate(dx, dy); + return this; } - /** 以弧度表示的旋转存储在这个矩阵中 */ - public get rotation(){ - return Math.atan2(this.m21, this.m11); + public scale(sx: number, sy: number): Matrix2D { + super.scale(sx, sy); + return this; } - public set rotation(value: number){ - let val1 = Math.cos(value); - let val2 = Math.sin(value); - - this.m11 = val1; - this.m12 = val2; - this.m21 = -val2; - this.m22 = val1; + public rotate(angle: number): Matrix2D { + super.rotate(angle); + return this; } - /** - * 以度为单位的旋转存储在这个矩阵中 - */ - public get rotationDegrees(){ - return MathHelper.toDegrees(this.rotation); - } - - public set rotationDegrees(value: number){ - this.rotation = MathHelper.toRadians(value); - } - - public get scale(){ - return new Vector2(this.m11, this.m22); - } - - public set scale(value: Vector2){ - this.m11 = value.x; - this.m12 = value.y; + public invert(): Matrix2D { + super.invert(); + return this; } /** * 创建一个新的matrix, 它包含两个矩阵的和。 - * @param matrix1 - * @param matrix2 + * @param matrix */ - public static add(matrix1: Matrix2D, matrix2: Matrix2D){ - matrix1.m11 += matrix2.m11; - matrix1.m12 += matrix2.m12; + public add(matrix: Matrix2D): Matrix2D{ + this.m11 += matrix.m11; + this.m12 += matrix.m12; - matrix1.m21 += matrix2.m21; - matrix1.m22 += matrix2.m22; + this.m21 += matrix.m21; + this.m22 += matrix.m22; - matrix1.m31 += matrix2.m31; - matrix1.m32 += matrix2.m32; + this.m31 += matrix.m31; + this.m32 += matrix.m32; - return matrix1; + return this; } - public static divide(matrix1: Matrix2D, matrix2: Matrix2D){ - matrix1.m11 /= matrix2.m11; - matrix1.m12 /= matrix2.m12; + public substract(matrix: Matrix2D): Matrix2D { + this.m11 -= matrix.m11; + this.m12 -= matrix.m12; - matrix1.m21 /= matrix2.m21; - matrix1.m22 /= matrix2.m22; + this.m21 -= matrix.m21; + this.m22 -= matrix.m22; - matrix1.m31 /= matrix2.m31; - matrix1.m32 /= matrix2.m32; + this.m31 -= matrix.m31; + this.m32 -= matrix.m32; - return matrix1; + return this; } - public static multiply(matrix1: Matrix2D, matrix2: Matrix2D){ - let result = new Matrix2D(); + public divide(matrix: Matrix2D): Matrix2D{ + this.m11 /= matrix.m11; + this.m12 /= matrix.m12; - let m11 = ( matrix1.m11 * matrix2.m11 ) + ( matrix1.m12 * matrix2.m21 ); - let m12 = ( matrix1.m11 * matrix2.m12 ) + ( matrix1.m12 * matrix2.m22 ); + this.m21 /= matrix.m21; + this.m22 /= matrix.m22; - let m21 = ( matrix1.m21 * matrix2.m11 ) + ( matrix1.m22 * matrix2.m21 ); - let m22 = ( matrix1.m21 * matrix2.m12 ) + ( matrix1.m22 * matrix2.m22 ); + this.m31 /= matrix.m31; + this.m32 /= matrix.m32; - let m31 = ( matrix1.m31 * matrix2.m11 ) + ( matrix1.m32 * matrix2.m21 ) + matrix2.m31; - let m32 = ( matrix1.m31 * matrix2.m12 ) + ( matrix1.m32 * matrix2.m22 ) + matrix2.m32; - - result.m11 = m11; - result.m12 = m12; - - result.m21 = m21; - result.m22 = m22; - - result.m31 = m31; - result.m32 = m32; - - return result; + return this; } - public static multiplyTranslation(matrix: Matrix2D, x: number, y: number){ - let trans = Matrix2D.createTranslation(x, y); - return Matrix2D.multiply(matrix, trans); + public multiply(matrix: Matrix2D): Matrix2D{ + let m11 = ( this.m11 * matrix.m11 ) + ( this.m12 * matrix.m21 ); + let m12 = ( this.m11 * matrix.m12 ) + ( this.m12 * matrix.m22 ); + + let m21 = ( this.m21 * matrix.m11 ) + ( this.m22 * matrix.m21 ); + let m22 = ( this.m21 * matrix.m12 ) + ( this.m22 * matrix.m22 ); + + let m31 = ( this.m31 * matrix.m11 ) + ( this.m32 * matrix.m21 ) + matrix.m31; + let m32 = ( this.m31 * matrix.m12 ) + ( this.m32 * matrix.m22 ) + matrix.m32; + + this.m11 = m11; + this.m12 = m12; + + this.m21 = m21; + this.m22 = m22; + + this.m31 = m31; + this.m32 = m32; + + return this; } public determinant(){ return this.m11 * this.m22 - this.m12 * this.m21; } - - public static invert(matrix: Matrix2D, result: Matrix2D = new Matrix2D()){ - let det = 1 / matrix.determinant(); - - result.m11 = matrix.m22 * det; - result.m12 = -matrix.m12 * det; - - result.m21 = -matrix.m21 * det; - result.m22 = matrix.m11 * det; - - result.m31 = (matrix.m32 * matrix.m21 - matrix.m31 * matrix.m22) * det; - result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det; - - return result; - } - - /** - * 创建一个新的tranlation - * @param xPosition - * @param yPosition - */ - public static createTranslation(xPosition: number, yPosition: number){ - let result = new Matrix2D(); - - result.m11 = 1; - result.m12 = 0; - - result.m21 = 0; - result.m22 = 1; - - result.m31 = xPosition; - result.m32 = yPosition; - - return result; - } - - /** - * 根据position 创建一个translation - * @param position - */ - public static createTranslationVector(position: Vector2){ - return this.createTranslation(position.x, position.y); - } - - public static createRotation(radians: number, result?: Matrix2D){ - result = new Matrix2D(); - - let val1 = Math.cos(radians); - let val2 = Math.sin(radians); - - result.m11 = val1; - result.m12 = val2; - result.m21 = -val2; - result.m22 = val1; - - return result; - } - - public static createScale(xScale: number, yScale: number, result: Matrix2D = new Matrix2D()){ - result.m11 = xScale; - result.m12 = 0; - - result.m21 = 0; - result.m22 = yScale; - - result.m31 = 0; - result.m32 = 0; - - return result; - } - - public toEgretMatrix(): egret.Matrix{ - let matrix = new egret.Matrix(this.m11, this.m12, this.m21, this.m22, this.m31, this.m32); - return matrix; - } } } diff --git a/source/src/Math/Vector2.ts b/source/src/Math/Vector2.ts index 13dbe2aa..fbce5533 100644 --- a/source/src/Math/Vector2.ts +++ b/source/src/Math/Vector2.ts @@ -34,6 +34,46 @@ module es { this.y = y ? y : this.x; } + /** + * + * @param value + */ + public add(value: Vector2): Vector2{ + this.x += value.x; + this.y += value.y; + return this; + } + + /** + * + * @param value + */ + public divide(value: Vector2): Vector2{ + this.x /= value.x; + this.y /= value.y; + return this; + } + + /** + * + * @param value + */ + public multiply(value: Vector2): Vector2{ + this.x *= value.x; + this.y *= value.y; + return this; + } + + /** + * + * @param value + */ + public subtract(value: Vector2){ + this.x -= value.x; + this.y -= value.y; + return this; + } + /** * * @param value1 diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index d6991b19..4493d380 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -177,7 +177,43 @@ module es { this.center = collider.localOffset; if (collider.shouldColliderScaleAndRotateWithTransform){ + let hasUnitScale = true; + let tempMat: Matrix2D; + let combinedMatrix = Matrix2D.create().translate(-this._polygonCenter.x, -this._polygonCenter.y); + + if (collider.entity.transform.scale != Vector2.zero){ + tempMat = Matrix2D.create().scale(collider.entity.transform.scale.x, collider.entity.transform.scale.y); + combinedMatrix = combinedMatrix.multiply(tempMat); + hasUnitScale = false; + + // 缩放偏移量并将其设置为中心。如果我们有旋转,它会在下面重置 + this.center = Vector2.multiply(collider.localOffset, collider.entity.transform.scale); + } + + if (collider.entity.transform.rotation != 0){ + tempMat = Matrix2D.create().rotate(collider.entity.transform.rotation); + combinedMatrix = combinedMatrix.multiply(tempMat); + + // 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动 + // 我们的偏移使角度为0我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。 + let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x); + let offsetLength = hasUnitScale ? collider._localOffsetLength : + Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); + this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, + collider.entity.transform.rotation + offsetAngle); + } + + tempMat = Matrix2D.create().translate(this._polygonCenter.x, this._polygonCenter.y); + combinedMatrix = combinedMatrix.multiply(tempMat); + + // 最后变换原始点 + Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points); + this.isUnrotated = collider.entity.transform.rotation == 0; + + // 如果旋转的话,我们只需要重建边的法线 + if (collider._isRotationDirty) + this._areEdgeNormalsDirty = true; } this.position = Vector2.add(collider.entity.transform.position, this.center); diff --git a/source/src/Physics/Shapes/Shape.ts b/source/src/Physics/Shapes/Shape.ts index 1dcb1951..9557753e 100644 --- a/source/src/Physics/Shapes/Shape.ts +++ b/source/src/Physics/Shapes/Shape.ts @@ -19,5 +19,9 @@ module es { public abstract pointCollidesWithShape(point: Vector2): CollisionResult; public abstract overlaps(other: Shape); public abstract collidesWithShape(other: Shape): CollisionResult; + + public clone(): Shape{ + return ObjectUtils.clone(this); + } } } From 347626a8ea33af3a1e26c23a16080d077d91f275 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Thu, 23 Jul 2020 13:26:52 +0800 Subject: [PATCH 07/15] =?UTF-8?q?=E5=BF=BD=E7=95=A5ide=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .idea/.gitignore | 3 --- .idea/egret-framework.iml | 12 ------------ .idea/misc.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ .vscode/launch.json | 15 --------------- 7 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/egret-framework.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .vscode/launch.json diff --git a/.gitignore b/.gitignore index 8e249491..4be61a4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /source/node_modules /demo/bin-debug /demo/bin-release +/.idea +/.vscode diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 0e40fe8f..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ - -# Default ignored files -/workspace.xml \ No newline at end of file diff --git a/.idea/egret-framework.iml b/.idea/egret-framework.iml deleted file mode 100644 index 24643cc3..00000000 --- a/.idea/egret-framework.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 28a804d8..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index bfd6610a..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 7b7a8605..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "pwa-chrome", - "request": "launch", - "name": "Launch Chrome against localhost", - "url": "http://localhost:8080", - "webRoot": "${workspaceFolder}" - } - ] -} \ No newline at end of file From 79c5d6990ceb3667b45334938147b1ac16551b66 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Thu, 23 Jul 2020 15:39:18 +0800 Subject: [PATCH 08/15] =?UTF-8?q?SceneManager=E6=9B=B4=E6=94=B9=E4=B8=BACo?= =?UTF-8?q?re=E7=BB=A7=E6=89=BFegret.DisplayContainer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.d.ts | 72 ++-- demo/libs/framework/framework.js | 386 ++++++++++-------- demo/libs/framework/framework.min.js | 2 +- demo/src/Main.ts | 5 +- source/bin/framework.d.ts | 72 ++-- source/bin/framework.js | 386 ++++++++++-------- source/bin/framework.min.js | 2 +- source/src/Debug/Debug.ts | 4 +- source/src/ECS/Components/Camera.ts | 12 +- source/src/ECS/Core.ts | 228 +++++++++++ source/src/ECS/CoreEvents.ts | 12 +- source/src/ECS/Scene.ts | 10 - source/src/ECS/SceneManager.ts | 146 ------- source/src/ECS/Utils/TextureUtils.ts | 2 +- .../Graphics/Effects/GaussianBlurEffect.ts | 4 +- source/src/Graphics/GraphicsDevice.ts | 10 +- .../Graphics/PostProcessing/PostProcessor.ts | 2 +- .../Graphics/Transitions/FadeTransition.ts | 6 +- .../Graphics/Transitions/SceneTransition.ts | 4 +- .../Graphics/Transitions/WindTransition.ts | 4 +- source/src/Graphics/Viewport.ts | 14 + source/src/Utils/Analysis/Layout.ts | 2 +- source/src/Utils/Analysis/TimeRuler.ts | 4 +- source/src/Utils/GlobalManager.ts | 47 ++- source/src/Utils/Input.ts | 18 +- 25 files changed, 832 insertions(+), 622 deletions(-) create mode 100644 source/src/ECS/Core.ts delete mode 100644 source/src/ECS/SceneManager.ts diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index 9f76bfa9..22ae545a 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -246,9 +246,40 @@ declare module es { clone(): Component; } } +declare module es { + class Core extends egret.DisplayObjectContainer { + static activeSceneChanged: Function; + static emitter: Emitter; + static graphicsDevice: GraphicsDevice; + static content: ContentManager; + static readonly Instance: Core; + static _instance: Core; + _scene: Scene; + _nextScene: Scene; + _sceneTransition: SceneTransition; + _globalManagers: GlobalManager[]; + static scene: Scene; + constructor(); + onOrientationChanged(): void; + protected onGraphicsDeviceReset(): void; + protected initialize(): void; + protected update(): void; + draw(): Promise; + startDebugUpdate(): void; + endDebugUpdate(): void; + onSceneChanged(): void; + static startSceneTransition(sceneTransition: T): T; + static registerActiveSceneChanged(current: Scene, next: Scene): void; + static registerGlobalManager(manager: es.GlobalManager): void; + static unregisterGlobalManager(manager: es.GlobalManager): void; + static getGlobalManager(type: any): T; + } +} declare module es { enum CoreEvents { - SceneChanged = 0 + GraphicsDeviceReset = 0, + SceneChanged = 1, + OrientationChanged = 2 } } declare module es { @@ -340,30 +371,6 @@ declare module es { getEntityProcessor(): T; } } -declare module es { - class SceneManager { - private static _scene; - private static _nextScene; - static sceneTransition: SceneTransition; - static stage: egret.Stage; - static activeSceneChanged: Function; - static emitter: Emitter; - static content: ContentManager; - private static _instnace; - private static timerRuler; - static readonly Instance: SceneManager; - constructor(stage: egret.Stage); - static scene: Scene; - static initialize(stage: egret.Stage): void; - static update(): void; - static render(): void; - static startSceneTransition(sceneTransition: T): T; - static registerActiveSceneChanged(current: Scene, next: Scene): void; - onSceneChanged(): void; - private static startDebugUpdate; - private static endDebugUpdate; - } -} declare module transform { enum Component { position = 0, @@ -942,9 +949,11 @@ declare module es { } declare module es { class GraphicsDevice { - private viewport; + private _viewport; + readonly viewport: Viewport; graphicsCapabilities: GraphicsCapabilities; constructor(); + private setup; } } declare module es { @@ -955,6 +964,8 @@ declare module es { private _height; private _minDepth; private _maxDepth; + height: number; + width: number; readonly aspectRatio: number; bounds: Rectangle; constructor(x: number, y: number, width: number, height: number); @@ -1398,16 +1409,12 @@ declare module es { } declare module es { class GlobalManager { - static globalManagers: GlobalManager[]; - private _enabled; enabled: boolean; setEnabled(isEnabled: boolean): void; + _enabled: boolean; onEnabled(): void; onDisabled(): void; update(): void; - static registerGlobalManager(manager: GlobalManager): void; - static unregisterGlobalManager(manager: GlobalManager): void; - static getGlobalManager(type: any): T; } } declare module es { @@ -1421,7 +1428,6 @@ declare module es { } class Input { private static _init; - private static _stage; private static _previousTouchState; private static _gameTouchs; private static _resolutionOffset; @@ -1434,7 +1440,7 @@ declare module es { static readonly totalTouchCount: number; static readonly gameTouchs: TouchState[]; static readonly touchPositionDelta: Vector2; - static initialize(stage: egret.Stage): void; + static initialize(): void; private static initTouchCache; private static touchBegin; private static touchMove; diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index 8d58b667..4e14fae4 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -955,8 +955,8 @@ var es; Debug.render = function () { if (this._debugDrawItems.length > 0) { var debugShape = new egret.Shape(); - if (es.SceneManager.scene) { - es.SceneManager.scene.addChild(debugShape); + if (es.Core.scene) { + es.Core.scene.addChild(debugShape); } for (var i = this._debugDrawItems.length - 1; i >= 0; i--) { var item = this._debugDrawItems[i]; @@ -1097,10 +1097,167 @@ var es; es.Component = Component; })(es || (es = {})); var es; +(function (es) { + var Core = (function (_super) { + __extends(Core, _super); + function Core() { + var _this = _super.call(this) || this; + _this._globalManagers = []; + Core._instance = _this; + Core.emitter = new es.Emitter(); + Core.graphicsDevice = new es.GraphicsDevice(); + Core.content = new es.ContentManager(); + _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this); + _this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this); + _this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this); + _this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this); + _this.addEventListener(egret.Event.RENDER, _this.draw, _this); + return _this; + } + Object.defineProperty(Core, "Instance", { + get: function () { + return this._instance; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Core, "scene", { + get: function () { + return this._instance._scene; + }, + set: function (value) { + if (!value) { + console.error("场景不能为空"); + return; + } + if (this._instance._scene == null) { + this._instance._scene = value; + this._instance._scene.begin(); + Core.Instance.onSceneChanged(); + } + else { + this._instance._nextScene = value; + } + this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene); + }, + enumerable: true, + configurable: true + }); + Core.prototype.onOrientationChanged = function () { + Core.emitter.emit(es.CoreEvents.OrientationChanged); + }; + Core.prototype.onGraphicsDeviceReset = function () { + Core.emitter.emit(es.CoreEvents.GraphicsDeviceReset); + }; + Core.prototype.initialize = function () { + }; + Core.prototype.update = function () { + this.startDebugUpdate(); + es.Time.update(egret.getTimer()); + if (this._scene) { + for (var i = this._globalManagers.length - 1; i >= 0; i--) { + if (this._globalManagers[i].enabled) + this._globalManagers[i].update(); + } + if (!this._sceneTransition || + (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) { + this._scene.update(); + } + if (this._nextScene) { + this._scene.end(); + this._scene = this._nextScene; + this._nextScene = null; + this.onSceneChanged(); + this._scene.begin(); + } + } + this.endDebugUpdate(); + }; + Core.prototype.draw = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this._sceneTransition) return [3, 4]; + this._sceneTransition.preRender(); + if (!(this._scene && !this._sceneTransition.hasPreviousSceneRender)) return [3, 2]; + this._scene.render(); + this._scene.postRender(); + return [4, this._sceneTransition.onBeginTransition()]; + case 1: + _a.sent(); + return [3, 3]; + case 2: + if (this._sceneTransition) { + if (this._scene && this._sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + this._sceneTransition.render(); + } + _a.label = 3; + case 3: return [3, 5]; + case 4: + if (this._scene) { + this._scene.render(); + es.Debug.render(); + this._scene.postRender(); + } + _a.label = 5; + case 5: return [2]; + } + }); + }); + }; + Core.prototype.startDebugUpdate = function () { + es.TimeRuler.Instance.startFrame(); + es.TimeRuler.Instance.beginMark("update", 0x00FF00); + }; + Core.prototype.endDebugUpdate = function () { + es.TimeRuler.Instance.endMark("update"); + }; + Core.prototype.onSceneChanged = function () { + Core.emitter.emit(es.CoreEvents.SceneChanged); + es.Time.sceneChanged(); + }; + Core.startSceneTransition = function (sceneTransition) { + if (this._instance._sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } + this._instance._sceneTransition = sceneTransition; + return sceneTransition; + }; + Core.registerActiveSceneChanged = function (current, next) { + if (this.activeSceneChanged) + this.activeSceneChanged(current, next); + }; + Core.registerGlobalManager = function (manager) { + this._instance._globalManagers.push(manager); + manager.enabled = true; + }; + Core.unregisterGlobalManager = function (manager) { + this._instance._globalManagers.remove(manager); + manager.enabled = false; + }; + Core.getGlobalManager = function (type) { + for (var i = 0; i < this._instance._globalManagers.length; i++) { + if (this._instance._globalManagers[i] instanceof type) + return this._instance._globalManagers[i]; + } + return null; + }; + return Core; + }(egret.DisplayObjectContainer)); + es.Core = Core; +})(es || (es = {})); +var es; (function (es) { var CoreEvents; (function (CoreEvents) { - CoreEvents[CoreEvents["SceneChanged"] = 0] = "SceneChanged"; + CoreEvents[CoreEvents["GraphicsDeviceReset"] = 0] = "GraphicsDeviceReset"; + CoreEvents[CoreEvents["SceneChanged"] = 1] = "SceneChanged"; + CoreEvents[CoreEvents["OrientationChanged"] = 2] = "OrientationChanged"; })(CoreEvents = es.CoreEvents || (es.CoreEvents = {})); })(es || (es = {})); var es; @@ -1347,8 +1504,6 @@ var es; _this.renderableComponents = new es.RenderableComponentList(); _this.content = new es.ContentManager(); _this.entityProcessors = new es.EntityProcessorList(); - _this.width = es.SceneManager.stage.stageWidth; - _this.height = es.SceneManager.stage.stageHeight; _this.initialize(); return _this; } @@ -1369,12 +1524,6 @@ var es; Scene.prototype.begin = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { - if (es.SceneManager.sceneTransition) { - es.SceneManager.stage.addChildAt(this, es.SceneManager.stage.numChildren - 1); - } - else { - es.SceneManager.stage.addChild(this); - } if (this._renderers.length == 0) { this.addRenderer(new es.DefaultRenderer()); console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); @@ -1528,120 +1677,6 @@ var es; }(egret.DisplayObjectContainer)); es.Scene = Scene; })(es || (es = {})); -var es; -(function (es) { - var SceneManager = (function () { - function SceneManager(stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - SceneManager._instnace = this; - SceneManager.emitter = new es.Emitter(); - SceneManager.content = new es.ContentManager(); - SceneManager.stage = stage; - SceneManager.initialize(stage); - SceneManager.timerRuler = new es.TimeRuler(); - } - Object.defineProperty(SceneManager, "Instance", { - get: function () { - return this._instnace; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SceneManager, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - if (!value) - throw new Error("场景不能为空"); - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - SceneManager.Instance.onSceneChanged(); - } - else { - this._nextScene = value; - } - this.registerActiveSceneChanged(this._scene, this._nextScene); - }, - enumerable: true, - configurable: true - }); - SceneManager.initialize = function (stage) { - es.Input.initialize(stage); - }; - SceneManager.update = function () { - SceneManager.startDebugUpdate(); - es.Time.update(egret.getTimer()); - if (SceneManager._scene) { - for (var i = es.GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (es.GlobalManager.globalManagers[i].enabled) - es.GlobalManager.globalManagers[i].update(); - } - if (!SceneManager.sceneTransition || - (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { - SceneManager._scene.update(); - } - if (SceneManager._nextScene) { - SceneManager._scene.end(); - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._instnace.onSceneChanged(); - SceneManager._scene.begin(); - } - } - SceneManager.endDebugUpdate(); - SceneManager.render(); - }; - SceneManager.render = function () { - if (this.sceneTransition) { - this.sceneTransition.preRender(); - if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } - else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { - this._scene.render(); - this._scene.postRender(); - } - this.sceneTransition.render(); - } - } - else if (this._scene) { - this._scene.render(); - es.Debug.render(); - this._scene.postRender(); - } - }; - SceneManager.startSceneTransition = function (sceneTransition) { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; - } - this.sceneTransition = sceneTransition; - return sceneTransition; - }; - SceneManager.registerActiveSceneChanged = function (current, next) { - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - }; - SceneManager.prototype.onSceneChanged = function () { - SceneManager.emitter.emit(es.CoreEvents.SceneChanged); - es.Time.sceneChanged(); - }; - SceneManager.startDebugUpdate = function () { - es.TimeRuler.Instance.startFrame(); - es.TimeRuler.Instance.beginMark("update", 0x00FF00); - }; - SceneManager.endDebugUpdate = function () { - es.TimeRuler.Instance.endMark("update"); - }; - return SceneManager; - }()); - es.SceneManager = SceneManager; -})(es || (es = {})); var transform; (function (transform) { var Component; @@ -1851,10 +1886,10 @@ var es; this.updateMatrixes(); if (this._areBoundsDirty) { var topLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, this._inset.top)); - var bottomRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, es.SceneManager.stage.stageHeight - this._inset.bottom)); + var bottomRight = this.screenToWorldPoint(new es.Vector2(es.Core.graphicsDevice.viewport.width - this._inset.right, es.Core.graphicsDevice.viewport.height - this._inset.bottom)); if (this.entity.transform.rotation != 0) { - var topRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, this._inset.top)); - var bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, es.SceneManager.stage.stageHeight - this._inset.bottom)); + var topRight = this.screenToWorldPoint(new es.Vector2(es.Core.graphicsDevice.viewport.width - this._inset.right, this._inset.top)); + var bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, es.Core.graphicsDevice.viewport.height - this._inset.bottom)); var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); @@ -2008,8 +2043,8 @@ var es; }; Camera.prototype.update = function () { var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)); - this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.Core.scene.scaleX + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y; this._worldSpaceDeadZone.width = this.deadzone.width; this._worldSpaceDeadZone.height = this.deadzone.height; if (this._targetEntity) @@ -4021,7 +4056,7 @@ var es; var offsetY = Math.round(bitmapData.$offsetY); var bitmapWidth = bitmapData.$bitmapWidth; var bitmapHeight = bitmapData.$bitmapHeight; - var $TextureScaleFactor = es.SceneManager.stage.textureScaleFactor; + var $TextureScaleFactor = es.Core._instance.stage.textureScaleFactor; this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); return surface; } @@ -4300,9 +4335,20 @@ var es; (function (es) { var GraphicsDevice = (function () { function GraphicsDevice() { + this.setup(); this.graphicsCapabilities = new es.GraphicsCapabilities(); this.graphicsCapabilities.initialize(this); } + Object.defineProperty(GraphicsDevice.prototype, "viewport", { + get: function () { + return this._viewport; + }, + enumerable: true, + configurable: true + }); + GraphicsDevice.prototype.setup = function () { + this._viewport = new es.Viewport(0, 0, es.Core._instance.stage.stageWidth, es.Core._instance.stage.stageHeight); + }; return GraphicsDevice; }()); es.GraphicsDevice = GraphicsDevice; @@ -4318,6 +4364,26 @@ var es; this._minDepth = 0; this._maxDepth = 1; } + Object.defineProperty(Viewport.prototype, "height", { + get: function () { + return this._height; + }, + set: function (value) { + this._height = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Viewport.prototype, "width", { + get: function () { + return this._width; + }, + set: function (value) { + this._width = value; + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Viewport.prototype, "aspectRatio", { get: function () { if ((this._height != 0) && (this._width != 0)) @@ -4350,8 +4416,8 @@ var es; __extends(GaussianBlurEffect, _super); function GaussianBlurEffect() { return _super.call(this, es.PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { - screenWidth: es.SceneManager.stage.stageWidth, - screenHeight: es.SceneManager.stage.stageHeight + screenWidth: es.Core.graphicsDevice.viewport.width, + screenHeight: es.Core.graphicsDevice.viewport.height }) || this; } GaussianBlurEffect.blur_frag = "precision mediump float;\n" + @@ -4435,7 +4501,7 @@ var es; this.scene = scene; this.shape = new egret.Shape(); this.shape.graphics.beginFill(0xFFFFFF, 1); - this.shape.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.shape.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this.shape.graphics.endFill(); scene.addChild(this.shape); }; @@ -4614,7 +4680,7 @@ var es; }); }; SceneTransition.prototype.transitionComplete = function () { - es.SceneManager.sceneTransition = null; + es.Core._instance._sceneTransition = null; if (this.onTransitionCompleted) { this.onTransitionCompleted(); } @@ -4630,7 +4696,7 @@ var es; if (!this.loadsNewScene) { this.isNewSceneLoaded = true; } - _a = es.SceneManager; + _a = es.Core; return [4, this.sceneLoadAction()]; case 1: _a.scene = _b.sent(); @@ -4673,9 +4739,8 @@ var es; var _this = this; return __generator(this, function (_a) { this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this._mask.graphics.endFill(); - es.SceneManager.stage.addChild(this._mask); egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) .call(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { @@ -4689,7 +4754,6 @@ var es; }); }).wait(this.delayBeforeFadeInDuration).call(function () { egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { _this.transitionComplete(); - es.SceneManager.stage.removeChild(_this._mask); }); }); return [2]; @@ -4699,7 +4763,7 @@ var es; FadeTransition.prototype.render = function () { this._mask.graphics.clear(); this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this._mask.graphics.endFill(); }; return FadeTransition; @@ -4744,10 +4808,9 @@ var es; }); _this._mask = new egret.Shape(); _this._mask.graphics.beginFill(0xFFFFFF, 1); - _this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + _this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); _this._mask.graphics.endFill(); _this._mask.filters = [_this._windEffect]; - es.SceneManager.stage.addChild(_this._mask); return _this; } Object.defineProperty(WindTransition.prototype, "windSegments", { @@ -4774,7 +4837,6 @@ var es; case 1: _a.sent(); this.transitionComplete(); - es.SceneManager.stage.removeChild(this._mask); return [2]; } }); @@ -6625,22 +6687,6 @@ var es; GlobalManager.prototype.onEnabled = function () { }; GlobalManager.prototype.onDisabled = function () { }; GlobalManager.prototype.update = function () { }; - GlobalManager.registerGlobalManager = function (manager) { - this.globalManagers.push(manager); - manager.enabled = true; - }; - GlobalManager.unregisterGlobalManager = function (manager) { - this.globalManagers.remove(manager); - manager.enabled = false; - }; - GlobalManager.getGlobalManager = function (type) { - for (var i = 0; i < this.globalManagers.length; i++) { - if (this.globalManagers[i] instanceof type) - return this.globalManagers[i]; - } - return null; - }; - GlobalManager.globalManagers = []; return GlobalManager; }()); es.GlobalManager = GlobalManager; @@ -6684,10 +6730,10 @@ var es; }); Object.defineProperty(Input, "maxSupportedTouch", { get: function () { - return this._stage.maxTouches; + return es.Core._instance.stage.maxTouches; }, set: function (value) { - this._stage.maxTouches = value; + es.Core._instance.stage.maxTouches = value; this.initTouchCache(); }, enumerable: true, @@ -6725,16 +6771,15 @@ var es; enumerable: true, configurable: true }); - Input.initialize = function (stage) { + Input.initialize = function () { if (this._init) return; this._init = true; - this._stage = stage; - this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); this.initTouchCache(); }; Input.initTouchCache = function () { @@ -7324,7 +7369,7 @@ var es; (function (es) { var Layout = (function () { function Layout() { - this.clientArea = new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.clientArea = new es.Rectangle(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this.safeArea = this.clientArea; } Layout.prototype.place = function (size, horizontalMargin, verticalMargine, alignment) { @@ -7530,7 +7575,8 @@ var es; for (var i = 0; i < this._logs.length; ++i) this._logs[i] = new FrameLog(); this.sampleFrames = this.targetSampleFrames = 1; - this.width = es.SceneManager.stage.stageWidth * 0.8; + this.width = es.Core.graphicsDevice.viewport.width * 0.8; + es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this); this.onGraphicsDeviceReset(); } TimeRuler.prototype.onGraphicsDeviceReset = function () { diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index a9d330a4..da2a3273 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.graphicsDevice=new t.GraphicsDevice,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.initialize,i),i.addEventListener(egret.Event.RESIZE,i.onGraphicsDeviceReset,i),i.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,i.onOrientationChanged,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i.addEventListener(egret.Event.RENDER,i.draw,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance._scene},set:function(t){t?(null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t,this.registerActiveSceneChanged(this._instance._scene,this._instance._nextScene)):console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/demo/src/Main.ts b/demo/src/Main.ts index 2233ec36..81c86779 100644 --- a/demo/src/Main.ts +++ b/demo/src/Main.ts @@ -28,7 +28,10 @@ ////////////////////////////////////////////////////////////////////////////////////// -class Main extends eui.UILayer { +import SceneManager = es.SceneManager; +import Emitter = es.Emitter; + +class Main extends SceneManager { public static emitter: Emitter; public static manager: SceneManager; diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 9f76bfa9..22ae545a 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -246,9 +246,40 @@ declare module es { clone(): Component; } } +declare module es { + class Core extends egret.DisplayObjectContainer { + static activeSceneChanged: Function; + static emitter: Emitter; + static graphicsDevice: GraphicsDevice; + static content: ContentManager; + static readonly Instance: Core; + static _instance: Core; + _scene: Scene; + _nextScene: Scene; + _sceneTransition: SceneTransition; + _globalManagers: GlobalManager[]; + static scene: Scene; + constructor(); + onOrientationChanged(): void; + protected onGraphicsDeviceReset(): void; + protected initialize(): void; + protected update(): void; + draw(): Promise; + startDebugUpdate(): void; + endDebugUpdate(): void; + onSceneChanged(): void; + static startSceneTransition(sceneTransition: T): T; + static registerActiveSceneChanged(current: Scene, next: Scene): void; + static registerGlobalManager(manager: es.GlobalManager): void; + static unregisterGlobalManager(manager: es.GlobalManager): void; + static getGlobalManager(type: any): T; + } +} declare module es { enum CoreEvents { - SceneChanged = 0 + GraphicsDeviceReset = 0, + SceneChanged = 1, + OrientationChanged = 2 } } declare module es { @@ -340,30 +371,6 @@ declare module es { getEntityProcessor(): T; } } -declare module es { - class SceneManager { - private static _scene; - private static _nextScene; - static sceneTransition: SceneTransition; - static stage: egret.Stage; - static activeSceneChanged: Function; - static emitter: Emitter; - static content: ContentManager; - private static _instnace; - private static timerRuler; - static readonly Instance: SceneManager; - constructor(stage: egret.Stage); - static scene: Scene; - static initialize(stage: egret.Stage): void; - static update(): void; - static render(): void; - static startSceneTransition(sceneTransition: T): T; - static registerActiveSceneChanged(current: Scene, next: Scene): void; - onSceneChanged(): void; - private static startDebugUpdate; - private static endDebugUpdate; - } -} declare module transform { enum Component { position = 0, @@ -942,9 +949,11 @@ declare module es { } declare module es { class GraphicsDevice { - private viewport; + private _viewport; + readonly viewport: Viewport; graphicsCapabilities: GraphicsCapabilities; constructor(); + private setup; } } declare module es { @@ -955,6 +964,8 @@ declare module es { private _height; private _minDepth; private _maxDepth; + height: number; + width: number; readonly aspectRatio: number; bounds: Rectangle; constructor(x: number, y: number, width: number, height: number); @@ -1398,16 +1409,12 @@ declare module es { } declare module es { class GlobalManager { - static globalManagers: GlobalManager[]; - private _enabled; enabled: boolean; setEnabled(isEnabled: boolean): void; + _enabled: boolean; onEnabled(): void; onDisabled(): void; update(): void; - static registerGlobalManager(manager: GlobalManager): void; - static unregisterGlobalManager(manager: GlobalManager): void; - static getGlobalManager(type: any): T; } } declare module es { @@ -1421,7 +1428,6 @@ declare module es { } class Input { private static _init; - private static _stage; private static _previousTouchState; private static _gameTouchs; private static _resolutionOffset; @@ -1434,7 +1440,7 @@ declare module es { static readonly totalTouchCount: number; static readonly gameTouchs: TouchState[]; static readonly touchPositionDelta: Vector2; - static initialize(stage: egret.Stage): void; + static initialize(): void; private static initTouchCache; private static touchBegin; private static touchMove; diff --git a/source/bin/framework.js b/source/bin/framework.js index 8d58b667..4e14fae4 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -955,8 +955,8 @@ var es; Debug.render = function () { if (this._debugDrawItems.length > 0) { var debugShape = new egret.Shape(); - if (es.SceneManager.scene) { - es.SceneManager.scene.addChild(debugShape); + if (es.Core.scene) { + es.Core.scene.addChild(debugShape); } for (var i = this._debugDrawItems.length - 1; i >= 0; i--) { var item = this._debugDrawItems[i]; @@ -1097,10 +1097,167 @@ var es; es.Component = Component; })(es || (es = {})); var es; +(function (es) { + var Core = (function (_super) { + __extends(Core, _super); + function Core() { + var _this = _super.call(this) || this; + _this._globalManagers = []; + Core._instance = _this; + Core.emitter = new es.Emitter(); + Core.graphicsDevice = new es.GraphicsDevice(); + Core.content = new es.ContentManager(); + _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this); + _this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this); + _this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this); + _this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this); + _this.addEventListener(egret.Event.RENDER, _this.draw, _this); + return _this; + } + Object.defineProperty(Core, "Instance", { + get: function () { + return this._instance; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Core, "scene", { + get: function () { + return this._instance._scene; + }, + set: function (value) { + if (!value) { + console.error("场景不能为空"); + return; + } + if (this._instance._scene == null) { + this._instance._scene = value; + this._instance._scene.begin(); + Core.Instance.onSceneChanged(); + } + else { + this._instance._nextScene = value; + } + this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene); + }, + enumerable: true, + configurable: true + }); + Core.prototype.onOrientationChanged = function () { + Core.emitter.emit(es.CoreEvents.OrientationChanged); + }; + Core.prototype.onGraphicsDeviceReset = function () { + Core.emitter.emit(es.CoreEvents.GraphicsDeviceReset); + }; + Core.prototype.initialize = function () { + }; + Core.prototype.update = function () { + this.startDebugUpdate(); + es.Time.update(egret.getTimer()); + if (this._scene) { + for (var i = this._globalManagers.length - 1; i >= 0; i--) { + if (this._globalManagers[i].enabled) + this._globalManagers[i].update(); + } + if (!this._sceneTransition || + (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) { + this._scene.update(); + } + if (this._nextScene) { + this._scene.end(); + this._scene = this._nextScene; + this._nextScene = null; + this.onSceneChanged(); + this._scene.begin(); + } + } + this.endDebugUpdate(); + }; + Core.prototype.draw = function () { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!this._sceneTransition) return [3, 4]; + this._sceneTransition.preRender(); + if (!(this._scene && !this._sceneTransition.hasPreviousSceneRender)) return [3, 2]; + this._scene.render(); + this._scene.postRender(); + return [4, this._sceneTransition.onBeginTransition()]; + case 1: + _a.sent(); + return [3, 3]; + case 2: + if (this._sceneTransition) { + if (this._scene && this._sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + this._sceneTransition.render(); + } + _a.label = 3; + case 3: return [3, 5]; + case 4: + if (this._scene) { + this._scene.render(); + es.Debug.render(); + this._scene.postRender(); + } + _a.label = 5; + case 5: return [2]; + } + }); + }); + }; + Core.prototype.startDebugUpdate = function () { + es.TimeRuler.Instance.startFrame(); + es.TimeRuler.Instance.beginMark("update", 0x00FF00); + }; + Core.prototype.endDebugUpdate = function () { + es.TimeRuler.Instance.endMark("update"); + }; + Core.prototype.onSceneChanged = function () { + Core.emitter.emit(es.CoreEvents.SceneChanged); + es.Time.sceneChanged(); + }; + Core.startSceneTransition = function (sceneTransition) { + if (this._instance._sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } + this._instance._sceneTransition = sceneTransition; + return sceneTransition; + }; + Core.registerActiveSceneChanged = function (current, next) { + if (this.activeSceneChanged) + this.activeSceneChanged(current, next); + }; + Core.registerGlobalManager = function (manager) { + this._instance._globalManagers.push(manager); + manager.enabled = true; + }; + Core.unregisterGlobalManager = function (manager) { + this._instance._globalManagers.remove(manager); + manager.enabled = false; + }; + Core.getGlobalManager = function (type) { + for (var i = 0; i < this._instance._globalManagers.length; i++) { + if (this._instance._globalManagers[i] instanceof type) + return this._instance._globalManagers[i]; + } + return null; + }; + return Core; + }(egret.DisplayObjectContainer)); + es.Core = Core; +})(es || (es = {})); +var es; (function (es) { var CoreEvents; (function (CoreEvents) { - CoreEvents[CoreEvents["SceneChanged"] = 0] = "SceneChanged"; + CoreEvents[CoreEvents["GraphicsDeviceReset"] = 0] = "GraphicsDeviceReset"; + CoreEvents[CoreEvents["SceneChanged"] = 1] = "SceneChanged"; + CoreEvents[CoreEvents["OrientationChanged"] = 2] = "OrientationChanged"; })(CoreEvents = es.CoreEvents || (es.CoreEvents = {})); })(es || (es = {})); var es; @@ -1347,8 +1504,6 @@ var es; _this.renderableComponents = new es.RenderableComponentList(); _this.content = new es.ContentManager(); _this.entityProcessors = new es.EntityProcessorList(); - _this.width = es.SceneManager.stage.stageWidth; - _this.height = es.SceneManager.stage.stageHeight; _this.initialize(); return _this; } @@ -1369,12 +1524,6 @@ var es; Scene.prototype.begin = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { - if (es.SceneManager.sceneTransition) { - es.SceneManager.stage.addChildAt(this, es.SceneManager.stage.numChildren - 1); - } - else { - es.SceneManager.stage.addChild(this); - } if (this._renderers.length == 0) { this.addRenderer(new es.DefaultRenderer()); console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); @@ -1528,120 +1677,6 @@ var es; }(egret.DisplayObjectContainer)); es.Scene = Scene; })(es || (es = {})); -var es; -(function (es) { - var SceneManager = (function () { - function SceneManager(stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - SceneManager._instnace = this; - SceneManager.emitter = new es.Emitter(); - SceneManager.content = new es.ContentManager(); - SceneManager.stage = stage; - SceneManager.initialize(stage); - SceneManager.timerRuler = new es.TimeRuler(); - } - Object.defineProperty(SceneManager, "Instance", { - get: function () { - return this._instnace; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SceneManager, "scene", { - get: function () { - return this._scene; - }, - set: function (value) { - if (!value) - throw new Error("场景不能为空"); - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - SceneManager.Instance.onSceneChanged(); - } - else { - this._nextScene = value; - } - this.registerActiveSceneChanged(this._scene, this._nextScene); - }, - enumerable: true, - configurable: true - }); - SceneManager.initialize = function (stage) { - es.Input.initialize(stage); - }; - SceneManager.update = function () { - SceneManager.startDebugUpdate(); - es.Time.update(egret.getTimer()); - if (SceneManager._scene) { - for (var i = es.GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (es.GlobalManager.globalManagers[i].enabled) - es.GlobalManager.globalManagers[i].update(); - } - if (!SceneManager.sceneTransition || - (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { - SceneManager._scene.update(); - } - if (SceneManager._nextScene) { - SceneManager._scene.end(); - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._instnace.onSceneChanged(); - SceneManager._scene.begin(); - } - } - SceneManager.endDebugUpdate(); - SceneManager.render(); - }; - SceneManager.render = function () { - if (this.sceneTransition) { - this.sceneTransition.preRender(); - if (this._scene && !this.sceneTransition.hasPreviousSceneRender) { - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } - else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { - this._scene.render(); - this._scene.postRender(); - } - this.sceneTransition.render(); - } - } - else if (this._scene) { - this._scene.render(); - es.Debug.render(); - this._scene.postRender(); - } - }; - SceneManager.startSceneTransition = function (sceneTransition) { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; - } - this.sceneTransition = sceneTransition; - return sceneTransition; - }; - SceneManager.registerActiveSceneChanged = function (current, next) { - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - }; - SceneManager.prototype.onSceneChanged = function () { - SceneManager.emitter.emit(es.CoreEvents.SceneChanged); - es.Time.sceneChanged(); - }; - SceneManager.startDebugUpdate = function () { - es.TimeRuler.Instance.startFrame(); - es.TimeRuler.Instance.beginMark("update", 0x00FF00); - }; - SceneManager.endDebugUpdate = function () { - es.TimeRuler.Instance.endMark("update"); - }; - return SceneManager; - }()); - es.SceneManager = SceneManager; -})(es || (es = {})); var transform; (function (transform) { var Component; @@ -1851,10 +1886,10 @@ var es; this.updateMatrixes(); if (this._areBoundsDirty) { var topLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, this._inset.top)); - var bottomRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, es.SceneManager.stage.stageHeight - this._inset.bottom)); + var bottomRight = this.screenToWorldPoint(new es.Vector2(es.Core.graphicsDevice.viewport.width - this._inset.right, es.Core.graphicsDevice.viewport.height - this._inset.bottom)); if (this.entity.transform.rotation != 0) { - var topRight = this.screenToWorldPoint(new es.Vector2(es.SceneManager.stage.stageWidth - this._inset.right, this._inset.top)); - var bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, es.SceneManager.stage.stageHeight - this._inset.bottom)); + var topRight = this.screenToWorldPoint(new es.Vector2(es.Core.graphicsDevice.viewport.width - this._inset.right, this._inset.top)); + var bottomLeft = this.screenToWorldPoint(new es.Vector2(this._inset.left, es.Core.graphicsDevice.viewport.height - this._inset.bottom)); var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); @@ -2008,8 +2043,8 @@ var es; }; Camera.prototype.update = function () { var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)); - this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.Core.scene.scaleX + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y; this._worldSpaceDeadZone.width = this.deadzone.width; this._worldSpaceDeadZone.height = this.deadzone.height; if (this._targetEntity) @@ -4021,7 +4056,7 @@ var es; var offsetY = Math.round(bitmapData.$offsetY); var bitmapWidth = bitmapData.$bitmapWidth; var bitmapHeight = bitmapData.$bitmapHeight; - var $TextureScaleFactor = es.SceneManager.stage.textureScaleFactor; + var $TextureScaleFactor = es.Core._instance.stage.textureScaleFactor; this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); return surface; } @@ -4300,9 +4335,20 @@ var es; (function (es) { var GraphicsDevice = (function () { function GraphicsDevice() { + this.setup(); this.graphicsCapabilities = new es.GraphicsCapabilities(); this.graphicsCapabilities.initialize(this); } + Object.defineProperty(GraphicsDevice.prototype, "viewport", { + get: function () { + return this._viewport; + }, + enumerable: true, + configurable: true + }); + GraphicsDevice.prototype.setup = function () { + this._viewport = new es.Viewport(0, 0, es.Core._instance.stage.stageWidth, es.Core._instance.stage.stageHeight); + }; return GraphicsDevice; }()); es.GraphicsDevice = GraphicsDevice; @@ -4318,6 +4364,26 @@ var es; this._minDepth = 0; this._maxDepth = 1; } + Object.defineProperty(Viewport.prototype, "height", { + get: function () { + return this._height; + }, + set: function (value) { + this._height = value; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Viewport.prototype, "width", { + get: function () { + return this._width; + }, + set: function (value) { + this._width = value; + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Viewport.prototype, "aspectRatio", { get: function () { if ((this._height != 0) && (this._width != 0)) @@ -4350,8 +4416,8 @@ var es; __extends(GaussianBlurEffect, _super); function GaussianBlurEffect() { return _super.call(this, es.PostProcessor.default_vert, GaussianBlurEffect.blur_frag, { - screenWidth: es.SceneManager.stage.stageWidth, - screenHeight: es.SceneManager.stage.stageHeight + screenWidth: es.Core.graphicsDevice.viewport.width, + screenHeight: es.Core.graphicsDevice.viewport.height }) || this; } GaussianBlurEffect.blur_frag = "precision mediump float;\n" + @@ -4435,7 +4501,7 @@ var es; this.scene = scene; this.shape = new egret.Shape(); this.shape.graphics.beginFill(0xFFFFFF, 1); - this.shape.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.shape.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this.shape.graphics.endFill(); scene.addChild(this.shape); }; @@ -4614,7 +4680,7 @@ var es; }); }; SceneTransition.prototype.transitionComplete = function () { - es.SceneManager.sceneTransition = null; + es.Core._instance._sceneTransition = null; if (this.onTransitionCompleted) { this.onTransitionCompleted(); } @@ -4630,7 +4696,7 @@ var es; if (!this.loadsNewScene) { this.isNewSceneLoaded = true; } - _a = es.SceneManager; + _a = es.Core; return [4, this.sceneLoadAction()]; case 1: _a.scene = _b.sent(); @@ -4673,9 +4739,8 @@ var es; var _this = this; return __generator(this, function (_a) { this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this._mask.graphics.endFill(); - es.SceneManager.stage.addChild(this._mask); egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType) .call(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { @@ -4689,7 +4754,6 @@ var es; }); }).wait(this.delayBeforeFadeInDuration).call(function () { egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () { _this.transitionComplete(); - es.SceneManager.stage.removeChild(_this._mask); }); }); return [2]; @@ -4699,7 +4763,7 @@ var es; FadeTransition.prototype.render = function () { this._mask.graphics.clear(); this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this._mask.graphics.endFill(); }; return FadeTransition; @@ -4744,10 +4808,9 @@ var es; }); _this._mask = new egret.Shape(); _this._mask.graphics.beginFill(0xFFFFFF, 1); - _this._mask.graphics.drawRect(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + _this._mask.graphics.drawRect(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); _this._mask.graphics.endFill(); _this._mask.filters = [_this._windEffect]; - es.SceneManager.stage.addChild(_this._mask); return _this; } Object.defineProperty(WindTransition.prototype, "windSegments", { @@ -4774,7 +4837,6 @@ var es; case 1: _a.sent(); this.transitionComplete(); - es.SceneManager.stage.removeChild(this._mask); return [2]; } }); @@ -6625,22 +6687,6 @@ var es; GlobalManager.prototype.onEnabled = function () { }; GlobalManager.prototype.onDisabled = function () { }; GlobalManager.prototype.update = function () { }; - GlobalManager.registerGlobalManager = function (manager) { - this.globalManagers.push(manager); - manager.enabled = true; - }; - GlobalManager.unregisterGlobalManager = function (manager) { - this.globalManagers.remove(manager); - manager.enabled = false; - }; - GlobalManager.getGlobalManager = function (type) { - for (var i = 0; i < this.globalManagers.length; i++) { - if (this.globalManagers[i] instanceof type) - return this.globalManagers[i]; - } - return null; - }; - GlobalManager.globalManagers = []; return GlobalManager; }()); es.GlobalManager = GlobalManager; @@ -6684,10 +6730,10 @@ var es; }); Object.defineProperty(Input, "maxSupportedTouch", { get: function () { - return this._stage.maxTouches; + return es.Core._instance.stage.maxTouches; }, set: function (value) { - this._stage.maxTouches = value; + es.Core._instance.stage.maxTouches = value; this.initTouchCache(); }, enumerable: true, @@ -6725,16 +6771,15 @@ var es; enumerable: true, configurable: true }); - Input.initialize = function (stage) { + Input.initialize = function () { if (this._init) return; this._init = true; - this._stage = stage; - this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + es.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); this.initTouchCache(); }; Input.initTouchCache = function () { @@ -7324,7 +7369,7 @@ var es; (function (es) { var Layout = (function () { function Layout() { - this.clientArea = new es.Rectangle(0, 0, es.SceneManager.stage.stageWidth, es.SceneManager.stage.stageHeight); + this.clientArea = new es.Rectangle(0, 0, es.Core.graphicsDevice.viewport.width, es.Core.graphicsDevice.viewport.height); this.safeArea = this.clientArea; } Layout.prototype.place = function (size, horizontalMargin, verticalMargine, alignment) { @@ -7530,7 +7575,8 @@ var es; for (var i = 0; i < this._logs.length; ++i) this._logs[i] = new FrameLog(); this.sampleFrames = this.targetSampleFrames = 1; - this.width = es.SceneManager.stage.stageWidth * 0.8; + this.width = es.Core.graphicsDevice.viewport.width * 0.8; + es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this); this.onGraphicsDeviceReset(); } TimeRuler.prototype.onGraphicsDeviceReset = function () { diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index a9d330a4..da2a3273 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.SceneManager.scene&&t.SceneManager.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){!function(t){t[t.SceneChanged=0]="SceneChanged"}(t.CoreEvents||(t.CoreEvents={}))}(es||(es={})),function(t){var e=function(){function e(n){this.updateInterval=1,this._tag=0,this._enabled=!0,this._updateOrder=0,this.components=new t.ComponentList(this),this.transform=new t.Transform(this),this.name=n,this.id=e._idGenerator++,this.componentBits=new t.BitSet}return Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isDestroyed",{get:function(){return this._isDestroyed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"childCount",{get:function(){return this.transform.childCount},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t.x,t.y)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),e.prototype.onTransformChanged=function(t){this.components.onEntityTransformChanged(t)},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.components.onEntityEnabled():this.components.onEntityDisabled()),this},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.destroy=function(){this._isDestroyed=!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.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t=0;n--)t.GlobalManager.globalManagers[n].enabled&&t.GlobalManager.globalManagers[n].update();e.sceneTransition&&(!e.sceneTransition||e.sceneTransition.loadsNewScene&&!e.sceneTransition.isNewSceneLoaded)||e._scene.update(),e._nextScene&&(e._scene.end(),e._scene=e._nextScene,e._nextScene=null,e._instnace.onSceneChanged(),e._scene.begin())}e.endDebugUpdate(),e.render()},e.render=function(){this.sceneTransition?(this.sceneTransition.preRender(),this._scene&&!this.sceneTransition.hasPreviousSceneRender?(this._scene.render(),this._scene.postRender(),this.sceneTransition.onBeginTransition()):this.sceneTransition&&(this._scene&&this.sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this.sceneTransition.render())):this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender())},e.startSceneTransition=function(t){if(!this.sceneTransition)return this.sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},e.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},e.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},e.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},e}();t.SceneManager=e}(es||(es={})),function(t){!function(t){t[t.position=0]="position",t[t.scale=1]="scale",t[t.rotation=2]="rotation"}(t.Component||(t.Component={}))}(transform||(transform={})),function(t){var e;!function(t){t[t.clean=0]="clean",t[t.positionDirty=1]="positionDirty",t[t.scaleDirty=2]="scaleDirty",t[t.rotationDirty=3]="rotationDirty"}(e=t.DirtyType||(t.DirtyType={}));var n=function(){function n(e){this.entity=e,this.scale=t.Vector2.one,this._children=[]}return Object.defineProperty(n.prototype,"parent",{get:function(){return this._parent},set:function(t){this.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"childCount",{get:function(){return this._children.length},enumerable:!0,configurable:!0}),n.prototype.getChild=function(t){return this._children[t]},n.prototype.setParent=function(t){return this._parent==t?this:(this._parent||(this._parent._children.remove(this),this._parent._children.push(this)),this._parent=t,this.setDirty(e.positionDirty),this)},n.prototype.setPosition=function(n,i){return this.position=new t.Vector2(n,i),this.setDirty(e.positionDirty),this},n.prototype.setRotation=function(t){return this.rotation=t,this.setDirty(e.rotationDirty),this},n.prototype.setScale=function(t){return this.scale=t,this.setDirty(e.scaleDirty),this},n.prototype.lookAt=function(e){var n=this.position.x>e.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.SceneManager.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.SceneManager.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){return function(){this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.SceneManager.stage.stageWidth,screenHeight:t.SceneManager.stage.stageHeight})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.SceneManager.stage.stageWidth,t.SceneManager.stage.stageHeight),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.graphicsDevice=new t.GraphicsDevice,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.initialize,i),i.addEventListener(egret.Event.RESIZE,i.onGraphicsDeviceReset,i),i.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,i.onOrientationChanged,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i.addEventListener(egret.Event.RENDER,i.draw,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance._scene},set:function(t){t?(null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t,this.registerActiveSceneChanged(this._instance._scene,this._instance._nextScene)):console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/Debug/Debug.ts b/source/src/Debug/Debug.ts index a1ebdce9..f889b517 100644 --- a/source/src/Debug/Debug.ts +++ b/source/src/Debug/Debug.ts @@ -9,8 +9,8 @@ module es { public static render(){ if (this._debugDrawItems.length > 0){ let debugShape = new egret.Shape(); - if (SceneManager.scene){ - SceneManager.scene.addChild(debugShape); + if (Core.scene){ + Core.scene.addChild(debugShape); } for (let i = this._debugDrawItems.length - 1; i >= 0; i --){ diff --git a/source/src/ECS/Components/Camera.ts b/source/src/ECS/Components/Camera.ts index 6ab4bfad..fae49cb1 100644 --- a/source/src/ECS/Components/Camera.ts +++ b/source/src/ECS/Components/Camera.ts @@ -105,15 +105,15 @@ module es { if (this._areBoundsDirty){ // 旋转或非旋转的边界都需要左上角和右下角 let topLeft = this.screenToWorldPoint(new Vector2(this._inset.left, this._inset.top)); - let bottomRight = this.screenToWorldPoint(new Vector2(SceneManager.stage.stageWidth - this._inset.right, - SceneManager.stage.stageHeight - this._inset.bottom)); + let bottomRight = this.screenToWorldPoint(new Vector2(Core.graphicsDevice.viewport.width - this._inset.right, + Core.graphicsDevice.viewport.height - this._inset.bottom)); if (this.entity.transform.rotation != 0){ // 特别注意旋转的边界。我们需要找到绝对的最小/最大值并从中创建边界 - let topRight = this.screenToWorldPoint(new Vector2(SceneManager.stage.stageWidth - this._inset.right, + let topRight = this.screenToWorldPoint(new Vector2(Core.graphicsDevice.viewport.width - this._inset.right, this._inset.top)); let bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, - SceneManager.stage.stageHeight - this._inset.bottom)); + Core.graphicsDevice.viewport.height - this._inset.bottom)); let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); @@ -386,8 +386,8 @@ module es { public update() { let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5)); - this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * SceneManager.scene.scaleX + this.deadzone.x + this.focusOffset.x; - this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * SceneManager.scene.scaleY + this.deadzone.y + this.focusOffset.y; + this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * Core.scene.scaleX + this.deadzone.x + this.focusOffset.x; + this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * Core.scene.scaleY + this.deadzone.y + this.focusOffset.y; this._worldSpaceDeadZone.width = this.deadzone.width; this._worldSpaceDeadZone.height = this.deadzone.height; diff --git a/source/src/ECS/Core.ts b/source/src/ECS/Core.ts new file mode 100644 index 00000000..767e03a7 --- /dev/null +++ b/source/src/ECS/Core.ts @@ -0,0 +1,228 @@ +module es { + /** + * 全局核心类 + */ + export class Core extends egret.DisplayObjectContainer { + /** + * 订阅此事件以在活动场景发生更改时得到通知。 + */ + public static activeSceneChanged: Function; + /** + * 核心发射器。只发出核心级别的事件 + */ + public static emitter: Emitter; + /** + * 全局访问图形设备 + */ + public static graphicsDevice: GraphicsDevice; + /** + * 全局内容管理器加载任何应该停留在场景之间的资产 + */ + public static content: ContentManager; + + /** + * 提供对单例/游戏实例的访问 + * @constructor + */ + public static get Instance(){ + return this._instance; + } + + /** + * 简化对内部类的全局内容实例的访问 + */ + public static _instance: Core; + public _scene: Scene; + public _nextScene: Scene; + public _sceneTransition: SceneTransition; + /** + * 全局访问系统 + */ + public _globalManagers: GlobalManager[] = []; + + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + */ + public static get scene() { + return this._instance._scene; + } + + /** + * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 + * @param value + */ + public static set scene(value: Scene) { + if (!value){ + console.error("场景不能为空"); + return; + } + + if (this._instance._scene == null) { + this._instance._scene = value; + this._instance._scene.begin(); + Core.Instance.onSceneChanged(); + } else { + this._instance._nextScene = value; + } + + this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene); + } + + constructor() { + super(); + + Core._instance = this; + Core.emitter = new Emitter(); + Core.graphicsDevice = new GraphicsDevice(); + Core.content = new ContentManager(); + + this.addEventListener(egret.Event.ADDED_TO_STAGE, this.initialize, this); + this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); + this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); + this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); + this.addEventListener(egret.Event.RENDER, this.draw, this); + } + + public onOrientationChanged(){ + Core.emitter.emit(CoreEvents.OrientationChanged); + } + + /** + * 当屏幕大小发生改变时调用 + */ + protected onGraphicsDeviceReset(){ + Core.emitter.emit(CoreEvents.GraphicsDeviceReset); + } + + protected initialize(){ + } + + protected update() { + this.startDebugUpdate(); + + // 更新我们所有的系统管理器 + Time.update(egret.getTimer()); + + if (this._scene) { + for (let i = this._globalManagers.length - 1; i >= 0; i--) { + if (this._globalManagers[i].enabled) + this._globalManagers[i].update(); + } + + // 仔细阅读: + // 当场景转换发生时,我们不会更新场景 + // -除非是不改变场景的场景转换(没有理由不更新) + // -或者它是一个已经切换到新场景的场景转换(新场景需要做它自己的事情) + if (!this._sceneTransition || + (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) { + this._scene.update(); + } + + if (this._nextScene) { + this._scene.end(); + + this._scene = this._nextScene; + this._nextScene = null; + this.onSceneChanged(); + + this._scene.begin(); + } + } + + this.endDebugUpdate(); + } + + public async draw() { + if (this._sceneTransition){ + this._sceneTransition.preRender(); + + // 如果我们有场景转换的特殊处理。我们要么渲染场景过渡,要么渲染场景 + if (this._scene && !this._sceneTransition.hasPreviousSceneRender){ + this._scene.render(); + this._scene.postRender(); + await this._sceneTransition.onBeginTransition(); + } else if (this._sceneTransition) { + if (this._scene && this._sceneTransition.isNewSceneLoaded) { + this._scene.render(); + this._scene.postRender(); + } + + this._sceneTransition.render(); + } + } else if (this._scene) { + this._scene.render(); + + Debug.render(); + + // 如果我们没有一个活跃的场景转换,就像平常一样渲染 + this._scene.postRender(); + } + } + + public startDebugUpdate(){ + TimeRuler.Instance.startFrame(); + TimeRuler.Instance.beginMark("update", 0x00FF00); + } + + public endDebugUpdate(){ + TimeRuler.Instance.endMark("update"); + } + + /** + * 在一个场景结束后,下一个场景开始之前调用 + */ + public onSceneChanged(){ + Core.emitter.emit(CoreEvents.SceneChanged); + Time.sceneChanged(); + } + + /** + * 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。 + * @param sceneTransition + */ + public static startSceneTransition(sceneTransition: T): T { + if (this._instance._sceneTransition) { + console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); + return; + } + + this._instance._sceneTransition = sceneTransition; + return sceneTransition; + } + + public static registerActiveSceneChanged(current: Scene, next: Scene){ + if (this.activeSceneChanged) + this.activeSceneChanged(current, next); + } + + /** + * 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。 + * @param manager + */ + public static registerGlobalManager(manager: es.GlobalManager){ + this._instance._globalManagers.push(manager); + manager.enabled = true; + } + + /** + * 删除全局管理器对象 + * @param manager + */ + public static unregisterGlobalManager(manager: es.GlobalManager){ + this._instance._globalManagers.remove(manager); + manager.enabled = false; + } + + /** + * 获取类型为T的全局管理器 + * @param type + */ + public static getGlobalManager(type): T { + for (let i = 0; i < this._instance._globalManagers.length; i ++){ + if (this._instance._globalManagers[i] instanceof type) + return this._instance._globalManagers[i] as T; + } + return null; + } + } +} diff --git a/source/src/ECS/CoreEvents.ts b/source/src/ECS/CoreEvents.ts index c9893382..72581adc 100644 --- a/source/src/ECS/CoreEvents.ts +++ b/source/src/ECS/CoreEvents.ts @@ -1,6 +1,16 @@ module es { export enum CoreEvents{ - /** 当场景发生变化时触发 */ + /** + * 在图形设备重置时触发。当这种情况发生时,任何渲染目标或其他内容的VRAM将被擦除,需要重新生成 + */ + GraphicsDeviceReset, + /** + * 当场景发生变化时触发 + */ SceneChanged, + /** + * 当设备方向改变时触发 + */ + OrientationChanged, } } diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index 84fb8f65..16359e42 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -48,9 +48,6 @@ module es { this.entityProcessors = new EntityProcessorList(); - this.width = SceneManager.stage.stageWidth; - this.height = SceneManager.stage.stageHeight; - this.initialize(); } @@ -81,13 +78,6 @@ module es { public onDeactive() {} public async begin() { - // 如果是场景转换需要在最顶层 - if (SceneManager.sceneTransition){ - SceneManager.stage.addChildAt(this, SceneManager.stage.numChildren - 1); - }else{ - SceneManager.stage.addChild(this); - } - if (this._renderers.length == 0) { this.addRenderer(new DefaultRenderer()); console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); diff --git a/source/src/ECS/SceneManager.ts b/source/src/ECS/SceneManager.ts deleted file mode 100644 index cf5b74b7..00000000 --- a/source/src/ECS/SceneManager.ts +++ /dev/null @@ -1,146 +0,0 @@ -module es { - /** 运行时的场景管理。 */ - export class SceneManager { - private static _scene: Scene; - private static _nextScene: Scene; - public static sceneTransition: SceneTransition; - public static stage: egret.Stage; - /** 订阅此事件以在活动场景发生更改时得到通知。 */ - public static activeSceneChanged: Function; - /** 核心发射器。只发出核心级别的事件 */ - public static emitter: Emitter; - /** 全局内容管理器加载任何应该停留在场景之间的资产 */ - public static content: ContentManager; - /** 简化对内部类的全局内容实例的访问 */ - private static _instnace: SceneManager; - private static timerRuler: TimeRuler; - public static get Instance(){ - return this._instnace; - } - - constructor(stage: egret.Stage) { - stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); - - SceneManager._instnace = this; - SceneManager.emitter = new Emitter(); - SceneManager.content = new ContentManager(); - - SceneManager.stage = stage; - SceneManager.initialize(stage); - SceneManager.timerRuler = new TimeRuler(); - } - - public static get scene() { - return this._scene; - } - public static set scene(value: Scene) { - if (!value) - throw new Error("场景不能为空"); - - if (this._scene == null) { - this._scene = value; - this._scene.begin(); - SceneManager.Instance.onSceneChanged(); - } else { - this._nextScene = value; - } - - this.registerActiveSceneChanged(this._scene, this._nextScene); - } - - public static initialize(stage: egret.Stage) { - Input.initialize(stage); - } - - public static update() { - SceneManager.startDebugUpdate(); - Time.update(egret.getTimer()); - - if (SceneManager._scene) { - for (let i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } - - if (!SceneManager.sceneTransition || - (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { - SceneManager._scene.update(); - } - - if (SceneManager._nextScene) { - SceneManager._scene.end(); - - SceneManager._scene = SceneManager._nextScene; - SceneManager._nextScene = null; - SceneManager._instnace.onSceneChanged(); - - SceneManager._scene.begin(); - } - } - - SceneManager.endDebugUpdate(); - SceneManager.render(); - } - - public static render() { - if (this.sceneTransition){ - this.sceneTransition.preRender(); - - if (this._scene && !this.sceneTransition.hasPreviousSceneRender){ - this._scene.render(); - this._scene.postRender(); - this.sceneTransition.onBeginTransition(); - } else if (this.sceneTransition) { - if (this._scene && this.sceneTransition.isNewSceneLoaded) { - this._scene.render(); - this._scene.postRender(); - } - - this.sceneTransition.render(); - } - } else if (this._scene) { - this._scene.render(); - - Debug.render(); - - this._scene.postRender(); - } - } - - /** - * 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。 - * @param sceneTransition - */ - public static startSceneTransition(sceneTransition: T): T { - if (this.sceneTransition) { - console.warn("在前一个场景完成之前,不能开始一个新的场景转换。"); - return; - } - - this.sceneTransition = sceneTransition; - return sceneTransition; - } - - public static registerActiveSceneChanged(current: Scene, next: Scene){ - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - } - - /** - * 在一个场景结束后,下一个场景开始之前调用 - */ - public onSceneChanged(){ - SceneManager.emitter.emit(CoreEvents.SceneChanged); - Time.sceneChanged(); - } - - private static startDebugUpdate(){ - TimeRuler.Instance.startFrame(); - TimeRuler.Instance.beginMark("update", 0x00FF00); - } - - private static endDebugUpdate(){ - TimeRuler.Instance.endMark("update"); - } - } -} diff --git a/source/src/ECS/Utils/TextureUtils.ts b/source/src/ECS/Utils/TextureUtils.ts index 2da8e6e3..169740f6 100644 --- a/source/src/ECS/Utils/TextureUtils.ts +++ b/source/src/ECS/Utils/TextureUtils.ts @@ -78,7 +78,7 @@ module es { let offsetY: number = Math.round(bitmapData.$offsetY); let bitmapWidth: number = bitmapData.$bitmapWidth; let bitmapHeight: number = bitmapData.$bitmapHeight; - let $TextureScaleFactor = SceneManager.stage.textureScaleFactor; + let $TextureScaleFactor = Core._instance.stage.textureScaleFactor; this.sharedContext.drawImage(bitmapData.$bitmapData.source, bitmapData.$bitmapX + rect.x / $TextureScaleFactor, bitmapData.$bitmapY + rect.y / $TextureScaleFactor, bitmapWidth * rect.width / w, bitmapHeight * rect.height / h, offsetX, offsetY, rect.width, rect.height); return surface; diff --git a/source/src/Graphics/Effects/GaussianBlurEffect.ts b/source/src/Graphics/Effects/GaussianBlurEffect.ts index 50f0b03c..b5ca7849 100644 --- a/source/src/Graphics/Effects/GaussianBlurEffect.ts +++ b/source/src/Graphics/Effects/GaussianBlurEffect.ts @@ -66,8 +66,8 @@ module es { constructor(){ super(PostProcessor.default_vert, GaussianBlurEffect.blur_frag,{ - screenWidth: SceneManager.stage.stageWidth, - screenHeight: SceneManager.stage.stageHeight + screenWidth: Core.graphicsDevice.viewport.width, + screenHeight: Core.graphicsDevice.viewport.height }); } } diff --git a/source/src/Graphics/GraphicsDevice.ts b/source/src/Graphics/GraphicsDevice.ts index f1878e1e..ea5fb9ea 100644 --- a/source/src/Graphics/GraphicsDevice.ts +++ b/source/src/Graphics/GraphicsDevice.ts @@ -1,12 +1,20 @@ module es { export class GraphicsDevice { - private viewport: Viewport; + private _viewport: Viewport; + public get viewport(): Viewport{ + return this._viewport; + } public graphicsCapabilities: GraphicsCapabilities; constructor(){ + this.setup(); this.graphicsCapabilities = new GraphicsCapabilities(); this.graphicsCapabilities.initialize(this); } + + private setup(){ + this._viewport = new Viewport(0, 0, Core._instance.stage.stageWidth, Core._instance.stage.stageHeight); + } } } diff --git a/source/src/Graphics/PostProcessing/PostProcessor.ts b/source/src/Graphics/PostProcessing/PostProcessor.ts index c1a3fce9..516b8cdd 100644 --- a/source/src/Graphics/PostProcessing/PostProcessor.ts +++ b/source/src/Graphics/PostProcessing/PostProcessor.ts @@ -32,7 +32,7 @@ module es { this.scene = scene; this.shape = new egret.Shape(); this.shape.graphics.beginFill(0xFFFFFF, 1); - this.shape.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this.shape.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height); this.shape.graphics.endFill(); scene.addChild(this.shape); } diff --git a/source/src/Graphics/Transitions/FadeTransition.ts b/source/src/Graphics/Transitions/FadeTransition.ts index a7878efa..4aa0e148 100644 --- a/source/src/Graphics/Transitions/FadeTransition.ts +++ b/source/src/Graphics/Transitions/FadeTransition.ts @@ -15,9 +15,8 @@ module es { public async onBeginTransition() { this._mask.graphics.beginFill(this.fadeToColor, 1); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height); this._mask.graphics.endFill(); - SceneManager.stage.addChild(this._mask); egret.Tween.get(this).to({ _alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType) .call(async () => { @@ -25,7 +24,6 @@ module es { }).wait(this.delayBeforeFadeInDuration).call(() => { egret.Tween.get(this).to({ _alpha: 0 }, this.fadeOutDuration * 1000, this.fadeEaseType).call(() => { this.transitionComplete(); - SceneManager.stage.removeChild(this._mask); }); }); } @@ -33,7 +31,7 @@ module es { public render(){ this._mask.graphics.clear(); this._mask.graphics.beginFill(this.fadeToColor, this._alpha); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height); this._mask.graphics.endFill(); } } diff --git a/source/src/Graphics/Transitions/SceneTransition.ts b/source/src/Graphics/Transitions/SceneTransition.ts index 620a8264..34143455 100644 --- a/source/src/Graphics/Transitions/SceneTransition.ts +++ b/source/src/Graphics/Transitions/SceneTransition.ts @@ -44,7 +44,7 @@ module es { } protected transitionComplete() { - SceneManager.sceneTransition = null; + Core._instance._sceneTransition = null; if (this.onTransitionCompleted) { this.onTransitionCompleted(); @@ -59,7 +59,7 @@ module es { this.isNewSceneLoaded = true; } - SceneManager.scene = await this.sceneLoadAction(); + Core.scene = await this.sceneLoadAction(); this.isNewSceneLoaded = true; } diff --git a/source/src/Graphics/Transitions/WindTransition.ts b/source/src/Graphics/Transitions/WindTransition.ts index 4fe72e54..c476879b 100644 --- a/source/src/Graphics/Transitions/WindTransition.ts +++ b/source/src/Graphics/Transitions/WindTransition.ts @@ -51,17 +51,15 @@ module es { this._mask = new egret.Shape(); this._mask.graphics.beginFill(0xFFFFFF, 1); - this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this._mask.graphics.drawRect(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height); this._mask.graphics.endFill(); this._mask.filters = [this._windEffect]; - SceneManager.stage.addChild(this._mask); } public async onBeginTransition() { this.loadNextScene(); await this.tickEffectProgressProperty(this._windEffect, this.duration, this.easeType); this.transitionComplete(); - SceneManager.stage.removeChild(this._mask); } } } diff --git a/source/src/Graphics/Viewport.ts b/source/src/Graphics/Viewport.ts index 182b4223..18b39636 100644 --- a/source/src/Graphics/Viewport.ts +++ b/source/src/Graphics/Viewport.ts @@ -7,6 +7,20 @@ module es { private _minDepth: number; private _maxDepth: number; + public get height(){ + return this._height; + } + public set height(value: number){ + this._height = value; + } + + public get width(){ + return this._width; + } + public set width(value: number){ + this._width = value; + } + public get aspectRatio(){ if ((this._height != 0) && (this._width != 0)) return (this._width / this._height); diff --git a/source/src/Utils/Analysis/Layout.ts b/source/src/Utils/Analysis/Layout.ts index d11b611f..052dca9c 100644 --- a/source/src/Utils/Analysis/Layout.ts +++ b/source/src/Utils/Analysis/Layout.ts @@ -7,7 +7,7 @@ module es { public safeArea: Rectangle; constructor(){ - this.clientArea = new Rectangle(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight); + this.clientArea = new Rectangle(0, 0, Core.graphicsDevice.viewport.width, Core.graphicsDevice.viewport.height); this.safeArea = this.clientArea; } diff --git a/source/src/Utils/Analysis/TimeRuler.ts b/source/src/Utils/Analysis/TimeRuler.ts index 846043aa..83ccc4c8 100644 --- a/source/src/Utils/Analysis/TimeRuler.ts +++ b/source/src/Utils/Analysis/TimeRuler.ts @@ -62,7 +62,9 @@ module es { this._logs[i] = new FrameLog(); this.sampleFrames = this.targetSampleFrames = 1; - this.width = SceneManager.stage.stageWidth * 0.8; + this.width = Core.graphicsDevice.viewport.width * 0.8; + + es.Core.emitter.addObserver(CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this); this.onGraphicsDeviceReset(); } diff --git a/source/src/Utils/GlobalManager.ts b/source/src/Utils/GlobalManager.ts index e962b6c3..fc6d520d 100644 --- a/source/src/Utils/GlobalManager.ts +++ b/source/src/Utils/GlobalManager.ts @@ -1,14 +1,26 @@ module es { export class GlobalManager { - public static globalManagers: GlobalManager[] = []; - private _enabled: boolean; - + /** + * 如果true则启用了GlobalManager。 + * 状态的改变会导致调用OnEnabled/OnDisable + */ public get enabled(){ return this._enabled; } + + /** + * 如果true则启用了GlobalManager。 + * 状态的改变会导致调用OnEnabled/OnDisable + * @param value + */ public set enabled(value: boolean){ this.setEnabled(value); } + + /** + * 启用/禁用这个GlobalManager + * @param isEnabled + */ public setEnabled(isEnabled: boolean){ if (this._enabled != isEnabled){ this._enabled = isEnabled; @@ -19,30 +31,21 @@ module es { } } } + public _enabled: boolean; + /** + * 此GlobalManager启用时调用 + */ public onEnabled(){} + /** + * 此GlobalManager禁用时调用 + */ public onDisabled(){} + /** + * 在frame .update之前调用每一帧 + */ public update(){} - - public static registerGlobalManager(manager: GlobalManager){ - this.globalManagers.push(manager); - manager.enabled = true; - } - - public static unregisterGlobalManager(manager: GlobalManager){ - this.globalManagers.remove(manager); - manager.enabled = false; - } - - public static getGlobalManager(type){ - for (let i = 0; i < this.globalManagers.length; i ++){ - if (this.globalManagers[i] instanceof type) - return this.globalManagers[i] as T; - } - - return null; - } } } diff --git a/source/src/Utils/Input.ts b/source/src/Utils/Input.ts index a66e9493..c6500199 100644 --- a/source/src/Utils/Input.ts +++ b/source/src/Utils/Input.ts @@ -18,7 +18,6 @@ module es { export class Input { private static _init: boolean = false; - private static _stage: egret.Stage; private static _previousTouchState: TouchState = new TouchState(); private static _gameTouchs: TouchState[] = []; private static _resolutionOffset: Vector2 = new Vector2(); @@ -33,13 +32,13 @@ module es { } /** 获取最大触摸数 */ public static get maxSupportedTouch(){ - return this._stage.maxTouches; + return Core._instance.stage.maxTouches; } /** * 设置最大触摸数 */ public static set maxSupportedTouch(value: number){ - this._stage.maxTouches = value; + Core._instance.stage.maxTouches = value; this.initTouchCache(); } /** 获取缩放值 默认为1 */ @@ -68,17 +67,16 @@ module es { return delta; } - public static initialize(stage: egret.Stage){ + public static initialize(){ if (this._init) return; this._init = true; - this._stage = stage; - this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); - this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); + Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMove, this); + Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchEnd, this); + Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchEnd, this); this.initTouchCache(); } From d4c244daf582d1433b24d9a7296ca52272d4669d Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Thu, 23 Jul 2020 19:28:01 +0800 Subject: [PATCH 09/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.d.ts | 6 +- demo/libs/framework/framework.js | 34 ++-- demo/libs/framework/framework.min.js | 2 +- demo/libs/modules/egret/egret.web.min.js | 2 +- demo/manifest.json | 3 +- demo/src/Main.ts | 60 +------ demo/src/game/CoreEmitterType.ts | 3 - demo/src/game/MainScene.ts | 169 ++++++++++---------- demo/src/game/PlayerController.ts | 98 ++++++------ demo/src/game/SimplePooled.ts | 12 +- demo/src/game/SpawnerComponent.ts | 62 +++---- demo/src/game/SpawnerSystem.ts | 60 +++---- source/bin/framework.d.ts | 6 +- source/bin/framework.js | 34 ++-- source/bin/framework.min.js | 2 +- source/src/ECS/Core.ts | 23 ++- source/src/Graphics/GraphicsCapabilities.ts | 2 + source/src/Utils/Analysis/TimeRuler.ts | 8 +- 18 files changed, 283 insertions(+), 303 deletions(-) delete mode 100644 demo/src/game/CoreEmitterType.ts diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index 22ae545a..acfa237f 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -248,7 +248,6 @@ declare module es { } declare module es { class Core extends egret.DisplayObjectContainer { - static activeSceneChanged: Function; static emitter: Emitter; static graphicsDevice: GraphicsDevice; static content: ContentManager; @@ -260,6 +259,7 @@ declare module es { _globalManagers: GlobalManager[]; static scene: Scene; constructor(); + private onAddToStage; onOrientationChanged(): void; protected onGraphicsDeviceReset(): void; protected initialize(): void; @@ -269,7 +269,6 @@ declare module es { endDebugUpdate(): void; onSceneChanged(): void; static startSceneTransition(sceneTransition: T): T; - static registerActiveSceneChanged(current: Scene, next: Scene): void; static registerGlobalManager(manager: es.GlobalManager): void; static unregisterGlobalManager(manager: es.GlobalManager): void; static getGlobalManager(type: any): T; @@ -1679,7 +1678,8 @@ declare module es { static readonly logSnapDuration: number; static readonly barPadding: number; static readonly autoAdjustDelay: number; - static Instance: TimeRuler; + private static _instance; + static readonly Instance: TimeRuler; private _frameKey; private _logKey; private _logs; diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index 4e14fae4..ff829892 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -1105,13 +1105,8 @@ var es; _this._globalManagers = []; Core._instance = _this; Core.emitter = new es.Emitter(); - Core.graphicsDevice = new es.GraphicsDevice(); Core.content = new es.ContentManager(); - _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this); - _this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this); - _this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this); - _this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this); - _this.addEventListener(egret.Event.RENDER, _this.draw, _this); + _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this); return _this; } Object.defineProperty(Core, "Instance", { @@ -1123,6 +1118,8 @@ var es; }); Object.defineProperty(Core, "scene", { get: function () { + if (!this._instance) + return null; return this._instance._scene; }, set: function (value) { @@ -1138,11 +1135,18 @@ var es; else { this._instance._nextScene = value; } - this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene); }, enumerable: true, configurable: true }); + Core.prototype.onAddToStage = function () { + Core.graphicsDevice = new es.GraphicsDevice(); + this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); + this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); + this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); + this.addEventListener(egret.Event.RENDER, this.draw, this); + this.initialize(); + }; Core.prototype.onOrientationChanged = function () { Core.emitter.emit(es.CoreEvents.OrientationChanged); }; @@ -1228,10 +1232,6 @@ var es; this._instance._sceneTransition = sceneTransition; return sceneTransition; }; - Core.registerActiveSceneChanged = function (current, next) { - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - }; Core.registerGlobalManager = function (manager) { this._instance._globalManagers.push(manager); manager.enabled = true; @@ -4308,6 +4308,8 @@ var es; this.platformInitialize(device); }; GraphicsCapabilities.prototype.platformInitialize = function (device) { + if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME) + return; var capabilities = this; capabilities["isMobile"] = true; var systemInfo = wx.getSystemInfoSync(); @@ -7570,7 +7572,6 @@ var es; this.stopwacth = new stopwatch.Stopwatch(); this._markerNameToIdMap = new Map(); this.showLog = false; - TimeRuler.Instance = this; this._logs = new Array(2); for (var i = 0; i < this._logs.length; ++i) this._logs[i] = new FrameLog(); @@ -7579,6 +7580,15 @@ var es; es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this); this.onGraphicsDeviceReset(); } + Object.defineProperty(TimeRuler, "Instance", { + get: function () { + if (!this._instance) + this._instance = new TimeRuler(); + return this._instance; + }, + enumerable: true, + configurable: true + }); TimeRuler.prototype.onGraphicsDeviceReset = function () { var layout = new es.Layout(); this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location; diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index da2a3273..73b277e8 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.graphicsDevice=new t.GraphicsDevice,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.initialize,i),i.addEventListener(egret.Event.RESIZE,i.onGraphicsDeviceReset,i),i.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,i.onOrientationChanged,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i.addEventListener(egret.Event.RENDER,i.draw,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance._scene},set:function(t){t?(null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t,this.registerActiveSceneChanged(this._instance._scene,this._instance._nextScene)):console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/demo/libs/modules/egret/egret.web.min.js b/demo/libs/modules/egret/egret.web.min.js index 268b33be..f6c20063 100644 --- a/demo/libs/modules/egret/egret.web.min.js +++ b/demo/libs/modules/egret/egret.web.min.js @@ -1,5 +1,5 @@ var __reflect=this&&this.__reflect||function(e,t,r){e.__class__=t,r?r.push(t):r=[t],e.__types__=e.__types__?r.concat(e.__types__):r},__extends=this&&this.__extends||function(e,t){function r(){this.constructor=e}for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);r.prototype=t.prototype,e.prototype=new r},egret;!function(e){var t;!function(t){var r=function(t){function r(r){var i=t.call(this)||this;return i.onUpdate=function(t){var r=new e.GeolocationEvent(e.Event.CHANGE),n=t.coords;r.altitude=n.altitude,r.heading=n.heading,r.accuracy=n.accuracy,r.latitude=n.latitude,r.longitude=n.longitude,r.speed=n.speed,r.altitudeAccuracy=n.altitudeAccuracy,i.dispatchEvent(r)},i.onError=function(t){var r=e.GeolocationEvent.UNAVAILABLE;t.code==t.PERMISSION_DENIED&&(r=e.GeolocationEvent.PERMISSION_DENIED);var n=new e.GeolocationEvent(e.IOErrorEvent.IO_ERROR);n.errorType=r,n.errorMessage=t.message,i.dispatchEvent(n)},i.geolocation=navigator.geolocation,i}return __extends(r,t),r.prototype.start=function(){var t=this.geolocation;t?this.watchId=t.watchPosition(this.onUpdate,this.onError):this.onError({code:2,message:e.sys.tr(3004),PERMISSION_DENIED:1,POSITION_UNAVAILABLE:2})},r.prototype.stop=function(){var e=this.geolocation;e.clearWatch(this.watchId)},r}(e.EventDispatcher);t.WebGeolocation=r,__reflect(r.prototype,"egret.web.WebGeolocation",["egret.Geolocation"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var r=null!==t&&t.apply(this,arguments)||this;return r.onChange=function(t){var i=new e.MotionEvent(e.Event.CHANGE),n={x:t.acceleration.x,y:t.acceleration.y,z:t.acceleration.z},a={x:t.accelerationIncludingGravity.x,y:t.accelerationIncludingGravity.y,z:t.accelerationIncludingGravity.z},o={alpha:t.rotationRate.alpha,beta:t.rotationRate.beta,gamma:t.rotationRate.gamma};i.acceleration=n,i.accelerationIncludingGravity=a,i.rotationRate=o,r.dispatchEvent(i)},r}return __extends(r,t),r.prototype.start=function(){window.addEventListener("devicemotion",this.onChange)},r.prototype.stop=function(){window.removeEventListener("devicemotion",this.onChange)},r}(e.EventDispatcher);t.WebMotion=r,__reflect(r.prototype,"egret.web.WebMotion",["egret.Motion"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(e){if(window.location){var t=location.search;if(""==t)return"";t=t.slice(1);for(var r=t.split("&"),i=r.length,n=0;i>n;n++){var a=r[n],o=a.split("=");if(o[0]==e)return o[1]}}return""}t.getOption=r,e.getOption=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(t){var i=r.call(this)||this;return i.$startTime=0,i.audio=null,i.isStopped=!1,i.canPlay=function(){i.audio.removeEventListener("canplay",i.canPlay);try{i.audio.currentTime=i.$startTime}catch(e){}finally{i.audio.play()}},i.onPlayEnd=function(){return 1==i.$loops?(i.stop(),void i.dispatchEventWith(e.Event.SOUND_COMPLETE)):(i.$loops>0&&i.$loops--,void i.$play())},i._volume=1,t.addEventListener("ended",i.onPlayEnd),i.audio=t,i}return __extends(i,r),i.prototype.$play=function(){if(this.isStopped)return void e.$error(1036);try{this.audio.volume=this._volume,this.audio.currentTime=this.$startTime}catch(t){return void this.audio.addEventListener("canplay",this.canPlay)}this.audio.play()},i.prototype.stop=function(){if(this.audio){this.isStopped||e.sys.$popSoundChannel(this),this.isStopped=!0;var r=this.audio;r.removeEventListener("ended",this.onPlayEnd),r.removeEventListener("canplay",this.canPlay),r.volume=0,this._volume=0,this.audio=null;var i=this.$url;window.setTimeout(function(){r.pause(),t.HtmlSound.$recycle(i,r)},200)}},Object.defineProperty(i.prototype,"volume",{get:function(){return this._volume},set:function(t){return this.isStopped?void e.$error(1036):(this._volume=t,void(this.audio&&(this.audio.volume=t)))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"position",{get:function(){return this.audio?this.audio.currentTime:0},enumerable:!0,configurable:!0}),i}(e.EventDispatcher);t.HtmlSoundChannel=r,__reflect(r.prototype,"egret.web.HtmlSoundChannel",["egret.SoundChannel","egret.IEventDispatcher"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(){function t(){}return t.decodeAudios=function(){if(!(t.decodeArr.length<=0||t.isDecoding)){t.isDecoding=!0;var r=t.decodeArr.shift();t.ctx.decodeAudioData(r.buffer,function(e){r.self.audioBuffer=e,r.success&&r.success(),t.isDecoding=!1,t.decodeAudios()},function(){e.log("sound decode error"),r.fail&&r.fail(),t.isDecoding=!1,t.decodeAudios()})}},t.decodeArr=[],t.isDecoding=!1,t}();t.WebAudioDecode=r,__reflect(r.prototype,"egret.web.WebAudioDecode");var i=function(i){function n(){var e=i.call(this)||this;return e.loaded=!1,e}return __extends(n,i),Object.defineProperty(n.prototype,"length",{get:function(){if(this.audioBuffer)return this.audioBuffer.duration;throw new Error("sound not loaded!")},enumerable:!0,configurable:!0}),n.prototype.load=function(t){function i(){a.loaded=!0,a.dispatchEventWith(e.Event.COMPLETE)}function n(){a.dispatchEventWith(e.IOErrorEvent.IO_ERROR)}var a=this;this.url=t;var o=new XMLHttpRequest;o.open("GET",t,!0),o.responseType="arraybuffer",o.addEventListener("load",function(){var t=o.status>=400;t?a.dispatchEventWith(e.IOErrorEvent.IO_ERROR):(r.decodeArr.push({buffer:o.response,success:i,fail:n,self:a,url:a.url}),r.decodeAudios())}),o.addEventListener("error",function(){a.dispatchEventWith(e.IOErrorEvent.IO_ERROR)}),o.send()},n.prototype.play=function(r,i){r=+r||0,i=+i||0;var n=new t.WebAudioSoundChannel;return n.$url=this.url,n.$loops=i,n.$audioBuffer=this.audioBuffer,n.$startTime=r,n.$play(),e.sys.$pushSoundChannel(n),n},n.prototype.close=function(){},n.MUSIC="music",n.EFFECT="effect",n}(e.EventDispatcher);t.WebAudioSound=i,__reflect(i.prototype,"egret.web.WebAudioSound",["egret.Sound"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(){var i=r.call(this)||this;return i.$startTime=0,i.bufferSource=null,i.context=t.WebAudioDecode.ctx,i.isStopped=!1,i._currentTime=0,i._volume=1,i.onPlayEnd=function(){return 1==i.$loops?(i.stop(),void i.dispatchEventWith(e.Event.SOUND_COMPLETE)):(i.$loops>0&&i.$loops--,void i.$play())},i._startTime=0,i.context.createGain?i.gain=i.context.createGain():i.gain=i.context.createGainNode(),i}return __extends(i,r),i.prototype.$play=function(){if(this.isStopped)return void e.$error(1036);this.bufferSource&&(this.bufferSource.onended=null,this.bufferSource=null);var t=this.context,r=this.gain,i=t.createBufferSource();this.bufferSource=i,i.buffer=this.$audioBuffer,i.connect(r),r.connect(t.destination),i.onended=this.onPlayEnd,this._startTime=Date.now(),this.gain.gain.value=this._volume,i.start(0,this.$startTime),this._currentTime=0},i.prototype.stop=function(){if(this.bufferSource){var t=this.bufferSource;t.stop?t.stop(0):t.noteOff(0),t.onended=null,t.disconnect(),this.bufferSource=null,this.$audioBuffer=null}this.isStopped||e.sys.$popSoundChannel(this),this.isStopped=!0},Object.defineProperty(i.prototype,"volume",{get:function(){return this._volume},set:function(t){return this.isStopped?void e.$error(1036):(this._volume=t,void(this.gain.gain.value=t))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"position",{get:function(){return this.bufferSource?(Date.now()-this._startTime)/1e3+this.$startTime:0},enumerable:!0,configurable:!0}),i}(e.EventDispatcher);t.WebAudioSoundChannel=r,__reflect(r.prototype,"egret.web.WebAudioSoundChannel",["egret.SoundChannel","egret.IEventDispatcher"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(r,i){void 0===i&&(i=!0);var n=t.call(this)||this;return n.loaded=!1,n.closed=!1,n.heightSet=0/0,n.widthSet=0/0,n.waiting=!1,n.userPause=!1,n.userPlay=!1,n.isPlayed=!1,n.screenChanged=function(t){var r=document.fullscreenEnabled||document.webkitIsFullScreen;r||(n.checkFullScreen(!1),e.Capabilities.isMobile||(n._fullscreen=r))},n._fullscreen=!0,n.onVideoLoaded=function(){n.video.removeEventListener("canplay",n.onVideoLoaded);var t=n.video;n.loaded=!0,n.posterData&&(n.posterData.width=n.getPlayWidth(),n.posterData.height=n.getPlayHeight()),t.width=t.videoWidth,t.height=t.videoHeight,window.setTimeout(function(){n.dispatchEventWith(e.Event.COMPLETE)},200)},n.$renderNode=new e.sys.BitmapNode,n.src=r,n.once(e.Event.ADDED_TO_STAGE,n.loadPoster,n),r&&n.load(),n}return __extends(r,t),r.prototype.createNativeDisplayObject=function(){this.$nativeDisplayObject=new egret_native.NativeDisplayObject(1)},r.prototype.load=function(t,r){var i=this;if(void 0===r&&(r=!0),t=t||this.src,this.src=t,!this.video||this.video.src!=t){var n;!this.video||e.Capabilities.isMobile?(n=document.createElement("video"),this.video=n,n.controls=null):n=this.video,n.src=t,n.setAttribute("autoplay","autoplay"),n.setAttribute("webkit-playsinline","true"),n.addEventListener("canplay",this.onVideoLoaded),n.addEventListener("error",function(){return i.onVideoError()}),n.addEventListener("ended",function(){return i.onVideoEnded()});var a=!1;n.addEventListener("canplay",function(){i.waiting=!1,a?i.userPause?i.pause():i.userPlay&&i.play():(a=!0,n.pause())}),n.addEventListener("waiting",function(){i.waiting=!0}),n.load(),this.videoPlay(),n.style.position="absolute",n.style.top="0px",n.style.zIndex="-88888",n.style.left="0px",n.height=1,n.width=1}},r.prototype.play=function(t,r){var i=this;if(void 0===r&&(r=!1),0==this.loaded)return this.load(this.src),void this.once(e.Event.COMPLETE,function(e){return i.play(t,r)},this);this.isPlayed=!0;var n=this.video;void 0!=t&&(n.currentTime=+t||0),n.loop=!!r,e.Capabilities.isMobile?n.style.zIndex="-88888":n.style.zIndex="9999",n.style.position="absolute",n.style.top="0px",n.style.left="0px",n.height=n.videoHeight,n.width=n.videoWidth,"Windows PC"!=e.Capabilities.os&&"Mac OS"!=e.Capabilities.os&&window.setTimeout(function(){n.width=0},1e3),this.checkFullScreen(this._fullscreen)},r.prototype.videoPlay=function(){return this.userPause=!1,this.waiting?void(this.userPlay=!0):(this.userPlay=!1,void this.video.play())},r.prototype.checkFullScreen=function(t){var r=this.video;if(t)null==r.parentElement&&(r.removeAttribute("webkit-playsinline"),document.body.appendChild(r)),e.stopTick(this.markDirty,this),this.goFullscreen();else if(null!=r.parentElement&&r.parentElement.removeChild(r),r.setAttribute("webkit-playsinline","true"),this.setFullScreenMonitor(!1),e.startTick(this.markDirty,this),e.Capabilities.isMobile)return this.video.currentTime=0,void this.onVideoEnded();this.videoPlay()},r.prototype.goFullscreen=function(){var t,r=this.video;return t=e.web.getPrefixStyleName("requestFullscreen",r),r[t]||(t=e.web.getPrefixStyleName("requestFullScreen",r),r[t])?(r.removeAttribute("webkit-playsinline"),r[t](),this.setFullScreenMonitor(!0),!0):!0},r.prototype.setFullScreenMonitor=function(e){var t=this.video;e?(t.addEventListener("mozfullscreenchange",this.screenChanged),t.addEventListener("webkitfullscreenchange",this.screenChanged),t.addEventListener("mozfullscreenerror",this.screenError),t.addEventListener("webkitfullscreenerror",this.screenError)):(t.removeEventListener("mozfullscreenchange",this.screenChanged),t.removeEventListener("webkitfullscreenchange",this.screenChanged),t.removeEventListener("mozfullscreenerror",this.screenError),t.removeEventListener("webkitfullscreenerror",this.screenError))},r.prototype.screenError=function(){e.$error(3014)},r.prototype.exitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.oCancelFullScreen?document.oCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen()},r.prototype.onVideoEnded=function(){this.pause(),this.isPlayed=!1,this.dispatchEventWith(e.Event.ENDED)},r.prototype.onVideoError=function(){this.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},r.prototype.close=function(){var e=this;this.closed=!0,this.video.removeEventListener("canplay",this.onVideoLoaded),this.video.removeEventListener("error",function(){return e.onVideoError()}),this.video.removeEventListener("ended",function(){return e.onVideoEnded()}),this.pause(),0==this.loaded&&this.video&&(this.video.src=""),this.video&&this.video.parentElement&&(this.video.parentElement.removeChild(this.video),this.video=null),this.loaded=!1},r.prototype.pause=function(){return this.userPlay=!1,this.waiting?void(this.userPause=!0):(this.userPause=!1,this.video.pause(),void e.stopTick(this.markDirty,this))},Object.defineProperty(r.prototype,"volume",{get:function(){return this.video?this.video.volume:1},set:function(e){this.video&&(this.video.volume=e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"position",{get:function(){return this.video?this.video.currentTime:0},set:function(e){this.video&&(this.video.currentTime=e)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"fullscreen",{get:function(){return this._fullscreen},set:function(t){e.Capabilities.isMobile||(this._fullscreen=!!t,this.video&&0==this.video.paused&&this.checkFullScreen(this._fullscreen))},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"bitmapData",{get:function(){return this.video&&this.loaded?(this._bitmapData||(this.video.width=this.video.videoWidth,this.video.height=this.video.videoHeight,this._bitmapData=new e.BitmapData(this.video),this._bitmapData.$deleteSource=!1),this._bitmapData):null},enumerable:!0,configurable:!0}),r.prototype.loadPoster=function(){var t=this,r=this.poster;if(r){var i=new e.ImageLoader;i.once(e.Event.COMPLETE,function(r){i.data;if(t.posterData=i.data,t.$renderDirty=!0,t.posterData.width=t.getPlayWidth(),t.posterData.height=t.getPlayHeight(),e.nativeRender){var n=new e.Texture;n._setBitmapData(t.posterData),t.$nativeDisplayObject.setTexture(n)}},this),i.load(r)}},r.prototype.$measureContentBounds=function(e){var t=this.bitmapData,r=this.posterData;t?e.setTo(0,0,this.getPlayWidth(),this.getPlayHeight()):r?e.setTo(0,0,this.getPlayWidth(),this.getPlayHeight()):e.setEmpty()},r.prototype.getPlayWidth=function(){return isNaN(this.widthSet)?this.bitmapData?this.bitmapData.width:this.posterData?this.posterData.width:0/0:this.widthSet},r.prototype.getPlayHeight=function(){return isNaN(this.heightSet)?this.bitmapData?this.bitmapData.height:this.posterData?this.posterData.height:0/0:this.heightSet},r.prototype.$updateRenderNode=function(){var t=this.$renderNode,r=this.bitmapData,i=this.posterData,n=this.getPlayWidth(),a=this.getPlayHeight();this.isPlayed&&!e.Capabilities.isMobile||!i?this.isPlayed&&r&&(t.image=r,t.imageWidth=r.width,t.imageHeight=r.height,e.WebGLUtils.deleteWebGLTexture(r.webGLTexture),r.webGLTexture=null,t.drawImage(0,0,r.width,r.height,0,0,n,a)):(t.image=i,t.imageWidth=n,t.imageHeight=a,t.drawImage(0,0,i.width,i.height,0,0,n,a))},r.prototype.markDirty=function(){return this.$renderDirty=!0,!0},r.prototype.$setHeight=function(e){if(this.heightSet=e,this.paused){var r=this;this.$renderDirty=!0,window.setTimeout(function(){r.$renderDirty=!1},200)}t.prototype.$setHeight.call(this,e)},r.prototype.$setWidth=function(e){if(this.widthSet=e,this.paused){var r=this;this.$renderDirty=!0,window.setTimeout(function(){r.$renderDirty=!1},200)}t.prototype.$setWidth.call(this,e)},Object.defineProperty(r.prototype,"paused",{get:function(){return this.video?this.video.paused:!0},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"length",{get:function(){if(this.video)return this.video.duration;throw new Error("Video not loaded!")},enumerable:!0,configurable:!0}),r}(e.DisplayObject);t.WebVideo=r,__reflect(r.prototype,"egret.web.WebVideo",["egret.Video","egret.DisplayObject"]),e.Video=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var e=t.call(this)||this;return e.timeout=0,e._url="",e._method="",e}return __extends(r,t),Object.defineProperty(r.prototype,"response",{get:function(){if(!this._xhr)return null;if(void 0!=this._xhr.response)return this._xhr.response;if("text"==this._responseType)return this._xhr.responseText;if("arraybuffer"==this._responseType&&/msie 9.0/i.test(navigator.userAgent)){var e=window;return e.convertResponseBodyToText(this._xhr.responseBody)}return"document"==this._responseType?this._xhr.responseXML:null},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"responseType",{get:function(){return this._responseType},set:function(e){this._responseType=e},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"withCredentials",{get:function(){return this._withCredentials},set:function(e){this._withCredentials=e},enumerable:!0,configurable:!0}),r.prototype.getXHR=function(){return window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("MSXML2.XMLHTTP")},r.prototype.open=function(e,t){void 0===t&&(t="GET"),this._url=e,this._method=t,this._xhr&&(this._xhr.abort(),this._xhr=null);var r=this.getXHR();window.XMLHttpRequest?(r.addEventListener("load",this.onload.bind(this)),r.addEventListener("error",this.onerror.bind(this))):r.onreadystatechange=this.onReadyStateChange.bind(this),r.onprogress=this.updateProgress.bind(this),r.ontimeout=this.onTimeout.bind(this),r.open(this._method,this._url,!0),this._xhr=r},r.prototype.send=function(e){if(null!=this._responseType&&(this._xhr.responseType=this._responseType),null!=this._withCredentials&&(this._xhr.withCredentials=this._withCredentials),this.headerObj)for(var t in this.headerObj)this._xhr.setRequestHeader(t,this.headerObj[t]);this._xhr.timeout=this.timeout,this._xhr.send(e)},r.prototype.abort=function(){this._xhr&&this._xhr.abort()},r.prototype.getAllResponseHeaders=function(){if(!this._xhr)return null;var e=this._xhr.getAllResponseHeaders();return e?e:""},r.prototype.setRequestHeader=function(e,t){this.headerObj||(this.headerObj={}),this.headerObj[e]=t},r.prototype.getResponseHeader=function(e){if(!this._xhr)return null;var t=this._xhr.getResponseHeader(e);return t?t:""},r.prototype.onTimeout=function(){this.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},r.prototype.onReadyStateChange=function(){var t=this._xhr;if(4==t.readyState){var r=t.status>=400||0==t.status,i=(this._url,this);window.setTimeout(function(){r?i.dispatchEventWith(e.IOErrorEvent.IO_ERROR):i.dispatchEventWith(e.Event.COMPLETE)},0)}},r.prototype.updateProgress=function(t){t.lengthComputable&&e.ProgressEvent.dispatchProgressEvent(this,e.ProgressEvent.PROGRESS,t.loaded,t.total)},r.prototype.onload=function(){var t=this,r=this._xhr,i=(this._url,r.status>=400);window.setTimeout(function(){i?t.dispatchEventWith(e.IOErrorEvent.IO_ERROR):t.dispatchEventWith(e.Event.COMPLETE)},0)},r.prototype.onerror=function(){var t=(this._url,this);window.setTimeout(function(){t.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},0)},r}(e.EventDispatcher);t.WebHttpRequest=r,__reflect(r.prototype,"egret.web.WebHttpRequest",["egret.HttpRequest"]),e.HttpRequest=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=window.URL||window.webkitURL,i=function(i){function n(){var e=null!==i&&i.apply(this,arguments)||this;return e.data=null,e._crossOrigin=null,e._hasCrossOriginSet=!1,e.currentImage=null,e.request=null,e}return __extends(n,i),Object.defineProperty(n.prototype,"crossOrigin",{get:function(){return this._crossOrigin},set:function(e){this._hasCrossOriginSet=!0,this._crossOrigin=e},enumerable:!0,configurable:!0}),n.prototype.load=function(r){if(t.Html5Capatibility._canUseBlob&&0!=r.indexOf("wxLocalResource:")&&0!=r.indexOf("data:")&&0!=r.indexOf("http:")&&0!=r.indexOf("https:")){var i=this.request;i||(i=this.request=new e.web.WebHttpRequest,i.addEventListener(e.Event.COMPLETE,this.onBlobLoaded,this),i.addEventListener(e.IOErrorEvent.IO_ERROR,this.onBlobError,this),i.responseType="blob"),i.open(r),i.send()}else this.loadImage(r)},n.prototype.onBlobLoaded=function(e){var t=this.request.response;this.request=void 0,this.loadImage(r.createObjectURL(t))},n.prototype.onBlobError=function(e){this.dispatchIOError(this.currentURL),this.request=void 0},n.prototype.loadImage=function(e){var t=new Image;this.data=null,this.currentImage=t,this._hasCrossOriginSet?this._crossOrigin&&(t.crossOrigin=this._crossOrigin):n.crossOrigin&&(t.crossOrigin=n.crossOrigin),t.onload=this.onImageComplete.bind(this),t.onerror=this.onLoadError.bind(this),t.src=e},n.prototype.onImageComplete=function(t){var r=this.getImage(t);if(r){this.data=new e.BitmapData(r);var i=this;window.setTimeout(function(){i.dispatchEventWith(e.Event.COMPLETE)},0)}},n.prototype.onLoadError=function(e){var t=this.getImage(e);t&&this.dispatchIOError(t.src)},n.prototype.dispatchIOError=function(t){var r=this;window.setTimeout(function(){r.dispatchEventWith(e.IOErrorEvent.IO_ERROR)},0)},n.prototype.getImage=function(t){var i=t.target,n=i.src;if(0==n.indexOf("blob:"))try{r.revokeObjectURL(i.src)}catch(a){e.$warn(1037)}return i.onerror=null,i.onload=null,this.currentImage!==i?null:(this.currentImage=null,i)},n.crossOrigin=null,n}(e.EventDispatcher);t.WebImageLoader=i,__reflect(i.prototype,"egret.web.WebImageLoader",["egret.ImageLoader"]),e.ImageLoader=i}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var e=t.call(this)||this;return e._isNeedShow=!1,e.inputElement=null,e.inputDiv=null,e._gscaleX=0,e._gscaleY=0,e.textValue="",e.colorValue=16777215,e._styleInfoes={},e}return __extends(r,t),r.prototype.$setTextField=function(e){return this.$textfield=e,!0},r.prototype.$addToStage=function(){this.htmlInput=e.web.$getTextAdapter(this.$textfield)},r.prototype._initElement=function(){var t=this.$textfield.localToGlobal(0,0),r=t.x,i=t.y,n=this.htmlInput.$scaleX,a=this.htmlInput.$scaleY;this.inputDiv.style.left=r*n+"px",this.inputDiv.style.top=i*a+"px",this.$textfield.multiline&&this.$textfield.height>this.$textfield.size?(this.inputDiv.style.top=i*a+"px",this.inputElement.style.top=-this.$textfield.lineSpacing/2*a+"px"):(this.inputDiv.style.top=i*a+"px",this.inputElement.style.top="0px");for(var o=this.$textfield,s=1,l=1,c=0;o.parent;)s*=o.scaleX,l*=o.scaleY,c+=o.rotation,o=o.parent;var h=e.web.getPrefixStyleName("transform");this.inputDiv.style[h]="rotate("+c+"deg)",this._gscaleX=n*s,this._gscaleY=a*l},r.prototype.$show=function(){this.htmlInput.isCurrentStageText(this)?this.inputElement.onblur=null:(this.inputElement=this.htmlInput.getInputElement(this),this.$textfield.multiline?this.inputElement.type="text":this.inputElement.type=this.$textfield.inputType,this.inputDiv=this.htmlInput._inputDIV),this.htmlInput._needShow=!0,this._isNeedShow=!0,this._initElement()},r.prototype.onBlurHandler=function(){this.htmlInput.clearInputElement(),window.scrollTo(0,0)},r.prototype.onFocusHandler=function(){var e=this;window.setTimeout(function(){e.inputElement&&e.inputElement.scrollIntoView()},200)},r.prototype.executeShow=function(){this.inputElement.value=this.$getText(),null==this.inputElement.onblur&&(this.inputElement.onblur=this.onBlurHandler.bind(this)),null==this.inputElement.onfocus&&(this.inputElement.onfocus=this.onFocusHandler.bind(this)),this.$resetStageText(),this.$textfield.maxChars>0?this.inputElement.setAttribute("maxlength",this.$textfield.maxChars):this.inputElement.removeAttribute("maxlength"),this.inputElement.selectionStart=this.inputElement.value.length,this.inputElement.selectionEnd=this.inputElement.value.length,this.inputElement.focus()},r.prototype.$hide=function(){this.htmlInput&&this.htmlInput.disconnectStageText(this)},r.prototype.$getText=function(){return this.textValue||(this.textValue=""),this.textValue},r.prototype.$setText=function(e){return this.textValue=e,this.resetText(),!0},r.prototype.resetText=function(){this.inputElement&&(this.inputElement.value=this.textValue)},r.prototype.$setColor=function(e){return this.colorValue=e,this.resetColor(),!0},r.prototype.resetColor=function(){this.inputElement&&this.setElementStyle("color",e.toColorString(this.colorValue))},r.prototype.$onBlur=function(){},r.prototype._onInput=function(){var t=this;window.setTimeout(function(){t.inputElement&&t.inputElement.selectionStart==t.inputElement.selectionEnd&&(t.textValue=t.inputElement.value,e.Event.dispatchEvent(t,"updateText",!1))},0)},r.prototype.setAreaHeight=function(){var t=this.$textfield;if(t.multiline){var r=e.TextFieldUtils.$getTextHeight(t);if(t.height<=t.size)this.setElementStyle("height",t.size*this._gscaleY+"px"),this.setElementStyle("padding","0px"),this.setElementStyle("lineHeight",t.size*this._gscaleY+"px");else if(t.height=0&&(a=o[s],void 0===n[a]);s--);try{Object.defineProperty(n,"imageSmoothingEnabled",{get:function(){return this[a]},set:function(e){this[a]=e}})}catch(l){n.imageSmoothingEnabled=n[a]}}return i}var i=function(){function t(t,i,n){this.surface=e.sys.createCanvasRenderBufferSurface(r,t,i,n),this.context=this.surface.getContext("2d"),this.context&&(this.context.$offsetX=0,this.context.$offsetY=0),this.resize(t,i) }return Object.defineProperty(t.prototype,"width",{get:function(){return this.surface.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this.surface.height},enumerable:!0,configurable:!0}),t.prototype.resize=function(t,r,i){e.sys.resizeCanvasRenderBuffer(this,t,r,i)},t.prototype.getPixels=function(e,t,r,i){return void 0===r&&(r=1),void 0===i&&(i=1),this.context.getImageData(e,t,r,i).data},t.prototype.toDataURL=function(e,t){return this.surface.toDataURL(e,t)},t.prototype.clear=function(){this.context.setTransform(1,0,0,1,0,0),this.context.clearRect(0,0,this.surface.width,this.surface.height)},t.prototype.destroy=function(){this.surface.width=this.surface.height=0},t}();t.CanvasRenderBuffer=i,__reflect(i.prototype,"egret.web.CanvasRenderBuffer",["egret.sys.RenderBuffer"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(r,i){var n=t.call(this)||this;return n.onTouchBegin=function(e){var t=n.getLocation(e);n.touch.onTouchBegin(t.x,t.y,e.identifier)},n.onMouseMove=function(e){0==e.buttons?n.onTouchEnd(e):n.onTouchMove(e)},n.onTouchMove=function(e){var t=n.getLocation(e);n.touch.onTouchMove(t.x,t.y,e.identifier)},n.onTouchEnd=function(e){var t=n.getLocation(e);n.touch.onTouchEnd(t.x,t.y,e.identifier)},n.scaleX=1,n.scaleY=1,n.rotation=0,n.canvas=i,n.touch=new e.sys.TouchHandler(r),n.addListeners(),n}return __extends(r,t),r.prototype.addListeners=function(){var t=this;window.navigator.msPointerEnabled?(this.canvas.addEventListener("MSPointerDown",function(e){e.identifier=e.pointerId,t.onTouchBegin(e),t.prevent(e)},!1),this.canvas.addEventListener("MSPointerMove",function(e){e.identifier=e.pointerId,t.onTouchMove(e),t.prevent(e)},!1),this.canvas.addEventListener("MSPointerUp",function(e){e.identifier=e.pointerId,t.onTouchEnd(e),t.prevent(e)},!1)):(e.Capabilities.isMobile||this.addMouseListener(),this.addTouchListener())},r.prototype.addMouseListener=function(){this.canvas.addEventListener("mousedown",this.onTouchBegin),this.canvas.addEventListener("mousemove",this.onMouseMove),this.canvas.addEventListener("mouseup",this.onTouchEnd)},r.prototype.addTouchListener=function(){var e=this;this.canvas.addEventListener("touchstart",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchBegin(t.changedTouches[i]);e.prevent(t)},!1),this.canvas.addEventListener("touchmove",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchMove(t.changedTouches[i]);e.prevent(t)},!1),this.canvas.addEventListener("touchend",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchEnd(t.changedTouches[i]);e.prevent(t)},!1),this.canvas.addEventListener("touchcancel",function(t){for(var r=t.changedTouches.length,i=0;r>i;i++)e.onTouchEnd(t.changedTouches[i]);e.prevent(t)},!1)},r.prototype.prevent=function(e){e.stopPropagation(),1==e.isScroll||this.canvas.userTyping||e.preventDefault()},r.prototype.getLocation=function(t){t.identifier=+t.identifier||0;var r=document.documentElement,i=this.canvas.getBoundingClientRect(),n=i.left+window.pageXOffset-r.clientLeft,a=i.top+window.pageYOffset-r.clientTop,o=t.pageX-n,s=o,l=t.pageY-a,c=l;return 90==this.rotation?(s=l,c=i.width-o):-90==this.rotation&&(s=i.height-l,c=o),s/=this.scaleX,c/=this.scaleY,e.$TempPoint.setTo(Math.round(s),Math.round(c))},r.prototype.updateScaleMode=function(e,t,r){this.scaleX=e,this.scaleY=t,this.rotation=r},r.prototype.$updateMaxTouches=function(){this.touch.$initMaxTouches()},r}(e.HashObject);t.WebTouchHandler=r,__reflect(r.prototype,"egret.web.WebTouchHandler")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){e.WebLifeCycleHandler=function(e){var t=function(){document[r]?e.pause():e.resume()};window.addEventListener("focus",e.resume,!1),window.addEventListener("blur",e.pause,!1);var r,i;"undefined"!=typeof document.hidden?(r="hidden",i="visibilitychange"):"undefined"!=typeof document.mozHidden?(r="mozHidden",i="mozvisibilitychange"):"undefined"!=typeof document.msHidden?(r="msHidden",i="msvisibilitychange"):"undefined"!=typeof document.webkitHidden?(r="webkitHidden",i="webkitvisibilitychange"):"undefined"!=typeof document.oHidden&&(r="oHidden",i="ovisibilitychange"),"onpageshow"in window&&"onpagehide"in window&&(window.addEventListener("pageshow",e.resume,!1),window.addEventListener("pagehide",e.pause,!1)),r&&i&&document.addEventListener(i,t,!1);var n=navigator.userAgent,a=/micromessenger/gi.test(n),o=/mqq/gi.test(n),s=/mobile.*qq/gi.test(n);if((s||a)&&(o=!1),o){var l=window.browser||{};l.execWebFn=l.execWebFn||{},l.execWebFn.postX5GamePlayerMessage=function(t){var r=t.type;"app_enter_background"==r?e.pause():"app_enter_foreground"==r&&e.resume()},window.browser=l}}}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(e,t){var r="";if(null!=t)r=i(e,t);else{if(null==o){var n=document.createElement("div").style;o=i("transform",n)}r=o}return""==r?e:r+e.charAt(0).toUpperCase()+e.substring(1,e.length)}function i(e,t){if(e in t)return"";e=e.charAt(0).toUpperCase()+e.substring(1,e.length);for(var r=["webkit","ms","Moz","O"],i=0;i=0||r.indexOf("ipad")>=0||r.indexOf("ipod")>=0;if(a)try{t.WebAudioDecode.ctx=new(window.AudioContext||window.webkitAudioContext||window.mozAudioContext)}catch(s){a=!1}var l,c=i._audioType;c==n.WEB_AUDIO&&a||c==n.HTML5_AUDIO?(l=!1,i.setAudioType(c)):!o&&r.indexOf("safari")>=0&&-1===r.indexOf("chrome")?(l=!1,i.setAudioType(n.WEB_AUDIO)):(l=!0,i.setAudioType(n.HTML5_AUDIO)),r.indexOf("android")>=0?l&&a&&i.setAudioType(n.WEB_AUDIO):o&&i.getIOSVersion()>=7&&(i._canUseBlob=!0,l&&a&&i.setAudioType(n.WEB_AUDIO));var h=window.URL||window.webkitURL;h||(i._canUseBlob=!1),r.indexOf("egretnative")>=0&&(i.setAudioType(n.HTML5_AUDIO),i._canUseBlob=!0),e.Sound=i._AudioClass},i.setAudioType=function(t){switch(i._audioType=t,t){case n.WEB_AUDIO:i._AudioClass=e.web.WebAudioSound;break;case n.HTML5_AUDIO:i._AudioClass=e.web.HtmlSound}},i.getIOSVersion=function(){var e=i.ua.toLowerCase().match(/cpu [^\d]*\d.*like mac os x/);if(!e||0==e.length)return 0;var t=e[0];return parseInt(t.match(/\d+(_\d)*/)[0])||0},i._canUseBlob=!1,i._audioType=0,i.ua="",i}(e.HashObject);t.Html5Capatibility=a,__reflect(a.prototype,"egret.web.Html5Capatibility");var o=null;t.getPrefixStyleName=r,t.getPrefix=i}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(e,t){return i(e,t)}function i(e,t){var r=document.createElement("canvas");return isNaN(e)||isNaN(t)||(r.width=e,r.height=t),r}function n(e,t,r,i){if(e){var n=e,a=n.surface;i?(a.widthr;r++){var i=e[r],n=i["egret-player"];n.updateScreenSize()}}function i(r){if(!s){s=!0,r||(r={});var i=navigator.userAgent.toLowerCase();if(i.indexOf("egretnative")>=0&&-1==i.indexOf("egretwebview")&&(e.Capabilities.runtimeType=e.RuntimeType.RUNTIME2),i.indexOf("egretnative")>=0&&e.nativeRender)egret_native.addModuleCallback(function(){if(t.Html5Capatibility.$init(),"webgl"==r.renderMode){var i=r.antialias;t.WebGLRenderContext.antialias=!!i}e.sys.CanvasRenderBuffer=t.CanvasRenderBuffer,n(r.renderMode),egret_native.nrSetRenderMode(2);var s;s=r.canvasScaleFactor?r.canvasScaleFactor:r.calculateCanvasScaleFactor?r.calculateCanvasScaleFactor(e.sys.canvasHitTestBuffer.context):window.devicePixelRatio,e.sys.DisplayList.$canvasScaleFactor=s;var c=e.ticker;a(c),r.screenAdapter?e.sys.screenAdapter=r.screenAdapter:e.sys.screenAdapter||(e.sys.screenAdapter=new e.sys.DefaultScreenAdapter);for(var h=document.querySelectorAll(".egret-player"),u=h.length,d=0;u>d;d++){var f=h[d],p=new t.WebPlayer(f,r);f["egret-player"]=p}window.addEventListener("resize",function(){isNaN(l)&&(l=window.setTimeout(o,300))})},null),egret_native.initNativeRender();else{t.Html5Capatibility._audioType=r.audioType,t.Html5Capatibility.$init();var c=r.renderMode;if("webgl"==c){var h=r.antialias;t.WebGLRenderContext.antialias=!!h}e.sys.CanvasRenderBuffer=t.CanvasRenderBuffer,i.indexOf("egretnative")>=0&&"webgl"!=c&&(e.$warn(1051),c="webgl"),n(c);var u=void 0;if(r.canvasScaleFactor)u=r.canvasScaleFactor;else if(r.calculateCanvasScaleFactor)u=r.calculateCanvasScaleFactor(e.sys.canvasHitTestBuffer.context);else{var d=e.sys.canvasHitTestBuffer.context,f=d.backingStorePixelRatio||d.webkitBackingStorePixelRatio||d.mozBackingStorePixelRatio||d.msBackingStorePixelRatio||d.oBackingStorePixelRatio||d.backingStorePixelRatio||1;u=(window.devicePixelRatio||1)/f}e.sys.DisplayList.$canvasScaleFactor=u;var p=e.ticker;a(p),r.screenAdapter?e.sys.screenAdapter=r.screenAdapter:e.sys.screenAdapter||(e.sys.screenAdapter=new e.sys.DefaultScreenAdapter);for(var v=document.querySelectorAll(".egret-player"),g=v.length,x=0;g>x;x++){var y=v[x],m=new t.WebPlayer(y,r);y["egret-player"]=m}window.addEventListener("resize",function(){isNaN(l)&&(l=window.setTimeout(o,300))})}}}function n(r){"webgl"==r&&e.WebGLUtils.checkCanUseWebGL()?(e.sys.RenderBuffer=t.WebGLRenderBuffer,e.sys.systemRenderer=new t.WebGLRenderer,e.sys.canvasRenderer=new e.CanvasRenderer,e.sys.customHitTestBuffer=new t.WebGLRenderBuffer(3,3),e.sys.canvasHitTestBuffer=new t.CanvasRenderBuffer(3,3),e.Capabilities.renderMode="webgl"):(e.sys.RenderBuffer=t.CanvasRenderBuffer,e.sys.systemRenderer=new e.CanvasRenderer,e.sys.canvasRenderer=e.sys.systemRenderer,e.sys.customHitTestBuffer=new t.CanvasRenderBuffer(3,3),e.sys.canvasHitTestBuffer=e.sys.customHitTestBuffer,e.Capabilities.renderMode="canvas")}function a(e){function t(){r(t),e.update()}var r=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;r||(r=function(e){return window.setTimeout(e,1e3/60)}),r(t)}function o(){l=0/0,e.updateAllScreens()}var s=!1;window.isNaN=function(e){return e=+e,e!==e},e.runEgret=i,e.updateAllScreens=r;var l=0/0}(t=e.web||(e.web={}))}(egret||(egret={}));var language,egret;!function(e){var t;!function(t){var r=function(){function t(){}return t.detect=function(){var r=e.Capabilities,i=navigator.userAgent.toLowerCase();r.isMobile=-1!=i.indexOf("mobile")||-1!=i.indexOf("android"),r.isMobile?i.indexOf("windows")<0&&(-1!=i.indexOf("iphone")||-1!=i.indexOf("ipad")||-1!=i.indexOf("ipod"))?r.os="iOS":-1!=i.indexOf("android")&&-1!=i.indexOf("linux")?r.os="Android":-1!=i.indexOf("windows")&&(r.os="Windows Phone"):-1!=i.indexOf("windows nt")?r.os="Windows PC":"MacIntel"==navigator.platform&&navigator.maxTouchPoints>1?(r.os="iOS",r.isMobile=!0):-1!=i.indexOf("mac os")&&(r.os="Mac OS");var n=(navigator.language||navigator.browserLanguage).toLowerCase(),a=n.split("-");a.length>1&&(a[1]=a[1].toUpperCase()),r.language=a.join("-"),t.injectUIntFixOnIE9()},t.injectUIntFixOnIE9=function(){if(/msie 9.0/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent)){var e="\r\n\r\n\r\n\r\n";document.write(e)}},t}();t.WebCapability=r,__reflect(r.prototype,"egret.web.WebCapability"),r.detect()}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(){function t(t,r,i,n,a){if(this.showPanle=!0,this.fpsHeight=0,this.WIDTH=101,this.HEIGHT=20,this.bgCanvasColor="#18304b",this.fpsFrontColor="#18fefe",this.WIDTH_COST=50,this.cost1Color="#18fefe",this.cost3Color="#ff0000",this.arrFps=[],this.arrCost=[],this.arrLog=[],r||i){"canvas"==e.Capabilities.renderMode?this.renderMode="Canvas":this.renderMode="WebGL",this.panelX=void 0===a.x?0:parseInt(a.x),this.panelY=void 0===a.y?0:parseInt(a.y),this.fontColor=void 0===a.textColor?"#ffffff":a.textColor.replace("0x","#"),this.fontSize=void 0===a.size?12:parseInt(a.size),e.Capabilities.isMobile&&(this.fontSize-=2);var o=document.createElement("div");o.style.position="absolute",o.style.background="rgba(0,0,0,"+a.bgAlpha+")",o.style.left=this.panelX+"px",o.style.top=this.panelY+"px",o.style.pointerEvents="none",o.id="egret-fps-panel",document.body.appendChild(o);var s=document.createElement("div");s.style.color=this.fontColor,s.style.fontSize=this.fontSize+"px",s.style.lineHeight=this.fontSize+"px",s.style.margin="4px 4px 4px 4px",this.container=s,o.appendChild(s),r&&this.addFps(),i&&this.addLog()}}return t.prototype.addFps=function(){var e=document.createElement("div");e.style.display="inline-block",this.containerFps=e,this.container.appendChild(e);var t=document.createElement("div");t.style.paddingBottom="2px",this.fps=t,this.containerFps.appendChild(t),t.innerHTML="0 FPS "+this.renderMode+"
min0 max0 avg0";var r=document.createElement("canvas");this.containerFps.appendChild(r),r.width=this.WIDTH,r.height=this.HEIGHT,this.canvasFps=r;var i=r.getContext("2d");this.contextFps=i,i.fillStyle=this.bgCanvasColor,i.fillRect(0,0,this.WIDTH,this.HEIGHT);var n=document.createElement("div");this.divDatas=n,this.containerFps.appendChild(n);var a=document.createElement("div");a.style["float"]="left",a.innerHTML="Draw
Cost",n.appendChild(a);var o=document.createElement("div");o.style.paddingLeft=a.offsetWidth+20+"px",n.appendChild(o);var s=document.createElement("div");this.divDraw=s,s.innerHTML="0
",o.appendChild(s);var l=document.createElement("div");this.divCost=l,l.innerHTML='0 0',o.appendChild(l),r=document.createElement("canvas"),this.canvasCost=r,this.containerFps.appendChild(r),r.width=this.WIDTH,r.height=this.HEIGHT,i=r.getContext("2d"),this.contextCost=i,i.fillStyle=this.bgCanvasColor,i.fillRect(0,0,this.WIDTH,this.HEIGHT),i.fillStyle="#000000",i.fillRect(this.WIDTH_COST,0,1,this.HEIGHT),this.fpsHeight=this.container.offsetHeight},t.prototype.addLog=function(){var e=document.createElement("div");e.style.maxWidth=document.body.clientWidth-8-this.panelX+"px",e.style.wordWrap="break-word",this.log=e,this.container.appendChild(e)},t.prototype.update=function(e,t){void 0===t&&(t=!1);var r,i,n;t?(r=this.arrFps[this.arrFps.length-1],i=this.arrCost[this.arrCost.length-1][0],n=this.arrCost[this.arrCost.length-1][1]):(r=e.fps,i=e.costTicker,n=e.costRender,this.lastNumDraw=e.draw,this.arrFps.push(r),this.arrCost.push([i,n]));var a=0,o=this.arrFps.length;o>101&&(o=101,this.arrFps.shift(),this.arrCost.shift());for(var s=this.arrFps[0],l=this.arrFps[0],c=0;o>c;c++){var h=this.arrFps[c];a+=h,s>h?s=h:h>l&&(l=h)}var u=this.WIDTH,d=this.HEIGHT,f=this.contextFps;f.drawImage(this.canvasFps,1,0,u-1,d,0,0,u-1,d),f.fillStyle=this.bgCanvasColor,f.fillRect(u-1,0,1,d);var p=Math.floor(r/60*20);1>p&&(p=1),f.fillStyle=this.fpsFrontColor,f.fillRect(u-1,20-p,1,p);var v=this.WIDTH_COST;f=this.contextCost,f.drawImage(this.canvasCost,1,0,v-1,d,0,0,v-1,d),f.drawImage(this.canvasCost,v+2,0,v-1,d,v+1,0,v-1,d);var g=Math.floor(i/2);1>g?g=1:g>20&&(g=20);var x=Math.floor(n/2);1>x?x=1:x>20&&(x=20),f.fillStyle=this.bgCanvasColor,f.fillRect(v-1,0,1,d),f.fillRect(2*v,0,1,d),f.fillRect(3*v+1,0,1,d),f.fillStyle=this.cost1Color,f.fillRect(v-1,20-g,1,g),f.fillStyle=this.cost3Color,f.fillRect(2*v,20-x,1,x);var y=Math.floor(a/o),m=r+" FPS "+this.renderMode;this.showPanle&&(m+="
min"+s+" max"+l+" avg"+y,this.divDraw.innerHTML=this.lastNumDraw+"
",this.divCost.innerHTML=''+i+' '+n+""),this.fps.innerHTML=m},t.prototype.updateInfo=function(e){this.arrLog.push(e),this.updateLogLayout()},t.prototype.updateWarn=function(e){this.arrLog.push("[Warning]"+e),this.updateLogLayout()},t.prototype.updateError=function(e){this.arrLog.push("[Error]"+e),this.updateLogLayout()},t.prototype.updateLogLayout=function(){for(this.log.innerHTML=this.arrLog.join("
");document.body.clientHeight")},t}();t.WebFps=r,__reflect(r.prototype,"egret.web.WebFps",["egret.FPSDisplay"]),e.FPSDisplay=r}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r;!function(r){function i(e){return window.localStorage.getItem(e)}function n(t,r){try{return window.localStorage.setItem(t,r),!0}catch(i){return e.$warn(1047,t,r),!1}}function a(e){window.localStorage.removeItem(e)}function o(){window.localStorage.clear()}t.getItem=i,t.setItem=n,t.removeItem=a,t.clear=o}(r=t.web||(t.web={}))}(t=e.localStorage||(e.localStorage={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(e,t){var i=r.call(this)||this;return i.init(e,t),i.initOrientation(),i}return __extends(i,r),i.prototype.init=function(r,i){console.log("Egret Engine Version:",e.Capabilities.engineVersion);var n=this.readOption(r,i),a=new e.Stage;a.$screen=this,a.$scaleMode=n.scaleMode,a.$orientation=n.orientation,a.$maxTouches=n.maxTouches,a.frameRate=n.frameRate,a.textureScaleFactor=n.textureScaleFactor;var o=new e.sys.RenderBuffer(void 0,void 0,!0),s=o.surface;this.attachCanvas(r,s);var l=new t.WebTouchHandler(a,s),c=new e.sys.Player(o,a,n.entryClassName);e.lifecycle.stage=a,e.lifecycle.addLifecycleListener(t.WebLifeCycleHandler);var h=new t.HTMLInput;(n.showFPS||n.showLog)&&(e.nativeRender||c.displayFPS(n.showFPS,n.showLog,n.logFilter,n.fpsStyles)),this.playerOption=n,this.container=r,this.canvas=s,this.stage=a,this.player=c,this.webTouchHandler=l,this.webInput=h,e.web.$cacheTextAdapter(h,a,r,s),this.updateScreenSize(),this.updateMaxTouches(),c.start()},i.prototype.initOrientation=function(){var t=this;window.addEventListener("orientationchange",function(){window.setTimeout(function(){e.StageOrientationEvent.dispatchStageOrientationEvent(t.stage,e.StageOrientationEvent.ORIENTATION_CHANGE)},350)})},i.prototype.readOption=function(t,r){var i={};i.entryClassName=t.getAttribute("data-entry-class"),i.scaleMode=t.getAttribute("data-scale-mode")||e.StageScaleMode.NO_SCALE,i.frameRate=+t.getAttribute("data-frame-rate")||30,i.contentWidth=+t.getAttribute("data-content-width")||480,i.contentHeight=+t.getAttribute("data-content-height")||800,i.orientation=t.getAttribute("data-orientation")||e.OrientationMode.AUTO,i.maxTouches=+t.getAttribute("data-multi-fingered")||2,i.textureScaleFactor=+t.getAttribute("texture-scale-factor")||1,i.showFPS="true"==t.getAttribute("data-show-fps");for(var n=t.getAttribute("data-show-fps-style")||"",a=n.split(","),o={},s=0;sa||l==e.OrientationMode.PORTRAIT&&a>o);var c=s?o:a,h=s?a:o;e.Capabilities.boundingClientWidth=c,e.Capabilities.boundingClientHeight=h;var u=e.sys.screenAdapter.calculateStageSize(this.stage.$scaleMode,c,h,r.contentWidth,r.contentHeight),d=u.stageWidth,f=u.stageHeight,p=u.displayWidth,v=u.displayHeight;t.style[e.web.getPrefixStyleName("transformOrigin")]="0% 0% 0px",t.width!=d&&(t.width=d),t.height!=f&&(t.height=f);var g=0;s?l==e.OrientationMode.LANDSCAPE?(g=90,t.style.top=n+(o-p)/2+"px",t.style.left=(a+v)/2+"px"):(g=-90,t.style.top=n+(o+p)/2+"px",t.style.left=(a-v)/2+"px"):(t.style.top=n+(o-v)/2+"px",t.style.left=(a-p)/2+"px");var x=p/d,y=v/f,m=x*e.sys.DisplayList.$canvasScaleFactor,b=y*e.sys.DisplayList.$canvasScaleFactor;"canvas"==e.Capabilities.renderMode&&(m=Math.ceil(m),b=Math.ceil(b));var w=e.Matrix.create();w.identity(),w.scale(x/m,y/b),w.rotate(g*Math.PI/180);var T="matrix("+w.a+","+w.b+","+w.c+","+w.d+","+w.tx+","+w.ty+")";e.Matrix.release(w),t.style[e.web.getPrefixStyleName("transform")]=T,e.sys.DisplayList.$setCanvasScale(m,b),this.webTouchHandler.updateScaleMode(x,y,g),this.webInput.$updateSize(),this.player.updateStageSize(d,f),e.nativeRender&&(t.width=d*m,t.height=f*b)}}},i.prototype.setContentSize=function(e,t){var r=this.playerOption;r.contentWidth=e,r.contentHeight=t,this.updateScreenSize()},i.prototype.updateMaxTouches=function(){this.webTouchHandler.$updateMaxTouches()},i}(e.HashObject);t.WebPlayer=r,__reflect(r.prototype,"egret.web.WebPlayer",["egret.sys.Screen"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){function r(t,r){s||(s=e.sys.createCanvas(),l=s.getContext("2d"));var i=t.$getTextureWidth(),n=t.$getTextureHeight();null==r&&(r=e.$TempRectangle,r.x=0,r.y=0,r.width=i,r.height=n),r.x=Math.min(r.x,i-1),r.y=Math.min(r.y,n-1),r.width=Math.min(r.width,i-r.x),r.height=Math.min(r.height,n-r.y);var a=r.width,o=r.height,c=s;if(c.style.width=a+"px",c.style.height=o+"px",s.width=a,s.height=o,"webgl"==e.Capabilities.renderMode){var h=void 0;t.$renderBuffer?h=t:(h=new e.RenderTexture,h.drawToTexture(new e.Bitmap(t)));for(var u=h.$renderBuffer.getPixels(r.x,r.y,a,o),d=new ImageData(a,o),f=0;fn;n++){var a=t.childNodes[n];if(1==a.nodeType)return i(a,null)}return null}function i(e,t){if("parsererror"==e.localName)throw new Error(e.textContent);for(var r=new a(e.localName,t,e.prefix,e.namespaceURI,e.nodeName),n=e.attributes,s=r.attributes,l=n.length,c=0;l>c;c++){var h=n[c],u=h.name;0!=u.indexOf("xmlns:")&&(s[u]=h.value,r["$"+u]=h.value)}var d=e.childNodes;l=d.length;for(var f=r.children,c=0;l>c;c++){var p=d[c],v=p.nodeType,g=null;if(1==v)g=i(p,r);else if(3==v){var x=p.textContent.trim();x&&(g=new o(x,r))}g&&f.push(g)}return r}var n=function(){function e(e,t){this.nodeType=e,this.parent=t}return e}();t.XMLNode=n,__reflect(n.prototype,"egret.web.XMLNode");var a=function(e){function t(t,r,i,n,a){var o=e.call(this,1,r)||this;return o.attributes={},o.children=[],o.localName=t,o.prefix=i,o.namespace=n,o.name=a,o}return __extends(t,e),t}(n);t.XML=a,__reflect(a.prototype,"egret.web.XML");var o=function(e){function t(t,r){var i=e.call(this,3,r)||this;return i.text=t,i}return __extends(t,e),t}(n);t.XMLText=o,__reflect(o.prototype,"egret.web.XMLText");var s=new DOMParser;e.XML={parse:r}}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(t){function r(){var r=null!==t&&t.apply(this,arguments)||this;return r.onChange=function(t){var i=new e.OrientationEvent(e.Event.CHANGE);i.beta=t.beta,i.gamma=t.gamma,i.alpha=t.alpha,r.dispatchEvent(i)},r}return __extends(r,t),r.prototype.start=function(){window.addEventListener("deviceorientation",this.onChange)},r.prototype.stop=function(){window.removeEventListener("deviceorientation",this.onChange)},r}(e.EventDispatcher);t.WebDeviceOrientation=r,__reflect(r.prototype,"egret.web.WebDeviceOrientation",["egret.DeviceOrientation"])}(t=e.web||(e.web={}))}(egret||(egret={})),egret.DeviceOrientation=egret.web.WebDeviceOrientation;var egret;!function(e){var t;!function(t){var r=function(){function e(){}return e.call=function(e,t){},e.addCallback=function(e,t){},e}();t.WebExternalInterface=r,__reflect(r.prototype,"egret.web.WebExternalInterface",["egret.ExternalInterface"]);var i=navigator.userAgent.toLowerCase();i.indexOf("egretnative")<0&&(e.ExternalInterface=r)}(t=e.web||(e.web={}))}(egret||(egret={})),function(e){var t;!function(t){function r(t){var r=JSON.parse(t),n=r.functionName,a=i[n];if(a){var o=r.value;a.call(null,o)}else e.$warn(1050,n)}var i={},n=function(){function e(){}return e.call=function(e,t){var r={};r.functionName=e,r.value=t,egret_native.sendInfoToPlugin(JSON.stringify(r))},e.addCallback=function(e,t){i[e]=t},e}();t.NativeExternalInterface=n,__reflect(n.prototype,"egret.web.NativeExternalInterface",["egret.ExternalInterface"]);var a=navigator.userAgent.toLowerCase();a.indexOf("egretnative")>=0&&(e.ExternalInterface=n,egret_native.receivedPluginInfo=r)}(t=e.web||(e.web={}))}(egret||(egret={})),function(e){var t;!function(t){var r={},i=function(){function t(){}return t.call=function(e,t){__global.ExternalInterface.call(e,t)},t.addCallback=function(e,t){r[e]=t},t.invokeCallback=function(t,i){var n=r[t];n?n.call(null,i):e.$warn(1050,t)},t}();t.WebViewExternalInterface=i,__reflect(i.prototype,"egret.web.WebViewExternalInterface",["egret.ExternalInterface"]);var n=navigator.userAgent.toLowerCase();n.indexOf("egretwebview")>=0&&(e.ExternalInterface=i)}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(){var e=r.call(this)||this;return e.loaded=!1,e}return __extends(i,r),Object.defineProperty(i.prototype,"length",{get:function(){if(this.originAudio)return this.originAudio.duration;throw new Error("sound not loaded!")},enumerable:!0,configurable:!0}),i.prototype.load=function(t){function r(){i.$recycle(o.url,s),a(),l.indexOf("firefox")>=0&&(s.pause(),s.muted=!1),c&&document.body.appendChild(s),o.loaded=!0,o.dispatchEventWith(e.Event.COMPLETE)}function n(){a(),o.dispatchEventWith(e.IOErrorEvent.IO_ERROR)}function a(){s.removeEventListener("canplaythrough",r),s.removeEventListener("error",n),c&&document.body.removeChild(s)}var o=this;this.url=t;var s=new Audio(t);s.addEventListener("canplaythrough",r),s.addEventListener("error",n);var l=navigator.userAgent.toLowerCase();l.indexOf("firefox")>=0&&(s.autoplay=!0,s.muted=!0);var c=l.indexOf("edge")>=0||l.indexOf("trident")>=0;c&&document.body.appendChild(s),s.load(),this.originAudio=s,i.clearAudios[this.url]&&delete i.clearAudios[this.url]},i.prototype.play=function(r,n){r=+r||0,n=+n||0;var a=i.$pop(this.url);null==a&&(a=this.originAudio.cloneNode()),a.autoplay=!0;var o=new t.HtmlSoundChannel(a);return o.$url=this.url,o.$loops=n,o.$startTime=r,o.$play(),e.sys.$pushSoundChannel(o),o},i.prototype.close=function(){this.loaded&&this.originAudio&&(this.originAudio.src=""),this.originAudio&&(this.originAudio=null),i.$clear(this.url),this.loaded=!1},i.$clear=function(e){i.clearAudios[e]=!0;var t=i.audios[e];t&&(t.length=0)},i.$pop=function(e){var t=i.audios[e];return t&&t.length>0?t.pop():null},i.$recycle=function(e,t){if(!i.clearAudios[e]){var r=i.audios[e];null==i.audios[e]&&(r=i.audios[e]=[]),r.push(t)}},i.MUSIC="music",i.EFFECT="effect",i.audios={},i.clearAudios={},i}(e.EventDispatcher);t.HtmlSound=r,__reflect(r.prototype,"egret.web.HtmlSound",["egret.Sound"])}(t=e.web||(e.web={}))}(egret||(egret={})); -var egret;!function(e){var t;!function(e){}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(){this.drawData=[],this.drawDataLen=0}return e.prototype.pushDrawRect=function(){if(0==this.drawDataLen||1!=this.drawData[this.drawDataLen-1].type){var e=this.drawData[this.drawDataLen]||{};e.type=1,e.count=0,this.drawData[this.drawDataLen]=e,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=2},e.prototype.pushDrawTexture=function(e,t,r,i,n){if(void 0===t&&(t=2),r){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.filter=r,a.count=t,a.textureWidth=i,a.textureHeight=n,this.drawData[this.drawDataLen]=a,this.drawDataLen++}else{if(0==this.drawDataLen||0!=this.drawData[this.drawDataLen-1].type||e!=this.drawData[this.drawDataLen-1].texture||this.drawData[this.drawDataLen-1].filter){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.count=0,this.drawData[this.drawDataLen]=a,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=t}},e.prototype.pushChangeSmoothing=function(e,t){e.smoothing=t;var r=this.drawData[this.drawDataLen]||{};r.type=10,r.texture=e,r.smoothing=t,this.drawData[this.drawDataLen]=r,this.drawDataLen++},e.prototype.pushPushMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=2,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushPopMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=3,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushSetBlend=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];if(n){if((0==n.type||1==n.type)&&(r=!0),!r&&4==n.type){this.drawData.splice(i,1),this.drawDataLen--;continue}if(4==n.type){if(n.value==e)return;break}}}var a=this.drawData[this.drawDataLen]||{};a.type=4,a.value=e,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushResize=function(e,t,r){var i=this.drawData[this.drawDataLen]||{};i.type=5,i.buffer=e,i.width=t,i.height=r,this.drawData[this.drawDataLen]=i,this.drawDataLen++},e.prototype.pushClearColor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=6,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.pushActivateBuffer=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];!n||(4!=n.type&&7!=n.type&&(r=!0),r||7!=n.type)||(this.drawData.splice(i,1),this.drawDataLen--)}var a=this.drawData[this.drawDataLen]||{};a.type=7,a.buffer=e,a.width=e.rootRenderTarget.width,a.height=e.rootRenderTarget.height,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushEnableScissor=function(e,t,r,i){var n=this.drawData[this.drawDataLen]||{};n.type=8,n.x=e,n.y=t,n.width=r,n.height=i,this.drawData[this.drawDataLen]=n,this.drawDataLen++},e.prototype.pushDisableScissor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=9,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.clear=function(){for(var e=0;er;r+=6,i+=4)this.indices[r+0]=i+0,this.indices[r+1]=i+1,this.indices[r+2]=i+2,this.indices[r+3]=i+0,this.indices[r+4]=i+2,this.indices[r+5]=i+3}return t.prototype.reachMaxSize=function(e,t){return void 0===e&&(e=4),void 0===t&&(t=6),this.vertexIndex>this.maxVertexCount-e||this.indexIndex>this.maxIndicesCount-t},t.prototype.getVertices=function(){var e=this.vertices.subarray(0,this.vertexIndex*this.vertSize);return e},t.prototype.getIndices=function(){return this.indices},t.prototype.getMeshIndices=function(){return this.indicesForMesh},t.prototype.changeToMeshIndices=function(){if(!this.hasMesh){for(var e=0,t=this.indexIndex;t>e;++e)this.indicesForMesh[e]=this.indices[e];this.hasMesh=!0}},t.prototype.isMesh=function(){return this.hasMesh},t.prototype.cacheArrays=function(t,r,i,n,a,o,s,l,c,h,u,d,f,p,v){var g=t.globalAlpha;g=Math.min(g,1);var x=t.globalTintColor||16777215,y=t.currentTexture;g=1>g&&y&&y[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]?e.WebGLUtils.premultiplyTint(x,g):x+(255*g<<24);var m=t.globalMatrix,b=m.a,w=m.b,T=m.c,E=m.d,_=m.tx,C=m.ty,S=t.$offsetX,R=t.$offsetY;if((0!=S||0!=R)&&(_=S*b+R*T+_,C=S*w+R*E+C),!f){(0!=o||0!=s)&&(_=o*b+s*T+_,C=o*w+s*E+C);var L=l/n;1!=L&&(b=L*b,w=L*w);var D=c/a;1!=D&&(T=D*T,E=D*E)}if(f){var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize,M=0,B=0,O=0,P=0,W=0,k=0,G=0;for(M=0,O=d.length;O>M;M+=2)B=$+5*M/2,k=f[M],G=f[M+1],P=d[M],W=d[M+1],A[B+0]=b*k+T*G+_,A[B+1]=w*k+E*G+C,v?(A[B+2]=(r+(1-W)*a)/h,A[B+3]=(i+P*n)/u):(A[B+2]=(r+P*n)/h,A[B+3]=(i+W*a)/u),I[B+4]=g;if(this.hasMesh)for(var H=0,F=p.length;F>H;++H)this.indicesForMesh[this.indexIndex+H]=p[H]+this.vertexIndex;this.vertexIndex+=d.length/2,this.indexIndex+=p.length}else{var U=h,N=u,X=n,z=a;r/=U,i/=N;var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize;if(v){var Y=n;n=a/U,a=Y/N,A[$++]=_,A[$++]=C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=i,I[$++]=g}else n/=U,a/=N,A[$++]=_,A[$++]=C,A[$++]=r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=a+i,I[$++]=g;if(this.hasMesh){var V=this.indicesForMesh;V[this.indexIndex+0]=0+this.vertexIndex,V[this.indexIndex+1]=1+this.vertexIndex,V[this.indexIndex+2]=2+this.vertexIndex,V[this.indexIndex+3]=0+this.vertexIndex,V[this.indexIndex+4]=2+this.vertexIndex,V[this.indexIndex+5]=3+this.vertexIndex}this.vertexIndex+=4,this.indexIndex+=6}},t.prototype.clear=function(){this.hasMesh=!1,this.vertexIndex=0,this.indexIndex=0},t}();t.WebGLVertexArrayObject=r,__reflect(r.prototype,"egret.web.WebGLVertexArrayObject")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(e,t,i){var n=r.call(this)||this;return n.clearColor=[0,0,0,0],n.useFrameBuffer=!0,n.gl=e,n._resize(t,i),n}return __extends(i,r),i.prototype._resize=function(e,t){e=e||1,t=t||1,1>e&&(e=1),1>t&&(t=1),this.width=e,this.height=t},i.prototype.resize=function(e,t){this._resize(e,t);var r=this.gl;this.frameBuffer&&(r.bindTexture(r.TEXTURE_2D,this.texture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.width,this.height,0,r.RGBA,r.UNSIGNED_BYTE,null)),this.stencilBuffer&&(r.deleteRenderbuffer(this.stencilBuffer),this.stencilBuffer=null)},i.prototype.activate=function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.getFrameBuffer())},i.prototype.getFrameBuffer=function(){return this.useFrameBuffer?this.frameBuffer:null},i.prototype.initFrameBuffer=function(){if(!this.frameBuffer){var e=this.gl;this.texture=this.createTexture(),this.frameBuffer=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.texture,0)}},i.prototype.createTexture=function(){var r=t.WebGLRenderContext.getInstance(0,0);return e.sys._createTexture(r,this.width,this.height,null)},i.prototype.clear=function(e){var t=this.gl;e&&this.activate(),t.colorMask(!0,!0,!0,!0),t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(t.COLOR_BUFFER_BIT)},i.prototype.enabledStencil=function(){if(this.frameBuffer&&!this.stencilBuffer){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),this.stencilBuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,this.width,this.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,this.stencilBuffer)}},i.prototype.dispose=function(){e.WebGLUtils.deleteWebGLTexture(this.texture)},i}(e.HashObject);t.WebGLRenderTarget=r,__reflect(r.prototype,"egret.web.WebGLRenderTarget")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r={},i=function(){function i(r,i){if(this._defaultEmptyTexture=null,this.glID=null,this.projectionX=0/0,this.projectionY=0/0,this.contextLost=!1,this._supportedCompressedTextureInfo=[],this.$scissorState=!1,this.vertSize=5,this.surface=e.sys.mainCanvas(r,i),!e.nativeRender){this.initWebGL(),this.$bufferStack=[];var n=this.context;this.vertexBuffer=n.createBuffer(),this.indexBuffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.vertexBuffer),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this.indexBuffer),this.drawCmdManager=new t.WebGLDrawCmdManager,this.vao=new t.WebGLVertexArrayObject,this.setGlobalCompositeOperation("source-over")}}return i.getInstance=function(e,t){return this.instance?this.instance:(this.instance=new i(e,t),this.instance)},i.prototype.pushBuffer=function(e){this.$bufferStack.push(e),e!=this.currentBuffer&&(this.currentBuffer,this.drawCmdManager.pushActivateBuffer(e)),this.currentBuffer=e},i.prototype.popBuffer=function(){if(!(this.$bufferStack.length<=1)){var e=this.$bufferStack.pop(),t=this.$bufferStack[this.$bufferStack.length-1];e!=t&&this.drawCmdManager.pushActivateBuffer(t),this.currentBuffer=t}},i.prototype.activateBuffer=function(e,t,r){e.rootRenderTarget.activate(),this.bindIndices||this.uploadIndicesArray(this.vao.getIndices()),e.restoreStencil(),e.restoreScissor(),this.onResize(t,r)},i.prototype.uploadVerticesArray=function(e){var t=this.context;t.bufferData(t.ARRAY_BUFFER,e,t.STREAM_DRAW)},i.prototype.uploadIndicesArray=function(e){var t=this.context;t.bufferData(t.ELEMENT_ARRAY_BUFFER,e,t.STATIC_DRAW),this.bindIndices=!0},i.prototype.destroy=function(){this.surface.width=this.surface.height=0},i.prototype.onResize=function(e,t){e=e||this.surface.width,t=t||this.surface.height,this.projectionX=e/2,this.projectionY=-t/2,this.context&&this.context.viewport(0,0,e,t)},i.prototype.resize=function(t,r,i){e.sys.resizeContext(this,t,r,i)},i.prototype._buildSupportedCompressedTextureInfo=function(e){for(var t=[],r=0,i=e;rr; ++r)for(var n=e[r],a=n.supportedFormats,o=0,s=a.length; s>o; ++o)if(a[o][1]===t)return!0;return!1},i.prototype.$debugLogCompressedTextureNotSupported=function(t,i){if(!r[i]){r[i]=!0,e.log("internalFormat = "+i+":0x"+i.toString(16)+", the current hardware does not support the corresponding compression format.");for(var n=0,a=t.length;a>n;++n){var o=t[n];if(o.supportedFormats.length>0){e.log("support = "+o.extensionName);for(var s=0,l=o.supportedFormats.length;l>s;++s){var c=o.supportedFormats[s];e.log(c[0]+" : "+c[1]+" : 0x"+c[1].toString(16))}}}}},i.prototype.createCompressedTexture=function(t,r,i,n,a){var o=this.checkCompressedTextureInternalFormat(this._supportedCompressedTextureInfo,a);if(!o)return this.$debugLogCompressedTextureNotSupported(this._supportedCompressedTextureInfo,a),this.defaultEmptyTexture;var s=this.context,l=s.createTexture();return l?(l[e.glContext]=s,l[e.is_compressed_texture]=!0,s.bindTexture(s.TEXTURE_2D,l),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),l[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]=!0,s.compressedTexImage2D(s.TEXTURE_2D,n,a,r,i,0,t),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.bindTexture(s.TEXTURE_2D,null),l):void(this.contextLost=!0)},i.prototype.updateTexture=function(e,t){var r=this.context;r.bindTexture(r.TEXTURE_2D,e),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t)},Object.defineProperty(i.prototype,"defaultEmptyTexture",{get:function(){if(!this._defaultEmptyTexture){var t=16,r=e.sys.createCanvas(t,t),i=e.sys.getContext2d(r);i.fillStyle="white",i.fillRect(0,0,t,t),this._defaultEmptyTexture=this.createTexture(r),this._defaultEmptyTexture[e.engine_default_empty_texture]=!0}return this._defaultEmptyTexture},enumerable:!0,configurable:!0}),i.prototype.getWebGLTexture=function(t){if(!t.webGLTexture){if("image"!=t.format||t.hasCompressed2d()){if(t.hasCompressed2d()){var r=t.getCompressed2dTextureData();t.webGLTexture=this.createCompressedTexture(r.byteArray,r.width,r.height,r.level,r.glInternalFormat);var i=t.etcAlphaMask;if(i){var n=this.getWebGLTexture(i);n&&(t.webGLTexture[e.etc_alpha_mask]=n)}}}else t.webGLTexture=this.createTexture(t.source);t.$deleteSource&&t.webGLTexture&&(t.source&&(t.source.src="",t.source=null),t.clearCompressedTextureData()),t.webGLTexture&&(t.webGLTexture.smoothing=!0)}return t.webGLTexture},i.prototype.clearRect=function(e,t,r,i){if(0!=e||0!=t||r!=this.surface.width||i!=this.surface.height){var n=this.currentBuffer;if(n.$hasScissor)this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over");else{var a=n.globalMatrix;0==a.b&&0==a.c?(e=e*a.a+a.tx,t=t*a.d+a.ty,r*=a.a,i*=a.d,this.enableScissor(e,-t-i+n.height,r,i),this.clear(),this.disableScissor()):(this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over"))}}else this.clear()},i.prototype.setGlobalCompositeOperation=function(e){this.drawCmdManager.pushSetBlend(e)},i.prototype.drawImage=function(e,t,r,i,n,a,o,s,l,c,h,u,d){var f=this.currentBuffer;if(!this.contextLost&&e&&f){var p,v,g;if(e.texture||e.source&&e.source.texture)p=e.texture||e.source.texture,f.saveTransform(),v=f.$offsetX,g=f.$offsetY,f.useOffset(),f.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;p=this.getWebGLTexture(e)}p&&(this.drawTexture(p,t,r,i,n,a,o,s,l,c,h,void 0,void 0,void 0,void 0,u,d),e.source&&e.source.texture&&(f.$offsetX=v,f.$offsetY=g,f.restoreTransform()))}},i.prototype.drawMesh=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){var y,m,b;if(e.texture||e.source&&e.source.texture)y=e.texture||e.source.texture,x.saveTransform(),m=x.$offsetX,b=x.$offsetY,x.useOffset(),x.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;y=this.getWebGLTexture(e)}y&&(this.drawTexture(y,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g),(e.texture||e.source&&e.source.texture)&&(x.$offsetX=m,x.$offsetY=b,x.restoreTransform()))}},i.prototype.drawTexture=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){d&&f?this.vao.reachMaxSize(d.length/2,f.length)&&this.$drawWebGL():this.vao.reachMaxSize()&&this.$drawWebGL(),void 0!=g&&e.smoothing!=g&&this.drawCmdManager.pushChangeSmoothing(e,g),u&&this.vao.changeToMeshIndices();var y=f?f.length/3:2;this.drawCmdManager.pushDrawTexture(e,y,this.$filter,c,h),x.currentTexture=e,this.vao.cacheArrays(x,t,r,i,n,a,o,s,l,c,h,u,d,f,v)}},i.prototype.drawRect=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushDrawRect(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.pushMask=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(n.$stencilList.push({x:e,y:t,width:r,height:i}),this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPushMask(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.popMask=function(){var e=this.currentBuffer;if(!this.contextLost&&e){var t=e.$stencilList.pop();this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPopMask(),e.currentTexture=null,this.vao.cacheArrays(e,0,0,t.width,t.height,t.x,t.y,t.width,t.height,t.width,t.height)}},i.prototype.clear=function(){this.drawCmdManager.pushClearColor()},i.prototype.enableScissor=function(e,t,r,i){var n=this.currentBuffer;this.drawCmdManager.pushEnableScissor(e,t,r,i),n.$hasScissor=!0},i.prototype.disableScissor=function(){var e=this.currentBuffer;this.drawCmdManager.pushDisableScissor(),e.$hasScissor=!1},i.prototype.$drawWebGL=function(){if(0!=this.drawCmdManager.drawDataLen&&!this.contextLost){this.uploadVerticesArray(this.vao.getVertices()),this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getMeshIndices());for(var e=this.drawCmdManager.drawDataLen,t=0,r=0;e>r;r++){var i=this.drawCmdManager.drawData[r];t=this.drawData(i,t),7==i.type&&(this.activatedBuffer=i.buffer),(0==i.type||1==i.type||2==i.type||3==i.type)&&this.activatedBuffer&&this.activatedBuffer.$computeDrawCall&&this.activatedBuffer.$drawCalls++}this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getIndices()),this.drawCmdManager.clear(),this.vao.clear()}},i.prototype.drawData=function(r,i){if(r){var n,a=this.context,o=r.filter;switch(r.type){case 0:o?"custom"===o.type?n=t.EgretWebGLProgram.getProgram(a,o.$vertexSrc,o.$fragmentSrc,o.$shaderKey):"colorTransform"===o.type?r.texture[e.etc_alpha_mask]?(a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask]),n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag_etc_alphamask_frag,"colorTransform_frag_etc_alphamask_frag")):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag,"colorTransform"):"blurX"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"blurY"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"glow"===o.type&&(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.glow_frag,"glow")):r.texture[e.etc_alpha_mask]?(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_etc_alphamask_frag,e.etc_alpha_mask),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask])):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_frag,"texture"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawTextureElements(r,i);break;case 1:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawRectElements(r,i);break;case 2:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPushMaskElements(r,i);break;case 3:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPopMaskElements(r,i);break;case 4:this.setBlendMode(r.value);break;case 5:r.buffer.rootRenderTarget.resize(r.width,r.height),this.onResize(r.width,r.height);break;case 6:if(this.activatedBuffer){var s=this.activatedBuffer.rootRenderTarget;(0!=s.width||0!=s.height)&&s.clear(!0)}break;case 7:this.activateBuffer(r.buffer,r.width,r.height);break;case 8:var l=this.activatedBuffer;l&&(l.rootRenderTarget&&l.rootRenderTarget.enabledStencil(),l.enableScissor(r.x,r.y,r.width,r.height));break;case 9:l=this.activatedBuffer,l&&l.disableScissor();break;case 10:a.bindTexture(a.TEXTURE_2D,r.texture),r.smoothing?(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR)):(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST))}return i}},i.prototype.activeProgram=function(e,t){if(t!=this.currentProgram){e.useProgram(t.id);var r=t.attributes;for(var i in r)"aVertexPosition"===i?(e.vertexAttribPointer(r.aVertexPosition.location,2,e.FLOAT,!1,20,0),e.enableVertexAttribArray(r.aVertexPosition.location)):"aTextureCoord"===i?(e.vertexAttribPointer(r.aTextureCoord.location,2,e.FLOAT,!1,20,8),e.enableVertexAttribArray(r.aTextureCoord.location)):"aColor"===i&&(e.vertexAttribPointer(r.aColor.location,4,e.UNSIGNED_BYTE,!0,20,16),e.enableVertexAttribArray(r.aColor.location));this.currentProgram=t}},i.prototype.syncUniforms=function(e,t,r,i){var n=e.uniforms;t&&"custom"===t.type;for(var a in n)if("projectionVector"===a)n[a].setValue({x:this.projectionX,y:this.projectionY});else if("uTextureSize"===a)n[a].setValue({x:r,y:i});else if("uSampler"===a)n[a].setValue(0);else if("uSamplerAlphaMask"===a)n[a].setValue(1);else{var o=t.$uniforms[a];void 0!==o&&n[a].setValue(o)}},i.prototype.drawTextureElements=function(t,r){return e.sys.drawTextureElements(this,t,r)},i.prototype.drawRectElements=function(e,t){var r=this.context,i=3*e.count;return r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),i},i.prototype.drawPushMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n){n.rootRenderTarget&&n.rootRenderTarget.enabledStencil(),0==n.stencilHandleCount&&(n.enableStencil(),r.clear(r.STENCIL_BUFFER_BIT));var a=n.stencilHandleCount;n.stencilHandleCount++,r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a,255),r.stencilOp(r.KEEP,r.KEEP,r.INCR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a+1,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.drawPopMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n)if(n.stencilHandleCount--,0==n.stencilHandleCount)n.disableStencil();else{var a=n.stencilHandleCount;r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a+1,255),r.stencilOp(r.KEEP,r.KEEP,r.DECR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.setBlendMode=function(e){var t=this.context,r=i.blendModesForGL[e];r&&t.blendFunc(r[0],r[1])},i.prototype.drawTargetWidthFilters=function(e,r){var i,n=r,a=e.length;if(a>1)for(var o=0;a-1>o;o++){var s=e[o],l=r.rootRenderTarget.width,c=r.rootRenderTarget.height;i=t.WebGLRenderBuffer.create(l,c),i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,this.drawToRenderTarget(s,r,i),r!=n&&t.WebGLRenderBuffer.release(r),r=i}var h=e[a-1];this.drawToRenderTarget(h,r,this.currentBuffer),r!=n&&t.WebGLRenderBuffer.release(r)},i.prototype.drawToRenderTarget=function(e,r,i){if(!this.contextLost){this.vao.reachMaxSize()&&this.$drawWebGL(),this.pushBuffer(i);var n,a=r,o=r.rootRenderTarget.width,s=r.rootRenderTarget.height;if("blur"==e.type){var l=e.blurXFilter,c=e.blurYFilter;0!=l.blurX&&0!=c.blurY?(n=t.WebGLRenderBuffer.create(o,s),n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,this.drawToRenderTarget(e.blurXFilter,r,n),r!=a&&t.WebGLRenderBuffer.release(r),r=n,e=c):e=0===l.blurX?c:l}i.saveTransform(),i.transform(1,0,0,-1,0,s),i.currentTexture=r.rootRenderTarget.texture,this.vao.cacheArrays(i,0,0,o,s,0,0,o,s,o,s),i.restoreTransform(),this.drawCmdManager.pushDrawTexture(r.rootRenderTarget.texture,2,e,o,s),r!=a&&t.WebGLRenderBuffer.release(r),this.popBuffer()}},i.initBlendMode=function(){i.blendModesForGL={},i.blendModesForGL["source-over"]=[1,771],i.blendModesForGL.lighter=[1,1],i.blendModesForGL["lighter-in"]=[770,771],i.blendModesForGL["destination-out"]=[0,771],i.blendModesForGL["destination-in"]=[0,770]},i.glContextId=0,i.blendModesForGL=null,i}();t.WebGLRenderContext=i,__reflect(i.prototype,"egret.web.WebGLRenderContext",["egret.sys.RenderContext"]),i.initBlendMode()}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function n(i,n,a){var o=r.call(this)||this;if(o.currentTexture=null,o.globalAlpha=1,o.globalTintColor=16777215,o.stencilState=!1,o.$stencilList=[],o.stencilHandleCount=0,o.$scissorState=!1,o.scissorRect=new e.Rectangle,o.$hasScissor=!1,o.$drawCalls=0,o.$computeDrawCall=!1,o.globalMatrix=new e.Matrix,o.savedGlobalMatrix=new e.Matrix,o.$offsetX=0,o.$offsetY=0,o.context=t.WebGLRenderContext.getInstance(i,n),e.nativeRender)return a?o.surface=o.context.surface:o.surface=new egret_native.NativeRenderSurface(o,i,n,a),o.rootRenderTarget=null,o;if(o.rootRenderTarget=new t.WebGLRenderTarget(o.context.context,3,3),i&&n&&o.resize(i,n),o.root=a,o.root)o.context.pushBuffer(o),o.surface=o.context.surface,o.$computeDrawCall=!0;else{var s=o.context.activatedBuffer;s&&s.rootRenderTarget.activate(),o.rootRenderTarget.initFrameBuffer(),o.surface=o.rootRenderTarget}return o}return __extends(n,r),n.prototype.enableStencil=function(){this.stencilState||(this.context.enableStencilTest(),this.stencilState=!0)},n.prototype.disableStencil=function(){this.stencilState&&(this.context.disableStencilTest(),this.stencilState=!1)},n.prototype.restoreStencil=function(){this.stencilState?this.context.enableStencilTest():this.context.disableStencilTest()},n.prototype.enableScissor=function(e,t,r,i){this.$scissorState||(this.$scissorState=!0,this.scissorRect.setTo(e,t,r,i),this.context.enableScissorTest(this.scissorRect))},n.prototype.disableScissor=function(){this.$scissorState&&(this.$scissorState=!1,this.scissorRect.setEmpty(),this.context.disableScissorTest())},n.prototype.restoreScissor=function(){this.$scissorState?this.context.enableScissorTest(this.scissorRect):this.context.disableScissorTest()},Object.defineProperty(n.prototype,"width",{get:function(){return e.nativeRender?this.surface.width:this.rootRenderTarget.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return e.nativeRender?this.surface.height:this.rootRenderTarget.height},enumerable:!0,configurable:!0}),n.prototype.resize=function(t,r,i){return t=t||1,r=r||1,e.nativeRender?void this.surface.resize(t,r):(this.context.pushBuffer(this),(t!=this.rootRenderTarget.width||r!=this.rootRenderTarget.height)&&(this.context.drawCmdManager.pushResize(this,t,r),this.rootRenderTarget.width=t,this.rootRenderTarget.height=r),this.root&&this.context.resize(t,r,i),this.context.clear(),void this.context.popBuffer())},n.prototype.getPixels=function(t,r,i,n){void 0===i&&(i=1),void 0===n&&(n=1);var a=new Uint8Array(4*i*n);if(e.nativeRender)egret_native.activateBuffer(this),egret_native.nrGetPixels(t,r,i,n,a),egret_native.activateBuffer(null);else{var o=this.rootRenderTarget.useFrameBuffer;this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.getPixels(t,r,i,n,a),this.rootRenderTarget.useFrameBuffer=o,this.rootRenderTarget.activate()}for(var s=new Uint8Array(4*i*n),l=0;n>l;l++)for(var c=0;i>c;c++){var h=4*(i*(n-l-1)+c),u=4*(i*l+c),d=a[u+3];s[h]=Math.round(a[u]/d*255),s[h+1]=Math.round(a[u+1]/d*255),s[h+2]=Math.round(a[u+2]/d*255),s[h+3]=a[u+3]}return s},n.prototype.toDataURL=function(e,t){return this.context.surface.toDataURL(e,t)},n.prototype.destroy=function(){this.context.destroy()},n.prototype.onRenderFinish=function(){this.$drawCalls=0},n.prototype.drawFrameBufferToSurface=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.rootRenderTarget,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.drawSurfaceToFrameBuffer=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.context.surface,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.clear=function(){this.context.pushBuffer(this),this.context.clear(),this.context.popBuffer()},n.prototype.setTransform=function(e,t,r,i,n,a){var o=this.globalMatrix;o.a=e,o.b=t,o.c=r,o.d=i,o.tx=n,o.ty=a},n.prototype.transform=function(e,t,r,i,n,a){var o=this.globalMatrix,s=o.a,l=o.b,c=o.c,h=o.d;(1!=e||0!=t||0!=r||1!=i)&&(o.a=e*s+t*c,o.b=e*l+t*h,o.c=r*s+i*c,o.d=r*l+i*h),o.tx=n*s+a*c+o.tx,o.ty=n*l+a*h+o.ty},n.prototype.useOffset=function(){var e=this;(0!=e.$offsetX||0!=e.$offsetY)&&(e.globalMatrix.append(1,0,0,1,e.$offsetX,e.$offsetY),e.$offsetX=e.$offsetY=0)},n.prototype.saveTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t.tx=e.tx,t.ty=e.ty},n.prototype.restoreTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e.tx=t.tx,e.ty=t.ty},n.create=function(e,t){var r=i.pop(); +var egret;!function(e){var t;!function(e){}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(){this.drawData=[],this.drawDataLen=0}return e.prototype.pushDrawRect=function(){if(0==this.drawDataLen||1!=this.drawData[this.drawDataLen-1].type){var e=this.drawData[this.drawDataLen]||{};e.type=1,e.count=0,this.drawData[this.drawDataLen]=e,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=2},e.prototype.pushDrawTexture=function(e,t,r,i,n){if(void 0===t&&(t=2),r){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.filter=r,a.count=t,a.textureWidth=i,a.textureHeight=n,this.drawData[this.drawDataLen]=a,this.drawDataLen++}else{if(0==this.drawDataLen||0!=this.drawData[this.drawDataLen-1].type||e!=this.drawData[this.drawDataLen-1].texture||this.drawData[this.drawDataLen-1].filter){var a=this.drawData[this.drawDataLen]||{};a.type=0,a.texture=e,a.count=0,this.drawData[this.drawDataLen]=a,this.drawDataLen++}this.drawData[this.drawDataLen-1].count+=t}},e.prototype.pushChangeSmoothing=function(e,t){e.smoothing=t;var r=this.drawData[this.drawDataLen]||{};r.type=10,r.texture=e,r.smoothing=t,this.drawData[this.drawDataLen]=r,this.drawDataLen++},e.prototype.pushPushMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=2,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushPopMask=function(e){void 0===e&&(e=1);var t=this.drawData[this.drawDataLen]||{};t.type=3,t.count=2*e,this.drawData[this.drawDataLen]=t,this.drawDataLen++},e.prototype.pushSetBlend=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];if(n){if((0==n.type||1==n.type)&&(r=!0),!r&&4==n.type){this.drawData.splice(i,1),this.drawDataLen--;continue}if(4==n.type){if(n.value==e)return;break}}}var a=this.drawData[this.drawDataLen]||{};a.type=4,a.value=e,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushResize=function(e,t,r){var i=this.drawData[this.drawDataLen]||{};i.type=5,i.buffer=e,i.width=t,i.height=r,this.drawData[this.drawDataLen]=i,this.drawDataLen++},e.prototype.pushClearColor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=6,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.pushActivateBuffer=function(e){for(var t=this.drawDataLen,r=!1,i=t-1;i>=0;i--){var n=this.drawData[i];!n||(4!=n.type&&7!=n.type&&(r=!0),r||7!=n.type)||(this.drawData.splice(i,1),this.drawDataLen--)}var a=this.drawData[this.drawDataLen]||{};a.type=7,a.buffer=e,a.width=e.rootRenderTarget.width,a.height=e.rootRenderTarget.height,this.drawData[this.drawDataLen]=a,this.drawDataLen++},e.prototype.pushEnableScissor=function(e,t,r,i){var n=this.drawData[this.drawDataLen]||{};n.type=8,n.x=e,n.y=t,n.width=r,n.height=i,this.drawData[this.drawDataLen]=n,this.drawDataLen++},e.prototype.pushDisableScissor=function(){var e=this.drawData[this.drawDataLen]||{};e.type=9,this.drawData[this.drawDataLen]=e,this.drawDataLen++},e.prototype.clear=function(){for(var e=0;er;r+=6,i+=4)this.indices[r+0]=i+0,this.indices[r+1]=i+1,this.indices[r+2]=i+2,this.indices[r+3]=i+0,this.indices[r+4]=i+2,this.indices[r+5]=i+3}return t.prototype.reachMaxSize=function(e,t){return void 0===e&&(e=4),void 0===t&&(t=6),this.vertexIndex>this.maxVertexCount-e||this.indexIndex>this.maxIndicesCount-t},t.prototype.getVertices=function(){var e=this.vertices.subarray(0,this.vertexIndex*this.vertSize);return e},t.prototype.getIndices=function(){return this.indices},t.prototype.getMeshIndices=function(){return this.indicesForMesh},t.prototype.changeToMeshIndices=function(){if(!this.hasMesh){for(var e=0,t=this.indexIndex;t>e;++e)this.indicesForMesh[e]=this.indices[e];this.hasMesh=!0}},t.prototype.isMesh=function(){return this.hasMesh},t.prototype.cacheArrays=function(t,r,i,n,a,o,s,l,c,h,u,d,f,p,v){var g=t.globalAlpha;g=Math.min(g,1);var x=t.globalTintColor||16777215,y=t.currentTexture;g=1>g&&y&&y[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]?e.WebGLUtils.premultiplyTint(x,g):x+(255*g<<24);var m=t.globalMatrix,b=m.a,w=m.b,T=m.c,E=m.d,_=m.tx,C=m.ty,S=t.$offsetX,R=t.$offsetY;if((0!=S||0!=R)&&(_=S*b+R*T+_,C=S*w+R*E+C),!f){(0!=o||0!=s)&&(_=o*b+s*T+_,C=o*w+s*E+C);var L=l/n;1!=L&&(b=L*b,w=L*w);var D=c/a;1!=D&&(T=D*T,E=D*E)}if(f){var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize,M=0,B=0,O=0,P=0,W=0,k=0,G=0;for(M=0,O=d.length;O>M;M+=2)B=$+5*M/2,k=f[M],G=f[M+1],P=d[M],W=d[M+1],A[B+0]=b*k+T*G+_,A[B+1]=w*k+E*G+C,v?(A[B+2]=(r+(1-W)*a)/h,A[B+3]=(i+P*n)/u):(A[B+2]=(r+P*n)/h,A[B+3]=(i+W*a)/u),I[B+4]=g;if(this.hasMesh)for(var H=0,F=p.length;F>H;++H)this.indicesForMesh[this.indexIndex+H]=p[H]+this.vertexIndex;this.vertexIndex+=d.length/2,this.indexIndex+=p.length}else{var U=h,N=u,X=n,z=a;r/=U,i/=N;var A=this.vertices,I=this._verticesUint32View,$=this.vertexIndex*this.vertSize;if(v){var Y=n;n=a/U,a=Y/N,A[$++]=_,A[$++]=C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=i,I[$++]=g}else n/=U,a/=N,A[$++]=_,A[$++]=C,A[$++]=r,A[$++]=i,I[$++]=g,A[$++]=b*X+_,A[$++]=w*X+C,A[$++]=n+r,A[$++]=i,I[$++]=g,A[$++]=b*X+T*z+_,A[$++]=E*z+w*X+C,A[$++]=n+r,A[$++]=a+i,I[$++]=g,A[$++]=T*z+_,A[$++]=E*z+C,A[$++]=r,A[$++]=a+i,I[$++]=g;if(this.hasMesh){var V=this.indicesForMesh;V[this.indexIndex+0]=0+this.vertexIndex,V[this.indexIndex+1]=1+this.vertexIndex,V[this.indexIndex+2]=2+this.vertexIndex,V[this.indexIndex+3]=0+this.vertexIndex,V[this.indexIndex+4]=2+this.vertexIndex,V[this.indexIndex+5]=3+this.vertexIndex}this.vertexIndex+=4,this.indexIndex+=6}},t.prototype.clear=function(){this.hasMesh=!1,this.vertexIndex=0,this.indexIndex=0},t}();t.WebGLVertexArrayObject=r,__reflect(r.prototype,"egret.web.WebGLVertexArrayObject")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function i(e,t,i){var n=r.call(this)||this;return n.clearColor=[0,0,0,0],n.useFrameBuffer=!0,n.gl=e,n._resize(t,i),n}return __extends(i,r),i.prototype._resize=function(e,t){e=e||1,t=t||1,1>e&&(e=1),1>t&&(t=1),this.width=e,this.height=t},i.prototype.resize=function(e,t){this._resize(e,t);var r=this.gl;this.frameBuffer&&(r.bindTexture(r.TEXTURE_2D,this.texture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.width,this.height,0,r.RGBA,r.UNSIGNED_BYTE,null)),this.stencilBuffer&&(r.deleteRenderbuffer(this.stencilBuffer),this.stencilBuffer=null)},i.prototype.activate=function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.getFrameBuffer())},i.prototype.getFrameBuffer=function(){return this.useFrameBuffer?this.frameBuffer:null},i.prototype.initFrameBuffer=function(){if(!this.frameBuffer){var e=this.gl;this.texture=this.createTexture(),this.frameBuffer=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this.texture,0)}},i.prototype.createTexture=function(){var r=t.WebGLRenderContext.getInstance(0,0);return e.sys._createTexture(r,this.width,this.height,null)},i.prototype.clear=function(e){var t=this.gl;e&&this.activate(),t.colorMask(!0,!0,!0,!0),t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(t.COLOR_BUFFER_BIT)},i.prototype.enabledStencil=function(){if(this.frameBuffer&&!this.stencilBuffer){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.frameBuffer),this.stencilBuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,this.width,this.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,this.stencilBuffer)}},i.prototype.dispose=function(){e.WebGLUtils.deleteWebGLTexture(this.texture)},i}(e.HashObject);t.WebGLRenderTarget=r,__reflect(r.prototype,"egret.web.WebGLRenderTarget")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r={},i=function(){function i(r,i){if(this._defaultEmptyTexture=null,this.glID=null,this.projectionX=0/0,this.projectionY=0/0,this.contextLost=!1,this._supportedCompressedTextureInfo=[],this.$scissorState=!1,this.vertSize=5,this.surface=e.sys.mainCanvas(r,i),!e.nativeRender){this.initWebGL(),this.$bufferStack=[];var n=this.context;this.vertexBuffer=n.createBuffer(),this.indexBuffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.vertexBuffer),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this.indexBuffer),this.drawCmdManager=new t.WebGLDrawCmdManager,this.vao=new t.WebGLVertexArrayObject,this.setGlobalCompositeOperation("source-over")}}return i.getInstance=function(e,t){return this.instance?this.instance:(this.instance=new i(e,t),this.instance)},i.prototype.pushBuffer=function(e){this.$bufferStack.push(e),e!=this.currentBuffer&&(this.currentBuffer,this.drawCmdManager.pushActivateBuffer(e)),this.currentBuffer=e},i.prototype.popBuffer=function(){if(!(this.$bufferStack.length<=1)){var e=this.$bufferStack.pop(),t=this.$bufferStack[this.$bufferStack.length-1];e!=t&&this.drawCmdManager.pushActivateBuffer(t),this.currentBuffer=t}},i.prototype.activateBuffer=function(e,t,r){e.rootRenderTarget.activate(),this.bindIndices||this.uploadIndicesArray(this.vao.getIndices()),e.restoreStencil(),e.restoreScissor(),this.onResize(t,r)},i.prototype.uploadVerticesArray=function(e){var t=this.context;t.bufferData(t.ARRAY_BUFFER,e,t.STREAM_DRAW)},i.prototype.uploadIndicesArray=function(e){var t=this.context;t.bufferData(t.ELEMENT_ARRAY_BUFFER,e,t.STATIC_DRAW),this.bindIndices=!0},i.prototype.destroy=function(){this.surface.width=this.surface.height=0},i.prototype.onResize=function(e,t){e=e||this.surface.width,t=t||this.surface.height,this.projectionX=e/2,this.projectionY=-t/2,this.context&&this.context.viewport(0,0,e,t)},i.prototype.resize=function(t,r,i){e.sys.resizeContext(this,t,r,i)},i.prototype._buildSupportedCompressedTextureInfo=function(e){for(var t=[],r=0,i=e;rr;++r)for(var n=e[r],a=n.supportedFormats,o=0,s=a.length;s>o;++o)if(a[o][1]===t)return!0;return!1},i.prototype.$debugLogCompressedTextureNotSupported=function(t,i){if(!r[i]){r[i]=!0,e.log("internalFormat = "+i+":0x"+i.toString(16)+", the current hardware does not support the corresponding compression format.");for(var n=0,a=t.length;a>n;++n){var o=t[n];if(o.supportedFormats.length>0){e.log("support = "+o.extensionName);for(var s=0,l=o.supportedFormats.length;l>s;++s){var c=o.supportedFormats[s];e.log(c[0]+" : "+c[1]+" : 0x"+c[1].toString(16))}}}}},i.prototype.createCompressedTexture=function(t,r,i,n,a){var o=this.checkCompressedTextureInternalFormat(this._supportedCompressedTextureInfo,a);if(!o)return this.$debugLogCompressedTextureNotSupported(this._supportedCompressedTextureInfo,a),this.defaultEmptyTexture;var s=this.context,l=s.createTexture();return l?(l[e.glContext]=s,l[e.is_compressed_texture]=!0,s.bindTexture(s.TEXTURE_2D,l),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),l[e.UNPACK_PREMULTIPLY_ALPHA_WEBGL]=!0,s.compressedTexImage2D(s.TEXTURE_2D,n,a,r,i,0,t),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),s.bindTexture(s.TEXTURE_2D,null),l):void(this.contextLost=!0)},i.prototype.updateTexture=function(e,t){var r=this.context;r.bindTexture(r.TEXTURE_2D,e),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t)},Object.defineProperty(i.prototype,"defaultEmptyTexture",{get:function(){if(!this._defaultEmptyTexture){var t=16,r=e.sys.createCanvas(t,t),i=e.sys.getContext2d(r);i.fillStyle="white",i.fillRect(0,0,t,t),this._defaultEmptyTexture=this.createTexture(r),this._defaultEmptyTexture[e.engine_default_empty_texture]=!0}return this._defaultEmptyTexture},enumerable:!0,configurable:!0}),i.prototype.getWebGLTexture=function(t){if(!t.webGLTexture){if("image"!=t.format||t.hasCompressed2d()){if(t.hasCompressed2d()){var r=t.getCompressed2dTextureData();t.webGLTexture=this.createCompressedTexture(r.byteArray,r.width,r.height,r.level,r.glInternalFormat);var i=t.etcAlphaMask;if(i){var n=this.getWebGLTexture(i);n&&(t.webGLTexture[e.etc_alpha_mask]=n)}}}else t.webGLTexture=this.createTexture(t.source);t.$deleteSource&&t.webGLTexture&&(t.source&&(t.source.src="",t.source=null),t.clearCompressedTextureData()),t.webGLTexture&&(t.webGLTexture.smoothing=!0)}return t.webGLTexture},i.prototype.clearRect=function(e,t,r,i){if(0!=e||0!=t||r!=this.surface.width||i!=this.surface.height){var n=this.currentBuffer;if(n.$hasScissor)this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over");else{var a=n.globalMatrix;0==a.b&&0==a.c?(e=e*a.a+a.tx,t=t*a.d+a.ty,r*=a.a,i*=a.d,this.enableScissor(e,-t-i+n.height,r,i),this.clear(),this.disableScissor()):(this.setGlobalCompositeOperation("destination-out"),this.drawRect(e,t,r,i),this.setGlobalCompositeOperation("source-over"))}}else this.clear()},i.prototype.setGlobalCompositeOperation=function(e){this.drawCmdManager.pushSetBlend(e)},i.prototype.drawImage=function(e,t,r,i,n,a,o,s,l,c,h,u,d){var f=this.currentBuffer;if(!this.contextLost&&e&&f){var p,v,g;if(e.texture||e.source&&e.source.texture)p=e.texture||e.source.texture,f.saveTransform(),v=f.$offsetX,g=f.$offsetY,f.useOffset(),f.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;p=this.getWebGLTexture(e)}p&&(this.drawTexture(p,t,r,i,n,a,o,s,l,c,h,void 0,void 0,void 0,void 0,u,d),e.source&&e.source.texture&&(f.$offsetX=v,f.$offsetY=g,f.restoreTransform()))}},i.prototype.drawMesh=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){var y,m,b;if(e.texture||e.source&&e.source.texture)y=e.texture||e.source.texture,x.saveTransform(),m=x.$offsetX,b=x.$offsetY,x.useOffset(),x.transform(1,0,0,-1,0,l+2*o);else{if(!e.source&&!e.webGLTexture)return;y=this.getWebGLTexture(e)}y&&(this.drawTexture(y,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g),(e.texture||e.source&&e.source.texture)&&(x.$offsetX=m,x.$offsetY=b,x.restoreTransform()))}},i.prototype.drawTexture=function(e,t,r,i,n,a,o,s,l,c,h,u,d,f,p,v,g){var x=this.currentBuffer;if(!this.contextLost&&e&&x){d&&f?this.vao.reachMaxSize(d.length/2,f.length)&&this.$drawWebGL():this.vao.reachMaxSize()&&this.$drawWebGL(),void 0!=g&&e.smoothing!=g&&this.drawCmdManager.pushChangeSmoothing(e,g),u&&this.vao.changeToMeshIndices();var y=f?f.length/3:2;this.drawCmdManager.pushDrawTexture(e,y,this.$filter,c,h),x.currentTexture=e,this.vao.cacheArrays(x,t,r,i,n,a,o,s,l,c,h,u,d,f,v)}},i.prototype.drawRect=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushDrawRect(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.pushMask=function(e,t,r,i){var n=this.currentBuffer;!this.contextLost&&n&&(n.$stencilList.push({x:e,y:t,width:r,height:i}),this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPushMask(),n.currentTexture=null,this.vao.cacheArrays(n,0,0,r,i,e,t,r,i,r,i))},i.prototype.popMask=function(){var e=this.currentBuffer;if(!this.contextLost&&e){var t=e.$stencilList.pop();this.vao.reachMaxSize()&&this.$drawWebGL(),this.drawCmdManager.pushPopMask(),e.currentTexture=null,this.vao.cacheArrays(e,0,0,t.width,t.height,t.x,t.y,t.width,t.height,t.width,t.height)}},i.prototype.clear=function(){this.drawCmdManager.pushClearColor()},i.prototype.enableScissor=function(e,t,r,i){var n=this.currentBuffer;this.drawCmdManager.pushEnableScissor(e,t,r,i),n.$hasScissor=!0},i.prototype.disableScissor=function(){var e=this.currentBuffer;this.drawCmdManager.pushDisableScissor(),e.$hasScissor=!1},i.prototype.$drawWebGL=function(){if(0!=this.drawCmdManager.drawDataLen&&!this.contextLost){this.uploadVerticesArray(this.vao.getVertices()),this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getMeshIndices());for(var e=this.drawCmdManager.drawDataLen,t=0,r=0;e>r;r++){var i=this.drawCmdManager.drawData[r];t=this.drawData(i,t),7==i.type&&(this.activatedBuffer=i.buffer),(0==i.type||1==i.type||2==i.type||3==i.type)&&this.activatedBuffer&&this.activatedBuffer.$computeDrawCall&&this.activatedBuffer.$drawCalls++}this.vao.isMesh()&&this.uploadIndicesArray(this.vao.getIndices()),this.drawCmdManager.clear(),this.vao.clear()}},i.prototype.drawData=function(r,i){if(r){var n,a=this.context,o=r.filter;switch(r.type){case 0:o?"custom"===o.type?n=t.EgretWebGLProgram.getProgram(a,o.$vertexSrc,o.$fragmentSrc,o.$shaderKey):"colorTransform"===o.type?r.texture[e.etc_alpha_mask]?(a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask]),n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag_etc_alphamask_frag,"colorTransform_frag_etc_alphamask_frag")):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.colorTransform_frag,"colorTransform"):"blurX"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"blurY"===o.type?n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.blur_frag,"blur"):"glow"===o.type&&(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.glow_frag,"glow")):r.texture[e.etc_alpha_mask]?(n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_etc_alphamask_frag,e.etc_alpha_mask),a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,r.texture[e.etc_alpha_mask])):n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.texture_frag,"texture"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawTextureElements(r,i);break;case 1:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawRectElements(r,i);break;case 2:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPushMaskElements(r,i);break;case 3:n=t.EgretWebGLProgram.getProgram(a,t.EgretShaderLib.default_vert,t.EgretShaderLib.primitive_frag,"primitive"),this.activeProgram(a,n),this.syncUniforms(n,o,r.textureWidth,r.textureHeight),i+=this.drawPopMaskElements(r,i);break;case 4:this.setBlendMode(r.value);break;case 5:r.buffer.rootRenderTarget.resize(r.width,r.height),this.onResize(r.width,r.height);break;case 6:if(this.activatedBuffer){var s=this.activatedBuffer.rootRenderTarget;(0!=s.width||0!=s.height)&&s.clear(!0)}break;case 7:this.activateBuffer(r.buffer,r.width,r.height);break;case 8:var l=this.activatedBuffer;l&&(l.rootRenderTarget&&l.rootRenderTarget.enabledStencil(),l.enableScissor(r.x,r.y,r.width,r.height));break;case 9:l=this.activatedBuffer,l&&l.disableScissor();break;case 10:a.bindTexture(a.TEXTURE_2D,r.texture),r.smoothing?(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR)):(a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.NEAREST),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.NEAREST))}return i}},i.prototype.activeProgram=function(e,t){if(t!=this.currentProgram){e.useProgram(t.id);var r=t.attributes;for(var i in r)"aVertexPosition"===i?(e.vertexAttribPointer(r.aVertexPosition.location,2,e.FLOAT,!1,20,0),e.enableVertexAttribArray(r.aVertexPosition.location)):"aTextureCoord"===i?(e.vertexAttribPointer(r.aTextureCoord.location,2,e.FLOAT,!1,20,8),e.enableVertexAttribArray(r.aTextureCoord.location)):"aColor"===i&&(e.vertexAttribPointer(r.aColor.location,4,e.UNSIGNED_BYTE,!0,20,16),e.enableVertexAttribArray(r.aColor.location));this.currentProgram=t}},i.prototype.syncUniforms=function(e,t,r,i){var n=e.uniforms;t&&"custom"===t.type;for(var a in n)if("projectionVector"===a)n[a].setValue({x:this.projectionX,y:this.projectionY});else if("uTextureSize"===a)n[a].setValue({x:r,y:i});else if("uSampler"===a)n[a].setValue(0);else if("uSamplerAlphaMask"===a)n[a].setValue(1);else{var o=t.$uniforms[a];void 0!==o&&n[a].setValue(o)}},i.prototype.drawTextureElements=function(t,r){return e.sys.drawTextureElements(this,t,r)},i.prototype.drawRectElements=function(e,t){var r=this.context,i=3*e.count;return r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),i},i.prototype.drawPushMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n){n.rootRenderTarget&&n.rootRenderTarget.enabledStencil(),0==n.stencilHandleCount&&(n.enableStencil(),r.clear(r.STENCIL_BUFFER_BIT));var a=n.stencilHandleCount;n.stencilHandleCount++,r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a,255),r.stencilOp(r.KEEP,r.KEEP,r.INCR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a+1,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.drawPopMaskElements=function(e,t){var r=this.context,i=3*e.count,n=this.activatedBuffer;if(n)if(n.stencilHandleCount--,0==n.stencilHandleCount)n.disableStencil();else{var a=n.stencilHandleCount;r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.EQUAL,a+1,255),r.stencilOp(r.KEEP,r.KEEP,r.DECR),r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,2*t),r.stencilFunc(r.EQUAL,a,255),r.colorMask(!0,!0,!0,!0),r.stencilOp(r.KEEP,r.KEEP,r.KEEP)}return i},i.prototype.setBlendMode=function(e){var t=this.context,r=i.blendModesForGL[e];r&&t.blendFunc(r[0],r[1])},i.prototype.drawTargetWidthFilters=function(e,r){var i,n=r,a=e.length;if(a>1)for(var o=0;a-1>o;o++){var s=e[o],l=r.rootRenderTarget.width,c=r.rootRenderTarget.height;i=t.WebGLRenderBuffer.create(l,c),i.setTransform(1,0,0,1,0,0),i.globalAlpha=1,this.drawToRenderTarget(s,r,i),r!=n&&t.WebGLRenderBuffer.release(r),r=i}var h=e[a-1];this.drawToRenderTarget(h,r,this.currentBuffer),r!=n&&t.WebGLRenderBuffer.release(r)},i.prototype.drawToRenderTarget=function(e,r,i){if(!this.contextLost){this.vao.reachMaxSize()&&this.$drawWebGL(),this.pushBuffer(i);var n,a=r,o=r.rootRenderTarget.width,s=r.rootRenderTarget.height;if("blur"==e.type){var l=e.blurXFilter,c=e.blurYFilter;0!=l.blurX&&0!=c.blurY?(n=t.WebGLRenderBuffer.create(o,s),n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,this.drawToRenderTarget(e.blurXFilter,r,n),r!=a&&t.WebGLRenderBuffer.release(r),r=n,e=c):e=0===l.blurX?c:l}i.saveTransform(),i.transform(1,0,0,-1,0,s),i.currentTexture=r.rootRenderTarget.texture,this.vao.cacheArrays(i,0,0,o,s,0,0,o,s,o,s),i.restoreTransform(),this.drawCmdManager.pushDrawTexture(r.rootRenderTarget.texture,2,e,o,s),r!=a&&t.WebGLRenderBuffer.release(r),this.popBuffer()}},i.initBlendMode=function(){i.blendModesForGL={},i.blendModesForGL["source-over"]=[1,771],i.blendModesForGL.lighter=[1,1],i.blendModesForGL["lighter-in"]=[770,771],i.blendModesForGL["destination-out"]=[0,771],i.blendModesForGL["destination-in"]=[0,770]},i.glContextId=0,i.blendModesForGL=null,i}();t.WebGLRenderContext=i,__reflect(i.prototype,"egret.web.WebGLRenderContext",["egret.sys.RenderContext"]),i.initBlendMode()}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(r){function n(i,n,a){var o=r.call(this)||this;if(o.currentTexture=null,o.globalAlpha=1,o.globalTintColor=16777215,o.stencilState=!1,o.$stencilList=[],o.stencilHandleCount=0,o.$scissorState=!1,o.scissorRect=new e.Rectangle,o.$hasScissor=!1,o.$drawCalls=0,o.$computeDrawCall=!1,o.globalMatrix=new e.Matrix,o.savedGlobalMatrix=new e.Matrix,o.$offsetX=0,o.$offsetY=0,o.context=t.WebGLRenderContext.getInstance(i,n),e.nativeRender)return a?o.surface=o.context.surface:o.surface=new egret_native.NativeRenderSurface(o,i,n,a),o.rootRenderTarget=null,o;if(o.rootRenderTarget=new t.WebGLRenderTarget(o.context.context,3,3),i&&n&&o.resize(i,n),o.root=a,o.root)o.context.pushBuffer(o),o.surface=o.context.surface,o.$computeDrawCall=!0;else{var s=o.context.activatedBuffer;s&&s.rootRenderTarget.activate(),o.rootRenderTarget.initFrameBuffer(),o.surface=o.rootRenderTarget}return o}return __extends(n,r),n.prototype.enableStencil=function(){this.stencilState||(this.context.enableStencilTest(),this.stencilState=!0)},n.prototype.disableStencil=function(){this.stencilState&&(this.context.disableStencilTest(),this.stencilState=!1)},n.prototype.restoreStencil=function(){this.stencilState?this.context.enableStencilTest():this.context.disableStencilTest()},n.prototype.enableScissor=function(e,t,r,i){this.$scissorState||(this.$scissorState=!0,this.scissorRect.setTo(e,t,r,i),this.context.enableScissorTest(this.scissorRect))},n.prototype.disableScissor=function(){this.$scissorState&&(this.$scissorState=!1,this.scissorRect.setEmpty(),this.context.disableScissorTest())},n.prototype.restoreScissor=function(){this.$scissorState?this.context.enableScissorTest(this.scissorRect):this.context.disableScissorTest()},Object.defineProperty(n.prototype,"width",{get:function(){return e.nativeRender?this.surface.width:this.rootRenderTarget.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return e.nativeRender?this.surface.height:this.rootRenderTarget.height},enumerable:!0,configurable:!0}),n.prototype.resize=function(t,r,i){return t=t||1,r=r||1,e.nativeRender?void this.surface.resize(t,r):(this.context.pushBuffer(this),(t!=this.rootRenderTarget.width||r!=this.rootRenderTarget.height)&&(this.context.drawCmdManager.pushResize(this,t,r),this.rootRenderTarget.width=t,this.rootRenderTarget.height=r),this.root&&this.context.resize(t,r,i),this.context.clear(),void this.context.popBuffer())},n.prototype.getPixels=function(t,r,i,n){void 0===i&&(i=1),void 0===n&&(n=1);var a=new Uint8Array(4*i*n);if(e.nativeRender)egret_native.activateBuffer(this),egret_native.nrGetPixels(t,r,i,n,a),egret_native.activateBuffer(null);else{var o=this.rootRenderTarget.useFrameBuffer;this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.getPixels(t,r,i,n,a),this.rootRenderTarget.useFrameBuffer=o,this.rootRenderTarget.activate()}for(var s=new Uint8Array(4*i*n),l=0;n>l;l++)for(var c=0;i>c;c++){var h=4*(i*(n-l-1)+c),u=4*(i*l+c),d=a[u+3];s[h]=Math.round(a[u]/d*255),s[h+1]=Math.round(a[u+1]/d*255),s[h+2]=Math.round(a[u+2]/d*255),s[h+3]=a[u+3]}return s},n.prototype.toDataURL=function(e,t){return this.context.surface.toDataURL(e,t)},n.prototype.destroy=function(){this.context.destroy()},n.prototype.onRenderFinish=function(){this.$drawCalls=0},n.prototype.drawFrameBufferToSurface=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.rootRenderTarget,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.drawSurfaceToFrameBuffer=function(e,t,r,i,n,a,o,s,l){void 0===l&&(l=!1),this.rootRenderTarget.useFrameBuffer=!0,this.rootRenderTarget.activate(),this.context.disableStencilTest(),this.context.disableScissorTest(),this.setTransform(1,0,0,1,0,0),this.globalAlpha=1,this.context.setGlobalCompositeOperation("source-over"),l&&this.context.clear(),this.context.drawImage(this.context.surface,e,t,r,i,n,a,o,s,r,i,!1),this.context.$drawWebGL(),this.rootRenderTarget.useFrameBuffer=!1,this.rootRenderTarget.activate(),this.restoreStencil(),this.restoreScissor()},n.prototype.clear=function(){this.context.pushBuffer(this),this.context.clear(),this.context.popBuffer()},n.prototype.setTransform=function(e,t,r,i,n,a){var o=this.globalMatrix;o.a=e,o.b=t,o.c=r,o.d=i,o.tx=n,o.ty=a},n.prototype.transform=function(e,t,r,i,n,a){var o=this.globalMatrix,s=o.a,l=o.b,c=o.c,h=o.d;(1!=e||0!=t||0!=r||1!=i)&&(o.a=e*s+t*c,o.b=e*l+t*h,o.c=r*s+i*c,o.d=r*l+i*h),o.tx=n*s+a*c+o.tx,o.ty=n*l+a*h+o.ty},n.prototype.useOffset=function(){var e=this;(0!=e.$offsetX||0!=e.$offsetY)&&(e.globalMatrix.append(1,0,0,1,e.$offsetX,e.$offsetY),e.$offsetX=e.$offsetY=0)},n.prototype.saveTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t.tx=e.tx,t.ty=e.ty},n.prototype.restoreTransform=function(){var e=this.globalMatrix,t=this.savedGlobalMatrix;e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e.tx=t.tx,e.ty=t.ty},n.create=function(e,t){var r=i.pop(); if(r){r.resize(e,t);var a=r.globalMatrix;a.a=1,a.b=0,a.c=0,a.d=1,a.tx=0,a.ty=0,r.globalAlpha=1,r.$offsetX=0,r.$offsetY=0}else r=new n(e,t),r.$computeDrawCall=!1;return r},n.release=function(e){i.push(e)},n.autoClear=!0,n}(e.HashObject);t.WebGLRenderBuffer=r,__reflect(r.prototype,"egret.web.WebGLRenderBuffer",["egret.sys.RenderBuffer"]);var i=[]}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=["source-over","lighter","destination-out"],i="source-over",n=[],a=function(){function a(){this.wxiOS10=!1,this.nestLevel=0}return a.prototype.render=function(t,r,i,a){this.nestLevel++;var o=r,s=o.context;s.pushBuffer(o),o.transform(i.a,i.b,i.c,i.d,0,0),this.drawDisplayObject(t,o,i.tx,i.ty,!0),s.$drawWebGL();var l=o.$drawCalls;o.onRenderFinish(),s.popBuffer();var c=e.Matrix.create();if(i.$invertInto(c),o.transform(c.a,c.b,c.c,c.d,0,0),e.Matrix.release(c),this.nestLevel--,0===this.nestLevel){n.length>6&&(n.length=6);for(var h=n.length,u=0;h>u;u++)n[u].resize(0,0)}return l},a.prototype.drawDisplayObject=function(t,r,i,n,a){var o,s=0,l=t.$displayList;if(l&&!a?((t.$cacheDirty||t.$renderDirty||l.$canvasScaleX!=e.sys.DisplayList.$canvasScaleX||l.$canvasScaleY!=e.sys.DisplayList.$canvasScaleY)&&(s+=l.drawToSurface()),o=l.$renderNode):o=t.$renderDirty?t.$getRenderNode():t.$renderNode,t.$cacheDirty=!1,o){switch(s++,r.$offsetX=i,r.$offsetY=n,o.type){case 1:this.renderBitmap(o,r);break;case 2:this.renderText(o,r);break;case 3:this.renderGraphics(o,r);break;case 4:this.renderGroup(o,r);break;case 5:this.renderMesh(o,r);break;case 6:this.renderNormalBitmap(o,r)}r.$offsetX=0,r.$offsetY=0}if(l&&!a)return s;var c=t.$children;if(c){t.sortableChildren&&t.$sortDirty&&t.sortChildren();for(var h=c.length,u=0;h>u;u++){var d=c[u],f=void 0,p=void 0,v=void 0,g=void 0;1!=d.$alpha&&(v=r.globalAlpha,r.globalAlpha*=d.$alpha),16777215!==d.tint&&(g=r.globalTintColor,r.globalTintColor=d.$tintRGB);var x=void 0;if(d.$useTranslate){var y=d.$getMatrix();f=i+d.$x,p=n+d.$y;var m=r.globalMatrix;x=e.Matrix.create(),x.a=m.a,x.b=m.b,x.c=m.c,x.d=m.d,x.tx=m.tx,x.ty=m.ty,r.transform(y.a,y.b,y.c,y.d,f,p),f=-d.$anchorOffsetX,p=-d.$anchorOffsetY}else f=i+d.$x-d.$anchorOffsetX,p=n+d.$y-d.$anchorOffsetY;switch(d.$renderMode){case 1:break;case 2:s+=this.drawWithFilter(d,r,f,p);break;case 3:s+=this.drawWithClip(d,r,f,p);break;case 4:s+=this.drawWithScrollRect(d,r,f,p);break;default:s+=this.drawDisplayObject(d,r,f,p)}if(v&&(r.globalAlpha=v),g&&(r.globalTintColor=g),x){var y=r.globalMatrix;y.a=x.a,y.b=x.b,y.c=x.c,y.d=x.d,y.tx=x.tx,y.ty=x.ty,e.Matrix.release(x)}}}return s},a.prototype.drawWithFilter=function(t,a,o,s){var l=0;if(t.$children&&0==t.$children.length&&(!t.$renderNode||0==t.$renderNode.$getRenderCount()))return l;var c,h=t.$filters,u=0!==t.$blendMode;u&&(c=r[t.$blendMode],c||(c=i));var d=t.$getOriginalBounds(),f=d.x,p=d.y,v=d.width,g=d.height;if(0>=v||0>=g)return l;if(!t.mask&&1==h.length&&("colorTransform"==h[0].type||"custom"===h[0].type&&0===h[0].padding)){var x=this.getRenderCount(t);if(!t.$children||1==x)return u&&a.context.setGlobalCompositeOperation(c),a.context.$filter=h[0],l+=t.$mask?this.drawWithClip(t,a,o,s):t.$scrollRect||t.$maskRect?this.drawWithScrollRect(t,a,o,s):this.drawDisplayObject(t,a,o,s),a.context.$filter=null,u&&a.context.setGlobalCompositeOperation(i),l}var y=this.createRenderBuffer(v,g);if(y.context.pushBuffer(y),l+=t.$mask?this.drawWithClip(t,y,-f,-p):t.$scrollRect||t.$maskRect?this.drawWithScrollRect(t,y,-f,-p):this.drawDisplayObject(t,y,-f,-p),y.context.popBuffer(),l>0){u&&a.context.setGlobalCompositeOperation(c),l++,a.$offsetX=o+f,a.$offsetY=s+p;var m=e.Matrix.create(),b=a.globalMatrix;m.a=b.a,m.b=b.b,m.c=b.c,m.d=b.d,m.tx=b.tx,m.ty=b.ty,a.useOffset(),a.context.drawTargetWidthFilters(h,y),b.a=m.a,b.b=m.b,b.c=m.c,b.d=m.d,b.tx=m.tx,b.ty=m.ty,e.Matrix.release(m),u&&a.context.setGlobalCompositeOperation(i)}return n.push(y),l},a.prototype.getRenderCount=function(e){var t=0,r=e.$getRenderNode();if(r&&(t+=r.$getRenderCount()),e.$children)for(var i=0,n=e.$children;i0)return 2;if(a.$children)t+=this.getRenderCount(a);else{var s=a.$getRenderNode();s&&(t+=s.$getRenderCount())}}return t},a.prototype.drawWithClip=function(t,a,o,s){var l,c=0,h=0!==t.$blendMode;h&&(l=r[t.$blendMode],l||(l=i));var u=t.$scrollRect?t.$scrollRect:t.$maskRect,d=t.$mask;if(d){var f=d.$getMatrix();if(0==f.a&&0==f.b||0==f.c&&0==f.d)return c}if(d||t.$children&&0!=t.$children.length){var p=t.$getOriginalBounds(),v=p.x,g=p.y,x=p.width,y=p.height;if(0>=x||0>=y)return c;var m=this.createRenderBuffer(x,y);if(m.context.pushBuffer(m),c+=this.drawDisplayObject(t,m,-v,-g),d){var b=this.createRenderBuffer(x,y);b.context.pushBuffer(b);var w=e.Matrix.create();w.copyFrom(d.$getConcatenatedMatrix()),d.$getConcatenatedMatrixAt(t,w),w.translate(-v,-g),b.setTransform(w.a,w.b,w.c,w.d,w.tx,w.ty),e.Matrix.release(w),c+=this.drawDisplayObject(d,b,0,0),b.context.popBuffer(),m.context.setGlobalCompositeOperation("destination-in"),m.setTransform(1,0,0,-1,0,b.height);var T=b.rootRenderTarget.width,E=b.rootRenderTarget.height;m.context.drawTexture(b.rootRenderTarget.texture,0,0,T,E,0,0,T,E,T,E),m.setTransform(1,0,0,1,0,0),m.context.setGlobalCompositeOperation("source-over"),b.setTransform(1,0,0,1,0,0),n.push(b)}if(m.context.setGlobalCompositeOperation(i),m.context.popBuffer(),c>0){c++,h&&a.context.setGlobalCompositeOperation(l),u&&a.context.pushMask(u.x+o,u.y+s,u.width,u.height);var _=e.Matrix.create(),C=a.globalMatrix;_.a=C.a,_.b=C.b,_.c=C.c,_.d=C.d,_.tx=C.tx,_.ty=C.ty,C.append(1,0,0,-1,o+v,s+g+m.height);var S=m.rootRenderTarget.width,R=m.rootRenderTarget.height;a.context.drawTexture(m.rootRenderTarget.texture,0,0,S,R,0,0,S,R,S,R),u&&m.context.popMask(),h&&a.context.setGlobalCompositeOperation(i);var L=a.globalMatrix;L.a=_.a,L.b=_.b,L.c=_.c,L.d=_.d,L.tx=_.tx,L.ty=_.ty,e.Matrix.release(_)}return n.push(m),c}return u&&a.context.pushMask(u.x+o,u.y+s,u.width,u.height),h&&a.context.setGlobalCompositeOperation(l),c+=this.drawDisplayObject(t,a,o,s),h&&a.context.setGlobalCompositeOperation(i),u&&a.context.popMask(),c},a.prototype.drawWithScrollRect=function(e,t,r,i){var n=0,a=e.$scrollRect?e.$scrollRect:e.$maskRect;if(a.isEmpty())return n;e.$scrollRect&&(r-=a.x,i-=a.y);var o=t.globalMatrix,s=t.context,l=!1;if(t.$hasScissor||0!=o.b||0!=o.c)t.context.pushMask(a.x+r,a.y+i,a.width,a.height);else{var c=o.a,h=o.d,u=o.tx,d=o.ty,f=a.x+r,p=a.y+i,v=f+a.width,g=p+a.height,x=void 0,y=void 0,m=void 0,b=void 0;if(1==c&&1==h)x=f+u,y=p+d,m=v+u,b=g+d;else{var w=c*f+u,T=h*p+d,E=c*v+u,_=h*p+d,C=c*v+u,S=h*g+d,R=c*f+u,L=h*g+d,D=0;w>E&&(D=w,w=E,E=D),C>R&&(D=C,C=R,R=D),x=C>w?w:C,m=E>R?E:R,T>_&&(D=T,T=_,_=D),S>L&&(D=S,S=L,L=D),y=S>T?T:S,b=_>L?_:L}s.enableScissor(x,-b+t.height,m-x,b-y),l=!0}return n+=this.drawDisplayObject(e,t,r,i),l?s.disableScissor():s.popMask(),n},a.prototype.drawNodeToBuffer=function(e,t,r,i){var n=t;n.context.pushBuffer(n),n.setTransform(r.a,r.b,r.c,r.d,r.tx,r.ty),this.renderNode(e,t,0,0,i),n.context.$drawWebGL(),n.onRenderFinish(),n.context.popBuffer()},a.prototype.drawDisplayToBuffer=function(e,t,r){t.context.pushBuffer(t),r&&t.setTransform(r.a,r.b,r.c,r.d,r.tx,r.ty);var i;i=e.$renderDirty?e.$getRenderNode():e.$renderNode;var n=0;if(i)switch(n++,i.type){case 1:this.renderBitmap(i,t);break;case 2:this.renderText(i,t);break;case 3:this.renderGraphics(i,t);break;case 4:this.renderGroup(i,t);break;case 5:this.renderMesh(i,t);break;case 6:this.renderNormalBitmap(i,t)}var a=e.$children;if(a)for(var o=a.length,s=0;o>s;s++){var l=a[s];switch(l.$renderMode){case 1:break;case 2:n+=this.drawWithFilter(l,t,0,0);break;case 3:n+=this.drawWithClip(l,t,0,0);break;case 4:n+=this.drawWithScrollRect(l,t,0,0);break;default:n+=this.drawDisplayObject(l,t,0,0)}}return t.context.$drawWebGL(),t.onRenderFinish(),t.context.popBuffer(),n},a.prototype.renderNode=function(e,t,r,i,n){switch(t.$offsetX=r,t.$offsetY=i,e.type){case 1:this.renderBitmap(e,t);break;case 2:this.renderText(e,t);break;case 3:this.renderGraphics(e,t,n);break;case 4:this.renderGroup(e,t);break;case 5:this.renderMesh(e,t);break;case 6:this.renderNormalBitmap(e,t)}},a.prototype.renderNormalBitmap=function(e,t){var r=e.image;r&&t.context.drawImage(r,e.sourceX,e.sourceY,e.sourceW,e.sourceH,e.drawX,e.drawY,e.drawW,e.drawH,e.imageWidth,e.imageHeight,e.rotated,e.smoothing)},a.prototype.renderBitmap=function(t,n){var a=t.image;if(a){var o,s,l,c=t.drawData,h=c.length,u=0,d=t.matrix,f=t.blendMode,p=t.alpha;if(d){o=e.Matrix.create();var v=n.globalMatrix;o.a=v.a,o.b=v.b,o.c=v.c,o.d=v.d,o.tx=v.tx,o.ty=v.ty,s=n.$offsetX,l=n.$offsetY,n.useOffset(),n.transform(d.a,d.b,d.c,d.d,d.tx,d.ty)}f&&n.context.setGlobalCompositeOperation(r[f]);var g;if(p==p&&(g=n.globalAlpha,n.globalAlpha*=p),t.filter){for(n.context.$filter=t.filter;h>u;)n.context.drawImage(a,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.rotated,t.smoothing);n.context.$filter=null}else for(;h>u;)n.context.drawImage(a,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.rotated,t.smoothing);if(f&&n.context.setGlobalCompositeOperation(i),p==p&&(n.globalAlpha=g),d){var x=n.globalMatrix;x.a=o.a,x.b=o.b,x.c=o.c,x.d=o.d,x.tx=o.tx,x.ty=o.ty,n.$offsetX=s,n.$offsetY=l,e.Matrix.release(o)}}},a.prototype.renderMesh=function(t,n){var a,o,s,l=t.image,c=t.drawData,h=c.length,u=0,d=t.matrix,f=t.blendMode,p=t.alpha;if(d){a=e.Matrix.create();var v=n.globalMatrix;a.a=v.a,a.b=v.b,a.c=v.c,a.d=v.d,a.tx=v.tx,a.ty=v.ty,o=n.$offsetX,s=n.$offsetY,n.useOffset(),n.transform(d.a,d.b,d.c,d.d,d.tx,d.ty)}f&&n.context.setGlobalCompositeOperation(r[f]);var g;if(p==p&&(g=n.globalAlpha,n.globalAlpha*=p),t.filter){for(n.context.$filter=t.filter;h>u;)n.context.drawMesh(l,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.uvs,t.vertices,t.indices,t.bounds,t.rotated,t.smoothing);n.context.$filter=null}else for(;h>u;)n.context.drawMesh(l,c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],c[u++],t.imageWidth,t.imageHeight,t.uvs,t.vertices,t.indices,t.bounds,t.rotated,t.smoothing);if(f&&n.context.setGlobalCompositeOperation(i),p==p&&(n.globalAlpha=g),d){var x=n.globalMatrix;x.a=a.a,x.b=a.b,x.c=a.c,x.d=a.d,x.tx=a.tx,x.ty=a.ty,n.$offsetX=o,n.$offsetY=s,e.Matrix.release(a)}},a.prototype.___renderText____=function(r,i){var n=r.width-r.x,a=r.height-r.y;if(!(0>=n||0>=a)&&n&&a&&0!==r.drawData.length){var o=e.sys.DisplayList.$canvasScaleX,s=e.sys.DisplayList.$canvasScaleY,l=i.context.$maxTextureSize;n*o>l&&(o*=l/(n*o)),a*s>l&&(s*=l/(a*s)),n*=o,a*=s;var c=r.x*o,h=r.y*s;(r.$canvasScaleX!==o||r.$canvasScaleY!==s)&&(r.$canvasScaleX=o,r.$canvasScaleY=s,r.dirtyRender=!0),(c||h)&&i.transform(1,0,0,1,c/o,h/s),r.dirtyRender&&t.TextAtlasRender.analysisTextNodeAndFlushDrawLabel(r);var u=r[t.property_drawLabel];if(u&&u.length>0){for(var d=i.$offsetX,f=i.$offsetY,p=null,v=0,g=0,x=null,y=null,m=null,b=0,w=u.length;w>b;++b){p=u[b],v=p.anchorX,g=p.anchorY,x=p.textBlocks,i.$offsetX=d+v;for(var T=0,E=x.length;E>T;++T)y=x[T],T>0&&(i.$offsetX-=y.canvasWidthOffset),i.$offsetY=f+g-(y.measureHeight+(y.stroke2?y.canvasHeightOffset:0))/2,m=y.line.page,i.context.drawTexture(m.webGLTexture,y.u,y.v,y.contentWidth,y.contentHeight,0,0,y.contentWidth,y.contentHeight,m.pageWidth,m.pageHeight),i.$offsetX+=y.contentWidth-y.canvasWidthOffset}i.$offsetX=d,i.$offsetY=f}(c||h)&&i.transform(1,0,0,1,-c/o,-h/s),r.dirtyRender=!1}},a.prototype.renderText=function(r,i){if(t.textAtlasRenderEnable)return void this.___renderText____(r,i);var n=r.width-r.x,a=r.height-r.y;if(!(0>=n||0>=a)&&n&&a&&0!=r.drawData.length){var o=e.sys.DisplayList.$canvasScaleX,s=e.sys.DisplayList.$canvasScaleY,l=i.context.$maxTextureSize;n*o>l&&(o*=l/(n*o)),a*s>l&&(s*=l/(a*s)),n*=o,a*=s;var c=r.x*o,h=r.y*s;if((r.$canvasScaleX!=o||r.$canvasScaleY!=s)&&(r.$canvasScaleX=o,r.$canvasScaleY=s,r.dirtyRender=!0),this.wxiOS10?(this.canvasRenderer||(this.canvasRenderer=new e.CanvasRenderer),r.dirtyRender&&(this.canvasRenderBuffer=new t.CanvasRenderBuffer(n,a))):this.canvasRenderBuffer&&this.canvasRenderBuffer.context?r.dirtyRender&&this.canvasRenderBuffer.resize(n,a):(this.canvasRenderer=new e.CanvasRenderer,this.canvasRenderBuffer=new t.CanvasRenderBuffer(n,a)),this.canvasRenderBuffer.context){if((1!=o||1!=s)&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,0,0),c||h?(r.dirtyRender&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,-c,-h),i.transform(1,0,0,1,c/o,h/s)):(1!=o||1!=s)&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,0,0),r.dirtyRender){var u=this.canvasRenderBuffer.surface;if(this.canvasRenderer.renderText(r,this.canvasRenderBuffer.context),this.wxiOS10)u.isCanvas=!0,r.$texture=u;else{var d=r.$texture;d?i.context.updateTexture(d,u):(d=i.context.createTexture(u),r.$texture=d)}r.$textureWidth=u.width,r.$textureHeight=u.height}var f=r.$textureWidth,p=r.$textureHeight;i.context.drawTexture(r.$texture,0,0,f,p,0,0,f/o,p/s,f,p),(c||h)&&(r.dirtyRender&&this.canvasRenderBuffer.context.setTransform(o,0,0,s,0,0),i.transform(1,0,0,1,-c/o,-h/s)),r.dirtyRender=!1}}},a.prototype.renderGraphics=function(r,i,n){var a=r.width,o=r.height;if(!(0>=a||0>=o)&&a&&o&&0!=r.drawData.length){var s=e.sys.DisplayList.$canvasScaleX,l=e.sys.DisplayList.$canvasScaleY;(1>a*s||1>o*l)&&(s=l=1),(r.$canvasScaleX!=s||r.$canvasScaleY!=l)&&(r.$canvasScaleX=s,r.$canvasScaleY=l,r.dirtyRender=!0),a*=s,o*=l;var c=Math.ceil(a),h=Math.ceil(o);if(s*=c/a,l*=h/o,a=c,o=h,this.wxiOS10?(this.canvasRenderer||(this.canvasRenderer=new e.CanvasRenderer),r.dirtyRender&&(this.canvasRenderBuffer=new t.CanvasRenderBuffer(a,o))):this.canvasRenderBuffer&&this.canvasRenderBuffer.context?r.dirtyRender&&this.canvasRenderBuffer.resize(a,o):(this.canvasRenderer=new e.CanvasRenderer,this.canvasRenderBuffer=new t.CanvasRenderBuffer(a,o)),this.canvasRenderBuffer.context){(1!=s||1!=l)&&this.canvasRenderBuffer.context.setTransform(s,0,0,l,0,0),(r.x||r.y)&&((r.dirtyRender||n)&&this.canvasRenderBuffer.context.translate(-r.x,-r.y),i.transform(1,0,0,1,r.x,r.y));var u=this.canvasRenderBuffer.surface;if(n){this.canvasRenderer.renderGraphics(r,this.canvasRenderBuffer.context,!0);var d=void 0;this.wxiOS10?(u.isCanvas=!0,d=u):(e.WebGLUtils.deleteWebGLTexture(u),d=i.context.getWebGLTexture(u)),i.context.drawTexture(d,0,0,a,o,0,0,a,o,u.width,u.height)}else{if(r.dirtyRender){if(this.canvasRenderer.renderGraphics(r,this.canvasRenderBuffer.context),this.wxiOS10)u.isCanvas=!0,r.$texture=u;else{var d=r.$texture;d?i.context.updateTexture(d,u):(d=i.context.createTexture(u),r.$texture=d)}r.$textureWidth=u.width,r.$textureHeight=u.height}var f=r.$textureWidth,p=r.$textureHeight;i.context.drawTexture(r.$texture,0,0,f,p,0,0,f/s,p/l,f,p)}(r.x||r.y)&&((r.dirtyRender||n)&&this.canvasRenderBuffer.context.translate(r.x,r.y),i.transform(1,0,0,1,-r.x,-r.y)),n||(r.dirtyRender=!1)}}},a.prototype.renderGroup=function(t,r){var i,n,a,o=t.matrix;if(o){i=e.Matrix.create();var s=r.globalMatrix;i.a=s.a,i.b=s.b,i.c=s.c,i.d=s.d,i.tx=s.tx,i.ty=s.ty,n=r.$offsetX,a=r.$offsetY,r.useOffset(),r.transform(o.a,o.b,o.c,o.d,o.tx,o.ty)}for(var l=t.drawData,c=l.length,h=0;c>h;h++){var u=l[h];this.renderNode(u,r,r.$offsetX,r.$offsetY)}if(o){var d=r.globalMatrix;d.a=i.a,d.b=i.b,d.c=i.c,d.d=i.d,d.tx=i.tx,d.ty=i.ty,r.$offsetX=n,r.$offsetY=a,e.Matrix.release(i)}},a.prototype.createRenderBuffer=function(e,r){var i=n.pop();return i?i.resize(e,r):(i=new t.WebGLRenderBuffer(e,r),i.$computeDrawCall=!1),i},a}();t.WebGLRenderer=a,__reflect(a.prototype,"egret.web.WebGLRenderer",["egret.sys.SystemRenderer"])}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(t){var r=function(e){function t(t,r,i,n,a,o,s,l){var c=e.call(this)||this;return c._width=0,c._height=0,c._border=0,c.line=null,c.x=0,c.y=0,c.u=0,c.v=0,c.tag="",c.measureWidth=0,c.measureHeight=0,c.canvasWidthOffset=0,c.canvasHeightOffset=0,c.stroke2=0,c._width=t,c._height=r,c._border=l,c.measureWidth=i,c.measureHeight=n,c.canvasWidthOffset=a,c.canvasHeightOffset=o,c.stroke2=s,c}return __extends(t,e),Object.defineProperty(t.prototype,"border",{get:function(){return this._border},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width+2*this.border},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height+2*this.border},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contentWidth",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"contentHeight",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"page",{get:function(){return this.line?this.line.page:null},enumerable:!0,configurable:!0}),t.prototype.updateUV=function(){var e=this.line;return e?(this.u=e.x+this.x+1*this.border,this.v=e.y+this.y+1*this.border,!0):!1},Object.defineProperty(t.prototype,"subImageOffsetX",{get:function(){var e=this.line;return e?e.x+this.x+this.border:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"subImageOffsetY",{get:function(){var e=this.line;return e?e.y+this.y+this.border:0},enumerable:!0,configurable:!0}),t}(e.HashObject);t.TextBlock=r,__reflect(r.prototype,"egret.web.TextBlock");var i=function(e){function t(t){var r=e.call(this)||this;return r.page=null,r.textBlocks=[],r.dynamicMaxHeight=0,r.maxWidth=0,r.x=0,r.y=0,r.maxWidth=t,r}return __extends(t,e),t.prototype.isCapacityOf=function(e){if(!e)return!1;var t=0,r=0,i=this.lastTextBlock();return i&&(t=i.x+i.width,r=i.y),t+e.width>this.maxWidth?!1:this.dynamicMaxHeight>0&&(e.height>this.dynamicMaxHeight||e.height/this.dynamicMaxHeight<.5)?!1:!0},t.prototype.lastTextBlock=function(){var e=this.textBlocks;return e.length>0?e[e.length-1]:null},t.prototype.addTextBlock=function(e,t){if(!e)return!1;if(t&&!this.isCapacityOf(e))return!1;var r=0,i=0,n=this.lastTextBlock();return n&&(r=n.x+n.width,i=n.y),e.x=r,e.y=i,e.line=this,this.textBlocks.push(e),this.dynamicMaxHeight=Math.max(this.dynamicMaxHeight,e.height),!0},t}(e.HashObject);t.Line=i,__reflect(i.prototype,"egret.web.Line");var n=function(e){function t(t,r){var i=e.call(this)||this;return i.lines=[],i.pageWidth=0,i.pageHeight=0,i.webGLTexture=null,i.pageWidth=t,i.pageHeight=r,i}return __extends(t,e),t.prototype.addLine=function(e){if(!e)return!1;var t=0,r=0,i=this.lines;if(i.length>0){var n=i[i.length-1];t=n.x,r=n.y+n.dynamicMaxHeight}return e.maxWidth>this.pageWidth?(console.error("line.maxWidth = "+e.maxWidth+", this.pageWidth = "+this.pageWidth),!1):r+e.dynamicMaxHeight>this.pageHeight?!1:(e.x=t,e.y=r,e.page=this,this.lines.push(e),!0)},t}(e.HashObject);t.Page=n,__reflect(n.prototype,"egret.web.Page");var a=function(e){function t(t,r){var i=e.call(this)||this;return i._pages=[],i._sortLines=[],i._maxSize=1024,i._border=1,i._maxSize=t,i._border=r,i}return __extends(t,e),t.prototype.addTextBlock=function(e){var t=this._addTextBlock(e);if(!t)return!1;e.updateUV();for(var r=!1,i=t,n=this._sortLines,a=0,o=n;athis._maxSize||e.height>this._maxSize)return null;for(var t=this._sortLines,r=0,n=t.length;n>r;++r){var a=t[r];if(a.isCapacityOf(e)&&a.addTextBlock(e,!1))return[a.page,a]}var o=new i(this._maxSize);if(!o.addTextBlock(e,!0))return console.error("_addTextBlock !newLine.addTextBlock(textBlock, true)"),null;for(var s=this._pages,r=0,l=s.length;l>r;++r){var c=s[r];if(c.addLine(o))return[c,o]}var h=this.createPage(this._maxSize,this._maxSize);return h.addLine(o)?[h,o]:(console.error("_addText newPage.addLine failed"),null)},t.prototype.createPage=function(e,t){var r=new n(e,t);return this._pages.push(r),r},t.prototype.sort=function(){if(!(this._sortLines.length<=1)){var e=function(e,t){return e.dynamicMaxHeight=0)return void console.error("DrawLabel.back repeat");e.clear(),i.push(e)}},t.pool=[],t}(e.HashObject);t.DrawLabel=i,__reflect(i.prototype,"egret.web.DrawLabel");var n=function(t){function i(i,n){var a=t.call(this)||this;a.format=null;var o=0;r&&(o=i.textColor,i.textColor=16711680),a.textColor=i.textColor,a.strokeColor=i.strokeColor,a.size=i.size,a.stroke=i.stroke,a.bold=i.bold,a.italic=i.italic,a.fontFamily=i.fontFamily,a.format=n,a.font=e.getFontString(i,a.format);var s=n.textColor?n.textColor:i.textColor,l=n.strokeColor?n.strokeColor:i.strokeColor,c=n.stroke?n.stroke:i.stroke,h=n.size?n.size:i.size;return a.description=""+a.font+"-"+h,a.description+="-"+e.toColorString(s),a.description+="-"+e.toColorString(l),c&&(a.description+="-"+2*c),r&&(i.textColor=o),a}return __extends(i,t),i}(e.HashObject);__reflect(n.prototype,"StyleInfo");var a=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e["char"]="",e.styleInfo=null,e.hashCodeString="",e.charWithStyleHashCode=0,e.measureWidth=0,e.measureHeight=0,e.canvasWidthOffset=0,e.canvasHeightOffset=0,e.stroke2=0,e}return __extends(r,t),r.prototype.reset=function(t,r){return this["char"]=t,this.styleInfo=r,this.hashCodeString=t+":"+r.description,this.charWithStyleHashCode=e.NumberUtils.convertStringToHashCode(this.hashCodeString),this.canvasWidthOffset=0,this.canvasHeightOffset=0,this.stroke2=0,this},r.prototype.measureAndDraw=function(t){var r=t;if(r){var i=this["char"],n=this.styleInfo.format,a=n.textColor?n.textColor:this.styleInfo.textColor,o=n.strokeColor?n.strokeColor:this.styleInfo.strokeColor,s=n.stroke?n.stroke:this.styleInfo.stroke,l=n.size?n.size:this.styleInfo.size;this.measureWidth=this.measure(i,this.styleInfo,l),this.measureHeight=l;var c=this.measureWidth,h=this.measureHeight,u=2*s;u>0&&(c+=2*u,h+=2*u),this.stroke2=u,r.width=c=Math.ceil(c)+4,r.height=h=Math.ceil(h)+4,this.canvasWidthOffset=(r.width-this.measureWidth)/2,this.canvasHeightOffset=(r.height-this.measureHeight)/2;var d=3,f=Math.pow(10,d);this.canvasWidthOffset=Math.floor(this.canvasWidthOffset*f)/f,this.canvasHeightOffset=Math.floor(this.canvasHeightOffset*f)/f;var p=e.sys.getContext2d(r);p.save(),p.textAlign="center",p.textBaseline="middle",p.lineJoin="round",p.font=this.styleInfo.font,p.fillStyle=e.toColorString(a),p.strokeStyle=e.toColorString(o),p.clearRect(0,0,r.width,r.height),s&&(p.lineWidth=2*s,p.strokeText(i,r.width/2,r.height/2)),p.fillText(i,r.width/2,r.height/2),p.restore()}},r.prototype.measure=function(t,i,n){var a=r.chineseCharactersRegExp.test(t);if(a&&r.chineseCharacterMeasureFastMap[i.font])return r.chineseCharacterMeasureFastMap[i.font];var o=e.sys.measureText(t,i.fontFamily,n||i.size,i.bold,i.italic);return a&&(r.chineseCharacterMeasureFastMap[i.font]=o),o},r.chineseCharactersRegExp=new RegExp("^[一-龥]$"),r.chineseCharacterMeasureFastMap={},r}(e.HashObject);__reflect(a.prototype,"CharImageRender");var o=function(o){function s(e,r,i){var n=o.call(this)||this;return n.book=null,n.charImageRender=new a,n.textBlockMap={},n._canvas=null,n.textAtlasTextureCache=[],n.webglRenderContext=null,n.webglRenderContext=e,n.book=new t.Book(r,i),n}return __extends(s,o),s.analysisTextNodeAndFlushDrawLabel=function(a){if(a){if(!t.__textAtlasRender__){var o=e.web.WebGLRenderContext.getInstance(0,0);t.__textAtlasRender__=new s(o,512,r?12:1)}a[t.property_drawLabel]=a[t.property_drawLabel]||[];for(var l=a[t.property_drawLabel],c=0,h=l;cm;m+=d){p=f[m+0],v=f[m+1],g=f[m+2],x=f[m+3]||{},y.length=0,t.__textAtlasRender__.convertLabelStringToTextAtlas(g,new n(a,x),y);var u=i.create();u.anchorX=p,u.anchorY=v,u.textBlocks=[].concat(y),l.push(u)}}},s.prototype.convertLabelStringToTextAtlas=function(t,i,n){for(var a=this.canvas,o=this.charImageRender,s=this.textBlockMap,l=0,c=t;la;a++){var o=t.getActiveAttrib(r,a),s=o.name,l=new e.EgretWebGLAttribute(t,r,o);i[s]=l}return i}function n(t,r){for(var i={},n=t.getProgramParameter(r,t.ACTIVE_UNIFORMS),a=0;n>a;a++){var o=t.getActiveUniform(r,a),s=o.name,l=new e.EgretWebGLUniform(t,r,o);i[s]=l}return i}var a=function(){function e(e,a,o){this.vshaderSource=a,this.fshaderSource=o,this.vertexShader=t(e,e.VERTEX_SHADER,this.vshaderSource),this.fragmentShader=t(e,e.FRAGMENT_SHADER,this.fshaderSource),this.id=r(e,this.vertexShader,this.fragmentShader),this.uniforms=n(e,this.id),this.attributes=i(e,this.id)}return e.getProgram=function(t,r,i,n){return this.programCache[n]||(this.programCache[n]=new e(t,r,i)),this.programCache[n]},e.deleteProgram=function(e,t,r,i){},e.programCache={},e}();e.EgretWebGLProgram=a,__reflect(a.prototype,"egret.web.EgretWebGLProgram")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(e,t,r){this.gl=e,this.name=r.name,this.type=r.type,this.size=r.size,this.location=e.getUniformLocation(t,this.name),this.setDefaultValue(),this.generateSetValue(),this.generateUpload()}return e.prototype.setDefaultValue=function(){var e=this.type;switch(e){case 5126:case 35678:case 35680:case 35670:case 5124:this.value=0;break;case 35664:case 35671:case 35667:this.value=[0,0];break;case 35665:case 35672:case 35668:this.value=[0,0,0];break;case 35666:case 35673:case 35669:this.value=[0,0,0,0];break;case 35674:this.value=new Float32Array([1,0,0,1]);break;case 35675:this.value=new Float32Array([1,0,0,0,1,0,0,0,1]);break;case 35676:this.value=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}},e.prototype.generateSetValue=function(){var e=this.type;switch(e){case 5126:case 35678:case 35680:case 35670:case 5124:this.setValue=function(e){var t=this.value!==e;this.value=e,t&&this.upload()};break;case 35664:case 35671:case 35667:this.setValue=function(e){var t=this.value[0]!==e.x||this.value[1]!==e.y;this.value[0]=e.x,this.value[1]=e.y,t&&this.upload()};break;case 35665:case 35672:case 35668:this.setValue=function(e){this.value[0]=e.x,this.value[1]=e.y,this.value[2]=e.z,this.upload()};break;case 35666:case 35673:case 35669:this.setValue=function(e){this.value[0]=e.x,this.value[1]=e.y,this.value[2]=e.z,this.value[3]=e.w,this.upload()};break;case 35674:case 35675:case 35676:this.setValue=function(e){this.value.set(e),this.upload()}}},e.prototype.generateUpload=function(){var e=this.gl,t=this.type,r=this.location;switch(t){case 5126:this.upload=function(){var t=this.value;e.uniform1f(r,t)};break;case 35664:this.upload=function(){var t=this.value;e.uniform2f(r,t[0],t[1])};break;case 35665:this.upload=function(){var t=this.value;e.uniform3f(r,t[0],t[1],t[2])};break;case 35666:this.upload=function(){var t=this.value;e.uniform4f(r,t[0],t[1],t[2],t[3])};break;case 35678:case 35680:case 35670:case 5124:this.upload=function(){var t=this.value;e.uniform1i(r,t)};break;case 35671:case 35667:this.upload=function(){var t=this.value;e.uniform2i(r,t[0],t[1])};break;case 35672:case 35668:this.upload=function(){var t=this.value;e.uniform3i(r,t[0],t[1],t[2])};break;case 35673:case 35669:this.upload=function(){var t=this.value;e.uniform4i(r,t[0],t[1],t[2],t[3])};break;case 35674:this.upload=function(){var t=this.value;e.uniformMatrix2fv(r,!1,t)};break;case 35675:this.upload=function(){var t=this.value;e.uniformMatrix3fv(r,!1,t)};break;case 35676:this.upload=function(){var t=this.value;e.uniformMatrix4fv(r,!1,t)}}},e}();e.EgretWebGLUniform=t,__reflect(t.prototype,"egret.web.EgretWebGLUniform")}(t=e.web||(e.web={}))}(egret||(egret={}));var egret;!function(e){var t;!function(e){var t=function(){function e(){}return e.blur_frag="precision mediump float;\r\nuniform vec2 blur;\r\nuniform sampler2D uSampler;\r\nvarying vec2 vTextureCoord;\r\nuniform vec2 uTextureSize;\r\nvoid main()\r\n{\r\n const int sampleRadius = 5;\r\n const int samples = sampleRadius * 2 + 1;\r\n vec2 blurUv = blur / uTextureSize;\r\n vec4 color = vec4(0, 0, 0, 0);\r\n vec2 uv = vec2(0.0, 0.0);\r\n blurUv /= float(sampleRadius);\r\n\r\n for (int i = -sampleRadius; i <= sampleRadius; i++) {\r\n uv.x = vTextureCoord.x + float(i) * blurUv.x;\r\n uv.y = vTextureCoord.y + float(i) * blurUv.y;\r\n color += texture2D(uSampler, uv);\r\n }\r\n\r\n color /= float(samples);\r\n gl_FragColor = color;\r\n}",e.colorTransform_frag="precision mediump float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform mat4 matrix;\r\nuniform vec4 colorAdd;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n vec4 texColor = texture2D(uSampler, vTextureCoord);\r\n if(texColor.a > 0.) {\r\n // 抵消预乘的alpha通道\r\n texColor = vec4(texColor.rgb / texColor.a, texColor.a);\r\n }\r\n vec4 locColor = clamp(texColor * matrix + colorAdd, 0., 1.);\r\n gl_FragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);\r\n}",e.default_vert="attribute vec2 aVertexPosition;\r\nattribute vec2 aTextureCoord;\r\nattribute vec4 aColor;\r\n\r\nuniform vec2 projectionVector;\r\n// uniform vec2 offsetVector;\r\n\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nconst vec2 center = vec2(-1.0, 1.0);\r\n\r\nvoid main(void) {\r\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\r\n vTextureCoord = aTextureCoord;\r\n vColor = aColor;\r\n}",e.glow_frag="precision highp float;\r\nvarying vec2 vTextureCoord;\r\n\r\nuniform sampler2D uSampler;\r\n\r\nuniform float dist;\r\nuniform float angle;\r\nuniform vec4 color;\r\nuniform float alpha;\r\nuniform float blurX;\r\nuniform float blurY;\r\n// uniform vec4 quality;\r\nuniform float strength;\r\nuniform float inner;\r\nuniform float knockout;\r\nuniform float hideObject;\r\n\r\nuniform vec2 uTextureSize;\r\n\r\nfloat random(vec2 scale)\r\n{\r\n return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);\r\n}\r\n\r\nvoid main(void) {\r\n vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);\r\n // TODO 自动调节采样次数?\r\n const float linearSamplingTimes = 7.0;\r\n const float circleSamplingTimes = 12.0;\r\n vec4 ownColor = texture2D(uSampler, vTextureCoord);\r\n vec4 curColor;\r\n float totalAlpha = 0.0;\r\n float maxTotalAlpha = 0.0;\r\n float curDistanceX = 0.0;\r\n float curDistanceY = 0.0;\r\n float offsetX = dist * cos(angle) * px.x;\r\n float offsetY = dist * sin(angle) * px.y;\r\n\r\n const float PI = 3.14159265358979323846264;\r\n float cosAngle;\r\n float sinAngle;\r\n float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));\r\n float stepX = blurX * px.x / linearSamplingTimes;\r\n float stepY = blurY * px.y / linearSamplingTimes;\r\n for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {\r\n cosAngle = cos(a + offset);\r\n sinAngle = sin(a + offset);\r\n for (float i = 1.0; i <= linearSamplingTimes; i++) {\r\n curDistanceX = i * stepX * cosAngle;\r\n curDistanceY = i * stepY * sinAngle;\r\n if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0){\r\n curColor = texture2D(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));\r\n totalAlpha += (linearSamplingTimes - i) * curColor.a;\r\n }\r\n maxTotalAlpha += (linearSamplingTimes - i);\r\n }\r\n }\r\n\r\n ownColor.a = max(ownColor.a, 0.0001);\r\n ownColor.rgb = ownColor.rgb / ownColor.a;\r\n\r\n float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1. - inner) * max(min(hideObject, knockout), 1. - ownColor.a);\r\n float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;\r\n\r\n ownColor.a = max(ownColor.a * knockout * (1. - hideObject), 0.0001);\r\n vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));\r\n vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));\r\n float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.);\r\n gl_FragColor = vec4(mix2 * resultAlpha, resultAlpha);\r\n}",e.primitive_frag="precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n gl_FragColor = vColor;\r\n}",e.texture_frag="precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uSampler;\r\n\r\nvoid main(void) {\r\n gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;\r\n}",e.texture_etc_alphamask_frag="precision lowp float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uSampler;\r\nuniform sampler2D uSamplerAlphaMask;\r\nvoid main(void) {\r\nfloat alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r;\r\nif (alpha < 0.0039) { discard; }\r\nvec4 v4Color = texture2D(uSampler, vTextureCoord);\r\nv4Color.rgb = v4Color.rgb * alpha;\r\nv4Color.a = alpha;\r\ngl_FragColor = v4Color * vColor;\r\n}",e.colorTransform_frag_etc_alphamask_frag="precision mediump float;\r\nvarying vec2 vTextureCoord;\r\nvarying vec4 vColor;\r\nuniform mat4 matrix;\r\nuniform vec4 colorAdd;\r\nuniform sampler2D uSampler;\r\nuniform sampler2D uSamplerAlphaMask;\r\n\r\nvoid main(void){\r\nfloat alpha = texture2D(uSamplerAlphaMask, vTextureCoord).r;\r\nif (alpha < 0.0039) { discard; }\r\nvec4 texColor = texture2D(uSampler, vTextureCoord);\r\nif(texColor.a > 0.0) {\r\n // 抵消预乘的alpha通道\r\ntexColor = vec4(texColor.rgb / texColor.a, texColor.a);\r\n}\r\nvec4 v4Color = clamp(texColor * matrix + colorAdd, 0.0, 1.0);\r\nv4Color.rgb = v4Color.rgb * alpha;\r\nv4Color.a = alpha;\r\ngl_FragColor = v4Color * vColor;\r\n}",e }();e.EgretShaderLib=t,__reflect(t.prototype,"egret.web.EgretShaderLib")}(t=e.web||(e.web={}))}(egret||(egret={})); \ No newline at end of file diff --git a/demo/manifest.json b/demo/manifest.json index 2d454643..522c8eec 100644 --- a/demo/manifest.json +++ b/demo/manifest.json @@ -11,12 +11,11 @@ "libs/long/long.js" ], "game": [ - "bin-debug/game/CoreEmitterType.js", "bin-debug/AssetAdapter.js", + "bin-debug/LoadingUI.js", "bin-debug/Main.js", "bin-debug/Platform.js", "bin-debug/ThemeAdapter.js", - "bin-debug/LoadingUI.js", "bin-debug/game/MainScene.js", "bin-debug/game/PlayerController.js", "bin-debug/game/SimplePooled.js", diff --git a/demo/src/Main.ts b/demo/src/Main.ts index 81c86779..155539af 100644 --- a/demo/src/Main.ts +++ b/demo/src/Main.ts @@ -27,43 +27,9 @@ // ////////////////////////////////////////////////////////////////////////////////////// - -import SceneManager = es.SceneManager; -import Emitter = es.Emitter; - -class Main extends SceneManager { - public static emitter: Emitter; - public static manager: SceneManager; - - protected createChildren(): void { - super.createChildren(); - - egret.lifecycle.addLifecycleListener((context) => { - // custom lifecycle plugin - }) - - egret.lifecycle.onPause = () => { - egret.ticker.pause(); - } - - egret.lifecycle.onResume = () => { - egret.ticker.resume(); - } - - //inject the custom material parser - //注入自定义的素材解析器 - let assetAdapter = new AssetAdapter(); - egret.registerImplementation("eui.IAssetAdapter", assetAdapter); - egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter()); - - Main.manager = new SceneManager(this.stage); - Main.emitter = new Emitter(); - this.addEventListener(egret.Event.ENTER_FRAME, this.updateFrame, this); - this.runGame(); - } - - private updateFrame(evt: egret.Event){ - Main.emitter.emit(CoreEmitterType.Update, evt); +class Main extends es.Core { + protected async initialize() { + await this.runGame(); } private async runGame() { @@ -71,12 +37,12 @@ class Main extends SceneManager { this.createGameScene(); } + private async loadResource() { try { const loadingView = new LoadingUI(); this.stage.addChild(loadingView); await RES.loadConfig("resource/default.res.json", "resource/"); - await this.loadTheme(); await RES.loadGroup("preload", 0, loadingView); this.stage.removeChild(loadingView); } @@ -85,27 +51,11 @@ class Main extends SceneManager { } } - private loadTheme() { - return new Promise((resolve, reject) => { - // load skin theme configuration file, you can manually modify the file. And replace the default skin. - //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。 - let theme = new eui.Theme("resource/default.thm.json", this.stage); - theme.addEventListener(eui.UIEvent.COMPLETE, () => { - resolve(); - }, this); - - }) - } - /** * 创建场景界面 * Create scene interface */ protected createGameScene(): void { - SceneManager.scene = new MainScene(); - - // Main.emitter.addObserver(CoreEmitterType.Update, ()=>{ - // console.log("update emitter"); - // }); + es.Core.scene = new scene.MainScene(); } } diff --git a/demo/src/game/CoreEmitterType.ts b/demo/src/game/CoreEmitterType.ts deleted file mode 100644 index 6f845ce5..00000000 --- a/demo/src/game/CoreEmitterType.ts +++ /dev/null @@ -1,3 +0,0 @@ -enum CoreEmitterType { - Update, -} \ No newline at end of file diff --git a/demo/src/game/MainScene.ts b/demo/src/game/MainScene.ts index 543c2f4d..06b787f3 100644 --- a/demo/src/game/MainScene.ts +++ b/demo/src/game/MainScene.ts @@ -1,95 +1,90 @@ -class MainScene extends Scene { - constructor() { - super(); +module scene { + export class MainScene extends es.Scene { + constructor() { + super(); - // this.addEntityProcessor(new SpawnerSystem(new Matcher())); - this.astarTest(); - this.dijkstraTest(); - this.breadthfirstTest(); - } - - public async onStart() { - let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); - let bg = this.createEntity("bg"); - bg.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xff0000); - bg.addComponent(new PlayerController()); - bg.addComponent(new Mover()); - bg.addComponent(new ScrollingSpriteRenderer(sprite)); - bg.addComponent(new BoxCollider()); - bg.position = new Vector2(Math.random() * 200, Math.random() * 200); - - for (let i = 0; i < 1; i++) { - let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); - let player2 = this.createEntity("player2"); - player2.addComponent(new SpriteRenderer()).setSprite(sprite); - player2.position = new Vector2(Math.random() * 100, Math.random() * 100); - player2.addComponent(new BoxCollider()); + // this.addEntityProcessor(new SpawnerSystem(new Matcher())); + this.astarTest(); + this.dijkstraTest(); + this.breadthfirstTest(); } - this.camera.follow(bg, CameraStyle.lockOn); + public async onStart() { + let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png")); + let bg = this.createEntity("bg"); + bg.addComponent(new es.SpriteRenderer()).setSprite(sprite).setColor(0xff0000); + bg.addComponent(new component.PlayerController()); + bg.addComponent(new es.Mover()); + bg.addComponent(new es.ScrollingSpriteRenderer(sprite)); + bg.addComponent(new es.BoxCollider()); + bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200); - let pool = new ComponentPool(SimplePooled); - let c1 = pool.obtain(); - let c2 = pool.obtain(); - pool.free(c1); - let c1b = pool.obtain(); + for (let i = 0; i < 1; i++) { + let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png")); + let player2 = this.createEntity("player2"); + player2.addComponent(new es.SpriteRenderer()).setSprite(sprite); + player2.position = new es.Vector2(Math.random() * 100, Math.random() * 100); + player2.addComponent(new es.BoxCollider()); + } - console.log(c1 != c2); - console.log(c1 == c1b); + this.camera.follow(bg, es.CameraStyle.lockOn); - let button = new eui.Button(); - button.label = "切换场景"; - this.addChild(button); - button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { - SceneManager.startSceneTransition(new FadeTransition(() => { - return new MainScene(); - })); - }, this); + let pool = new es.ComponentPool(component.SimplePooled); + let c1 = pool.obtain(); + let c2 = pool.obtain(); + pool.free(c1); + let c1b = pool.obtain(); - Main.emitter.addObserver(CoreEmitterType.Update, this.handleFuncTest, this); + console.log(c1 != c2); + console.log(c1 == c1b); + + let button = new eui.Button(); + button.label = "切换场景"; + this.addChild(button); + button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => { + es.Core.startSceneTransition(new es.FadeTransition(() => { + return new MainScene(); + })); + }, this); + } + + public breadthfirstTest() { + let graph = new es.UnweightedGraph(); + + graph.addEdgesForNode("a", ["b"]); // a->b + graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d + graph.addEdgesForNode("c", ["a"]); // c->a + graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a + graph.addEdgesForNode("e", ["b"]); // e->b + + // 计算从c到e的路径 + let path = es.BreadthFirstPathfinder.search(graph, "c", "e"); + console.log(path); + } + + public dijkstraTest() { + let graph = new es.WeightedGridGraph(20, 20); + + graph.weightedNodes.push(new es.Vector2(3, 3)); + graph.weightedNodes.push(new es.Vector2(3, 4)); + graph.weightedNodes.push(new es.Vector2(4, 3)); + graph.weightedNodes.push(new es.Vector2(4, 4)); + + let path = graph.search(new es.Vector2(3, 4), new es.Vector2(15, 17)); + console.log(path); + } + + public astarTest() { + let graph = new es.AstarGridGraph(30, 30); + + // graph.weightedNodes.push(new Vector2(3, 3)); + // graph.weightedNodes.push(new Vector2(3, 4)); + // graph.weightedNodes.push(new Vector2(4, 3)); + // graph.weightedNodes.push(new Vector2(4, 4)); + + let startTime = egret.getTimer(); + let path = graph.search(new es.Vector2(1, 1), new es.Vector2(29, 29)); + console.log(egret.getTimer() - startTime); + } } - - /** 测试Emitter */ - private handleFuncTest(){ - Main.emitter.removeObserver(CoreEmitterType.Update, this.handleFuncTest); - } - - public breadthfirstTest() { - let graph = new UnweightedGraph(); - - graph.addEdgesForNode("a", ["b"]); // a->b - graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d - graph.addEdgesForNode("c", ["a"]); // c->a - graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a - graph.addEdgesForNode("e", ["b"]); // e->b - - // 计算从c到e的路径 - let path = BreadthFirstPathfinder.search(graph, "c", "e"); - console.log(path); - } - - public dijkstraTest() { - let graph = new WeightedGridGraph(20, 20); - - graph.weightedNodes.push(new Vector2(3, 3)); - graph.weightedNodes.push(new Vector2(3, 4)); - graph.weightedNodes.push(new Vector2(4, 3)); - graph.weightedNodes.push(new Vector2(4, 4)); - - let path = graph.search(new Vector2(3, 4), new Vector2(15, 17)); - console.log(path); - } - - public astarTest() { - let graph = new AstarGridGraph(30, 30); - - // graph.weightedNodes.push(new Vector2(3, 3)); - // graph.weightedNodes.push(new Vector2(3, 4)); - // graph.weightedNodes.push(new Vector2(4, 3)); - // graph.weightedNodes.push(new Vector2(4, 4)); - - let startTime = egret.getTimer(); - let path = graph.search(new Vector2(1, 1), new Vector2(29, 29)); - console.log(egret.getTimer() - startTime); - } -} \ No newline at end of file +} diff --git a/demo/src/game/PlayerController.ts b/demo/src/game/PlayerController.ts index 3bb844a5..c72b00b2 100644 --- a/demo/src/game/PlayerController.ts +++ b/demo/src/game/PlayerController.ts @@ -1,56 +1,64 @@ -class PlayerController extends Component { - private down: boolean = false; - private touchPoint: Vector2 = Vector2.zero; - private mover: Mover; - private spriteRenderer: SpriteRenderer; +module component { + import Component = es.Component; + import Vector2 = es.Vector2; + import Mover = es.Mover; + import SpriteRenderer = es.SpriteRenderer; + import Time = es.Time; + import Input = es.Input; - public onAddedToEntity(){ - this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); - this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this); - this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); - } + export class PlayerController extends Component { + private down: boolean = false; + private touchPoint: Vector2 = Vector2.zero; + private mover: Mover; + private spriteRenderer: SpriteRenderer; - private touchBegin(evt: egret.TouchEvent){ - this.down = true; - this.touchPoint = new Vector2(evt.stageX, evt.stageY); - } + public onAddedToEntity(){ + this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this); + this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this); + this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this); + } - private touchEnd(evt: egret.TouchEvent){ - this.down = false; - this.touchPoint = new Vector2(evt.stageX, evt.stageY); - } + private touchBegin(evt: egret.TouchEvent){ + this.down = true; + this.touchPoint = new Vector2(evt.stageX, evt.stageY); + } - public update(){ - if (!this.mover) - this.mover = this.entity.getComponent(Mover); + private touchEnd(evt: egret.TouchEvent){ + this.down = false; + this.touchPoint = new Vector2(evt.stageX, evt.stageY); + } - if (!this.spriteRenderer) - this.spriteRenderer = this.entity.getComponent(SpriteRenderer); + public update(){ + if (!this.mover) + this.mover = this.entity.getComponent(Mover); - if (!this.mover) - return; + if (!this.spriteRenderer) + this.spriteRenderer = this.entity.getComponent(SpriteRenderer); - if (!SpriteRenderer) - return; + if (!this.mover) + return; - if (this.down){ - let camera = SceneManager.scene.camera; - let moveLeft: number = 0; - let moveRight: number = 0; - let speed = 100; - let worldPos = Input.touchPosition; - if (worldPos.x < this.spriteRenderer.localPosition.x){ - moveLeft = -1; - } else if(worldPos.x > this.spriteRenderer.localPosition.x){ - moveLeft = 1; + if (!SpriteRenderer) + return; + + if (this.down){ + let moveLeft: number = 0; + let moveRight: number = 0; + let speed = 100; + let worldPos = Input.touchPosition; + if (worldPos.x < this.spriteRenderer.transform.position.x){ + moveLeft = -1; + } else if(worldPos.x > this.spriteRenderer.transform.position.x){ + moveLeft = 1; + } + + if (worldPos.y < this.spriteRenderer.transform.position.y){ + moveRight = -1; + } else if(worldPos.y > this.spriteRenderer.transform.position.y){ + moveRight = 1; + } + this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime)); } - - if (worldPos.y < this.spriteRenderer.localPosition.y){ - moveRight = -1; - } else if(worldPos.y > this.spriteRenderer.localPosition.y){ - moveRight = 1; - } - this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime)); } } -} \ No newline at end of file +} diff --git a/demo/src/game/SimplePooled.ts b/demo/src/game/SimplePooled.ts index c9345b4c..c455db33 100644 --- a/demo/src/game/SimplePooled.ts +++ b/demo/src/game/SimplePooled.ts @@ -1,5 +1,9 @@ -class SimplePooled extends PooledComponent { - public reset(){ - +module component { + import PooledComponent = es.PooledComponent; + + export class SimplePooled extends PooledComponent { + public reset(){ + + } } -} \ No newline at end of file +} diff --git a/demo/src/game/SpawnerComponent.ts b/demo/src/game/SpawnerComponent.ts index 381b8b14..fb50ee0e 100644 --- a/demo/src/game/SpawnerComponent.ts +++ b/demo/src/game/SpawnerComponent.ts @@ -1,35 +1,37 @@ -class SpawnComponent extends Component implements ITriggerListener { - public cooldown = -1; - public minInterval = 2; - public maxInterval = 60; - public enemyType = EnemyType.worm; - public numSpawned = 0; - public numAlive = 0; +module component { + export class SpawnComponent extends es.Component implements es.ITriggerListener { + public cooldown = -1; + public minInterval = 2; + public maxInterval = 60; + public enemyType = EnemyType.worm; + public numSpawned = 0; + public numAlive = 0; - constructor(enemyType: EnemyType) { - super(); - this.enemyType = enemyType; + constructor(enemyType: EnemyType) { + super(); + this.enemyType = enemyType; + } + + public initialize() { + // console.log("initialize"); + } + + public update() { + // console.log("update"); + } + + public onTriggerEnter(other: es.Collider, local: es.Collider){ + if (other == local) + console.log("repeat collider"); + console.log("enter collider"); + } + + public onTriggerExit(other: es.Collider, local: es.Collider){ + console.log("exit collider"); + } } - public initialize() { - // console.log("initialize"); - } - - public update() { - // console.log("update"); - } - - public onTriggerEnter(other: Collider, local: Collider){ - if (other == local) - console.log("repeat collider") - console.log("enter collider"); - } - - public onTriggerExit(other: Collider, local: Collider){ - console.log("exit collider"); + export enum EnemyType { + worm } } - -enum EnemyType { - worm -} \ No newline at end of file diff --git a/demo/src/game/SpawnerSystem.ts b/demo/src/game/SpawnerSystem.ts index 019cbef2..fa3a418a 100644 --- a/demo/src/game/SpawnerSystem.ts +++ b/demo/src/game/SpawnerSystem.ts @@ -1,34 +1,36 @@ -class SpawnerSystem extends EntityProcessingSystem { - constructor(matcher: Matcher){ - super(matcher); - } - - public processEntity(entity: Entity){ - let spawner = entity.getComponent(SpawnComponent); - if (!spawner) - return; - - if (spawner.numAlive <= 0) - spawner.enabled = true; - - if (!spawner.enabled) - return; - - console.log("cooldown", spawner.cooldown); - if (spawner.cooldown == -1){ - spawner.cooldown = Math.random() * 60; - spawner.cooldown /= 4; +module system { + export class SpawnerSystem extends es.EntityProcessingSystem { + constructor(matcher: es.Matcher){ + super(matcher); } - spawner.cooldown -= Time.deltaTime; - if (spawner.cooldown <= 0){ - spawner.cooldown = Math.random() * 60; - // CreateEnemy - spawner.numSpawned ++; - spawner.numAlive ++; + public processEntity(entity: es.Entity){ + let spawner = entity.getComponent(component.SpawnComponent); + if (!spawner) + return; - if (spawner.numAlive > 0) - spawner.enabled = false; + if (spawner.numAlive <= 0) + spawner.enabled = true; + + if (!spawner.enabled) + return; + + console.log("cooldown", spawner.cooldown); + if (spawner.cooldown == -1){ + spawner.cooldown = Math.random() * 60; + spawner.cooldown /= 4; + } + + spawner.cooldown -= es.Time.deltaTime; + if (spawner.cooldown <= 0){ + spawner.cooldown = Math.random() * 60; + // CreateEnemy + spawner.numSpawned ++; + spawner.numAlive ++; + + if (spawner.numAlive > 0) + spawner.enabled = false; + } } } -} \ No newline at end of file +} diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index 22ae545a..acfa237f 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -248,7 +248,6 @@ declare module es { } declare module es { class Core extends egret.DisplayObjectContainer { - static activeSceneChanged: Function; static emitter: Emitter; static graphicsDevice: GraphicsDevice; static content: ContentManager; @@ -260,6 +259,7 @@ declare module es { _globalManagers: GlobalManager[]; static scene: Scene; constructor(); + private onAddToStage; onOrientationChanged(): void; protected onGraphicsDeviceReset(): void; protected initialize(): void; @@ -269,7 +269,6 @@ declare module es { endDebugUpdate(): void; onSceneChanged(): void; static startSceneTransition(sceneTransition: T): T; - static registerActiveSceneChanged(current: Scene, next: Scene): void; static registerGlobalManager(manager: es.GlobalManager): void; static unregisterGlobalManager(manager: es.GlobalManager): void; static getGlobalManager(type: any): T; @@ -1679,7 +1678,8 @@ declare module es { static readonly logSnapDuration: number; static readonly barPadding: number; static readonly autoAdjustDelay: number; - static Instance: TimeRuler; + private static _instance; + static readonly Instance: TimeRuler; private _frameKey; private _logKey; private _logs; diff --git a/source/bin/framework.js b/source/bin/framework.js index 4e14fae4..ff829892 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1105,13 +1105,8 @@ var es; _this._globalManagers = []; Core._instance = _this; Core.emitter = new es.Emitter(); - Core.graphicsDevice = new es.GraphicsDevice(); Core.content = new es.ContentManager(); - _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this); - _this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this); - _this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this); - _this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this); - _this.addEventListener(egret.Event.RENDER, _this.draw, _this); + _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this); return _this; } Object.defineProperty(Core, "Instance", { @@ -1123,6 +1118,8 @@ var es; }); Object.defineProperty(Core, "scene", { get: function () { + if (!this._instance) + return null; return this._instance._scene; }, set: function (value) { @@ -1138,11 +1135,18 @@ var es; else { this._instance._nextScene = value; } - this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene); }, enumerable: true, configurable: true }); + Core.prototype.onAddToStage = function () { + Core.graphicsDevice = new es.GraphicsDevice(); + this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); + this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); + this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); + this.addEventListener(egret.Event.RENDER, this.draw, this); + this.initialize(); + }; Core.prototype.onOrientationChanged = function () { Core.emitter.emit(es.CoreEvents.OrientationChanged); }; @@ -1228,10 +1232,6 @@ var es; this._instance._sceneTransition = sceneTransition; return sceneTransition; }; - Core.registerActiveSceneChanged = function (current, next) { - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - }; Core.registerGlobalManager = function (manager) { this._instance._globalManagers.push(manager); manager.enabled = true; @@ -4308,6 +4308,8 @@ var es; this.platformInitialize(device); }; GraphicsCapabilities.prototype.platformInitialize = function (device) { + if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME) + return; var capabilities = this; capabilities["isMobile"] = true; var systemInfo = wx.getSystemInfoSync(); @@ -7570,7 +7572,6 @@ var es; this.stopwacth = new stopwatch.Stopwatch(); this._markerNameToIdMap = new Map(); this.showLog = false; - TimeRuler.Instance = this; this._logs = new Array(2); for (var i = 0; i < this._logs.length; ++i) this._logs[i] = new FrameLog(); @@ -7579,6 +7580,15 @@ var es; es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this); this.onGraphicsDeviceReset(); } + Object.defineProperty(TimeRuler, "Instance", { + get: function () { + if (!this._instance) + this._instance = new TimeRuler(); + return this._instance; + }, + enumerable: true, + configurable: true + }); TimeRuler.prototype.onGraphicsDeviceReset = function () { var layout = new es.Layout(); this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location; diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index da2a3273..73b277e8 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.graphicsDevice=new t.GraphicsDevice,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.initialize,i),i.addEventListener(egret.Event.RESIZE,i.onGraphicsDeviceReset,i),i.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,i.onOrientationChanged,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i.addEventListener(egret.Event.RENDER,i.draw,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance._scene},set:function(t){t?(null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t,this.registerActiveSceneChanged(this._instance._scene,this._instance._nextScene)):console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerActiveSceneChanged=function(t,e){this.activeSceneChanged&&this.activeSceneChanged(t,e)},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":n.indexOf("android")>-1&&(this.os="Android");var i=e.language;i=i.indexOf("zh")>-1?"zh-CN":"en-US",this.language=i},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,e.Instance=this,this._logs=new Array(2);for(var i=0;i=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Core.ts b/source/src/ECS/Core.ts index 767e03a7..2f4f714c 100644 --- a/source/src/ECS/Core.ts +++ b/source/src/ECS/Core.ts @@ -3,10 +3,6 @@ module es { * 全局核心类 */ export class Core extends egret.DisplayObjectContainer { - /** - * 订阅此事件以在活动场景发生更改时得到通知。 - */ - public static activeSceneChanged: Function; /** * 核心发射器。只发出核心级别的事件 */ @@ -44,6 +40,8 @@ module es { * 当前活动的场景。注意,如果设置了该设置,在更新结束之前场景实际上不会改变 */ public static get scene() { + if (!this._instance) + return null; return this._instance._scene; } @@ -64,8 +62,6 @@ module es { } else { this._instance._nextScene = value; } - - this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene); } constructor() { @@ -73,14 +69,20 @@ module es { Core._instance = this; Core.emitter = new Emitter(); - Core.graphicsDevice = new GraphicsDevice(); Core.content = new ContentManager(); - this.addEventListener(egret.Event.ADDED_TO_STAGE, this.initialize, this); + this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this); + } + + private onAddToStage(){ + Core.graphicsDevice = new GraphicsDevice(); + this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); this.addEventListener(egret.Event.RENDER, this.draw, this); + + this.initialize(); } public onOrientationChanged(){ @@ -190,11 +192,6 @@ module es { return sceneTransition; } - public static registerActiveSceneChanged(current: Scene, next: Scene){ - if (this.activeSceneChanged) - this.activeSceneChanged(current, next); - } - /** * 添加一个全局管理器对象,它的更新方法将调用场景前的每一帧。 * @param manager diff --git a/source/src/Graphics/GraphicsCapabilities.ts b/source/src/Graphics/GraphicsCapabilities.ts index 99f94864..b967b22a 100644 --- a/source/src/Graphics/GraphicsCapabilities.ts +++ b/source/src/Graphics/GraphicsCapabilities.ts @@ -6,6 +6,8 @@ module es { } private platformInitialize(device: GraphicsDevice){ + if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME) + return; let capabilities = this; capabilities["isMobile"] = true; diff --git a/source/src/Utils/Analysis/TimeRuler.ts b/source/src/Utils/Analysis/TimeRuler.ts index 83ccc4c8..d90b9b27 100644 --- a/source/src/Utils/Analysis/TimeRuler.ts +++ b/source/src/Utils/Analysis/TimeRuler.ts @@ -17,7 +17,12 @@ module es { public static readonly logSnapDuration = 120; public static readonly barPadding = 2; public static readonly autoAdjustDelay = 30; - public static Instance: TimeRuler; + private static _instance; + public static get Instance(): TimeRuler{ + if (!this._instance) + this._instance = new TimeRuler(); + return this._instance; + } private _frameKey = 'frame'; private _logKey = 'log'; @@ -56,7 +61,6 @@ module es { private _frameAdjust: number; constructor() { - TimeRuler.Instance = this; this._logs = new Array(2); for (let i = 0; i < this._logs.length; ++i) this._logs[i] = new FrameLog(); From 6be43fc9ace94c542316618f9a9779587b8d0b4f Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Fri, 24 Jul 2020 15:29:07 +0800 Subject: [PATCH 10/15] =?UTF-8?q?=E4=BC=98=E5=8C=96transform=E7=BB=93?= =?UTF-8?q?=E6=9E=84=20=E6=96=B0=E5=A2=9E=E5=AE=9E=E4=BD=93=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.d.ts | 78 +++- demo/libs/framework/framework.js | 559 +++++++++++++++++++++------ demo/libs/framework/framework.min.js | 2 +- source/bin/framework.d.ts | 78 +++- source/bin/framework.js | 559 +++++++++++++++++++++------ source/bin/framework.min.js | 2 +- source/src/ECS/Core.ts | 4 +- source/src/ECS/Entity.ts | 62 ++- source/src/ECS/Transform.ts | 362 +++++++++++++++-- source/src/ECS/Utils/EntityList.ts | 262 ++++++++----- source/src/Physics/Shapes/Polygon.ts | 5 +- 11 files changed, 1595 insertions(+), 378 deletions(-) diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index acfa237f..deb26253 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -263,7 +263,7 @@ declare module es { onOrientationChanged(): void; protected onGraphicsDeviceReset(): void; protected initialize(): void; - protected update(): void; + protected update(): Promise; draw(): Promise; startDebugUpdate(): void; endDebugUpdate(): void; @@ -302,8 +302,16 @@ declare module es { parent: Transform; readonly childCount: number; position: Vector2; + localPosition: Vector2; rotation: number; + rotationDegrees: number; + localRotation: number; + localRotationDegrees: number; scale: Vector2; + localScale: Vector2; + readonly worldInverseTransform: Matrix2D; + readonly localToWorldTransform: Matrix2D; + readonly worldToLocalTransform: Matrix2D; constructor(name: string); onTransformChanged(comp: transform.Component): void; setTag(tag: number): Entity; @@ -325,6 +333,7 @@ declare module es { removeComponent(component: Component): void; removeComponentForType(type: any): boolean; removeAllComponents(): void; + compareTo(other: Entity): number; toString(): string; } } @@ -389,21 +398,56 @@ declare module es { parent: Transform; readonly childCount: number; position: Vector2; + localPosition: Vector2; rotation: number; + rotationDegrees: number; + localRotation: number; + localRotationDegrees: number; scale: Vector2; + localScale: Vector2; + readonly worldInverseTransform: Matrix2D; + readonly localToWorldTransform: Matrix2D; + readonly worldToLocalTransform: Matrix2D; _parent: Transform; hierarchyDirty: DirtyType; + _localDirty: boolean; + _localPositionDirty: boolean; + _localScaleDirty: boolean; + _localRotationDirty: boolean; + _positionDirty: boolean; + _worldToLocalDirty: boolean; + _worldInverseDirty: boolean; + _localTransform: Matrix2D; + _worldTransform: Matrix2D; + _worldToLocalTransform: Matrix2D; + _worldInverseTransform: Matrix2D; + _rotationMatrix: Matrix2D; + _translationMatrix: Matrix2D; + _scaleMatrix: Matrix2D; + _position: Vector2; + _scale: Vector2; + _rotation: number; + _localPosition: Vector2; + _localScale: Vector2; + _localRotation: number; _children: Transform[]; constructor(entity: Entity); getChild(index: number): Transform; setParent(parent: Transform): Transform; setPosition(x: number, y: number): Transform; - setRotation(degrees: number): Transform; - setScale(scale: Vector2): Transform; + setLocalPosition(localPosition: Vector2): Transform; + setRotation(radians: number): Transform; + setRotationDegrees(degrees: number): Transform; lookAt(pos: Vector2): void; + setLocalRotation(radians: number): this; + setLocalRotationDegrees(degrees: number): Transform; + setScale(scale: Vector2): Transform; + setLocalScale(scale: Vector2): Transform; roundPosition(): void; + updateTransform(): void; setDirty(dirtyFlagType: DirtyType): void; copyFrom(transform: Transform): void; + toString(): string; } } declare module es { @@ -796,28 +840,32 @@ declare module es { declare module es { class EntityList { scene: Scene; - private _entitiesToRemove; - private _entitiesToAdded; - private _tempEntityList; - private _entities; - private _entityDict; - private _unsortedTags; + _entities: Entity[]; + _entitiesToAdded: Entity[]; + _entitiesToRemove: Entity[]; + _isEntityListUnsorted: boolean; + _entityDict: Map; + _unsortedTags: number[]; + _tempEntityList: Entity[]; constructor(scene: Scene); readonly count: number; readonly buffer: Entity[]; + markEntityListUnsorted(): void; + markTagUnsorted(tag: number): void; add(entity: Entity): void; remove(entity: Entity): void; + removeAllEntities(): void; + contains(entity: Entity): boolean; + getTagList(tag: number): Entity[]; + addToTagList(entity: Entity): void; + removeFromTagList(entity: Entity): void; + update(): void; + updateLists(): void; findEntity(name: string): Entity; entitiesWithTag(tag: number): Entity[]; entitiesOfType(type: any): T[]; findComponentOfType(type: any): T; findComponentsOfType(type: any): T[]; - getTagList(tag: number): Entity[]; - addToTagList(entity: Entity): void; - removeFromTagList(entity: Entity): void; - update(): void; - removeAllEntities(): void; - updateLists(): void; } } declare module es { diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index ff829892..264328a4 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -1156,26 +1156,37 @@ var es; Core.prototype.initialize = function () { }; Core.prototype.update = function () { - this.startDebugUpdate(); - es.Time.update(egret.getTimer()); - if (this._scene) { - for (var i = this._globalManagers.length - 1; i >= 0; i--) { - if (this._globalManagers[i].enabled) - this._globalManagers[i].update(); - } - if (!this._sceneTransition || - (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) { - this._scene.update(); - } - if (this._nextScene) { - this._scene.end(); - this._scene = this._nextScene; - this._nextScene = null; - this.onSceneChanged(); - this._scene.begin(); - } - } - this.endDebugUpdate(); + return __awaiter(this, void 0, void 0, function () { + var i; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.startDebugUpdate(); + es.Time.update(egret.getTimer()); + if (!this._scene) return [3, 2]; + for (i = this._globalManagers.length - 1; i >= 0; i--) { + if (this._globalManagers[i].enabled) + this._globalManagers[i].update(); + } + if (!this._sceneTransition || + (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) { + this._scene.update(); + } + if (!this._nextScene) return [3, 2]; + this._scene.end(); + this._scene = this._nextScene; + this._nextScene = null; + this.onSceneChanged(); + return [4, this._scene.begin()]; + case 1: + _a.sent(); + _a.label = 2; + case 2: + this.endDebugUpdate(); + return [2]; + } + }); + }); }; Core.prototype.draw = function () { return __awaiter(this, void 0, void 0, function () { @@ -1338,6 +1349,16 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Entity.prototype, "localPosition", { + get: function () { + return this.transform.localPosition; + }, + set: function (value) { + this.transform.setLocalPosition(value); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Entity.prototype, "rotation", { get: function () { return this.transform.rotation; @@ -1348,6 +1369,36 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Entity.prototype, "rotationDegrees", { + get: function () { + return this.transform.rotationDegrees; + }, + set: function (value) { + this.transform.setRotationDegrees(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "localRotation", { + get: function () { + return this.transform.localRotation; + }, + set: function (value) { + this.transform.setLocalRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "localRotationDegrees", { + get: function () { + return this.transform.localRotationDegrees; + }, + set: function (value) { + this.transform.setLocalRotationDegrees(value); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Entity.prototype, "scale", { get: function () { return this.transform.scale; @@ -1358,6 +1409,37 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Entity.prototype, "localScale", { + get: function () { + return this.transform.localScale; + }, + set: function (value) { + this.transform.setLocalScale(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "worldInverseTransform", { + get: function () { + return this.transform.worldInverseTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "localToWorldTransform", { + get: function () { + return this.transform.localToWorldTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "worldToLocalTransform", { + get: function () { + return this.transform.worldToLocalTransform; + }, + enumerable: true, + configurable: true + }); Entity.prototype.onTransformChanged = function (comp) { this.components.onEntityTransformChanged(comp); }; @@ -1385,6 +1467,8 @@ var es; if (this._updateOrder != updateOrder) { this._updateOrder = updateOrder; if (this.scene) { + this.scene.entities.markEntityListUnsorted(); + this.scene.entities.markTagUnsorted(this.tag); } return this; } @@ -1484,6 +1568,12 @@ var es; this.removeComponent(this.components.buffer[i]); } }; + Entity.prototype.compareTo = function (other) { + var compare = this._updateOrder - other._updateOrder; + if (compare == 0) + compare = this.id - other.id; + return compare; + }; Entity.prototype.toString = function () { return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]"; }; @@ -1697,6 +1787,9 @@ var es; })(DirtyType = es.DirtyType || (es.DirtyType = {})); var Transform = (function () { function Transform(entity) { + this._worldTransform = es.Matrix2D.create().identity(); + this._worldToLocalTransform = es.Matrix2D.create().identity(); + this._worldInverseTransform = es.Matrix2D.create().identity(); this.entity = entity; this.scale = es.Vector2.one; this._children = []; @@ -1718,6 +1811,139 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Transform.prototype, "position", { + get: function () { + this.updateTransform(); + if (this._positionDirty) { + if (!this.parent) { + this._position = this._localPosition; + } + else { + this.parent.updateTransform(); + this._position = es.Vector2Ext.transformR(this._localPosition, this.parent._worldTransform); + } + this._positionDirty = false; + } + return this._position; + }, + set: function (value) { + this.setPosition(value.x, value.y); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localPosition", { + get: function () { + this.updateTransform(); + return this._localPosition; + }, + set: function (value) { + this.setLocalPosition(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "rotation", { + get: function () { + this.updateTransform(); + return this._rotation; + }, + set: function (value) { + this.setRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "rotationDegrees", { + get: function () { + return es.MathHelper.toDegrees(this._rotation); + }, + set: function (value) { + this.setRotation(es.MathHelper.toRadians(value)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localRotation", { + get: function () { + this.updateTransform(); + return this._localRotation; + }, + set: function (value) { + this.setLocalRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localRotationDegrees", { + get: function () { + return es.MathHelper.toDegrees(this._localRotation); + }, + set: function (value) { + this.localRotation = es.MathHelper.toRadians(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "scale", { + get: function () { + this.updateTransform(); + return this._scale; + }, + set: function (value) { + this.setScale(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localScale", { + get: function () { + this.updateTransform(); + return this._localScale; + }, + set: function (value) { + this.setLocalScale(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "worldInverseTransform", { + get: function () { + this.updateTransform(); + if (this._worldInverseDirty) { + this._worldInverseTransform = this._worldTransform.invert(); + this._worldInverseDirty = false; + } + return this._worldInverseTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localToWorldTransform", { + get: function () { + this.updateTransform(); + return this._worldTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "worldToLocalTransform", { + get: function () { + if (this._worldToLocalDirty) { + if (!this.parent) { + this._worldToLocalTransform = es.Matrix2D.create().identity(); + } + else { + this.parent.updateTransform(); + this._worldToLocalTransform = this.parent._worldTransform.invert(); + } + this._worldToLocalDirty = false; + } + return this._worldToLocalTransform; + }, + enumerable: true, + configurable: true + }); Transform.prototype.getChild = function (index) { return this._children[index]; }; @@ -1733,27 +1959,110 @@ var es; return this; }; Transform.prototype.setPosition = function (x, y) { - this.position = new es.Vector2(x, y); + var position = new es.Vector2(x, y); + if (position == this._position) + return this; + this._position = position; + if (this.parent) { + this.localPosition = es.Vector2Ext.transformR(this._position, this._worldToLocalTransform); + } + else { + this.localPosition = position; + } + this._positionDirty = false; + return this; + }; + Transform.prototype.setLocalPosition = function (localPosition) { + if (localPosition == this._localPosition) + return this; + this._localPosition = localPosition; + this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; this.setDirty(DirtyType.positionDirty); return this; }; - Transform.prototype.setRotation = function (degrees) { - this.rotation = degrees; - this.setDirty(DirtyType.rotationDirty); + Transform.prototype.setRotation = function (radians) { + this._rotation = radians; + if (this.parent) { + this.localRotation = this.parent.rotation + radians; + } + else { + this.localRotation = radians; + } return this; }; - Transform.prototype.setScale = function (scale) { - this.scale = scale; - this.setDirty(DirtyType.scaleDirty); - return this; + Transform.prototype.setRotationDegrees = function (degrees) { + return this.setRotation(es.MathHelper.toRadians(degrees)); }; Transform.prototype.lookAt = function (pos) { var sign = this.position.x > pos.x ? -1 : 1; var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos)); this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY)); }; + Transform.prototype.setLocalRotation = function (radians) { + this._localRotation = radians; + this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; + this.setDirty(DirtyType.rotationDirty); + return this; + }; + Transform.prototype.setLocalRotationDegrees = function (degrees) { + return this.setLocalRotation(es.MathHelper.toRadians(degrees)); + }; + Transform.prototype.setScale = function (scale) { + this._scale = scale; + if (this.parent) { + this.localScale = es.Vector2.divide(scale, this.parent._scale); + } + else { + this.localScale = scale; + } + return this; + }; + Transform.prototype.setLocalScale = function (scale) { + this._localScale = scale; + this._localDirty = this._positionDirty = this._localScaleDirty = true; + this.setDirty(DirtyType.scaleDirty); + return this; + }; Transform.prototype.roundPosition = function () { - this.position = this.position.round(); + this.position = this._position.round(); + }; + Transform.prototype.updateTransform = function () { + if (this.hierarchyDirty != DirtyType.clean) { + if (this.parent) + this.parent.updateTransform(); + if (this._localDirty) { + if (this._localPositionDirty) { + this._translationMatrix = es.Matrix2D.create().translate(this._localPosition.x, this._localPosition.y); + this._localPositionDirty = false; + } + if (this._localRotationDirty) { + this._rotationMatrix = es.Matrix2D.create().rotate(this._localRotation); + this._localRotationDirty = false; + } + if (this._localScaleDirty) { + this._scaleMatrix = es.Matrix2D.create().scale(this._localScale.x, this._localScale.y); + this._localScaleDirty = false; + } + this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix); + this._localTransform = this._localTransform.multiply(this._translationMatrix); + if (!this.parent) { + this._worldTransform = this._localTransform; + this._rotation = this._localRotation; + this._scale = this._localScale; + this._worldInverseDirty = true; + } + this._localDirty = false; + } + if (this.parent) { + this._worldTransform = this._localTransform.multiply(this.parent._worldTransform); + this._rotation = this._localRotation + this.parent._rotation; + this._scale = es.Vector2.multiply(this.parent._scale, this._localScale); + this._worldInverseDirty = true; + } + this._worldToLocalDirty = true; + this._positionDirty = true; + this.hierarchyDirty = DirtyType.clean; + } }; Transform.prototype.setDirty = function (dirtyFlagType) { if ((this.hierarchyDirty & dirtyFlagType) == 0) { @@ -1776,13 +2085,19 @@ var es; } }; Transform.prototype.copyFrom = function (transform) { - this.position = transform.position; - this.rotation = transform.rotation; - this.scale = transform.scale; + this._position = transform.position; + this._localPosition = transform._localPosition; + this._rotation = transform._rotation; + this._localRotation = transform._localRotation; + this._scale = transform._scale; + this._localScale = transform._localScale; this.setDirty(DirtyType.positionDirty); this.setDirty(DirtyType.rotationDirty); this.setDirty(DirtyType.scaleDirty); }; + Transform.prototype.toString = function () { + return "[Transform: parent: " + this.parent + ", position: " + this.position + ", rotation: " + this.rotation + ",\n scale: " + this.scale + ", localPosition: " + this._localPosition + ", localRotation: " + this._localRotation + ",\n localScale: " + this._localScale + "]"; + }; return Transform; }()); es.Transform = Transform; @@ -3432,12 +3747,12 @@ var es; (function (es) { var EntityList = (function () { function EntityList(scene) { - this._entitiesToRemove = []; - this._entitiesToAdded = []; - this._tempEntityList = []; this._entities = []; + this._entitiesToAdded = []; + this._entitiesToRemove = []; this._entityDict = new Map(); this._unsortedTags = []; + this._tempEntityList = []; this.scene = scene; } Object.defineProperty(EntityList.prototype, "count", { @@ -3454,11 +3769,21 @@ var es; enumerable: true, configurable: true }); + EntityList.prototype.markEntityListUnsorted = function () { + this._isEntityListUnsorted = true; + }; + EntityList.prototype.markTagUnsorted = function (tag) { + this._unsortedTags.push(tag); + }; EntityList.prototype.add = function (entity) { if (this._entitiesToAdded.indexOf(entity) == -1) this._entitiesToAdded.push(entity); }; EntityList.prototype.remove = function (entity) { + if (!this._entitiesToRemove.contains(entity)) { + console.warn("You are trying to remove an entity (" + entity.name + ") that you already removed"); + return; + } if (this._entitiesToAdded.contains(entity)) { this._entitiesToAdded.remove(entity); return; @@ -3466,6 +3791,92 @@ var es; if (!this._entitiesToRemove.contains(entity)) this._entitiesToRemove.push(entity); }; + EntityList.prototype.removeAllEntities = function () { + this._unsortedTags.length = 0; + this._entitiesToAdded.length = 0; + this._isEntityListUnsorted = false; + this.updateLists(); + for (var i = 0; i < this._entities.length; i++) { + this._entities[i]._isDestroyed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + this._entities.length = 0; + this._entityDict.clear(); + }; + EntityList.prototype.contains = function (entity) { + return this._entities.contains(entity) || this._entitiesToAdded.contains(entity); + }; + EntityList.prototype.getTagList = function (tag) { + var list = this._entityDict.get(tag); + if (!list) { + list = []; + this._entityDict.set(tag, list); + } + return this._entityDict.get(tag); + }; + EntityList.prototype.addToTagList = function (entity) { + var list = this.getTagList(entity.tag); + if (!list.contains(entity)) { + list.push(entity); + this._unsortedTags.push(entity.tag); + } + }; + EntityList.prototype.removeFromTagList = function (entity) { + var list = this._entityDict.get(entity.tag); + if (list) { + list.remove(entity); + } + }; + EntityList.prototype.update = function () { + for (var i = 0; i < this._entities.length; i++) { + var entity = this._entities[i]; + if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0)) + entity.update(); + } + }; + EntityList.prototype.updateLists = function () { + var _this = this; + if (this._entitiesToRemove.length > 0) { + var temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + _this.removeFromTagList(entity); + _this._entities.remove(entity); + entity.onRemovedFromScene(); + entity.scene = null; + _this.scene.entityProcessors.onEntityRemoved(entity); + }); + this._tempEntityList.length = 0; + } + if (this._entitiesToAdded.length > 0) { + var temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + if (!_this._entities.contains(entity)) { + _this._entities.push(entity); + entity.scene = _this.scene; + _this.addToTagList(entity); + _this.scene.entityProcessors.onEntityAdded(entity); + } + }); + this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); + this._tempEntityList.length = 0; + this._isEntityListUnsorted = true; + } + if (this._isEntityListUnsorted) { + this._entities.sort(); + this._isEntityListUnsorted = false; + } + if (this._unsortedTags.length > 0) { + this._unsortedTags.forEach(function (tag) { + _this._entityDict.get(tag).sort(); + }); + this._unsortedTags.length = 0; + } + }; EntityList.prototype.findEntity = function (name) { for (var i = 0; i < this._entities.length; i++) { if (this._entities[i].name == name) @@ -3523,79 +3934,6 @@ var es; } return comps; }; - EntityList.prototype.getTagList = function (tag) { - var list = this._entityDict.get(tag); - if (!list) { - list = []; - this._entityDict.set(tag, list); - } - return this._entityDict.get(tag); - }; - EntityList.prototype.addToTagList = function (entity) { - var list = this.getTagList(entity.tag); - if (!list.contains(entity)) { - list.push(entity); - this._unsortedTags.push(entity.tag); - } - }; - EntityList.prototype.removeFromTagList = function (entity) { - var list = this._entityDict.get(entity.tag); - if (list) { - list.remove(entity); - } - }; - EntityList.prototype.update = function () { - for (var i = 0; i < this._entities.length; i++) { - var entity = this._entities[i]; - if (entity.enabled) - entity.update(); - } - }; - EntityList.prototype.removeAllEntities = function () { - this._entitiesToAdded.length = 0; - this.updateLists(); - for (var i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestroyed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; - } - this._entities.length = 0; - this._entityDict.clear(); - }; - EntityList.prototype.updateLists = function () { - var _this = this; - if (this._entitiesToRemove.length > 0) { - var temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - _this._entities.remove(entity); - entity.scene = null; - _this.scene.entityProcessors.onEntityRemoved(entity); - }); - this._tempEntityList.length = 0; - } - if (this._entitiesToAdded.length > 0) { - var temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - if (!_this._entities.contains(entity)) { - _this._entities.push(entity); - entity.scene = _this.scene; - _this.scene.entityProcessors.onEntityAdded(entity); - } - }); - this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); - this._tempEntityList.length = 0; - } - if (this._unsortedTags.length > 0) { - this._unsortedTags.forEach(function (tag) { - _this._entityDict.get(tag).sort(); - }); - this._unsortedTags.length = 0; - } - }; return EntityList; }()); es.EntityList = EntityList; @@ -5650,8 +5988,7 @@ var es; distanceSquared = tempDistanceSquared; closestPoint = closest; var line = es.Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; + edgeNormal = new es.Vector2(-line.y, line.x); } } edgeNormal = es.Vector2.normalize(edgeNormal); @@ -5672,7 +6009,7 @@ var es; if (collider.entity.transform.rotation != 0) { tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation); combinedMatrix = combinedMatrix.multiply(tempMat); - var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x); + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg; var offsetLength = hasUnitScale ? collider._localOffsetLength : es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 73b277e8..df2aad05 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return this.endDebugUpdate(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index acfa237f..deb26253 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -263,7 +263,7 @@ declare module es { onOrientationChanged(): void; protected onGraphicsDeviceReset(): void; protected initialize(): void; - protected update(): void; + protected update(): Promise; draw(): Promise; startDebugUpdate(): void; endDebugUpdate(): void; @@ -302,8 +302,16 @@ declare module es { parent: Transform; readonly childCount: number; position: Vector2; + localPosition: Vector2; rotation: number; + rotationDegrees: number; + localRotation: number; + localRotationDegrees: number; scale: Vector2; + localScale: Vector2; + readonly worldInverseTransform: Matrix2D; + readonly localToWorldTransform: Matrix2D; + readonly worldToLocalTransform: Matrix2D; constructor(name: string); onTransformChanged(comp: transform.Component): void; setTag(tag: number): Entity; @@ -325,6 +333,7 @@ declare module es { removeComponent(component: Component): void; removeComponentForType(type: any): boolean; removeAllComponents(): void; + compareTo(other: Entity): number; toString(): string; } } @@ -389,21 +398,56 @@ declare module es { parent: Transform; readonly childCount: number; position: Vector2; + localPosition: Vector2; rotation: number; + rotationDegrees: number; + localRotation: number; + localRotationDegrees: number; scale: Vector2; + localScale: Vector2; + readonly worldInverseTransform: Matrix2D; + readonly localToWorldTransform: Matrix2D; + readonly worldToLocalTransform: Matrix2D; _parent: Transform; hierarchyDirty: DirtyType; + _localDirty: boolean; + _localPositionDirty: boolean; + _localScaleDirty: boolean; + _localRotationDirty: boolean; + _positionDirty: boolean; + _worldToLocalDirty: boolean; + _worldInverseDirty: boolean; + _localTransform: Matrix2D; + _worldTransform: Matrix2D; + _worldToLocalTransform: Matrix2D; + _worldInverseTransform: Matrix2D; + _rotationMatrix: Matrix2D; + _translationMatrix: Matrix2D; + _scaleMatrix: Matrix2D; + _position: Vector2; + _scale: Vector2; + _rotation: number; + _localPosition: Vector2; + _localScale: Vector2; + _localRotation: number; _children: Transform[]; constructor(entity: Entity); getChild(index: number): Transform; setParent(parent: Transform): Transform; setPosition(x: number, y: number): Transform; - setRotation(degrees: number): Transform; - setScale(scale: Vector2): Transform; + setLocalPosition(localPosition: Vector2): Transform; + setRotation(radians: number): Transform; + setRotationDegrees(degrees: number): Transform; lookAt(pos: Vector2): void; + setLocalRotation(radians: number): this; + setLocalRotationDegrees(degrees: number): Transform; + setScale(scale: Vector2): Transform; + setLocalScale(scale: Vector2): Transform; roundPosition(): void; + updateTransform(): void; setDirty(dirtyFlagType: DirtyType): void; copyFrom(transform: Transform): void; + toString(): string; } } declare module es { @@ -796,28 +840,32 @@ declare module es { declare module es { class EntityList { scene: Scene; - private _entitiesToRemove; - private _entitiesToAdded; - private _tempEntityList; - private _entities; - private _entityDict; - private _unsortedTags; + _entities: Entity[]; + _entitiesToAdded: Entity[]; + _entitiesToRemove: Entity[]; + _isEntityListUnsorted: boolean; + _entityDict: Map; + _unsortedTags: number[]; + _tempEntityList: Entity[]; constructor(scene: Scene); readonly count: number; readonly buffer: Entity[]; + markEntityListUnsorted(): void; + markTagUnsorted(tag: number): void; add(entity: Entity): void; remove(entity: Entity): void; + removeAllEntities(): void; + contains(entity: Entity): boolean; + getTagList(tag: number): Entity[]; + addToTagList(entity: Entity): void; + removeFromTagList(entity: Entity): void; + update(): void; + updateLists(): void; findEntity(name: string): Entity; entitiesWithTag(tag: number): Entity[]; entitiesOfType(type: any): T[]; findComponentOfType(type: any): T; findComponentsOfType(type: any): T[]; - getTagList(tag: number): Entity[]; - addToTagList(entity: Entity): void; - removeFromTagList(entity: Entity): void; - update(): void; - removeAllEntities(): void; - updateLists(): void; } } declare module es { diff --git a/source/bin/framework.js b/source/bin/framework.js index ff829892..264328a4 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1156,26 +1156,37 @@ var es; Core.prototype.initialize = function () { }; Core.prototype.update = function () { - this.startDebugUpdate(); - es.Time.update(egret.getTimer()); - if (this._scene) { - for (var i = this._globalManagers.length - 1; i >= 0; i--) { - if (this._globalManagers[i].enabled) - this._globalManagers[i].update(); - } - if (!this._sceneTransition || - (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) { - this._scene.update(); - } - if (this._nextScene) { - this._scene.end(); - this._scene = this._nextScene; - this._nextScene = null; - this.onSceneChanged(); - this._scene.begin(); - } - } - this.endDebugUpdate(); + return __awaiter(this, void 0, void 0, function () { + var i; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + this.startDebugUpdate(); + es.Time.update(egret.getTimer()); + if (!this._scene) return [3, 2]; + for (i = this._globalManagers.length - 1; i >= 0; i--) { + if (this._globalManagers[i].enabled) + this._globalManagers[i].update(); + } + if (!this._sceneTransition || + (this._sceneTransition && (!this._sceneTransition.loadsNewScene || this._sceneTransition.isNewSceneLoaded))) { + this._scene.update(); + } + if (!this._nextScene) return [3, 2]; + this._scene.end(); + this._scene = this._nextScene; + this._nextScene = null; + this.onSceneChanged(); + return [4, this._scene.begin()]; + case 1: + _a.sent(); + _a.label = 2; + case 2: + this.endDebugUpdate(); + return [2]; + } + }); + }); }; Core.prototype.draw = function () { return __awaiter(this, void 0, void 0, function () { @@ -1338,6 +1349,16 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Entity.prototype, "localPosition", { + get: function () { + return this.transform.localPosition; + }, + set: function (value) { + this.transform.setLocalPosition(value); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Entity.prototype, "rotation", { get: function () { return this.transform.rotation; @@ -1348,6 +1369,36 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Entity.prototype, "rotationDegrees", { + get: function () { + return this.transform.rotationDegrees; + }, + set: function (value) { + this.transform.setRotationDegrees(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "localRotation", { + get: function () { + return this.transform.localRotation; + }, + set: function (value) { + this.transform.setLocalRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "localRotationDegrees", { + get: function () { + return this.transform.localRotationDegrees; + }, + set: function (value) { + this.transform.setLocalRotationDegrees(value); + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Entity.prototype, "scale", { get: function () { return this.transform.scale; @@ -1358,6 +1409,37 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Entity.prototype, "localScale", { + get: function () { + return this.transform.localScale; + }, + set: function (value) { + this.transform.setLocalScale(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "worldInverseTransform", { + get: function () { + return this.transform.worldInverseTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "localToWorldTransform", { + get: function () { + return this.transform.localToWorldTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Entity.prototype, "worldToLocalTransform", { + get: function () { + return this.transform.worldToLocalTransform; + }, + enumerable: true, + configurable: true + }); Entity.prototype.onTransformChanged = function (comp) { this.components.onEntityTransformChanged(comp); }; @@ -1385,6 +1467,8 @@ var es; if (this._updateOrder != updateOrder) { this._updateOrder = updateOrder; if (this.scene) { + this.scene.entities.markEntityListUnsorted(); + this.scene.entities.markTagUnsorted(this.tag); } return this; } @@ -1484,6 +1568,12 @@ var es; this.removeComponent(this.components.buffer[i]); } }; + Entity.prototype.compareTo = function (other) { + var compare = this._updateOrder - other._updateOrder; + if (compare == 0) + compare = this.id - other.id; + return compare; + }; Entity.prototype.toString = function () { return "[Entity: name: " + this.name + ", tag: " + this.tag + ", enabled: " + this.enabled + ", depth: " + this.updateOrder + "]"; }; @@ -1697,6 +1787,9 @@ var es; })(DirtyType = es.DirtyType || (es.DirtyType = {})); var Transform = (function () { function Transform(entity) { + this._worldTransform = es.Matrix2D.create().identity(); + this._worldToLocalTransform = es.Matrix2D.create().identity(); + this._worldInverseTransform = es.Matrix2D.create().identity(); this.entity = entity; this.scale = es.Vector2.one; this._children = []; @@ -1718,6 +1811,139 @@ var es; enumerable: true, configurable: true }); + Object.defineProperty(Transform.prototype, "position", { + get: function () { + this.updateTransform(); + if (this._positionDirty) { + if (!this.parent) { + this._position = this._localPosition; + } + else { + this.parent.updateTransform(); + this._position = es.Vector2Ext.transformR(this._localPosition, this.parent._worldTransform); + } + this._positionDirty = false; + } + return this._position; + }, + set: function (value) { + this.setPosition(value.x, value.y); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localPosition", { + get: function () { + this.updateTransform(); + return this._localPosition; + }, + set: function (value) { + this.setLocalPosition(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "rotation", { + get: function () { + this.updateTransform(); + return this._rotation; + }, + set: function (value) { + this.setRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "rotationDegrees", { + get: function () { + return es.MathHelper.toDegrees(this._rotation); + }, + set: function (value) { + this.setRotation(es.MathHelper.toRadians(value)); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localRotation", { + get: function () { + this.updateTransform(); + return this._localRotation; + }, + set: function (value) { + this.setLocalRotation(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localRotationDegrees", { + get: function () { + return es.MathHelper.toDegrees(this._localRotation); + }, + set: function (value) { + this.localRotation = es.MathHelper.toRadians(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "scale", { + get: function () { + this.updateTransform(); + return this._scale; + }, + set: function (value) { + this.setScale(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localScale", { + get: function () { + this.updateTransform(); + return this._localScale; + }, + set: function (value) { + this.setLocalScale(value); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "worldInverseTransform", { + get: function () { + this.updateTransform(); + if (this._worldInverseDirty) { + this._worldInverseTransform = this._worldTransform.invert(); + this._worldInverseDirty = false; + } + return this._worldInverseTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "localToWorldTransform", { + get: function () { + this.updateTransform(); + return this._worldTransform; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(Transform.prototype, "worldToLocalTransform", { + get: function () { + if (this._worldToLocalDirty) { + if (!this.parent) { + this._worldToLocalTransform = es.Matrix2D.create().identity(); + } + else { + this.parent.updateTransform(); + this._worldToLocalTransform = this.parent._worldTransform.invert(); + } + this._worldToLocalDirty = false; + } + return this._worldToLocalTransform; + }, + enumerable: true, + configurable: true + }); Transform.prototype.getChild = function (index) { return this._children[index]; }; @@ -1733,27 +1959,110 @@ var es; return this; }; Transform.prototype.setPosition = function (x, y) { - this.position = new es.Vector2(x, y); + var position = new es.Vector2(x, y); + if (position == this._position) + return this; + this._position = position; + if (this.parent) { + this.localPosition = es.Vector2Ext.transformR(this._position, this._worldToLocalTransform); + } + else { + this.localPosition = position; + } + this._positionDirty = false; + return this; + }; + Transform.prototype.setLocalPosition = function (localPosition) { + if (localPosition == this._localPosition) + return this; + this._localPosition = localPosition; + this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; this.setDirty(DirtyType.positionDirty); return this; }; - Transform.prototype.setRotation = function (degrees) { - this.rotation = degrees; - this.setDirty(DirtyType.rotationDirty); + Transform.prototype.setRotation = function (radians) { + this._rotation = radians; + if (this.parent) { + this.localRotation = this.parent.rotation + radians; + } + else { + this.localRotation = radians; + } return this; }; - Transform.prototype.setScale = function (scale) { - this.scale = scale; - this.setDirty(DirtyType.scaleDirty); - return this; + Transform.prototype.setRotationDegrees = function (degrees) { + return this.setRotation(es.MathHelper.toRadians(degrees)); }; Transform.prototype.lookAt = function (pos) { var sign = this.position.x > pos.x ? -1 : 1; var vectorToAlignTo = es.Vector2.normalize(es.Vector2.subtract(this.position, pos)); this.rotation = sign * Math.acos(es.Vector2.dot(vectorToAlignTo, es.Vector2.unitY)); }; + Transform.prototype.setLocalRotation = function (radians) { + this._localRotation = radians; + this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; + this.setDirty(DirtyType.rotationDirty); + return this; + }; + Transform.prototype.setLocalRotationDegrees = function (degrees) { + return this.setLocalRotation(es.MathHelper.toRadians(degrees)); + }; + Transform.prototype.setScale = function (scale) { + this._scale = scale; + if (this.parent) { + this.localScale = es.Vector2.divide(scale, this.parent._scale); + } + else { + this.localScale = scale; + } + return this; + }; + Transform.prototype.setLocalScale = function (scale) { + this._localScale = scale; + this._localDirty = this._positionDirty = this._localScaleDirty = true; + this.setDirty(DirtyType.scaleDirty); + return this; + }; Transform.prototype.roundPosition = function () { - this.position = this.position.round(); + this.position = this._position.round(); + }; + Transform.prototype.updateTransform = function () { + if (this.hierarchyDirty != DirtyType.clean) { + if (this.parent) + this.parent.updateTransform(); + if (this._localDirty) { + if (this._localPositionDirty) { + this._translationMatrix = es.Matrix2D.create().translate(this._localPosition.x, this._localPosition.y); + this._localPositionDirty = false; + } + if (this._localRotationDirty) { + this._rotationMatrix = es.Matrix2D.create().rotate(this._localRotation); + this._localRotationDirty = false; + } + if (this._localScaleDirty) { + this._scaleMatrix = es.Matrix2D.create().scale(this._localScale.x, this._localScale.y); + this._localScaleDirty = false; + } + this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix); + this._localTransform = this._localTransform.multiply(this._translationMatrix); + if (!this.parent) { + this._worldTransform = this._localTransform; + this._rotation = this._localRotation; + this._scale = this._localScale; + this._worldInverseDirty = true; + } + this._localDirty = false; + } + if (this.parent) { + this._worldTransform = this._localTransform.multiply(this.parent._worldTransform); + this._rotation = this._localRotation + this.parent._rotation; + this._scale = es.Vector2.multiply(this.parent._scale, this._localScale); + this._worldInverseDirty = true; + } + this._worldToLocalDirty = true; + this._positionDirty = true; + this.hierarchyDirty = DirtyType.clean; + } }; Transform.prototype.setDirty = function (dirtyFlagType) { if ((this.hierarchyDirty & dirtyFlagType) == 0) { @@ -1776,13 +2085,19 @@ var es; } }; Transform.prototype.copyFrom = function (transform) { - this.position = transform.position; - this.rotation = transform.rotation; - this.scale = transform.scale; + this._position = transform.position; + this._localPosition = transform._localPosition; + this._rotation = transform._rotation; + this._localRotation = transform._localRotation; + this._scale = transform._scale; + this._localScale = transform._localScale; this.setDirty(DirtyType.positionDirty); this.setDirty(DirtyType.rotationDirty); this.setDirty(DirtyType.scaleDirty); }; + Transform.prototype.toString = function () { + return "[Transform: parent: " + this.parent + ", position: " + this.position + ", rotation: " + this.rotation + ",\n scale: " + this.scale + ", localPosition: " + this._localPosition + ", localRotation: " + this._localRotation + ",\n localScale: " + this._localScale + "]"; + }; return Transform; }()); es.Transform = Transform; @@ -3432,12 +3747,12 @@ var es; (function (es) { var EntityList = (function () { function EntityList(scene) { - this._entitiesToRemove = []; - this._entitiesToAdded = []; - this._tempEntityList = []; this._entities = []; + this._entitiesToAdded = []; + this._entitiesToRemove = []; this._entityDict = new Map(); this._unsortedTags = []; + this._tempEntityList = []; this.scene = scene; } Object.defineProperty(EntityList.prototype, "count", { @@ -3454,11 +3769,21 @@ var es; enumerable: true, configurable: true }); + EntityList.prototype.markEntityListUnsorted = function () { + this._isEntityListUnsorted = true; + }; + EntityList.prototype.markTagUnsorted = function (tag) { + this._unsortedTags.push(tag); + }; EntityList.prototype.add = function (entity) { if (this._entitiesToAdded.indexOf(entity) == -1) this._entitiesToAdded.push(entity); }; EntityList.prototype.remove = function (entity) { + if (!this._entitiesToRemove.contains(entity)) { + console.warn("You are trying to remove an entity (" + entity.name + ") that you already removed"); + return; + } if (this._entitiesToAdded.contains(entity)) { this._entitiesToAdded.remove(entity); return; @@ -3466,6 +3791,92 @@ var es; if (!this._entitiesToRemove.contains(entity)) this._entitiesToRemove.push(entity); }; + EntityList.prototype.removeAllEntities = function () { + this._unsortedTags.length = 0; + this._entitiesToAdded.length = 0; + this._isEntityListUnsorted = false; + this.updateLists(); + for (var i = 0; i < this._entities.length; i++) { + this._entities[i]._isDestroyed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + this._entities.length = 0; + this._entityDict.clear(); + }; + EntityList.prototype.contains = function (entity) { + return this._entities.contains(entity) || this._entitiesToAdded.contains(entity); + }; + EntityList.prototype.getTagList = function (tag) { + var list = this._entityDict.get(tag); + if (!list) { + list = []; + this._entityDict.set(tag, list); + } + return this._entityDict.get(tag); + }; + EntityList.prototype.addToTagList = function (entity) { + var list = this.getTagList(entity.tag); + if (!list.contains(entity)) { + list.push(entity); + this._unsortedTags.push(entity.tag); + } + }; + EntityList.prototype.removeFromTagList = function (entity) { + var list = this._entityDict.get(entity.tag); + if (list) { + list.remove(entity); + } + }; + EntityList.prototype.update = function () { + for (var i = 0; i < this._entities.length; i++) { + var entity = this._entities[i]; + if (entity.enabled && (entity.updateInterval == 1 || es.Time.frameCount % entity.updateInterval == 0)) + entity.update(); + } + }; + EntityList.prototype.updateLists = function () { + var _this = this; + if (this._entitiesToRemove.length > 0) { + var temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + _this.removeFromTagList(entity); + _this._entities.remove(entity); + entity.onRemovedFromScene(); + entity.scene = null; + _this.scene.entityProcessors.onEntityRemoved(entity); + }); + this._tempEntityList.length = 0; + } + if (this._entitiesToAdded.length > 0) { + var temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(function (entity) { + if (!_this._entities.contains(entity)) { + _this._entities.push(entity); + entity.scene = _this.scene; + _this.addToTagList(entity); + _this.scene.entityProcessors.onEntityAdded(entity); + } + }); + this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); + this._tempEntityList.length = 0; + this._isEntityListUnsorted = true; + } + if (this._isEntityListUnsorted) { + this._entities.sort(); + this._isEntityListUnsorted = false; + } + if (this._unsortedTags.length > 0) { + this._unsortedTags.forEach(function (tag) { + _this._entityDict.get(tag).sort(); + }); + this._unsortedTags.length = 0; + } + }; EntityList.prototype.findEntity = function (name) { for (var i = 0; i < this._entities.length; i++) { if (this._entities[i].name == name) @@ -3523,79 +3934,6 @@ var es; } return comps; }; - EntityList.prototype.getTagList = function (tag) { - var list = this._entityDict.get(tag); - if (!list) { - list = []; - this._entityDict.set(tag, list); - } - return this._entityDict.get(tag); - }; - EntityList.prototype.addToTagList = function (entity) { - var list = this.getTagList(entity.tag); - if (!list.contains(entity)) { - list.push(entity); - this._unsortedTags.push(entity.tag); - } - }; - EntityList.prototype.removeFromTagList = function (entity) { - var list = this._entityDict.get(entity.tag); - if (list) { - list.remove(entity); - } - }; - EntityList.prototype.update = function () { - for (var i = 0; i < this._entities.length; i++) { - var entity = this._entities[i]; - if (entity.enabled) - entity.update(); - } - }; - EntityList.prototype.removeAllEntities = function () { - this._entitiesToAdded.length = 0; - this.updateLists(); - for (var i = 0; i < this._entities.length; i++) { - this._entities[i]._isDestroyed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; - } - this._entities.length = 0; - this._entityDict.clear(); - }; - EntityList.prototype.updateLists = function () { - var _this = this; - if (this._entitiesToRemove.length > 0) { - var temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - _this._entities.remove(entity); - entity.scene = null; - _this.scene.entityProcessors.onEntityRemoved(entity); - }); - this._tempEntityList.length = 0; - } - if (this._entitiesToAdded.length > 0) { - var temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(function (entity) { - if (!_this._entities.contains(entity)) { - _this._entities.push(entity); - entity.scene = _this.scene; - _this.scene.entityProcessors.onEntityAdded(entity); - } - }); - this._tempEntityList.forEach(function (entity) { return entity.onAddedToScene(); }); - this._tempEntityList.length = 0; - } - if (this._unsortedTags.length > 0) { - this._unsortedTags.forEach(function (tag) { - _this._entityDict.get(tag).sort(); - }); - this._unsortedTags.length = 0; - } - }; return EntityList; }()); es.EntityList = EntityList; @@ -5650,8 +5988,7 @@ var es; distanceSquared = tempDistanceSquared; closestPoint = closest; var line = es.Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; + edgeNormal = new es.Vector2(-line.y, line.x); } } edgeNormal = es.Vector2.normalize(edgeNormal); @@ -5672,7 +6009,7 @@ var es; if (collider.entity.transform.rotation != 0) { tempMat = es.Matrix2D.create().rotate(collider.entity.transform.rotation); combinedMatrix = combinedMatrix.multiply(tempMat); - var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x); + var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg; var offsetLength = hasUnitScale ? collider._localOffsetLength : es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 73b277e8..df2aad05 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),this._scene){for(var e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.endDebugUpdate()},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.roundPosition=function(){this.position=this.position.round()},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e}();t.EntityList=e}(es||(es={})),function(t){var e=function(){function e(){this._processors=[]}return e.prototype.add=function(t){this._processors.push(t)},e.prototype.remove=function(t){this._processors.remove(t)},e.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},e.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},e.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return this.endDebugUpdate(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Core.ts b/source/src/ECS/Core.ts index 2f4f714c..bdf7c53a 100644 --- a/source/src/ECS/Core.ts +++ b/source/src/ECS/Core.ts @@ -99,7 +99,7 @@ module es { protected initialize(){ } - protected update() { + protected async update() { this.startDebugUpdate(); // 更新我们所有的系统管理器 @@ -127,7 +127,7 @@ module es { this._nextScene = null; this.onSceneChanged(); - this._scene.begin(); + await this._scene.begin(); } } diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 0aa137d2..527e0a2d 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -107,6 +107,14 @@ module es { this.transform.setPosition(value.x, value.y); } + public get localPosition(): Vector2 { + return this.transform.localPosition; + } + + public set localPosition(value: Vector2){ + this.transform.setLocalPosition(value); + } + public get rotation(): number { return this.transform.rotation; } @@ -115,6 +123,29 @@ module es { this.transform.setRotation(value); } + public get rotationDegrees(): number { + return this.transform.rotationDegrees; + } + + public set rotationDegrees(value: number){ + this.transform.setRotationDegrees(value); + } + + public get localRotation(): number { + return this.transform.localRotation; + } + + public set localRotation(value: number){ + this.transform.setLocalRotation(value); + } + + public get localRotationDegrees(): number { + return this.transform.localRotationDegrees; + } + + public set localRotationDegrees(value: number){ + this.transform.setLocalRotationDegrees(value); + } public get scale(): Vector2 { return this.transform.scale; @@ -124,6 +155,26 @@ module es { this.transform.setScale(value); } + public get localScale(): Vector2 { + return this.transform.localScale; + } + + public set localScale(value: Vector2){ + this.transform.setLocalScale(value); + } + + public get worldInverseTransform(): Matrix2D { + return this.transform.worldInverseTransform; + } + + public get localToWorldTransform(): Matrix2D { + return this.transform.localToWorldTransform; + } + + public get worldToLocalTransform(): Matrix2D { + return this.transform.worldToLocalTransform; + } + constructor(name: string) { this.components = new ComponentList(this); this.transform = new Transform(this); @@ -180,8 +231,8 @@ module es { if (this._updateOrder != updateOrder) { this._updateOrder = updateOrder; if (this.scene) { - // TODO: markEntityListSorted - // markTagUnsorted + this.scene.entities.markEntityListUnsorted(); + this.scene.entities.markTagUnsorted(this.tag); } return this; @@ -370,6 +421,13 @@ module es { } } + public compareTo(other: Entity): number { + let compare = this._updateOrder - other._updateOrder; + if (compare == 0) + compare = this.id - other.id; + return compare; + } + public toString(): string { return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`; } diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts index 1a69464a..a3249369 100644 --- a/source/src/ECS/Transform.ts +++ b/source/src/ECS/Transform.ts @@ -42,18 +42,204 @@ module es { /** * 变换在世界空间中的位置 */ - public position: Vector2; + public get position(): Vector2 { + this.updateTransform(); + if (this._positionDirty){ + if (!this.parent){ + this._position = this._localPosition; + }else{ + this.parent.updateTransform(); + this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform); + } + + this._positionDirty = false; + } + + return this._position; + } + + /** + * 变换在世界空间中的位置 + * @param value + */ + public set position(value: Vector2){ + this.setPosition(value.x, value.y); + } + + /** + * 转换相对于父转换的位置。如果转换没有父元素,则与transform.position相同 + */ + public get localPosition(): Vector2 { + this.updateTransform(); + return this._localPosition; + } + + /** + * 转换相对于父转换的位置。如果转换没有父元素,则与transform.position相同 + * @param value + */ + public set localPosition(value: Vector2){ + this.setLocalPosition(value); + } + + /** + * 在世界空间中以弧度旋转的变换 + */ + public get rotation(): number { + this.updateTransform(); + return this._rotation; + } + /** * 变换在世界空间的旋转度 */ - public rotation: number; + public get rotationDegrees(): number { + return MathHelper.toDegrees(this._rotation); + } + + /** + * 变换在世界空间的旋转度 + * @param value + */ + public set rotationDegrees(value: number){ + this.setRotation(MathHelper.toRadians(value)); + } + + /** + * 变换在世界空间的旋转度 + * @param value + */ + public set rotation(value: number){ + this.setRotation(value); + } + + /** + * 相对于父变换的旋转,变换的旋转。如果转换没有父元素,则与transform.rotation相同 + */ + public get localRotation(): number { + this.updateTransform(); + return this._localRotation; + } + + /** + * 相对于父变换的旋转,变换的旋转。如果转换没有父元素,则与transform.rotation相同 + * @param value + */ + public set localRotation(value: number){ + this.setLocalRotation(value); + } + + /** + * 旋转相对于父变换旋转的角度 + */ + public get localRotationDegrees(): number { + return MathHelper.toDegrees(this._localRotation); + } + + /** + * 旋转相对于父变换旋转的角度 + * @param value + */ + public set localRotationDegrees(value: number){ + this.localRotation = MathHelper.toRadians(value); + } + /** * 变换在世界空间的缩放 */ - public scale: Vector2; + public get scale(): Vector2{ + this.updateTransform(); + return this._scale; + } + + /** + * 变换在世界空间的缩放 + * @param value + */ + public set scale(value: Vector2){ + this.setScale(value); + } + + /** + * 转换相对于父元素的比例。如果转换没有父元素,则与transform.scale相同 + */ + public get localScale(): Vector2 { + this.updateTransform(); + return this._localScale; + } + + /** + * 转换相对于父元素的比例。如果转换没有父元素,则与transform.scale相同 + * @param value + */ + public set localScale(value: Vector2){ + this.setLocalScale(value); + } + + public get worldInverseTransform(): Matrix2D { + this.updateTransform(); + if (this._worldInverseDirty){ + this._worldInverseTransform = this._worldTransform.invert(); + this._worldInverseDirty = false; + } + + return this._worldInverseTransform; + } + + public get localToWorldTransform(): Matrix2D { + this.updateTransform(); + return this._worldTransform; + } + + public get worldToLocalTransform(): Matrix2D { + if (this._worldToLocalDirty){ + if (!this.parent){ + this._worldToLocalTransform = Matrix2D.create().identity(); + }else{ + this.parent.updateTransform(); + this._worldToLocalTransform = this.parent._worldTransform.invert(); + } + + this._worldToLocalDirty = false; + } + + return this._worldToLocalTransform; + } public _parent: Transform; public hierarchyDirty: DirtyType; + + public _localDirty: boolean; + public _localPositionDirty: boolean; + public _localScaleDirty: boolean; + public _localRotationDirty: boolean; + public _positionDirty: boolean; + public _worldToLocalDirty: boolean; + public _worldInverseDirty: boolean; + + /** + * 值会根据位置、旋转和比例自动重新计算 + */ + public _localTransform: Matrix2D; + /** + * 值将自动从本地和父矩阵重新计算。 + */ + public _worldTransform = Matrix2D.create().identity(); + public _worldToLocalTransform = Matrix2D.create().identity(); + public _worldInverseTransform = Matrix2D.create().identity(); + + public _rotationMatrix: Matrix2D; + public _translationMatrix: Matrix2D; + public _scaleMatrix: Matrix2D; + + public _position: Vector2; + public _scale: Vector2; + public _rotation: number; + + public _localPosition: Vector2; + public _localScale: Vector2; + public _localRotation: number; + public _children: Transform[]; constructor(entity: Entity) { @@ -95,8 +281,49 @@ module es { * @param y */ public setPosition(x: number, y: number): Transform { - this.position = new Vector2(x, y); + let position = new Vector2(x, y); + if (position == this._position) + return this; + + this._position = position; + if (this.parent){ + this.localPosition = Vector2Ext.transformR(this._position, this._worldToLocalTransform); + } else { + this.localPosition = position; + } + this._positionDirty = false; + + return this; + } + + /** + * 设置转换相对于父转换的位置。如果转换没有父元素,则与transform.position相同 + * @param localPosition + */ + public setLocalPosition(localPosition: Vector2): Transform { + if (localPosition == this._localPosition) + return this; + + this._localPosition = localPosition; + this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; this.setDirty(DirtyType.positionDirty); + + return this; + } + + + /** + * 设置变换在世界空间的旋转度 + * @param radians + */ + public setRotation(radians: number): Transform { + this._rotation = radians; + if (this.parent){ + this.localRotation = this.parent.rotation + radians; + } else { + this.localRotation = radians; + } + return this; } @@ -104,20 +331,8 @@ module es { * 设置变换在世界空间的旋转度 * @param degrees */ - public setRotation(degrees: number): Transform { - this.rotation = degrees; - this.setDirty(DirtyType.rotationDirty); - return this; - } - - /** - * 设置变换在世界空间中的缩放 - * @param scale - */ - public setScale(scale: Vector2): Transform { - this.scale = scale; - this.setDirty(DirtyType.scaleDirty); - return this; + public setRotationDegrees(degrees: number): Transform { + return this.setRotation(MathHelper.toRadians(degrees)); } /** @@ -130,11 +345,105 @@ module es { this.rotation = sign * Math.acos(Vector2.dot(vectorToAlignTo, Vector2.unitY)); } + /** + * 相对于父变换的旋转设置变换的旋转。如果转换没有父元素,则与transform.rotation相同 + * @param radians + */ + public setLocalRotation(radians: number){ + this._localRotation = radians; + this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; + this.setDirty(DirtyType.rotationDirty); + + return this; + } + + /** + * 相对于父变换的旋转设置变换的旋转。如果转换没有父元素,则与transform.rotation相同 + * @param degrees + */ + public setLocalRotationDegrees(degrees: number): Transform { + return this.setLocalRotation(MathHelper.toRadians(degrees)); + } + + /** + * 设置变换在世界空间中的缩放 + * @param scale + */ + public setScale(scale: Vector2): Transform { + this._scale = scale; + if (this.parent){ + this.localScale = Vector2.divide(scale, this.parent._scale); + }else{ + this.localScale = scale; + } + return this; + } + + /** + * 设置转换相对于父对象的比例。如果转换没有父元素,则与transform.scale相同 + * @param scale + */ + public setLocalScale(scale: Vector2): Transform { + this._localScale = scale; + this._localDirty = this._positionDirty = this._localScaleDirty = true; + this.setDirty(DirtyType.scaleDirty); + + return this; + } + /** * 对精灵坐标进行四舍五入 */ public roundPosition() { - this.position = this.position.round(); + this.position = this._position.round(); + } + + public updateTransform(){ + if (this.hierarchyDirty != DirtyType.clean){ + if (this.parent) + this.parent.updateTransform(); + + if (this._localDirty){ + if (this._localPositionDirty){ + this._translationMatrix = Matrix2D.create().translate(this._localPosition.x, this._localPosition.y); + this._localPositionDirty = false; + } + + if (this._localRotationDirty){ + this._rotationMatrix = Matrix2D.create().rotate(this._localRotation); + this._localRotationDirty = false; + } + + if (this._localScaleDirty){ + this._scaleMatrix = Matrix2D.create().scale(this._localScale.x, this._localScale.y); + this._localScaleDirty = false; + } + + this._localTransform = this._scaleMatrix.multiply(this._rotationMatrix); + this._localTransform = this._localTransform.multiply(this._translationMatrix); + + if (!this.parent){ + this._worldTransform = this._localTransform; + this._rotation = this._localRotation; + this._scale = this._localScale; + this._worldInverseDirty = true; + } + + this._localDirty = false; + } + + if (this.parent){ + this._worldTransform = this._localTransform.multiply(this.parent._worldTransform); + + this._rotation = this._localRotation + this.parent._rotation; + this._scale = Vector2.multiply(this.parent._scale, this._localScale); + this._worldInverseDirty = true; + } + + this._worldToLocalDirty = true; + this._positionDirty = true; + this.hierarchyDirty = DirtyType.clean; + } } public setDirty(dirtyFlagType: DirtyType){ @@ -167,13 +476,22 @@ module es { * @param transform */ public copyFrom(transform: Transform) { - this.position = transform.position; - this.rotation = transform.rotation; - this.scale = transform.scale; + this._position = transform.position; + this._localPosition = transform._localPosition; + this._rotation = transform._rotation; + this._localRotation = transform._localRotation; + this._scale = transform._scale; + this._localScale = transform._localScale; this.setDirty(DirtyType.positionDirty); this.setDirty(DirtyType.rotationDirty); this.setDirty(DirtyType.scaleDirty); } + + public toString(): string{ + return `[Transform: parent: ${this.parent}, position: ${this.position}, rotation: ${this.rotation}, + scale: ${this.scale}, localPosition: ${this._localPosition}, localRotation: ${this._localRotation}, + localScale: ${this._localScale}]`; + } } } \ No newline at end of file diff --git a/source/src/ECS/Utils/EntityList.ts b/source/src/ECS/Utils/EntityList.ts index a30961a0..379bbca3 100644 --- a/source/src/ECS/Utils/EntityList.ts +++ b/source/src/ECS/Utils/EntityList.ts @@ -1,12 +1,31 @@ module es { export class EntityList{ public scene: Scene; - private _entitiesToRemove: Entity[] = []; - private _entitiesToAdded: Entity[] = []; - private _tempEntityList: Entity[] = []; - private _entities: Entity[] = []; - private _entityDict: Map = new Map(); - private _unsortedTags: number[] = []; + /** + * 添加到场景中的实体列表 + */ + public _entities: Entity[] = []; + /** + * 添加到此框架的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + */ + public _entitiesToAdded: Entity[] = []; + /** + * 标记要删除此框架的实体列表。用于对实体进行分组,以便我们可以同时处理它们 + */ + public _entitiesToRemove: Entity[] = []; + /** + * 用于确定是否需要在此框架中对实体进行排序的标志 + */ + public _isEntityListUnsorted: boolean; + /** + * 通过标签跟踪实体,便于检索 + */ + public _entityDict: Map = new Map(); + public _unsortedTags: number[] = []; + /** + * 在updateLists中用于双缓冲区,以便可以在其他地方修改原始列表 + */ + public _tempEntityList: Entity[] = []; constructor(scene: Scene){ this.scene = scene; @@ -20,12 +39,34 @@ module es { return this._entities; } + public markEntityListUnsorted(){ + this._isEntityListUnsorted = true; + } + + public markTagUnsorted(tag: number){ + this._unsortedTags.push(tag); + } + + /** + * 将实体添加到列表中。所有生命周期方法将在下一帧中被调用。 + * @param entity + */ public add(entity: Entity){ if (this._entitiesToAdded.indexOf(entity) == -1) this._entitiesToAdded.push(entity); } + /** + * 从列表中删除一个实体。所有生命周期方法将在下一帧中被调用。 + * @param entity + */ public remove(entity: Entity){ + if (!this._entitiesToRemove.contains(entity)){ + console.warn(`You are trying to remove an entity (${entity.name}) that you already removed`); + return; + } + + // 防止在同一帧中添加或删除实体 if (this._entitiesToAdded.contains(entity)){ this._entitiesToAdded.remove(entity); return; @@ -35,6 +76,126 @@ module es { this._entitiesToRemove.push(entity); } + /** + * 从实体列表中删除所有实体 + */ + public removeAllEntities(){ + this._unsortedTags.length = 0; + this._entitiesToAdded.length = 0; + this._isEntityListUnsorted = false; + + // 为什么我们要在这里更新列表?主要用于处理场景切换前分离的实体。 + // 它们仍然在_entitiesToRemove列表中,该列表将由更新列表处理。 + this.updateLists(); + + for (let i = 0; i < this._entities.length; i ++){ + this._entities[i]._isDestroyed = true; + this._entities[i].onRemovedFromScene(); + this._entities[i].scene = null; + } + + this._entities.length = 0; + this._entityDict.clear(); + } + + /** + * 检查该实体当前是否由此EntityList管理 + * @param entity + */ + public contains(entity: Entity): boolean { + return this._entities.contains(entity) || this._entitiesToAdded.contains(entity); + } + + public getTagList(tag: number){ + let list = this._entityDict.get(tag); + if (!list){ + list = []; + this._entityDict.set(tag, list); + } + + return this._entityDict.get(tag); + } + + public addToTagList(entity: Entity){ + let list = this.getTagList(entity.tag); + if (!list.contains(entity)){ + list.push(entity); + this._unsortedTags.push(entity.tag); + } + } + + public removeFromTagList(entity: Entity){ + let list = this._entityDict.get(entity.tag); + if (list){ + list.remove(entity); + } + } + + public update(){ + for (let i = 0; i < this._entities.length; i++){ + let entity = this._entities[i]; + if (entity.enabled && (entity.updateInterval == 1 || Time.frameCount % entity.updateInterval == 0)) + entity.update(); + } + } + + public updateLists(){ + if (this._entitiesToRemove.length > 0){ + let temp = this._entitiesToRemove; + this._entitiesToRemove = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(entity => { + this.removeFromTagList(entity); + + this._entities.remove(entity); + entity.onRemovedFromScene(); + entity.scene = null; + + this.scene.entityProcessors.onEntityRemoved(entity); + }); + + this._tempEntityList.length = 0; + } + + if (this._entitiesToAdded.length > 0){ + let temp = this._entitiesToAdded; + this._entitiesToAdded = this._tempEntityList; + this._tempEntityList = temp; + this._tempEntityList.forEach(entity => { + if (!this._entities.contains(entity)){ + this._entities.push(entity); + entity.scene = this.scene; + + this.addToTagList(entity); + + this.scene.entityProcessors.onEntityAdded(entity) + } + }); + + // 现在所有实体都被添加到场景中,我们再次循环并调用onAddedToScene + this._tempEntityList.forEach(entity => entity.onAddedToScene()); + this._tempEntityList.length = 0; + this._isEntityListUnsorted = true; + } + + if (this._isEntityListUnsorted){ + this._entities.sort(); + this._isEntityListUnsorted = false; + } + + if (this._unsortedTags.length > 0){ + this._unsortedTags.forEach(tag => { + this._entityDict.get(tag).sort(); + }); + + this._unsortedTags.length = 0; + } + } + + /** + * 返回找到的第一个实体的名称。如果没有找到,则返回null。 + * @param name + */ public findEntity(name: string){ for (let i = 0; i < this._entities.length; i ++){ if (this._entities[i].name == name) @@ -120,94 +281,5 @@ module es { return comps; } - - public getTagList(tag: number){ - let list = this._entityDict.get(tag); - if (!list){ - list = []; - this._entityDict.set(tag, list); - } - - return this._entityDict.get(tag); - } - - public addToTagList(entity: Entity){ - let list = this.getTagList(entity.tag); - if (!list.contains(entity)){ - list.push(entity); - this._unsortedTags.push(entity.tag); - } - } - - public removeFromTagList(entity: Entity){ - let list = this._entityDict.get(entity.tag); - if (list){ - list.remove(entity); - } - } - - public update(){ - for (let i = 0; i < this._entities.length; i++){ - let entity = this._entities[i]; - if (entity.enabled) - entity.update(); - } - } - - public removeAllEntities(){ - this._entitiesToAdded.length = 0; - - this.updateLists(); - - for (let i = 0; i < this._entities.length; i ++){ - this._entities[i]._isDestroyed = true; - this._entities[i].onRemovedFromScene(); - this._entities[i].scene = null; - } - - this._entities.length = 0; - this._entityDict.clear(); - } - - public updateLists(){ - if (this._entitiesToRemove.length > 0){ - let temp = this._entitiesToRemove; - this._entitiesToRemove = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(entity => { - this._entities.remove(entity); - entity.scene = null; - - this.scene.entityProcessors.onEntityRemoved(entity); - }); - - this._tempEntityList.length = 0; - } - - if (this._entitiesToAdded.length > 0){ - let temp = this._entitiesToAdded; - this._entitiesToAdded = this._tempEntityList; - this._tempEntityList = temp; - this._tempEntityList.forEach(entity => { - if (!this._entities.contains(entity)){ - this._entities.push(entity); - entity.scene = this.scene; - - this.scene.entityProcessors.onEntityAdded(entity) - } - }); - - this._tempEntityList.forEach(entity => entity.onAddedToScene()); - this._tempEntityList.length = 0; - } - - if (this._unsortedTags.length > 0){ - this._unsortedTags.forEach(tag => { - this._entityDict.get(tag).sort(); - }); - - this._unsortedTags.length = 0; - } - } } } diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index 4493d380..2904800f 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -162,8 +162,7 @@ module es { // 求直线的法线 let line = Vector2.subtract(points[j], points[i]); - edgeNormal.x = -line.y; - edgeNormal.y = line.x; + edgeNormal = new Vector2(-line.y, line.x); } } @@ -196,7 +195,7 @@ module es { // 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动 // 我们的偏移使角度为0我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。 - let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x); + let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; let offsetLength = hasUnitScale ? collider._localOffsetLength : Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length(); this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, From 2b13e5ee7d2b052c2e053210142315f0ff6e9a83 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Fri, 24 Jul 2020 16:57:26 +0800 Subject: [PATCH 11/15] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=95=B0=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.d.ts | 2 + demo/libs/framework/framework.js | 79 +++++++++++++++++++++++----- demo/libs/framework/framework.min.js | 2 +- demo/src/Main.ts | 18 ++++--- source/bin/framework.d.ts | 2 + source/bin/framework.js | 77 ++++++++++++++++++++++----- source/bin/framework.min.js | 2 +- source/src/ECS/Components/Camera.ts | 16 +++--- source/src/ECS/Core.ts | 7 ++- source/src/ECS/Transform.ts | 20 +++---- source/src/Math/Matrix2D.ts | 53 ++++++++++++++++--- 11 files changed, 217 insertions(+), 61 deletions(-) diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index deb26253..cc4d4203 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -1165,6 +1165,7 @@ declare module es { } } declare module es { + var matrixPool: any[]; class Matrix2D extends egret.Matrix { m11: number; m12: number; @@ -1183,6 +1184,7 @@ declare module es { divide(matrix: Matrix2D): Matrix2D; multiply(matrix: Matrix2D): Matrix2D; determinant(): number; + release(matrix: Matrix2D): void; } } declare module es { diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index 264328a4..f16162b6 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -14,7 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); + }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; @@ -1129,6 +1129,7 @@ var es; } if (this._instance._scene == null) { this._instance._scene = value; + this._instance.addChild(value); this._instance._scene.begin(); Core.Instance.onSceneChanged(); } @@ -1161,7 +1162,6 @@ var es; return __generator(this, function (_a) { switch (_a.label) { case 0: - this.startDebugUpdate(); es.Time.update(egret.getTimer()); if (!this._scene) return [3, 2]; for (i = this._globalManagers.length - 1; i >= 0; i--) { @@ -1173,17 +1173,17 @@ var es; this._scene.update(); } if (!this._nextScene) return [3, 2]; + this.removeChild(this._scene); this._scene.end(); this._scene = this._nextScene; this._nextScene = null; this.onSceneChanged(); + this.addChild(this._scene); return [4, this._scene.begin()]; case 1: _a.sent(); _a.label = 2; - case 2: - this.endDebugUpdate(); - return [2]; + case 2: return [2]; } }); }); @@ -1787,9 +1787,19 @@ var es; })(DirtyType = es.DirtyType || (es.DirtyType = {})); var Transform = (function () { function Transform(entity) { + this._localTransform = es.Matrix2D.create(); this._worldTransform = es.Matrix2D.create().identity(); this._worldToLocalTransform = es.Matrix2D.create().identity(); this._worldInverseTransform = es.Matrix2D.create().identity(); + this._rotationMatrix = es.Matrix2D.create(); + this._translationMatrix = es.Matrix2D.create(); + this._scaleMatrix = es.Matrix2D.create(); + this._position = es.Vector2.zero; + this._scale = es.Vector2.one; + this._rotation = 0; + this._localPosition = es.Vector2.zero; + this._localScale = es.Vector2.one; + this._localRotation = 0; this.entity = entity; this.scale = es.Vector2.one; this._children = []; @@ -2111,6 +2121,10 @@ var es; })(CameraStyle = es.CameraStyle || (es.CameraStyle = {})); var CameraInset = (function () { function CameraInset() { + this.left = 0; + this.right = 0; + this.top = 0; + this.bottom = 0; } return CameraInset; }()); @@ -2123,6 +2137,8 @@ var es; var _this = _super.call(this) || this; _this._minimumZoom = 0.3; _this._maximumZoom = 3; + _this._bounds = new es.Rectangle(); + _this._inset = new CameraInset(); _this._transformMatrix = new es.Matrix2D().identity(); _this._inverseTransformMatrix = new es.Matrix2D().identity(); _this._origin = es.Vector2.zero; @@ -2131,9 +2147,9 @@ var es; _this._isProjectionMatrixDirty = true; _this.followLerp = 0.1; _this.deadzone = new es.Rectangle(); - _this.focusOffset = new es.Vector2(); + _this.focusOffset = es.Vector2.zero; _this.mapLockEnabled = false; - _this.mapSize = new es.Vector2(); + _this.mapSize = es.Vector2.zero; _this._desiredPositionDelta = new es.Vector2(); _this._worldSpaceDeadZone = new es.Rectangle(); _this._targetEntity = targetEntity; @@ -5317,6 +5333,7 @@ var es; })(es || (es = {})); var es; (function (es) { + es.matrixPool = []; var Matrix2D = (function (_super) { __extends(Matrix2D, _super); function Matrix2D() { @@ -5383,26 +5400,57 @@ var es; configurable: true }); Matrix2D.create = function () { - return egret.Matrix.create(); + var matrix = es.matrixPool.pop(); + if (!matrix) + matrix = new Matrix2D(); + return matrix; }; Matrix2D.prototype.identity = function () { - _super.prototype.identity.call(this); + this.a = this.d = 1; + this.b = this.c = this.tx = this.ty = 0; return this; }; Matrix2D.prototype.translate = function (dx, dy) { - _super.prototype.translate.call(this, dx, dy); + this.tx += dx; + this.ty += dy; return this; }; Matrix2D.prototype.scale = function (sx, sy) { - _super.prototype.scale.call(this, sx, sy); + if (sx !== 1) { + this.a *= sx; + this.c *= sx; + this.tx *= sx; + } + if (sy !== 1) { + this.b *= sy; + this.d *= sy; + this.ty *= sy; + } return this; }; Matrix2D.prototype.rotate = function (angle) { - _super.prototype.rotate.call(this, angle); + angle = +angle; + if (angle !== 0) { + angle = angle / DEG_TO_RAD; + var u = Math.cos(angle); + var v = Math.sin(angle); + var ta = this.a; + var tb = this.b; + var tc = this.c; + var td = this.d; + var ttx = this.tx; + var tty = this.ty; + this.a = ta * u - tb * v; + this.b = ta * v + tb * u; + this.c = tc * u - td * v; + this.d = tc * v + td * u; + this.tx = ttx * u - tty * v; + this.ty = ttx * v + tty * u; + } return this; }; Matrix2D.prototype.invert = function () { - _super.prototype.invert.call(this); + this.$invertInto(this); return this; }; Matrix2D.prototype.add = function (matrix) { @@ -5450,6 +5498,11 @@ var es; Matrix2D.prototype.determinant = function () { return this.m11 * this.m22 - this.m12 * this.m21; }; + Matrix2D.prototype.release = function (matrix) { + if (!matrix) + return; + es.matrixPool.push(matrix); + }; return Matrix2D; }(egret.Matrix)); es.Matrix2D = Matrix2D; diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index df2aad05..77a3ade8 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return this.endDebugUpdate(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/demo/src/Main.ts b/demo/src/Main.ts index 155539af..bd2f177c 100644 --- a/demo/src/Main.ts +++ b/demo/src/Main.ts @@ -28,23 +28,25 @@ ////////////////////////////////////////////////////////////////////////////////////// class Main extends es.Core { - protected async initialize() { - await this.runGame(); + protected initialize() { + this.runGame(); } - private async runGame() { - await this.loadResource(); + private runGame() { + this.loadResource(); this.createGameScene(); } - private async loadResource() { + private loadResource() { try { const loadingView = new LoadingUI(); this.stage.addChild(loadingView); - await RES.loadConfig("resource/default.res.json", "resource/"); - await RES.loadGroup("preload", 0, loadingView); - this.stage.removeChild(loadingView); + RES.loadConfig("resource/default.res.json", "resource/").then(()=>{ + RES.loadGroup("preload", 0, loadingView).then(()=>{ + this.stage.removeChild(loadingView); + }); + }); } catch (e) { console.error(e); diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index deb26253..cc4d4203 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -1165,6 +1165,7 @@ declare module es { } } declare module es { + var matrixPool: any[]; class Matrix2D extends egret.Matrix { m11: number; m12: number; @@ -1183,6 +1184,7 @@ declare module es { divide(matrix: Matrix2D): Matrix2D; multiply(matrix: Matrix2D): Matrix2D; determinant(): number; + release(matrix: Matrix2D): void; } } declare module es { diff --git a/source/bin/framework.js b/source/bin/framework.js index 264328a4..f6f70f14 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -1129,6 +1129,7 @@ var es; } if (this._instance._scene == null) { this._instance._scene = value; + this._instance.addChild(value); this._instance._scene.begin(); Core.Instance.onSceneChanged(); } @@ -1161,7 +1162,6 @@ var es; return __generator(this, function (_a) { switch (_a.label) { case 0: - this.startDebugUpdate(); es.Time.update(egret.getTimer()); if (!this._scene) return [3, 2]; for (i = this._globalManagers.length - 1; i >= 0; i--) { @@ -1173,17 +1173,17 @@ var es; this._scene.update(); } if (!this._nextScene) return [3, 2]; + this.removeChild(this._scene); this._scene.end(); this._scene = this._nextScene; this._nextScene = null; this.onSceneChanged(); + this.addChild(this._scene); return [4, this._scene.begin()]; case 1: _a.sent(); _a.label = 2; - case 2: - this.endDebugUpdate(); - return [2]; + case 2: return [2]; } }); }); @@ -1787,9 +1787,19 @@ var es; })(DirtyType = es.DirtyType || (es.DirtyType = {})); var Transform = (function () { function Transform(entity) { + this._localTransform = es.Matrix2D.create(); this._worldTransform = es.Matrix2D.create().identity(); this._worldToLocalTransform = es.Matrix2D.create().identity(); this._worldInverseTransform = es.Matrix2D.create().identity(); + this._rotationMatrix = es.Matrix2D.create(); + this._translationMatrix = es.Matrix2D.create(); + this._scaleMatrix = es.Matrix2D.create(); + this._position = es.Vector2.zero; + this._scale = es.Vector2.one; + this._rotation = 0; + this._localPosition = es.Vector2.zero; + this._localScale = es.Vector2.one; + this._localRotation = 0; this.entity = entity; this.scale = es.Vector2.one; this._children = []; @@ -2111,6 +2121,10 @@ var es; })(CameraStyle = es.CameraStyle || (es.CameraStyle = {})); var CameraInset = (function () { function CameraInset() { + this.left = 0; + this.right = 0; + this.top = 0; + this.bottom = 0; } return CameraInset; }()); @@ -2123,6 +2137,8 @@ var es; var _this = _super.call(this) || this; _this._minimumZoom = 0.3; _this._maximumZoom = 3; + _this._bounds = new es.Rectangle(); + _this._inset = new CameraInset(); _this._transformMatrix = new es.Matrix2D().identity(); _this._inverseTransformMatrix = new es.Matrix2D().identity(); _this._origin = es.Vector2.zero; @@ -2131,9 +2147,9 @@ var es; _this._isProjectionMatrixDirty = true; _this.followLerp = 0.1; _this.deadzone = new es.Rectangle(); - _this.focusOffset = new es.Vector2(); + _this.focusOffset = es.Vector2.zero; _this.mapLockEnabled = false; - _this.mapSize = new es.Vector2(); + _this.mapSize = es.Vector2.zero; _this._desiredPositionDelta = new es.Vector2(); _this._worldSpaceDeadZone = new es.Rectangle(); _this._targetEntity = targetEntity; @@ -5317,6 +5333,7 @@ var es; })(es || (es = {})); var es; (function (es) { + es.matrixPool = []; var Matrix2D = (function (_super) { __extends(Matrix2D, _super); function Matrix2D() { @@ -5383,26 +5400,57 @@ var es; configurable: true }); Matrix2D.create = function () { - return egret.Matrix.create(); + var matrix = es.matrixPool.pop(); + if (!matrix) + matrix = new Matrix2D(); + return matrix; }; Matrix2D.prototype.identity = function () { - _super.prototype.identity.call(this); + this.a = this.d = 1; + this.b = this.c = this.tx = this.ty = 0; return this; }; Matrix2D.prototype.translate = function (dx, dy) { - _super.prototype.translate.call(this, dx, dy); + this.tx += dx; + this.ty += dy; return this; }; Matrix2D.prototype.scale = function (sx, sy) { - _super.prototype.scale.call(this, sx, sy); + if (sx !== 1) { + this.a *= sx; + this.c *= sx; + this.tx *= sx; + } + if (sy !== 1) { + this.b *= sy; + this.d *= sy; + this.ty *= sy; + } return this; }; Matrix2D.prototype.rotate = function (angle) { - _super.prototype.rotate.call(this, angle); + angle = +angle; + if (angle !== 0) { + angle = angle / DEG_TO_RAD; + var u = Math.cos(angle); + var v = Math.sin(angle); + var ta = this.a; + var tb = this.b; + var tc = this.c; + var td = this.d; + var ttx = this.tx; + var tty = this.ty; + this.a = ta * u - tb * v; + this.b = ta * v + tb * u; + this.c = tc * u - td * v; + this.d = tc * v + td * u; + this.tx = ttx * u - tty * v; + this.ty = ttx * v + tty * u; + } return this; }; Matrix2D.prototype.invert = function () { - _super.prototype.invert.call(this); + this.$invertInto(this); return this; }; Matrix2D.prototype.add = function (matrix) { @@ -5450,6 +5498,11 @@ var es; Matrix2D.prototype.determinant = function () { return this.m11 * this.m22 - this.m12 * this.m21; }; + Matrix2D.prototype.release = function (matrix) { + if (!matrix) + return; + es.matrixPool.push(matrix); + }; return Matrix2D; }(egret.Matrix)); es.Matrix2D = Matrix2D; diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index df2aad05..77a3ade8 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(this.startDebugUpdate(),t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return this.endDebugUpdate(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),e.create=function(){return egret.Matrix.create()},e.prototype.identity=function(){return t.prototype.identity.call(this),this},e.prototype.translate=function(e,n){return t.prototype.translate.call(this,e,n),this},e.prototype.scale=function(e,n){return t.prototype.scale.call(this,e,n),this},e.prototype.rotate=function(e){return t.prototype.rotate.call(this,e),this},e.prototype.invert=function(){return t.prototype.invert.call(this),this},e.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},e.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},e.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},e.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Components/Camera.ts b/source/src/ECS/Components/Camera.ts index fae49cb1..e3a61854 100644 --- a/source/src/ECS/Components/Camera.ts +++ b/source/src/ECS/Components/Camera.ts @@ -5,10 +5,10 @@ module es { } export class CameraInset { - public left: number; - public right: number; - public top: number; - public bottom: number; + public left: number = 0; + public right: number = 0; + public top: number = 0; + public bottom: number = 0; } export class Camera extends Component { @@ -167,8 +167,8 @@ module es { public _zoom; public _minimumZoom = 0.3; public _maximumZoom = 3; - public _bounds: Rectangle; - public _inset: CameraInset; + public _bounds: Rectangle = new Rectangle(); + public _inset: CameraInset = new CameraInset(); public _transformMatrix: Matrix2D = new Matrix2D().identity(); public _inverseTransformMatrix: Matrix2D = new Matrix2D().identity(); public _origin: Vector2 = Vector2.zero; @@ -190,7 +190,7 @@ module es { /** * 相机聚焦于屏幕中心的偏移 */ - public focusOffset: Vector2 = new Vector2(); + public focusOffset: Vector2 = Vector2.zero; /** * 如果为true 相机位置则不会超出地图矩形(0, 0, mapwidth, mapheight) */ @@ -198,7 +198,7 @@ module es { /** * 當前地圖映射的寬度和高度 */ - public mapSize: Vector2 = new Vector2(); + public mapSize: Vector2 = Vector2.zero; public _targetEntity: Entity; public _targetCollider: Collider; diff --git a/source/src/ECS/Core.ts b/source/src/ECS/Core.ts index bdf7c53a..4681d637 100644 --- a/source/src/ECS/Core.ts +++ b/source/src/ECS/Core.ts @@ -57,6 +57,7 @@ module es { if (this._instance._scene == null) { this._instance._scene = value; + this._instance.addChild(value); this._instance._scene.begin(); Core.Instance.onSceneChanged(); } else { @@ -100,7 +101,7 @@ module es { } protected async update() { - this.startDebugUpdate(); + // this.startDebugUpdate(); // 更新我们所有的系统管理器 Time.update(egret.getTimer()); @@ -121,17 +122,19 @@ module es { } if (this._nextScene) { + this.removeChild(this._scene); this._scene.end(); this._scene = this._nextScene; this._nextScene = null; this.onSceneChanged(); + this.addChild(this._scene); await this._scene.begin(); } } - this.endDebugUpdate(); + // this.endDebugUpdate(); } public async draw() { diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts index a3249369..34850e97 100644 --- a/source/src/ECS/Transform.ts +++ b/source/src/ECS/Transform.ts @@ -220,7 +220,7 @@ module es { /** * 值会根据位置、旋转和比例自动重新计算 */ - public _localTransform: Matrix2D; + public _localTransform: Matrix2D = Matrix2D.create(); /** * 值将自动从本地和父矩阵重新计算。 */ @@ -228,17 +228,17 @@ module es { public _worldToLocalTransform = Matrix2D.create().identity(); public _worldInverseTransform = Matrix2D.create().identity(); - public _rotationMatrix: Matrix2D; - public _translationMatrix: Matrix2D; - public _scaleMatrix: Matrix2D; + public _rotationMatrix: Matrix2D = Matrix2D.create(); + public _translationMatrix: Matrix2D = Matrix2D.create(); + public _scaleMatrix: Matrix2D = Matrix2D.create(); - public _position: Vector2; - public _scale: Vector2; - public _rotation: number; + public _position: Vector2 = Vector2.zero; + public _scale: Vector2 = Vector2.one; + public _rotation: number = 0; - public _localPosition: Vector2; - public _localScale: Vector2; - public _localRotation: number; + public _localPosition: Vector2 = Vector2.zero; + public _localScale: Vector2 = Vector2.one; + public _localRotation: number = 0; public _children: Transform[]; diff --git a/source/src/Math/Matrix2D.ts b/source/src/Math/Matrix2D.ts index f6d32cb6..cb91de0e 100644 --- a/source/src/Math/Matrix2D.ts +++ b/source/src/Math/Matrix2D.ts @@ -1,4 +1,5 @@ module es { + export var matrixPool = []; /** * 表示右手3 * 3的浮点矩阵,可以存储平移、缩放和旋转信息。 */ @@ -40,32 +41,66 @@ module es { this.ty = value; } + /** + * 从对象池中取出或创建一个新的Matrix对象。 + */ public static create(): Matrix2D{ - return egret.Matrix.create() as Matrix2D; + let matrix = matrixPool.pop(); + if (!matrix) + matrix = new Matrix2D(); + return matrix; } public identity(): Matrix2D{ - super.identity(); + this.a = this.d = 1; + this.b = this.c = this.tx = this.ty = 0; return this; } public translate(dx: number, dy: number): Matrix2D { - super.translate(dx, dy); + this.tx += dx; + this.ty += dy; return this; } public scale(sx: number, sy: number): Matrix2D { - super.scale(sx, sy); + if (sx !== 1){ + this.a *= sx; + this.c *= sx; + this.tx *= sx; + } + if (sy !== 1){ + this.b *= sy; + this.d *= sy; + this.ty *= sy; + } return this; } public rotate(angle: number): Matrix2D { - super.rotate(angle); + angle = +angle; + if (angle !== 0) { + angle = angle / DEG_TO_RAD; + let u = Math.cos(angle); + let v = Math.sin(angle); + let ta = this.a; + let tb = this.b; + let tc = this.c; + let td = this.d; + let ttx = this.tx; + let tty = this.ty; + this.a = ta * u - tb * v; + this.b = ta * v + tb * u; + this.c = tc * u - td * v; + this.d = tc * v + td * u; + this.tx = ttx * u - tty * v; + this.ty = ttx * v + tty * u; + } return this; } public invert(): Matrix2D { - super.invert(); + this.$invertInto(this); return this; } @@ -137,5 +172,11 @@ module es { public determinant(){ return this.m11 * this.m22 - this.m12 * this.m21; } + + public release(matrix: Matrix2D) { + if (!matrix) + return; + matrixPool.push(matrix); + } } } From 149a3e58336d1ce9b18a1dccba97b7db50e73560 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 26 Jul 2020 23:27:42 +0800 Subject: [PATCH 12/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtostring=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E5=BE=AA=E7=8E=AFmaxinum=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/.idea/.gitignore | 2 ++ demo/.idea/demo.iml | 8 +++++++ demo/.idea/misc.xml | 6 +++++ demo/.idea/modules.xml | 8 +++++++ demo/.idea/vcs.xml | 6 +++++ demo/libs/framework/framework.js | 4 ++-- demo/libs/framework/framework.min.js | 2 +- demo/src/Main.ts | 23 +++++++++---------- demo/tsconfig.json | 1 + source/bin/framework.js | 2 +- source/bin/framework.min.js | 2 +- .../src/ECS/Components/RenderableComponent.ts | 2 +- 12 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 demo/.idea/.gitignore create mode 100644 demo/.idea/demo.iml create mode 100644 demo/.idea/misc.xml create mode 100644 demo/.idea/modules.xml create mode 100644 demo/.idea/vcs.xml diff --git a/demo/.idea/.gitignore b/demo/.idea/.gitignore new file mode 100644 index 00000000..e7e9d11d --- /dev/null +++ b/demo/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/demo/.idea/demo.iml b/demo/.idea/demo.iml new file mode 100644 index 00000000..c956989b --- /dev/null +++ b/demo/.idea/demo.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/demo/.idea/misc.xml b/demo/.idea/misc.xml new file mode 100644 index 00000000..28a804d8 --- /dev/null +++ b/demo/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/demo/.idea/modules.xml b/demo/.idea/modules.xml new file mode 100644 index 00000000..c95e899e --- /dev/null +++ b/demo/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/demo/.idea/vcs.xml b/demo/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/demo/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index f16162b6..d10ed324 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -14,7 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); + }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; @@ -2597,7 +2597,7 @@ var es; return this; }; RenderableComponent.prototype.toString = function () { - return "[RenderableComponent] " + this + ", renderLayer: " + this.renderLayer; + return "[RenderableComponent] renderLayer: " + this.renderLayer; }; return RenderableComponent; }(es.Component)); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 77a3ade8..7129fc46 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/demo/src/Main.ts b/demo/src/Main.ts index bd2f177c..0ac8bbb8 100644 --- a/demo/src/Main.ts +++ b/demo/src/Main.ts @@ -34,23 +34,22 @@ class Main extends es.Core { private runGame() { this.loadResource(); - this.createGameScene(); } private loadResource() { - try { - const loadingView = new LoadingUI(); - this.stage.addChild(loadingView); - RES.loadConfig("resource/default.res.json", "resource/").then(()=>{ - RES.loadGroup("preload", 0, loadingView).then(()=>{ - this.stage.removeChild(loadingView); - }); + const loadingView = new LoadingUI(); + this.stage.addChild(loadingView); + RES.loadConfig("resource/default.res.json", "resource/").then(()=>{ + RES.loadGroup("preload", 0, loadingView).then(()=>{ + this.stage.removeChild(loadingView); + this.createGameScene(); + }).catch(err => { + console.error(err); }); - } - catch (e) { - console.error(e); - } + }).catch(err =>{ + console.error(err); + }); } /** diff --git a/demo/tsconfig.json b/demo/tsconfig.json index 5737e5ba..23bf9dbf 100644 --- a/demo/tsconfig.json +++ b/demo/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "es5", "outDir": "bin-debug", + "sourceMap": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, "lib": [ diff --git a/source/bin/framework.js b/source/bin/framework.js index f6f70f14..d10ed324 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -2597,7 +2597,7 @@ var es; return this; }; RenderableComponent.prototype.toString = function () { - return "[RenderableComponent] " + this + ", renderLayer: " + this.renderLayer; + return "[RenderableComponent] renderLayer: " + this.renderLayer; }; return RenderableComponent; }(es.Component)); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 77a3ade8..7129fc46 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] "+this+", renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Components/RenderableComponent.ts b/source/src/ECS/Components/RenderableComponent.ts index 8a961eb1..a99e5678 100644 --- a/source/src/ECS/Components/RenderableComponent.ts +++ b/source/src/ECS/Components/RenderableComponent.ts @@ -166,7 +166,7 @@ module es { } public toString(){ - return `[RenderableComponent] ${this}, renderLayer: ${this.renderLayer}`; + return `[RenderableComponent] renderLayer: ${this.renderLayer}`; } } } \ No newline at end of file From 506f8ddc0fcebcf278d6d405d2faa49a999887cc Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Mon, 27 Jul 2020 16:10:36 +0800 Subject: [PATCH 13/15] =?UTF-8?q?=E6=96=B0=E5=A2=9Erenderablecomponent?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20=E4=BC=98=E5=8C=96=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.d.ts | 81 +++-- demo/libs/framework/framework.js | 305 ++++++++++-------- demo/libs/framework/framework.min.js | 2 +- demo/src/game/PlayerController.ts | 6 +- source/bin/framework.d.ts | 81 +++-- source/bin/framework.js | 305 ++++++++++-------- source/bin/framework.min.js | 2 +- source/src/ECS/Components/Camera.ts | 2 +- .../Components/Physics/Colliders/Collider.ts | 13 +- source/src/ECS/Components/Physics/Mover.ts | 32 +- .../ECS/Components/Physics/ProjectileMover.ts | 4 +- .../src/ECS/Components/RenderableComponent.ts | 17 + source/src/ECS/Components/SpriteRenderer.ts | 13 +- source/src/ECS/Core.ts | 4 +- source/src/ECS/Transform.ts | 15 +- source/src/ECS/Utils/ComponentList.ts | 19 +- .../src/Graphics/Renderers/DefaultRenderer.ts | 4 + source/src/Graphics/Renderers/Renderer.ts | 35 +- source/src/Math/Rectangle.ts | 7 +- source/src/Math/Vector2.ts | 7 +- source/src/Physics/ColliderTriggerHelper.ts | 4 +- source/src/Physics/Physics.ts | 26 +- source/src/Physics/Shapes/Box.ts | 6 +- source/src/Physics/Shapes/Circle.ts | 15 +- source/src/Physics/Shapes/Polygon.ts | 35 +- source/src/Physics/Shapes/Shape.ts | 6 +- .../Shapes/ShapeCollisions/ShapeCollisions.ts | 87 +++-- source/src/Physics/Verlet/SpatialHash.ts | 10 +- 28 files changed, 631 insertions(+), 512 deletions(-) diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index cc4d4203..777d4119 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -133,6 +133,7 @@ declare module es { static transform(position: Vector2, matrix: Matrix2D): Vector2; static distance(value1: Vector2, value2: Vector2): number; static negate(value: Vector2): Vector2; + equals(other: Vector2): boolean; } } declare module es { @@ -387,13 +388,14 @@ declare module transform { } } declare module es { + import HashObject = egret.HashObject; enum DirtyType { clean = 0, positionDirty = 1, scaleDirty = 2, rotationDirty = 3 } - class Transform { + class Transform extends HashObject { readonly entity: Entity; parent: Transform; readonly childCount: number; @@ -448,6 +450,7 @@ declare module es { setDirty(dirtyFlagType: DirtyType): void; copyFrom(transform: Transform): void; toString(): string; + equals(other: Transform): boolean; } } declare module es { @@ -536,6 +539,7 @@ declare module es { } declare module es { abstract class RenderableComponent extends Component implements IRenderable { + displayObject: egret.DisplayObject; readonly width: number; readonly height: number; readonly bounds: Rectangle; @@ -556,6 +560,7 @@ declare module es { setRenderLayer(renderLayer: number): RenderableComponent; setColor(color: number): RenderableComponent; setLocalOffset(offset: Vector2): RenderableComponent; + sync(camera: Camera): void; toString(): string; } } @@ -667,12 +672,9 @@ declare module es { class Mover extends Component { private _triggerHelper; onAddedToEntity(): void; - calculateMovement(motion: Vector2): { - collisionResult: CollisionResult; - motion: Vector2; - }; + calculateMovement(motion: Vector2, collisionResult: CollisionResult): boolean; applyMovement(motion: Vector2): void; - move(motion: Vector2): CollisionResult; + move(motion: Vector2, collisionResult: CollisionResult): boolean; } } declare module es { @@ -712,8 +714,8 @@ declare module es { onDisabled(): void; registerColliderWithPhysicsSystem(): void; unregisterColliderWithPhysicsSystem(): void; - overlaps(other: Collider): any; - collidesWith(collider: Collider, motion: Vector2): CollisionResult; + overlaps(other: Collider): boolean; + collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean; clone(): Component; } } @@ -1054,15 +1056,20 @@ declare module es { declare module es { abstract class Renderer { camera: Camera; + readonly renderOrder: number; + protected constructor(renderOrder: number, camera?: Camera); onAddedToScene(scene: Scene): void; + unload(): void; protected beginRender(cam: Camera): void; abstract render(scene: Scene): any; - unload(): void; protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void; + onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; + compareTo(other: Renderer): number; } } declare module es { class DefaultRenderer extends Renderer { + constructor(); render(scene: Scene): void; } } @@ -1197,10 +1204,7 @@ declare module es { containsRect(value: Rectangle): boolean; getHalfSize(): Vector2; static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; - getClosestPointOnRectangleBorderToPoint(point: Vector2): { - res: Vector2; - edgeNormal: Vector2; - }; + getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2; getClosestPointOnBoundsToOrigin(): Vector2; calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void; setEgretRect(rect: egret.Rectangle): Rectangle; @@ -1260,14 +1264,8 @@ declare module es { static reset(): void; static clear(): void; static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; - static boxcastBroadphase(rect: Rectangle, layerMask?: number): { - colliders: Collider[]; - rect: Rectangle; - }; - static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): { - tempHashSet: Collider[]; - bounds: Rectangle; - }; + static boxcastBroadphase(rect: Rectangle, layerMask?: number): Collider[]; + static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): Collider[]; static addCollider(collider: Collider): void; static removeCollider(collider: Collider): void; static updateCollider(collider: Collider): void; @@ -1280,9 +1278,9 @@ declare module es { center: Vector2; bounds: Rectangle; abstract recalculateBounds(collider: Collider): any; - abstract pointCollidesWithShape(point: Vector2): CollisionResult; - abstract overlaps(other: Shape): any; - abstract collidesWithShape(other: Shape): CollisionResult; + abstract overlaps(other: Shape): boolean; + abstract collidesWithShape(other: Shape, collisionResult: CollisionResult): boolean; + abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; clone(): Shape; } } @@ -1303,16 +1301,12 @@ declare module es { static buildSymmetricalPolygon(vertCount: number, radius: number): any[]; static recenterPolygonVerts(points: Vector2[]): void; static findPolygonCenter(points: Vector2[]): Vector2; - static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { - closestPoint: any; - distanceSquared: any; - edgeNormal: any; - }; + static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2; recalculateBounds(collider: Collider): void; overlaps(other: Shape): any; - collidesWithShape(other: Shape): any; + collidesWithShape(other: Shape, result: CollisionResult): boolean; containsPoint(point: Vector2): boolean; - pointCollidesWithShape(point: Vector2): CollisionResult; + pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; } } declare module es { @@ -1323,7 +1317,7 @@ declare module es { private static buildBox; updateBox(width: number, height: number): void; overlaps(other: Shape): any; - collidesWithShape(other: Shape): any; + collidesWithShape(other: Shape, result: CollisionResult): boolean; containsPoint(point: Vector2): boolean; } } @@ -1334,8 +1328,8 @@ declare module es { constructor(radius: number); recalculateBounds(collider: es.Collider): void; overlaps(other: Shape): any; - collidesWithShape(other: Shape): CollisionResult; - pointCollidesWithShape(point: Vector2): CollisionResult; + collidesWithShape(other: Shape, result: CollisionResult): boolean; + pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; } } declare module es { @@ -1349,19 +1343,19 @@ declare module es { } declare module es { class ShapeCollisions { - static polygonToPolygon(first: Polygon, second: Polygon): CollisionResult; + static polygonToPolygon(first: Polygon, second: Polygon, result: CollisionResult): boolean; static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number; static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): { min: number; max: number; }; - static circleToPolygon(circle: Circle, polygon: Polygon): CollisionResult; - static circleToBox(circle: Circle, box: Box): CollisionResult; - static pointToCircle(point: Vector2, circle: Circle): CollisionResult; + static circleToPolygon(circle: Circle, polygon: Polygon, result: CollisionResult): boolean; + static circleToBox(circle: Circle, box: Box, result: CollisionResult): boolean; + static pointToCircle(point: Vector2, circle: Circle, result: CollisionResult): boolean; static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; - static pointToPoly(point: Vector2, poly: Polygon): CollisionResult; - static circleToCircle(first: Circle, second: Circle): CollisionResult; - static boxToBox(first: Box, second: Box): CollisionResult; + static pointToPoly(point: Vector2, poly: Polygon, result: CollisionResult): boolean; + static circleToCircle(first: Circle, second: Circle, result: CollisionResult): boolean; + static boxToBox(first: Box, second: Box, result: CollisionResult): boolean; private static minkowskiDifference; } } @@ -1383,10 +1377,7 @@ declare module es { clear(): void; debugDraw(secondsToDisplay: number, textScale?: number): void; private debugDrawCellDetails; - aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): { - tempHashSet: Collider[]; - bounds: Rectangle; - }; + aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[]; overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; } class NumberDictionary { diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index d10ed324..81b43a26 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -735,7 +735,7 @@ var es; return new Vector2(es.MathHelper.lerp(value1.x, value2.x, amount), es.MathHelper.lerp(value1.y, value2.y, amount)); }; Vector2.transform = function (position, matrix) { - return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31, (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32); }; Vector2.distance = function (value1, value2) { var v1 = value1.x - value2.x, v2 = value1.y - value2.y; @@ -747,6 +747,9 @@ var es; result.y = -value.y; return result; }; + Vector2.prototype.equals = function (other) { + return other.x == this.x && other.y == this.y; + }; Vector2.unitYVector = new Vector2(0, 1); Vector2.unitXVector = new Vector2(1, 0); Vector2.unitVector2 = new Vector2(1, 1); @@ -1145,7 +1148,7 @@ var es; this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); - this.addEventListener(egret.Event.RENDER, this.draw, this); + es.Input.initialize(); this.initialize(); }; Core.prototype.onOrientationChanged = function () { @@ -1183,7 +1186,10 @@ var es; case 1: _a.sent(); _a.label = 2; - case 2: return [2]; + case 2: return [4, this.draw()]; + case 3: + _a.sent(); + return [2]; } }); }); @@ -1778,6 +1784,7 @@ var transform; })(transform || (transform = {})); var es; (function (es) { + var HashObject = egret.HashObject; var DirtyType; (function (DirtyType) { DirtyType[DirtyType["clean"] = 0] = "clean"; @@ -1785,24 +1792,27 @@ var es; DirtyType[DirtyType["scaleDirty"] = 2] = "scaleDirty"; DirtyType[DirtyType["rotationDirty"] = 3] = "rotationDirty"; })(DirtyType = es.DirtyType || (es.DirtyType = {})); - var Transform = (function () { + var Transform = (function (_super) { + __extends(Transform, _super); function Transform(entity) { - this._localTransform = es.Matrix2D.create(); - this._worldTransform = es.Matrix2D.create().identity(); - this._worldToLocalTransform = es.Matrix2D.create().identity(); - this._worldInverseTransform = es.Matrix2D.create().identity(); - this._rotationMatrix = es.Matrix2D.create(); - this._translationMatrix = es.Matrix2D.create(); - this._scaleMatrix = es.Matrix2D.create(); - this._position = es.Vector2.zero; - this._scale = es.Vector2.one; - this._rotation = 0; - this._localPosition = es.Vector2.zero; - this._localScale = es.Vector2.one; - this._localRotation = 0; - this.entity = entity; - this.scale = es.Vector2.one; - this._children = []; + var _this = _super.call(this) || this; + _this._localTransform = es.Matrix2D.create(); + _this._worldTransform = es.Matrix2D.create().identity(); + _this._worldToLocalTransform = es.Matrix2D.create().identity(); + _this._worldInverseTransform = es.Matrix2D.create().identity(); + _this._rotationMatrix = es.Matrix2D.create(); + _this._translationMatrix = es.Matrix2D.create(); + _this._scaleMatrix = es.Matrix2D.create(); + _this._position = es.Vector2.zero; + _this._scale = es.Vector2.one; + _this._rotation = 0; + _this._localPosition = es.Vector2.zero; + _this._localScale = es.Vector2.one; + _this._localRotation = 0; + _this.entity = entity; + _this.scale = es.Vector2.one; + _this._children = []; + return _this; } Object.defineProperty(Transform.prototype, "parent", { get: function () { @@ -1958,7 +1968,7 @@ var es; return this._children[index]; }; Transform.prototype.setParent = function (parent) { - if (this._parent == parent) + if (this._parent.equals(parent)) return this; if (!this._parent) { this._parent._children.remove(this); @@ -1970,7 +1980,7 @@ var es; }; Transform.prototype.setPosition = function (x, y) { var position = new es.Vector2(x, y); - if (position == this._position) + if (position.equals(this._position)) return this; this._position = position; if (this.parent) { @@ -1983,7 +1993,7 @@ var es; return this; }; Transform.prototype.setLocalPosition = function (localPosition) { - if (localPosition == this._localPosition) + if (localPosition.equals(this._localPosition)) return this; this._localPosition = localPosition; this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; @@ -2108,8 +2118,11 @@ var es; Transform.prototype.toString = function () { return "[Transform: parent: " + this.parent + ", position: " + this.position + ", rotation: " + this.rotation + ",\n scale: " + this.scale + ", localPosition: " + this._localPosition + ", localRotation: " + this._localRotation + ",\n localScale: " + this._localScale + "]"; }; + Transform.prototype.equals = function (other) { + return other.hashCode == this.hashCode; + }; return Transform; - }()); + }(HashObject)); es.Transform = Transform; })(es || (es = {})); var es; @@ -2227,7 +2240,7 @@ var es; var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); this._bounds.location = new es.Vector2(minX, minY); this._bounds.width = maxX - minX; - this._bounds.height = maxX - minY; + this._bounds.height = maxY - minY; } else { this._bounds.location = topLeft; @@ -2499,6 +2512,7 @@ var es; __extends(RenderableComponent, _super); function RenderableComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; + _this.displayObject = new egret.DisplayObject(); _this.color = 0x000000; _this._localOffset = es.Vector2.zero; _this._renderLayer = 0; @@ -2570,8 +2584,10 @@ var es; this._areBoundsDirty = true; }; RenderableComponent.prototype.onBecameVisible = function () { + this.displayObject.visible = this.isVisible; }; RenderableComponent.prototype.onBecameInvisible = function () { + this.displayObject.visible = this.isVisible; }; RenderableComponent.prototype.isVisibleFromCamera = function (camera) { this.isVisible = camera.bounds.intersects(this.bounds); @@ -2596,6 +2612,13 @@ var es; } return this; }; + RenderableComponent.prototype.sync = function (camera) { + this.displayObject.x = this.entity.position.x + this.localOffset.x - camera.position.x + camera.origin.x; + this.displayObject.y = this.entity.position.y + this.localOffset.y - camera.position.y + camera.origin.y; + this.displayObject.scaleX = this.entity.scale.x; + this.displayObject.scaleY = this.entity.scale.y; + this.displayObject.rotation = this.entity.rotation; + }; RenderableComponent.prototype.toString = function () { return "[RenderableComponent] renderLayer: " + this.renderLayer; }; @@ -2626,6 +2649,7 @@ var es; })(es || (es = {})); var es; (function (es) { + var Bitmap = egret.Bitmap; var SpriteRenderer = (function (_super) { __extends(SpriteRenderer, _super); function SpriteRenderer(sprite) { @@ -2644,8 +2668,8 @@ var es; this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.sourceRect.width, this._sprite.sourceRect.height); this._areBoundsDirty = false; } - return this._bounds; } + return this._bounds; }, enumerable: true, configurable: true @@ -2684,12 +2708,17 @@ var es; this._sprite = sprite; if (this._sprite) { this._origin = this._sprite.origin; + this.displayObject.anchorOffsetX = this._origin.x; + this.displayObject.anchorOffsetY = this._origin.y; } + this.displayObject = new Bitmap(sprite.texture2D); return this; }; SpriteRenderer.prototype.setOrigin = function (origin) { if (this._origin != origin) { this._origin = origin; + this.displayObject.anchorOffsetX = this._origin.x; + this.displayObject.anchorOffsetY = this._origin.y; this._areBoundsDirty = true; } return this; @@ -2699,6 +2728,7 @@ var es; return this; }; SpriteRenderer.prototype.render = function (camera) { + this.sync(camera); }; return SpriteRenderer; }(es.RenderableComponent)); @@ -2942,10 +2972,9 @@ var es; Mover.prototype.onAddedToEntity = function () { this._triggerHelper = new es.ColliderTriggerHelper(this.entity); }; - Mover.prototype.calculateMovement = function (motion) { - var collisionResult = new es.CollisionResult(); + Mover.prototype.calculateMovement = function (motion, collisionResult) { if (!this.entity.getComponent(es.Collider) || !this._triggerHelper) { - return null; + return false; } var colliders = this.entity.getComponents(es.Collider); for (var i = 0; i < colliders.length; i++) { @@ -2955,36 +2984,32 @@ var es; var bounds = collider.bounds; bounds.x += motion.x; bounds.y += motion.y; - var boxcastResult = es.Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); - bounds = boxcastResult.bounds; - var neighbors = boxcastResult.tempHashSet; + var neighbors = es.Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); for (var j = 0; j < neighbors.length; j++) { var neighbor = neighbors[j]; if (neighbor.isTrigger) continue; - var _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult) { - motion = es.Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); - if (_internalcollisionResult.collider) { + var _internalcollisionResult = new es.CollisionResult(); + if (collider.collidesWith(neighbor, motion, _internalcollisionResult)) { + motion.subtract(_internalcollisionResult.minimumTranslationVector); + if (_internalcollisionResult.collider != null) { collisionResult = _internalcollisionResult; } } } } es.ListPool.free(colliders); - return { collisionResult: collisionResult, motion: motion }; + return collisionResult.collider != null; }; Mover.prototype.applyMovement = function (motion) { this.entity.position = es.Vector2.add(this.entity.position, motion); if (this._triggerHelper) this._triggerHelper.update(); }; - Mover.prototype.move = function (motion) { - var movementResult = this.calculateMovement(motion); - var collisionResult = movementResult.collisionResult; - motion = movementResult.motion; + Mover.prototype.move = function (motion, collisionResult) { + this.calculateMovement(motion, collisionResult); this.applyMovement(motion); - return collisionResult; + return collisionResult.collider != null; }; return Mover; }(es.Component)); @@ -3010,8 +3035,8 @@ var es; var didCollide = false; this.entity.position = es.Vector2.add(this.entity.position, motion); var neighbors = es.Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); - for (var i = 0; i < neighbors.colliders.length; i++) { - var neighbor = neighbors.colliders[i]; + for (var i = 0; i < neighbors.length; i++) { + var neighbor = neighbors[i]; if (this._collider.overlaps(neighbor) && neighbor.enabled) { didCollide = true; this.notifyTriggerListeners(this._collider, neighbor); @@ -3171,14 +3196,14 @@ var es; Collider.prototype.overlaps = function (other) { return this.shape.overlaps(other.shape); }; - Collider.prototype.collidesWith = function (collider, motion) { + Collider.prototype.collidesWith = function (collider, motion, result) { var oldPosition = this.entity.position; - this.entity.position = es.Vector2.add(this.entity.position, motion); - var result = this.shape.collidesWithShape(collider.shape); - if (result) + this.entity.position.add(motion); + var didCollide = this.shape.collidesWithShape(collider.shape, result); + if (didCollide) result.collider = collider; this.entity.position = oldPosition; - return result; + return didCollide; }; Collider.prototype.clone = function () { var collider = ObjectUtils.clone(this); @@ -3601,8 +3626,10 @@ var es; ComponentList.prototype.deregisterAllComponents = function () { for (var i = 0; i < this._components.length; i++) { var component = this._components[i]; - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.removeChild(component.displayObject); this._entity.scene.renderableComponents.remove(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); } @@ -3610,8 +3637,10 @@ var es; ComponentList.prototype.registerAllComponents = function () { for (var i = 0; i < this._components.length; i++) { var component = this._components[i]; - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.addChild(component.displayObject); this._entity.scene.renderableComponents.add(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); this._entity.scene.entityProcessors.onComponentAdded(this._entity); } @@ -3627,8 +3656,10 @@ var es; if (this._componentsToAdd.length > 0) { for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { var component = this._componentsToAdd[i]; - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.addChild(component.displayObject); this._entity.scene.renderableComponents.add(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); this._entity.scene.entityProcessors.onComponentAdded(this._entity); this._components.push(component); @@ -3651,8 +3682,10 @@ var es; } }; ComponentList.prototype.handleRemove = function (component) { - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.removeChild(component.displayObject); this._entity.scene.renderableComponents.remove(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); component.onRemovedFromEntity(); @@ -4909,15 +4942,23 @@ var es; var es; (function (es) { var Renderer = (function () { - function Renderer() { + function Renderer(renderOrder, camera) { + if (camera === void 0) { camera = null; } + this.renderOrder = 0; + this.camera = camera; + this.renderOrder = renderOrder; } Renderer.prototype.onAddedToScene = function (scene) { }; - Renderer.prototype.beginRender = function (cam) { - }; Renderer.prototype.unload = function () { }; + Renderer.prototype.beginRender = function (cam) { }; Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { renderable.render(cam); }; + Renderer.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { + }; + Renderer.prototype.compareTo = function (other) { + return this.renderOrder - other.renderOrder; + }; return Renderer; }()); es.Renderer = Renderer; @@ -4927,7 +4968,7 @@ var es; var DefaultRenderer = (function (_super) { __extends(DefaultRenderer, _super); function DefaultRenderer() { - return _super !== null && _super.apply(this, arguments) || this; + return _super.call(this, 0, null) || this; } DefaultRenderer.prototype.render = function (scene) { var cam = this.camera ? this.camera : scene.camera; @@ -5567,8 +5608,8 @@ var es; Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { return new Rectangle(minX, minY, maxX - minX, maxY - minY); }; - Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { - var edgeNormal = es.Vector2.zero; + Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point, edgeNormal) { + edgeNormal = es.Vector2.zero; var res = new es.Vector2(); res.x = es.MathHelper.clamp(point.x, this.left, this.right); res.y = es.MathHelper.clamp(point.y, this.top, this.bottom); @@ -5605,7 +5646,7 @@ var es; if (res.y == this.bottom) edgeNormal.y = 1; } - return { res: res, edgeNormal: edgeNormal }; + return res; }; Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () { var max = this.max; @@ -5688,9 +5729,7 @@ var es; var colliders = this._entity.getComponents(es.Collider); for (var i = 0; i < colliders.length; i++) { var collider = colliders[i]; - var boxcastResult = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); - collider.bounds = boxcastResult.rect; - var neighbors = boxcastResult.colliders; + var neighbors = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); var _loop_5 = function (j) { var neighbor = neighbors[j]; if (!collider.isTrigger && !neighbor.isTrigger) @@ -5914,12 +5953,15 @@ var es; }; Physics.overlapCircleAll = function (center, randius, results, layerMask) { if (layerMask === void 0) { layerMask = -1; } + if (results.length == 0) { + console.error("An empty results array was passed in. No results will ever be returned."); + return; + } return this._spatialHash.overlapCircle(center, randius, results, layerMask); }; Physics.boxcastBroadphase = function (rect, layerMask) { if (layerMask === void 0) { layerMask = this.allLayers; } - var boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); - return { colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds }; + return this._spatialHash.aabbBroadphase(rect, null, layerMask); }; Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { if (layerMask === void 0) { layerMask = this.allLayers; } @@ -6026,9 +6068,9 @@ var es; } return new es.Vector2(x / points.length, y / points.length); }; - Polygon.getClosestPointOnPolygonToPoint = function (points, point) { - var distanceSquared = Number.MAX_VALUE; - var edgeNormal = new es.Vector2(0, 0); + Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) { + distanceSquared = Number.MAX_VALUE; + edgeNormal = new es.Vector2(0, 0); var closestPoint = new es.Vector2(0, 0); var tempDistanceSquared; for (var i = 0; i < points.length; i++) { @@ -6044,8 +6086,8 @@ var es; edgeNormal = new es.Vector2(-line.y, line.x); } } - edgeNormal = es.Vector2.normalize(edgeNormal); - return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + es.Vector2Ext.normalize(edgeNormal); + return closestPoint; }; Polygon.prototype.recalculateBounds = function (collider) { this.center = collider.localOffset; @@ -6079,12 +6121,11 @@ var es; this.bounds.location = es.Vector2.add(this.bounds.location, this.position); }; Polygon.prototype.overlaps = function (other) { - var result; + var result = new es.CollisionResult(); if (other instanceof Polygon) - return es.ShapeCollisions.polygonToPolygon(this, other); + return es.ShapeCollisions.polygonToPolygon(this, other, result); if (other instanceof es.Circle) { - result = es.ShapeCollisions.circleToPolygon(other, this); - if (result) { + if (es.ShapeCollisions.circleToPolygon(other, this, result)) { result.invertResult(); return true; } @@ -6092,18 +6133,16 @@ var es; } throw new Error("overlaps of Pologon to " + other + " are not supported"); }; - Polygon.prototype.collidesWithShape = function (other) { - var result = new es.CollisionResult(); + Polygon.prototype.collidesWithShape = function (other, result) { if (other instanceof Polygon) { - return es.ShapeCollisions.polygonToPolygon(this, other); + return es.ShapeCollisions.polygonToPolygon(this, other, result); } if (other instanceof es.Circle) { - result = es.ShapeCollisions.circleToPolygon(other, this); - if (result) { + if (es.ShapeCollisions.circleToPolygon(other, this, result)) { result.invertResult(); - return result; + return true; } - return null; + return false; } throw new Error("overlaps of Polygon to " + other + " are not supported"); }; @@ -6119,8 +6158,8 @@ var es; } return isInside; }; - Polygon.prototype.pointCollidesWithShape = function (point) { - return es.ShapeCollisions.pointToPoly(point, this); + Polygon.prototype.pointCollidesWithShape = function (point, result) { + return es.ShapeCollisions.pointToPoly(point, this, result); }; return Polygon; }(es.Shape)); @@ -6167,11 +6206,11 @@ var es; } return _super.prototype.overlaps.call(this, other); }; - Box.prototype.collidesWithShape = function (other) { + Box.prototype.collidesWithShape = function (other, result) { if (other instanceof Box && other.isUnrotated) { - return es.ShapeCollisions.boxToBox(this, other); + return es.ShapeCollisions.boxToBox(this, other, result); } - return _super.prototype.collidesWithShape.call(this, other); + return _super.prototype.collidesWithShape.call(this, other, result); }; Box.prototype.containsPoint = function (point) { if (this.isUnrotated) @@ -6209,28 +6248,29 @@ var es; this.bounds = new es.Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); }; Circle.prototype.overlaps = function (other) { + var result = new es.CollisionResult(); if (other instanceof es.Box && other.isUnrotated) return es.Collisions.isRectToCircle(other.bounds, this.position, this.radius); if (other instanceof Circle) return es.Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); if (other instanceof es.Polygon) - return es.ShapeCollisions.circleToPolygon(this, other); + return es.ShapeCollisions.circleToPolygon(this, other, result); throw new Error("overlaps of circle to " + other + " are not supported"); }; - Circle.prototype.collidesWithShape = function (other) { + Circle.prototype.collidesWithShape = function (other, result) { if (other instanceof es.Box && other.isUnrotated) { - return es.ShapeCollisions.circleToBox(this, other); + return es.ShapeCollisions.circleToBox(this, other, result); } if (other instanceof Circle) { - return es.ShapeCollisions.circleToCircle(this, other); + return es.ShapeCollisions.circleToCircle(this, other, result); } if (other instanceof es.Polygon) { - return es.ShapeCollisions.circleToPolygon(this, other); + return es.ShapeCollisions.circleToPolygon(this, other, result); } throw new Error("Collisions of Circle to " + other + " are not supported"); }; - Circle.prototype.pointCollidesWithShape = function (point) { - return es.ShapeCollisions.pointToCircle(point, this); + Circle.prototype.pointCollidesWithShape = function (point, result) { + return es.ShapeCollisions.pointToCircle(point, this, result); }; return Circle; }(es.Shape)); @@ -6257,8 +6297,7 @@ var es; var ShapeCollisions = (function () { function ShapeCollisions() { } - ShapeCollisions.polygonToPolygon = function (first, second) { - var result = new es.CollisionResult(); + ShapeCollisions.polygonToPolygon = function (first, second, result) { var isIntersecting = true; var firstEdges = first.edgeNormals; var secondEdges = second.edgeNormals; @@ -6291,7 +6330,7 @@ var es; if (intervalDist > 0) isIntersecting = false; if (!isIntersecting) - return null; + return false; intervalDist = Math.abs(intervalDist); if (intervalDist < minIntervalDistance) { minIntervalDistance = intervalDist; @@ -6302,7 +6341,7 @@ var es; } result.normal = translationAxis; result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-translationAxis.x, -translationAxis.y), new es.Vector2(minIntervalDistance)); - return result; + return true; }; ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { if (minA < minB) @@ -6323,16 +6362,13 @@ var es; } return { min: min, max: max }; }; - ShapeCollisions.circleToPolygon = function (circle, polygon) { - var result = new es.CollisionResult(); + ShapeCollisions.circleToPolygon = function (circle, polygon, result) { var poly2Circle = es.Vector2.subtract(circle.position, polygon.position); - var gpp = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); - var closestPoint = gpp.closestPoint; - var distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; + var distanceSquared = 0; + var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle, distanceSquared, result.normal); var circleCenterInsidePoly = polygon.containsPoint(circle.position); if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) - return null; + return false; var mtv; if (circleCenterInsidePoly) { mtv = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared) - circle.radius)); @@ -6348,16 +6384,15 @@ var es; } result.minimumTranslationVector = mtv; result.point = es.Vector2.add(closestPoint, polygon.position); - return result; + return true; }; - ShapeCollisions.circleToBox = function (circle, box) { - var result = new es.CollisionResult(); - var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; + ShapeCollisions.circleToBox = function (circle, box, result) { + var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); if (box.containsPoint(circle.position)) { result.point = closestPointOnBounds; var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.subtract(result.normal, new es.Vector2(circle.radius))); result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace); - return result; + return true; } var sqrDistance = es.Vector2.distanceSquared(closestPointOnBounds, circle.position); if (sqrDistance == 0) { @@ -6366,14 +6401,14 @@ var es; else if (sqrDistance <= circle.radius * circle.radius) { result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds); var depth = result.normal.length() - circle.radius; - result.normal = es.Vector2Ext.normalize(result.normal); + result.point = closestPointOnBounds; + es.Vector2Ext.normalize(result.normal); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal); - return result; + return true; } - return null; + return false; }; - ShapeCollisions.pointToCircle = function (point, circle) { - var result = new es.CollisionResult(); + ShapeCollisions.pointToCircle = function (point, circle, result) { var distanceSquared = es.Vector2.distanceSquared(point, circle.position); var sumOfRadii = 1 + circle.radius; var collided = distanceSquared < sumOfRadii * sumOfRadii; @@ -6382,9 +6417,9 @@ var es; var depth = sumOfRadii - Math.sqrt(distanceSquared); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth, -depth), result.normal); result.point = es.Vector2.add(circle.position, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius, circle.radius))); - return result; + return true; } - return null; + return false; }; ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { var v = es.Vector2.subtract(lineB, lineA); @@ -6393,22 +6428,17 @@ var es; t = es.MathHelper.clamp(t, 0, 1); return es.Vector2.add(lineA, es.Vector2.multiply(v, new es.Vector2(t, t))); }; - ShapeCollisions.pointToPoly = function (point, poly) { - var result = new es.CollisionResult(); + ShapeCollisions.pointToPoly = function (point, poly, result) { if (poly.containsPoint(point)) { - var distanceSquared = void 0; - var gpp = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position)); - var closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; + var distanceSquared = 0; + var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position), distanceSquared, result.normal); result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); result.point = es.Vector2.add(closestPoint, poly.position); - return result; + return true; } - return null; + return false; }; - ShapeCollisions.circleToCircle = function (first, second) { - var result = new es.CollisionResult(); + ShapeCollisions.circleToCircle = function (first, second, result) { var distanceSquared = es.Vector2.distanceSquared(first.position, second.position); var sumOfRadii = first.radius + second.radius; var collided = distanceSquared < sumOfRadii * sumOfRadii; @@ -6417,22 +6447,21 @@ var es; var depth = sumOfRadii - Math.sqrt(distanceSquared); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth), result.normal); result.point = es.Vector2.add(second.position, es.Vector2.multiply(result.normal, new es.Vector2(second.radius))); - return result; + return true; } - return null; + return false; }; - ShapeCollisions.boxToBox = function (first, second) { - var result = new es.CollisionResult(); + ShapeCollisions.boxToBox = function (first, second, result) { var minkowskiDiff = this.minkowskiDifference(first, second); if (minkowskiDiff.contains(0, 0)) { result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); - if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) - return null; + if (result.minimumTranslationVector.equals(es.Vector2.zero)) + return false; result.normal = new es.Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); result.normal.normalize(); - return result; + return true; } - return null; + return false; }; ShapeCollisions.minkowskiDifference = function (first, second) { var positionOffset = es.Vector2.subtract(first.position, es.Vector2.add(first.bounds.location, es.Vector2.divide(first.bounds.size, new es.Vector2(2)))); @@ -6544,16 +6573,14 @@ var es; } } } - return { tempHashSet: this._tempHashSet, bounds: bounds }; + return this._tempHashSet; }; SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; this._overlapTestCircle.position = circleCenter; var resultCounter = 0; - var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); - bounds = aabbBroadphaseResult.bounds; - var potentials = aabbBroadphaseResult.tempHashSet; + var potentials = this.aabbBroadphase(bounds, null, layerMask); for (var i = 0; i < potentials.length; i++) { var collider = potentials[i]; if (collider instanceof es.BoxCollider) { diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 7129fc46..58777122 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/demo/src/game/PlayerController.ts b/demo/src/game/PlayerController.ts index c72b00b2..332fb945 100644 --- a/demo/src/game/PlayerController.ts +++ b/demo/src/game/PlayerController.ts @@ -5,6 +5,7 @@ module component { import SpriteRenderer = es.SpriteRenderer; import Time = es.Time; import Input = es.Input; + import CollisionResult = es.CollisionResult; export class PlayerController extends Component { private down: boolean = false; @@ -45,7 +46,7 @@ module component { let moveLeft: number = 0; let moveRight: number = 0; let speed = 100; - let worldPos = Input.touchPosition; + let worldPos = this.entity.scene.camera.mouseToWorldPoint(); if (worldPos.x < this.spriteRenderer.transform.position.x){ moveLeft = -1; } else if(worldPos.x > this.spriteRenderer.transform.position.x){ @@ -57,7 +58,8 @@ module component { } else if(worldPos.y > this.spriteRenderer.transform.position.y){ moveRight = 1; } - this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime)); + let collisionResult = new CollisionResult(); + this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime), collisionResult); } } } diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index cc4d4203..777d4119 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -133,6 +133,7 @@ declare module es { static transform(position: Vector2, matrix: Matrix2D): Vector2; static distance(value1: Vector2, value2: Vector2): number; static negate(value: Vector2): Vector2; + equals(other: Vector2): boolean; } } declare module es { @@ -387,13 +388,14 @@ declare module transform { } } declare module es { + import HashObject = egret.HashObject; enum DirtyType { clean = 0, positionDirty = 1, scaleDirty = 2, rotationDirty = 3 } - class Transform { + class Transform extends HashObject { readonly entity: Entity; parent: Transform; readonly childCount: number; @@ -448,6 +450,7 @@ declare module es { setDirty(dirtyFlagType: DirtyType): void; copyFrom(transform: Transform): void; toString(): string; + equals(other: Transform): boolean; } } declare module es { @@ -536,6 +539,7 @@ declare module es { } declare module es { abstract class RenderableComponent extends Component implements IRenderable { + displayObject: egret.DisplayObject; readonly width: number; readonly height: number; readonly bounds: Rectangle; @@ -556,6 +560,7 @@ declare module es { setRenderLayer(renderLayer: number): RenderableComponent; setColor(color: number): RenderableComponent; setLocalOffset(offset: Vector2): RenderableComponent; + sync(camera: Camera): void; toString(): string; } } @@ -667,12 +672,9 @@ declare module es { class Mover extends Component { private _triggerHelper; onAddedToEntity(): void; - calculateMovement(motion: Vector2): { - collisionResult: CollisionResult; - motion: Vector2; - }; + calculateMovement(motion: Vector2, collisionResult: CollisionResult): boolean; applyMovement(motion: Vector2): void; - move(motion: Vector2): CollisionResult; + move(motion: Vector2, collisionResult: CollisionResult): boolean; } } declare module es { @@ -712,8 +714,8 @@ declare module es { onDisabled(): void; registerColliderWithPhysicsSystem(): void; unregisterColliderWithPhysicsSystem(): void; - overlaps(other: Collider): any; - collidesWith(collider: Collider, motion: Vector2): CollisionResult; + overlaps(other: Collider): boolean; + collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean; clone(): Component; } } @@ -1054,15 +1056,20 @@ declare module es { declare module es { abstract class Renderer { camera: Camera; + readonly renderOrder: number; + protected constructor(renderOrder: number, camera?: Camera); onAddedToScene(scene: Scene): void; + unload(): void; protected beginRender(cam: Camera): void; abstract render(scene: Scene): any; - unload(): void; protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void; + onSceneBackBufferSizeChanged(newWidth: number, newHeight: number): void; + compareTo(other: Renderer): number; } } declare module es { class DefaultRenderer extends Renderer { + constructor(); render(scene: Scene): void; } } @@ -1197,10 +1204,7 @@ declare module es { containsRect(value: Rectangle): boolean; getHalfSize(): Vector2; static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; - getClosestPointOnRectangleBorderToPoint(point: Vector2): { - res: Vector2; - edgeNormal: Vector2; - }; + getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2; getClosestPointOnBoundsToOrigin(): Vector2; calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void; setEgretRect(rect: egret.Rectangle): Rectangle; @@ -1260,14 +1264,8 @@ declare module es { static reset(): void; static clear(): void; static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; - static boxcastBroadphase(rect: Rectangle, layerMask?: number): { - colliders: Collider[]; - rect: Rectangle; - }; - static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): { - tempHashSet: Collider[]; - bounds: Rectangle; - }; + static boxcastBroadphase(rect: Rectangle, layerMask?: number): Collider[]; + static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): Collider[]; static addCollider(collider: Collider): void; static removeCollider(collider: Collider): void; static updateCollider(collider: Collider): void; @@ -1280,9 +1278,9 @@ declare module es { center: Vector2; bounds: Rectangle; abstract recalculateBounds(collider: Collider): any; - abstract pointCollidesWithShape(point: Vector2): CollisionResult; - abstract overlaps(other: Shape): any; - abstract collidesWithShape(other: Shape): CollisionResult; + abstract overlaps(other: Shape): boolean; + abstract collidesWithShape(other: Shape, collisionResult: CollisionResult): boolean; + abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; clone(): Shape; } } @@ -1303,16 +1301,12 @@ declare module es { static buildSymmetricalPolygon(vertCount: number, radius: number): any[]; static recenterPolygonVerts(points: Vector2[]): void; static findPolygonCenter(points: Vector2[]): Vector2; - static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { - closestPoint: any; - distanceSquared: any; - edgeNormal: any; - }; + static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2; recalculateBounds(collider: Collider): void; overlaps(other: Shape): any; - collidesWithShape(other: Shape): any; + collidesWithShape(other: Shape, result: CollisionResult): boolean; containsPoint(point: Vector2): boolean; - pointCollidesWithShape(point: Vector2): CollisionResult; + pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; } } declare module es { @@ -1323,7 +1317,7 @@ declare module es { private static buildBox; updateBox(width: number, height: number): void; overlaps(other: Shape): any; - collidesWithShape(other: Shape): any; + collidesWithShape(other: Shape, result: CollisionResult): boolean; containsPoint(point: Vector2): boolean; } } @@ -1334,8 +1328,8 @@ declare module es { constructor(radius: number); recalculateBounds(collider: es.Collider): void; overlaps(other: Shape): any; - collidesWithShape(other: Shape): CollisionResult; - pointCollidesWithShape(point: Vector2): CollisionResult; + collidesWithShape(other: Shape, result: CollisionResult): boolean; + pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; } } declare module es { @@ -1349,19 +1343,19 @@ declare module es { } declare module es { class ShapeCollisions { - static polygonToPolygon(first: Polygon, second: Polygon): CollisionResult; + static polygonToPolygon(first: Polygon, second: Polygon, result: CollisionResult): boolean; static intervalDistance(minA: number, maxA: number, minB: number, maxB: any): number; static getInterval(axis: Vector2, polygon: Polygon, min: number, max: number): { min: number; max: number; }; - static circleToPolygon(circle: Circle, polygon: Polygon): CollisionResult; - static circleToBox(circle: Circle, box: Box): CollisionResult; - static pointToCircle(point: Vector2, circle: Circle): CollisionResult; + static circleToPolygon(circle: Circle, polygon: Polygon, result: CollisionResult): boolean; + static circleToBox(circle: Circle, box: Box, result: CollisionResult): boolean; + static pointToCircle(point: Vector2, circle: Circle, result: CollisionResult): boolean; static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2; - static pointToPoly(point: Vector2, poly: Polygon): CollisionResult; - static circleToCircle(first: Circle, second: Circle): CollisionResult; - static boxToBox(first: Box, second: Box): CollisionResult; + static pointToPoly(point: Vector2, poly: Polygon, result: CollisionResult): boolean; + static circleToCircle(first: Circle, second: Circle, result: CollisionResult): boolean; + static boxToBox(first: Box, second: Box, result: CollisionResult): boolean; private static minkowskiDifference; } } @@ -1383,10 +1377,7 @@ declare module es { clear(): void; debugDraw(secondsToDisplay: number, textScale?: number): void; private debugDrawCellDetails; - aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): { - tempHashSet: Collider[]; - bounds: Rectangle; - }; + aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[]; overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; } class NumberDictionary { diff --git a/source/bin/framework.js b/source/bin/framework.js index d10ed324..81b43a26 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -735,7 +735,7 @@ var es; return new Vector2(es.MathHelper.lerp(value1.x, value2.x, amount), es.MathHelper.lerp(value1.y, value2.y, amount)); }; Vector2.transform = function (position, matrix) { - return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31, (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32); }; Vector2.distance = function (value1, value2) { var v1 = value1.x - value2.x, v2 = value1.y - value2.y; @@ -747,6 +747,9 @@ var es; result.y = -value.y; return result; }; + Vector2.prototype.equals = function (other) { + return other.x == this.x && other.y == this.y; + }; Vector2.unitYVector = new Vector2(0, 1); Vector2.unitXVector = new Vector2(1, 0); Vector2.unitVector2 = new Vector2(1, 1); @@ -1145,7 +1148,7 @@ var es; this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); - this.addEventListener(egret.Event.RENDER, this.draw, this); + es.Input.initialize(); this.initialize(); }; Core.prototype.onOrientationChanged = function () { @@ -1183,7 +1186,10 @@ var es; case 1: _a.sent(); _a.label = 2; - case 2: return [2]; + case 2: return [4, this.draw()]; + case 3: + _a.sent(); + return [2]; } }); }); @@ -1778,6 +1784,7 @@ var transform; })(transform || (transform = {})); var es; (function (es) { + var HashObject = egret.HashObject; var DirtyType; (function (DirtyType) { DirtyType[DirtyType["clean"] = 0] = "clean"; @@ -1785,24 +1792,27 @@ var es; DirtyType[DirtyType["scaleDirty"] = 2] = "scaleDirty"; DirtyType[DirtyType["rotationDirty"] = 3] = "rotationDirty"; })(DirtyType = es.DirtyType || (es.DirtyType = {})); - var Transform = (function () { + var Transform = (function (_super) { + __extends(Transform, _super); function Transform(entity) { - this._localTransform = es.Matrix2D.create(); - this._worldTransform = es.Matrix2D.create().identity(); - this._worldToLocalTransform = es.Matrix2D.create().identity(); - this._worldInverseTransform = es.Matrix2D.create().identity(); - this._rotationMatrix = es.Matrix2D.create(); - this._translationMatrix = es.Matrix2D.create(); - this._scaleMatrix = es.Matrix2D.create(); - this._position = es.Vector2.zero; - this._scale = es.Vector2.one; - this._rotation = 0; - this._localPosition = es.Vector2.zero; - this._localScale = es.Vector2.one; - this._localRotation = 0; - this.entity = entity; - this.scale = es.Vector2.one; - this._children = []; + var _this = _super.call(this) || this; + _this._localTransform = es.Matrix2D.create(); + _this._worldTransform = es.Matrix2D.create().identity(); + _this._worldToLocalTransform = es.Matrix2D.create().identity(); + _this._worldInverseTransform = es.Matrix2D.create().identity(); + _this._rotationMatrix = es.Matrix2D.create(); + _this._translationMatrix = es.Matrix2D.create(); + _this._scaleMatrix = es.Matrix2D.create(); + _this._position = es.Vector2.zero; + _this._scale = es.Vector2.one; + _this._rotation = 0; + _this._localPosition = es.Vector2.zero; + _this._localScale = es.Vector2.one; + _this._localRotation = 0; + _this.entity = entity; + _this.scale = es.Vector2.one; + _this._children = []; + return _this; } Object.defineProperty(Transform.prototype, "parent", { get: function () { @@ -1958,7 +1968,7 @@ var es; return this._children[index]; }; Transform.prototype.setParent = function (parent) { - if (this._parent == parent) + if (this._parent.equals(parent)) return this; if (!this._parent) { this._parent._children.remove(this); @@ -1970,7 +1980,7 @@ var es; }; Transform.prototype.setPosition = function (x, y) { var position = new es.Vector2(x, y); - if (position == this._position) + if (position.equals(this._position)) return this; this._position = position; if (this.parent) { @@ -1983,7 +1993,7 @@ var es; return this; }; Transform.prototype.setLocalPosition = function (localPosition) { - if (localPosition == this._localPosition) + if (localPosition.equals(this._localPosition)) return this; this._localPosition = localPosition; this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true; @@ -2108,8 +2118,11 @@ var es; Transform.prototype.toString = function () { return "[Transform: parent: " + this.parent + ", position: " + this.position + ", rotation: " + this.rotation + ",\n scale: " + this.scale + ", localPosition: " + this._localPosition + ", localRotation: " + this._localRotation + ",\n localScale: " + this._localScale + "]"; }; + Transform.prototype.equals = function (other) { + return other.hashCode == this.hashCode; + }; return Transform; - }()); + }(HashObject)); es.Transform = Transform; })(es || (es = {})); var es; @@ -2227,7 +2240,7 @@ var es; var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); this._bounds.location = new es.Vector2(minX, minY); this._bounds.width = maxX - minX; - this._bounds.height = maxX - minY; + this._bounds.height = maxY - minY; } else { this._bounds.location = topLeft; @@ -2499,6 +2512,7 @@ var es; __extends(RenderableComponent, _super); function RenderableComponent() { var _this = _super !== null && _super.apply(this, arguments) || this; + _this.displayObject = new egret.DisplayObject(); _this.color = 0x000000; _this._localOffset = es.Vector2.zero; _this._renderLayer = 0; @@ -2570,8 +2584,10 @@ var es; this._areBoundsDirty = true; }; RenderableComponent.prototype.onBecameVisible = function () { + this.displayObject.visible = this.isVisible; }; RenderableComponent.prototype.onBecameInvisible = function () { + this.displayObject.visible = this.isVisible; }; RenderableComponent.prototype.isVisibleFromCamera = function (camera) { this.isVisible = camera.bounds.intersects(this.bounds); @@ -2596,6 +2612,13 @@ var es; } return this; }; + RenderableComponent.prototype.sync = function (camera) { + this.displayObject.x = this.entity.position.x + this.localOffset.x - camera.position.x + camera.origin.x; + this.displayObject.y = this.entity.position.y + this.localOffset.y - camera.position.y + camera.origin.y; + this.displayObject.scaleX = this.entity.scale.x; + this.displayObject.scaleY = this.entity.scale.y; + this.displayObject.rotation = this.entity.rotation; + }; RenderableComponent.prototype.toString = function () { return "[RenderableComponent] renderLayer: " + this.renderLayer; }; @@ -2626,6 +2649,7 @@ var es; })(es || (es = {})); var es; (function (es) { + var Bitmap = egret.Bitmap; var SpriteRenderer = (function (_super) { __extends(SpriteRenderer, _super); function SpriteRenderer(sprite) { @@ -2644,8 +2668,8 @@ var es; this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.sourceRect.width, this._sprite.sourceRect.height); this._areBoundsDirty = false; } - return this._bounds; } + return this._bounds; }, enumerable: true, configurable: true @@ -2684,12 +2708,17 @@ var es; this._sprite = sprite; if (this._sprite) { this._origin = this._sprite.origin; + this.displayObject.anchorOffsetX = this._origin.x; + this.displayObject.anchorOffsetY = this._origin.y; } + this.displayObject = new Bitmap(sprite.texture2D); return this; }; SpriteRenderer.prototype.setOrigin = function (origin) { if (this._origin != origin) { this._origin = origin; + this.displayObject.anchorOffsetX = this._origin.x; + this.displayObject.anchorOffsetY = this._origin.y; this._areBoundsDirty = true; } return this; @@ -2699,6 +2728,7 @@ var es; return this; }; SpriteRenderer.prototype.render = function (camera) { + this.sync(camera); }; return SpriteRenderer; }(es.RenderableComponent)); @@ -2942,10 +2972,9 @@ var es; Mover.prototype.onAddedToEntity = function () { this._triggerHelper = new es.ColliderTriggerHelper(this.entity); }; - Mover.prototype.calculateMovement = function (motion) { - var collisionResult = new es.CollisionResult(); + Mover.prototype.calculateMovement = function (motion, collisionResult) { if (!this.entity.getComponent(es.Collider) || !this._triggerHelper) { - return null; + return false; } var colliders = this.entity.getComponents(es.Collider); for (var i = 0; i < colliders.length; i++) { @@ -2955,36 +2984,32 @@ var es; var bounds = collider.bounds; bounds.x += motion.x; bounds.y += motion.y; - var boxcastResult = es.Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); - bounds = boxcastResult.bounds; - var neighbors = boxcastResult.tempHashSet; + var neighbors = es.Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); for (var j = 0; j < neighbors.length; j++) { var neighbor = neighbors[j]; if (neighbor.isTrigger) continue; - var _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult) { - motion = es.Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); - if (_internalcollisionResult.collider) { + var _internalcollisionResult = new es.CollisionResult(); + if (collider.collidesWith(neighbor, motion, _internalcollisionResult)) { + motion.subtract(_internalcollisionResult.minimumTranslationVector); + if (_internalcollisionResult.collider != null) { collisionResult = _internalcollisionResult; } } } } es.ListPool.free(colliders); - return { collisionResult: collisionResult, motion: motion }; + return collisionResult.collider != null; }; Mover.prototype.applyMovement = function (motion) { this.entity.position = es.Vector2.add(this.entity.position, motion); if (this._triggerHelper) this._triggerHelper.update(); }; - Mover.prototype.move = function (motion) { - var movementResult = this.calculateMovement(motion); - var collisionResult = movementResult.collisionResult; - motion = movementResult.motion; + Mover.prototype.move = function (motion, collisionResult) { + this.calculateMovement(motion, collisionResult); this.applyMovement(motion); - return collisionResult; + return collisionResult.collider != null; }; return Mover; }(es.Component)); @@ -3010,8 +3035,8 @@ var es; var didCollide = false; this.entity.position = es.Vector2.add(this.entity.position, motion); var neighbors = es.Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); - for (var i = 0; i < neighbors.colliders.length; i++) { - var neighbor = neighbors.colliders[i]; + for (var i = 0; i < neighbors.length; i++) { + var neighbor = neighbors[i]; if (this._collider.overlaps(neighbor) && neighbor.enabled) { didCollide = true; this.notifyTriggerListeners(this._collider, neighbor); @@ -3171,14 +3196,14 @@ var es; Collider.prototype.overlaps = function (other) { return this.shape.overlaps(other.shape); }; - Collider.prototype.collidesWith = function (collider, motion) { + Collider.prototype.collidesWith = function (collider, motion, result) { var oldPosition = this.entity.position; - this.entity.position = es.Vector2.add(this.entity.position, motion); - var result = this.shape.collidesWithShape(collider.shape); - if (result) + this.entity.position.add(motion); + var didCollide = this.shape.collidesWithShape(collider.shape, result); + if (didCollide) result.collider = collider; this.entity.position = oldPosition; - return result; + return didCollide; }; Collider.prototype.clone = function () { var collider = ObjectUtils.clone(this); @@ -3601,8 +3626,10 @@ var es; ComponentList.prototype.deregisterAllComponents = function () { for (var i = 0; i < this._components.length; i++) { var component = this._components[i]; - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.removeChild(component.displayObject); this._entity.scene.renderableComponents.remove(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); } @@ -3610,8 +3637,10 @@ var es; ComponentList.prototype.registerAllComponents = function () { for (var i = 0; i < this._components.length; i++) { var component = this._components[i]; - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.addChild(component.displayObject); this._entity.scene.renderableComponents.add(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); this._entity.scene.entityProcessors.onComponentAdded(this._entity); } @@ -3627,8 +3656,10 @@ var es; if (this._componentsToAdd.length > 0) { for (var i = 0, count = this._componentsToAdd.length; i < count; i++) { var component = this._componentsToAdd[i]; - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.addChild(component.displayObject); this._entity.scene.renderableComponents.add(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component)); this._entity.scene.entityProcessors.onComponentAdded(this._entity); this._components.push(component); @@ -3651,8 +3682,10 @@ var es; } }; ComponentList.prototype.handleRemove = function (component) { - if (component instanceof es.RenderableComponent) + if (component instanceof es.RenderableComponent) { + this._entity.scene.removeChild(component.displayObject); this._entity.scene.renderableComponents.remove(component); + } this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); component.onRemovedFromEntity(); @@ -4909,15 +4942,23 @@ var es; var es; (function (es) { var Renderer = (function () { - function Renderer() { + function Renderer(renderOrder, camera) { + if (camera === void 0) { camera = null; } + this.renderOrder = 0; + this.camera = camera; + this.renderOrder = renderOrder; } Renderer.prototype.onAddedToScene = function (scene) { }; - Renderer.prototype.beginRender = function (cam) { - }; Renderer.prototype.unload = function () { }; + Renderer.prototype.beginRender = function (cam) { }; Renderer.prototype.renderAfterStateCheck = function (renderable, cam) { renderable.render(cam); }; + Renderer.prototype.onSceneBackBufferSizeChanged = function (newWidth, newHeight) { + }; + Renderer.prototype.compareTo = function (other) { + return this.renderOrder - other.renderOrder; + }; return Renderer; }()); es.Renderer = Renderer; @@ -4927,7 +4968,7 @@ var es; var DefaultRenderer = (function (_super) { __extends(DefaultRenderer, _super); function DefaultRenderer() { - return _super !== null && _super.apply(this, arguments) || this; + return _super.call(this, 0, null) || this; } DefaultRenderer.prototype.render = function (scene) { var cam = this.camera ? this.camera : scene.camera; @@ -5567,8 +5608,8 @@ var es; Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { return new Rectangle(minX, minY, maxX - minX, maxY - minY); }; - Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) { - var edgeNormal = es.Vector2.zero; + Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point, edgeNormal) { + edgeNormal = es.Vector2.zero; var res = new es.Vector2(); res.x = es.MathHelper.clamp(point.x, this.left, this.right); res.y = es.MathHelper.clamp(point.y, this.top, this.bottom); @@ -5605,7 +5646,7 @@ var es; if (res.y == this.bottom) edgeNormal.y = 1; } - return { res: res, edgeNormal: edgeNormal }; + return res; }; Rectangle.prototype.getClosestPointOnBoundsToOrigin = function () { var max = this.max; @@ -5688,9 +5729,7 @@ var es; var colliders = this._entity.getComponents(es.Collider); for (var i = 0; i < colliders.length; i++) { var collider = colliders[i]; - var boxcastResult = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); - collider.bounds = boxcastResult.rect; - var neighbors = boxcastResult.colliders; + var neighbors = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); var _loop_5 = function (j) { var neighbor = neighbors[j]; if (!collider.isTrigger && !neighbor.isTrigger) @@ -5914,12 +5953,15 @@ var es; }; Physics.overlapCircleAll = function (center, randius, results, layerMask) { if (layerMask === void 0) { layerMask = -1; } + if (results.length == 0) { + console.error("An empty results array was passed in. No results will ever be returned."); + return; + } return this._spatialHash.overlapCircle(center, randius, results, layerMask); }; Physics.boxcastBroadphase = function (rect, layerMask) { if (layerMask === void 0) { layerMask = this.allLayers; } - var boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); - return { colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds }; + return this._spatialHash.aabbBroadphase(rect, null, layerMask); }; Physics.boxcastBroadphaseExcludingSelf = function (collider, rect, layerMask) { if (layerMask === void 0) { layerMask = this.allLayers; } @@ -6026,9 +6068,9 @@ var es; } return new es.Vector2(x / points.length, y / points.length); }; - Polygon.getClosestPointOnPolygonToPoint = function (points, point) { - var distanceSquared = Number.MAX_VALUE; - var edgeNormal = new es.Vector2(0, 0); + Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) { + distanceSquared = Number.MAX_VALUE; + edgeNormal = new es.Vector2(0, 0); var closestPoint = new es.Vector2(0, 0); var tempDistanceSquared; for (var i = 0; i < points.length; i++) { @@ -6044,8 +6086,8 @@ var es; edgeNormal = new es.Vector2(-line.y, line.x); } } - edgeNormal = es.Vector2.normalize(edgeNormal); - return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + es.Vector2Ext.normalize(edgeNormal); + return closestPoint; }; Polygon.prototype.recalculateBounds = function (collider) { this.center = collider.localOffset; @@ -6079,12 +6121,11 @@ var es; this.bounds.location = es.Vector2.add(this.bounds.location, this.position); }; Polygon.prototype.overlaps = function (other) { - var result; + var result = new es.CollisionResult(); if (other instanceof Polygon) - return es.ShapeCollisions.polygonToPolygon(this, other); + return es.ShapeCollisions.polygonToPolygon(this, other, result); if (other instanceof es.Circle) { - result = es.ShapeCollisions.circleToPolygon(other, this); - if (result) { + if (es.ShapeCollisions.circleToPolygon(other, this, result)) { result.invertResult(); return true; } @@ -6092,18 +6133,16 @@ var es; } throw new Error("overlaps of Pologon to " + other + " are not supported"); }; - Polygon.prototype.collidesWithShape = function (other) { - var result = new es.CollisionResult(); + Polygon.prototype.collidesWithShape = function (other, result) { if (other instanceof Polygon) { - return es.ShapeCollisions.polygonToPolygon(this, other); + return es.ShapeCollisions.polygonToPolygon(this, other, result); } if (other instanceof es.Circle) { - result = es.ShapeCollisions.circleToPolygon(other, this); - if (result) { + if (es.ShapeCollisions.circleToPolygon(other, this, result)) { result.invertResult(); - return result; + return true; } - return null; + return false; } throw new Error("overlaps of Polygon to " + other + " are not supported"); }; @@ -6119,8 +6158,8 @@ var es; } return isInside; }; - Polygon.prototype.pointCollidesWithShape = function (point) { - return es.ShapeCollisions.pointToPoly(point, this); + Polygon.prototype.pointCollidesWithShape = function (point, result) { + return es.ShapeCollisions.pointToPoly(point, this, result); }; return Polygon; }(es.Shape)); @@ -6167,11 +6206,11 @@ var es; } return _super.prototype.overlaps.call(this, other); }; - Box.prototype.collidesWithShape = function (other) { + Box.prototype.collidesWithShape = function (other, result) { if (other instanceof Box && other.isUnrotated) { - return es.ShapeCollisions.boxToBox(this, other); + return es.ShapeCollisions.boxToBox(this, other, result); } - return _super.prototype.collidesWithShape.call(this, other); + return _super.prototype.collidesWithShape.call(this, other, result); }; Box.prototype.containsPoint = function (point) { if (this.isUnrotated) @@ -6209,28 +6248,29 @@ var es; this.bounds = new es.Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2); }; Circle.prototype.overlaps = function (other) { + var result = new es.CollisionResult(); if (other instanceof es.Box && other.isUnrotated) return es.Collisions.isRectToCircle(other.bounds, this.position, this.radius); if (other instanceof Circle) return es.Collisions.isCircleToCircle(this.position, this.radius, other.position, other.radius); if (other instanceof es.Polygon) - return es.ShapeCollisions.circleToPolygon(this, other); + return es.ShapeCollisions.circleToPolygon(this, other, result); throw new Error("overlaps of circle to " + other + " are not supported"); }; - Circle.prototype.collidesWithShape = function (other) { + Circle.prototype.collidesWithShape = function (other, result) { if (other instanceof es.Box && other.isUnrotated) { - return es.ShapeCollisions.circleToBox(this, other); + return es.ShapeCollisions.circleToBox(this, other, result); } if (other instanceof Circle) { - return es.ShapeCollisions.circleToCircle(this, other); + return es.ShapeCollisions.circleToCircle(this, other, result); } if (other instanceof es.Polygon) { - return es.ShapeCollisions.circleToPolygon(this, other); + return es.ShapeCollisions.circleToPolygon(this, other, result); } throw new Error("Collisions of Circle to " + other + " are not supported"); }; - Circle.prototype.pointCollidesWithShape = function (point) { - return es.ShapeCollisions.pointToCircle(point, this); + Circle.prototype.pointCollidesWithShape = function (point, result) { + return es.ShapeCollisions.pointToCircle(point, this, result); }; return Circle; }(es.Shape)); @@ -6257,8 +6297,7 @@ var es; var ShapeCollisions = (function () { function ShapeCollisions() { } - ShapeCollisions.polygonToPolygon = function (first, second) { - var result = new es.CollisionResult(); + ShapeCollisions.polygonToPolygon = function (first, second, result) { var isIntersecting = true; var firstEdges = first.edgeNormals; var secondEdges = second.edgeNormals; @@ -6291,7 +6330,7 @@ var es; if (intervalDist > 0) isIntersecting = false; if (!isIntersecting) - return null; + return false; intervalDist = Math.abs(intervalDist); if (intervalDist < minIntervalDistance) { minIntervalDistance = intervalDist; @@ -6302,7 +6341,7 @@ var es; } result.normal = translationAxis; result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-translationAxis.x, -translationAxis.y), new es.Vector2(minIntervalDistance)); - return result; + return true; }; ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) { if (minA < minB) @@ -6323,16 +6362,13 @@ var es; } return { min: min, max: max }; }; - ShapeCollisions.circleToPolygon = function (circle, polygon) { - var result = new es.CollisionResult(); + ShapeCollisions.circleToPolygon = function (circle, polygon, result) { var poly2Circle = es.Vector2.subtract(circle.position, polygon.position); - var gpp = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); - var closestPoint = gpp.closestPoint; - var distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; + var distanceSquared = 0; + var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle, distanceSquared, result.normal); var circleCenterInsidePoly = polygon.containsPoint(circle.position); if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) - return null; + return false; var mtv; if (circleCenterInsidePoly) { mtv = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared) - circle.radius)); @@ -6348,16 +6384,15 @@ var es; } result.minimumTranslationVector = mtv; result.point = es.Vector2.add(closestPoint, polygon.position); - return result; + return true; }; - ShapeCollisions.circleToBox = function (circle, box) { - var result = new es.CollisionResult(); - var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; + ShapeCollisions.circleToBox = function (circle, box, result) { + var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); if (box.containsPoint(circle.position)) { result.point = closestPointOnBounds; var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.subtract(result.normal, new es.Vector2(circle.radius))); result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace); - return result; + return true; } var sqrDistance = es.Vector2.distanceSquared(closestPointOnBounds, circle.position); if (sqrDistance == 0) { @@ -6366,14 +6401,14 @@ var es; else if (sqrDistance <= circle.radius * circle.radius) { result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds); var depth = result.normal.length() - circle.radius; - result.normal = es.Vector2Ext.normalize(result.normal); + result.point = closestPointOnBounds; + es.Vector2Ext.normalize(result.normal); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal); - return result; + return true; } - return null; + return false; }; - ShapeCollisions.pointToCircle = function (point, circle) { - var result = new es.CollisionResult(); + ShapeCollisions.pointToCircle = function (point, circle, result) { var distanceSquared = es.Vector2.distanceSquared(point, circle.position); var sumOfRadii = 1 + circle.radius; var collided = distanceSquared < sumOfRadii * sumOfRadii; @@ -6382,9 +6417,9 @@ var es; var depth = sumOfRadii - Math.sqrt(distanceSquared); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth, -depth), result.normal); result.point = es.Vector2.add(circle.position, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius, circle.radius))); - return result; + return true; } - return null; + return false; }; ShapeCollisions.closestPointOnLine = function (lineA, lineB, closestTo) { var v = es.Vector2.subtract(lineB, lineA); @@ -6393,22 +6428,17 @@ var es; t = es.MathHelper.clamp(t, 0, 1); return es.Vector2.add(lineA, es.Vector2.multiply(v, new es.Vector2(t, t))); }; - ShapeCollisions.pointToPoly = function (point, poly) { - var result = new es.CollisionResult(); + ShapeCollisions.pointToPoly = function (point, poly, result) { if (poly.containsPoint(point)) { - var distanceSquared = void 0; - var gpp = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position)); - var closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; + var distanceSquared = 0; + var closestPoint = es.Polygon.getClosestPointOnPolygonToPoint(poly.points, es.Vector2.subtract(point, poly.position), distanceSquared, result.normal); result.minimumTranslationVector = es.Vector2.multiply(result.normal, new es.Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); result.point = es.Vector2.add(closestPoint, poly.position); - return result; + return true; } - return null; + return false; }; - ShapeCollisions.circleToCircle = function (first, second) { - var result = new es.CollisionResult(); + ShapeCollisions.circleToCircle = function (first, second, result) { var distanceSquared = es.Vector2.distanceSquared(first.position, second.position); var sumOfRadii = first.radius + second.radius; var collided = distanceSquared < sumOfRadii * sumOfRadii; @@ -6417,22 +6447,21 @@ var es; var depth = sumOfRadii - Math.sqrt(distanceSquared); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(-depth), result.normal); result.point = es.Vector2.add(second.position, es.Vector2.multiply(result.normal, new es.Vector2(second.radius))); - return result; + return true; } - return null; + return false; }; - ShapeCollisions.boxToBox = function (first, second) { - var result = new es.CollisionResult(); + ShapeCollisions.boxToBox = function (first, second, result) { var minkowskiDiff = this.minkowskiDifference(first, second); if (minkowskiDiff.contains(0, 0)) { result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); - if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) - return null; + if (result.minimumTranslationVector.equals(es.Vector2.zero)) + return false; result.normal = new es.Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); result.normal.normalize(); - return result; + return true; } - return null; + return false; }; ShapeCollisions.minkowskiDifference = function (first, second) { var positionOffset = es.Vector2.subtract(first.position, es.Vector2.add(first.bounds.location, es.Vector2.divide(first.bounds.size, new es.Vector2(2)))); @@ -6544,16 +6573,14 @@ var es; } } } - return { tempHashSet: this._tempHashSet, bounds: bounds }; + return this._tempHashSet; }; SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { var bounds = new es.Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; this._overlapTestCircle.position = circleCenter; var resultCounter = 0; - var aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); - bounds = aabbBroadphaseResult.bounds; - var potentials = aabbBroadphaseResult.tempHashSet; + var potentials = this.aabbBroadphase(bounds, null, layerMask); for (var i = 0; i < potentials.length; i++) { var collider = potentials[i]; if (collider instanceof es.BoxCollider) { diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 7129fc46..58777122 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21,t.x*n.m12+t.y*n.m22)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),this.addEventListener(egret.Event.RENDER,this.draw,this),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=this._position.round()},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},n.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){},n.prototype.onBecameInvisible=function(){},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=function(e){function n(n){void 0===n&&(n=null);var i=e.call(this)||this;return n instanceof t.Sprite?i.setSprite(n):n instanceof egret.Texture&&i.setSprite(new t.Sprite(n)),i}return __extends(n,e),Object.defineProperty(n.prototype,"bounds",{get:function(){if(this._areBoundsDirty)return this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),n.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this},n.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this._areBoundsDirty=!0),this},n.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},n.prototype.render=function(t){},n}(t.RenderableComponent);t.SpriteRenderer=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e){var n=new t.CollisionResult;if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return null;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){},t.prototype.unload=function(){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},e.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e){return t.ShapeCollisions.pointToPoly(e,this)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return null;(g=Math.abs(g))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n){var i=new t.CollisionResult,r=t.Vector2.subtract(e.position,n.position),o=t.Polygon.getClosestPointOnPolygonToPoint(n.points,r),s=o.closestPoint,a=o.distanceSquared;i.normal=o.edgeNormal;var c,h=n.containsPoint(e.position);if(a>e.radius*e.radius&&!h)return null;if(h)c=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(a)-e.radius));else if(0==a)c=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else{var u=Math.sqrt(a);c=t.Vector2.multiply(new t.Vector2(-t.Vector2.subtract(r,s)),new t.Vector2((e.radius-a)/u))}return i.minimumTranslationVector=c,i.point=t.Vector2.add(s,n.position),i},e.circleToBox=function(e,n){var i=new t.CollisionResult,r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position).res;if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),i}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),i}return null},e.pointToCircle=function(e,n){var i=new t.CollisionResult,r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Components/Camera.ts b/source/src/ECS/Components/Camera.ts index e3a61854..1af2d159 100644 --- a/source/src/ECS/Components/Camera.ts +++ b/source/src/ECS/Components/Camera.ts @@ -122,7 +122,7 @@ module es { this._bounds.location = new Vector2(minX, minY); this._bounds.width = maxX - minX; - this._bounds.height = maxX - minY; + this._bounds.height = maxY - minY; } else { this._bounds.location = topLeft; this._bounds.width = bottomRight.x - topLeft.x; diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index e74088cc..416a3aa6 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -205,7 +205,7 @@ module es { * 检查这个形状是否与物理系统中的其他对撞机重叠 * @param other */ - public overlaps(other: Collider) { + public overlaps(other: Collider): boolean { return this.shape.overlaps(other.shape); } @@ -213,20 +213,21 @@ module es { * 检查这个与运动应用的碰撞器(移动向量)是否与碰撞器碰撞。如果是这样,将返回true,并且结果将填充碰撞数据。 * @param collider * @param motion + * @param result */ - public collidesWith(collider: Collider, motion: Vector2) { + public collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean { // 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠 let oldPosition = this.entity.position; - this.entity.position = Vector2.add(this.entity.position, motion); + this.entity.position.add(motion); - let result = this.shape.collidesWithShape(collider.shape); - if (result) + let didCollide = this.shape.collidesWithShape(collider.shape, result); + if (didCollide) result.collider = collider; // 将图形位置返回到检查前的位置 this.entity.position = oldPosition; - return result; + return didCollide; } public clone(): Component{ diff --git a/source/src/ECS/Components/Physics/Mover.ts b/source/src/ECS/Components/Physics/Mover.ts index 0de3dba3..c05f31c2 100644 --- a/source/src/ECS/Components/Physics/Mover.ts +++ b/source/src/ECS/Components/Physics/Mover.ts @@ -16,12 +16,11 @@ module es { /** * 计算修改运动矢量的运动,以考虑移动时可能发生的碰撞 * @param motion + * @param collisionResult */ - public calculateMovement(motion: Vector2){ - let collisionResult = new CollisionResult(); - + public calculateMovement(motion: Vector2, collisionResult: CollisionResult): boolean{ if (!this.entity.getComponent(Collider) || !this._triggerHelper){ - return null; + return false; } // 移动所有的非触发碰撞器并获得最近的碰撞 @@ -37,9 +36,7 @@ module es { let bounds = collider.bounds; bounds.x += motion.x; bounds.y += motion.y; - let boxcastResult = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); - bounds = boxcastResult.bounds; - let neighbors = boxcastResult.tempHashSet; + let neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers); for (let j = 0; j < neighbors.length; j ++){ let neighbor = neighbors[j]; @@ -47,13 +44,13 @@ module es { if (neighbor.isTrigger) continue; - let _internalcollisionResult = collider.collidesWith(neighbor, motion); - if (_internalcollisionResult){ + let _internalcollisionResult: CollisionResult = new CollisionResult(); + if (collider.collidesWith(neighbor, motion, _internalcollisionResult)){ // 如果碰撞 则退回之前的移动量 - motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector); + motion.subtract(_internalcollisionResult.minimumTranslationVector); // 如果我们碰到多个对象,为了简单起见,只取第一个。 - if (_internalcollisionResult.collider){ + if (_internalcollisionResult.collider != null){ collisionResult = _internalcollisionResult; } } @@ -62,7 +59,7 @@ module es { ListPool.free(colliders); - return {collisionResult: collisionResult, motion: motion}; + return collisionResult.collider != null; } /** @@ -81,15 +78,12 @@ module es { /** * 通过调用calculateMovement和applyMovement来移动考虑碰撞的实体; * @param motion + * @param collisionResult */ - public move(motion: Vector2){ - let movementResult = this.calculateMovement(motion); - let collisionResult = movementResult.collisionResult; - motion = movementResult.motion; - + public move(motion: Vector2, collisionResult: CollisionResult){ + this.calculateMovement(motion, collisionResult); this.applyMovement(motion); - - return collisionResult; + return collisionResult.collider != null; } } } diff --git a/source/src/ECS/Components/Physics/ProjectileMover.ts b/source/src/ECS/Components/Physics/ProjectileMover.ts index 72e10eec..bf018140 100644 --- a/source/src/ECS/Components/Physics/ProjectileMover.ts +++ b/source/src/ECS/Components/Physics/ProjectileMover.ts @@ -28,8 +28,8 @@ module es { // 获取任何可能在新位置发生碰撞的东西 let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers); - for (let i = 0; i < neighbors.colliders.length; i ++){ - let neighbor = neighbors.colliders[i]; + for (let i = 0; i < neighbors.length; i ++){ + let neighbor = neighbors[i]; if (this._collider.overlaps(neighbor) && neighbor.enabled){ didCollide = true; this.notifyTriggerListeners(this._collider, neighbor); diff --git a/source/src/ECS/Components/RenderableComponent.ts b/source/src/ECS/Components/RenderableComponent.ts index a99e5678..64190f85 100644 --- a/source/src/ECS/Components/RenderableComponent.ts +++ b/source/src/ECS/Components/RenderableComponent.ts @@ -4,6 +4,10 @@ module es { * 所有可渲染组件的基类 */ export abstract class RenderableComponent extends Component implements IRenderable { + /** + * 用于装载egret显示对象 + */ + public displayObject: egret.DisplayObject = new egret.DisplayObject(); /** * renderableComponent的宽度 * 如果你不重写bounds属性则需要实现这个 @@ -107,6 +111,7 @@ module es { * 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用 */ protected onBecameVisible() { + this.displayObject.visible = this.isVisible; } /** @@ -114,6 +119,7 @@ module es { * 如果渲染器不适用isVisibleFromCamera进行剔除检查 这些方法不会被调用 */ protected onBecameInvisible() { + this.displayObject.visible = this.isVisible; } /** @@ -165,6 +171,17 @@ module es { return this; } + /** + * 进行状态同步 + */ + public sync(camera: Camera){ + this.displayObject.x = this.entity.position.x + this.localOffset.x - camera.position.x + camera.origin.x; + this.displayObject.y = this.entity.position.y + this.localOffset.y - camera.position.y + camera.origin.y; + this.displayObject.scaleX = this.entity.scale.x; + this.displayObject.scaleY = this.entity.scale.y; + this.displayObject.rotation = this.entity.rotation; + } + public toString(){ return `[RenderableComponent] renderLayer: ${this.renderLayer}`; } diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts index f57f66e8..2e26ddff 100644 --- a/source/src/ECS/Components/SpriteRenderer.ts +++ b/source/src/ECS/Components/SpriteRenderer.ts @@ -1,4 +1,6 @@ module es { + import Bitmap = egret.Bitmap; + export class SpriteRenderer extends RenderableComponent { public get bounds() { if (this._areBoundsDirty) { @@ -8,9 +10,9 @@ module es { this._sprite.sourceRect.height); this._areBoundsDirty = false; } - - return this._bounds; } + + return this._bounds; } /** @@ -83,7 +85,10 @@ module es { this._sprite = sprite; if (this._sprite) { this._origin = this._sprite.origin; + this.displayObject.anchorOffsetX = this._origin.x; + this.displayObject.anchorOffsetY = this._origin.y; } + this.displayObject = new Bitmap(sprite.texture2D); return this; } @@ -95,6 +100,8 @@ module es { public setOrigin(origin: Vector2): SpriteRenderer { if (this._origin != origin) { this._origin = origin; + this.displayObject.anchorOffsetX = this._origin.x; + this.displayObject.anchorOffsetY = this._origin.y; this._areBoundsDirty = true; } @@ -113,7 +120,7 @@ module es { } public render(camera: Camera) { - // TODO: render + this.sync(camera); } } } diff --git a/source/src/ECS/Core.ts b/source/src/ECS/Core.ts index 4681d637..30ba1554 100644 --- a/source/src/ECS/Core.ts +++ b/source/src/ECS/Core.ts @@ -81,8 +81,8 @@ module es { this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this); this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this); this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); - this.addEventListener(egret.Event.RENDER, this.draw, this); + Input.initialize(); this.initialize(); } @@ -135,6 +135,8 @@ module es { } // this.endDebugUpdate(); + + await this.draw(); } public async draw() { diff --git a/source/src/ECS/Transform.ts b/source/src/ECS/Transform.ts index 34850e97..7b075238 100644 --- a/source/src/ECS/Transform.ts +++ b/source/src/ECS/Transform.ts @@ -7,6 +7,8 @@ module transform { } module es { + import HashObject = egret.HashObject; + export enum DirtyType { clean, positionDirty, @@ -14,7 +16,7 @@ module es { rotationDirty, } - export class Transform { + export class Transform extends HashObject { /** 与此转换关联的实体 */ public readonly entity: Entity; /** @@ -243,6 +245,7 @@ module es { public _children: Transform[]; constructor(entity: Entity) { + super(); this.entity = entity; this.scale = Vector2.one; this._children = []; @@ -261,7 +264,7 @@ module es { * @param parent */ public setParent(parent: Transform): Transform { - if (this._parent == parent) + if (this._parent.equals(parent)) return this; if (!this._parent) { @@ -282,7 +285,7 @@ module es { */ public setPosition(x: number, y: number): Transform { let position = new Vector2(x, y); - if (position == this._position) + if (position.equals(this._position)) return this; this._position = position; @@ -301,7 +304,7 @@ module es { * @param localPosition */ public setLocalPosition(localPosition: Vector2): Transform { - if (localPosition == this._localPosition) + if (localPosition.equals(this._localPosition)) return this; this._localPosition = localPosition; @@ -493,5 +496,9 @@ module es { scale: ${this.scale}, localPosition: ${this._localPosition}, localRotation: ${this._localRotation}, localScale: ${this._localScale}]`; } + + public equals(other: Transform){ + return other.hashCode == this.hashCode; + } } } \ No newline at end of file diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts index 38769848..67bb89bd 100644 --- a/source/src/ECS/Utils/ComponentList.ts +++ b/source/src/ECS/Utils/ComponentList.ts @@ -76,8 +76,11 @@ module es { let component = this._components[i]; // 处理渲染层列表 - if (component instanceof RenderableComponent) + if (component instanceof RenderableComponent){ + this._entity.scene.removeChild(component.displayObject); this._entity.scene.renderableComponents.remove(component); + } + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); @@ -88,8 +91,10 @@ module es { for (let i = 0; i < this._components.length; i++) { let component = this._components[i]; - if (component instanceof RenderableComponent) + if (component instanceof RenderableComponent){ + this._entity.scene.addChild(component.displayObject); this._entity.scene.renderableComponents.add(component); + } this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); this._entity.scene.entityProcessors.onComponentAdded(this._entity); @@ -112,8 +117,11 @@ module es { if (this._componentsToAdd.length > 0) { for (let i = 0, count = this._componentsToAdd.length; i < count; i++) { let component = this._componentsToAdd[i]; - if (component instanceof RenderableComponent) + if (component instanceof RenderableComponent){ + this._entity.scene.addChild(component.displayObject); this._entity.scene.renderableComponents.add(component); + } + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component)); this._entity.scene.entityProcessors.onComponentAdded(this._entity); @@ -148,8 +156,11 @@ module es { public handleRemove(component: Component) { // 处理渲染层列表 - if (component instanceof RenderableComponent) + if (component instanceof RenderableComponent){ + this._entity.scene.removeChild(component.displayObject); this._entity.scene.renderableComponents.remove(component); + } + this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false); this._entity.scene.entityProcessors.onComponentRemoved(this._entity); diff --git a/source/src/Graphics/Renderers/DefaultRenderer.ts b/source/src/Graphics/Renderers/DefaultRenderer.ts index 67fa419b..b862d70f 100644 --- a/source/src/Graphics/Renderers/DefaultRenderer.ts +++ b/source/src/Graphics/Renderers/DefaultRenderer.ts @@ -1,6 +1,10 @@ /// module es { export class DefaultRenderer extends Renderer { + constructor(){ + super(0, null); + } + public render(scene: Scene) { let cam = this.camera ? this.camera : scene.camera; this.beginRender(cam); diff --git a/source/src/Graphics/Renderers/Renderer.ts b/source/src/Graphics/Renderers/Renderer.ts index 6859059b..364cc520 100644 --- a/source/src/Graphics/Renderers/Renderer.ts +++ b/source/src/Graphics/Renderers/Renderer.ts @@ -9,6 +9,15 @@ module es { * Renderer子类可以选择调用beginRender时使用的摄像头 */ public camera: Camera; + /** + * 指定场景调用渲染器的顺序 + */ + public readonly renderOrder: number = 0; + + protected constructor(renderOrder: number, camera: Camera = null){ + this.camera = camera; + this.renderOrder = renderOrder; + } /** * 当渲染器被添加到场景时调用 @@ -16,17 +25,18 @@ module es { */ public onAddedToScene(scene: Scene){} - protected beginRender(cam: Camera){ - - } + /** + * 当场景结束或渲染器从场景中移除时调用。使用这个进行清理。 + */ + public unload(){ } /** * - * @param scene + * @param cam */ - public abstract render(scene: Scene); + protected beginRender(cam: Camera){ } - public unload(){ } + public abstract render(scene: Scene); /** * @@ -36,5 +46,18 @@ module es { protected renderAfterStateCheck(renderable: IRenderable, cam: Camera){ renderable.render(cam); } + + /** + * 当默认场景渲染目标被调整大小和当场景已经开始添加渲染器时调用 + * @param newWidth + * @param newHeight + */ + public onSceneBackBufferSizeChanged(newWidth: number, newHeight: number){ + + } + + public compareTo(other: Renderer): number{ + return this.renderOrder - other.renderOrder; + } } } diff --git a/source/src/Math/Rectangle.ts b/source/src/Math/Rectangle.ts index 22e368e4..4bd43328 100644 --- a/source/src/Math/Rectangle.ts +++ b/source/src/Math/Rectangle.ts @@ -70,9 +70,10 @@ module es { /** * 获取矩形边界上与给定点最近的点 * @param point + * @param edgeNormal */ - public getClosestPointOnRectangleBorderToPoint(point: Vector2): { res: Vector2, edgeNormal: Vector2 } { - let edgeNormal = Vector2.zero; + public getClosestPointOnRectangleBorderToPoint(point: Vector2, edgeNormal: Vector2): Vector2 { + edgeNormal = Vector2.zero; // 对于每个轴,如果点在盒子外面 let res = new Vector2(); @@ -107,7 +108,7 @@ module es { if (res.y == this.bottom) edgeNormal.y = 1; } - return { res: res, edgeNormal: edgeNormal }; + return res; } /** diff --git a/source/src/Math/Vector2.ts b/source/src/Math/Vector2.ts index fbce5533..de4afad7 100644 --- a/source/src/Math/Vector2.ts +++ b/source/src/Math/Vector2.ts @@ -197,7 +197,8 @@ module es { * @param matrix */ public static transform(position: Vector2, matrix: Matrix2D){ - return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22)); + return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31, + (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32); } /** @@ -221,5 +222,9 @@ module es { return result; } + + public equals(other: Vector2){ + return other.x == this.x && other.y == this.y; + } } } diff --git a/source/src/Physics/ColliderTriggerHelper.ts b/source/src/Physics/ColliderTriggerHelper.ts index c4a5de78..4496d54d 100644 --- a/source/src/Physics/ColliderTriggerHelper.ts +++ b/source/src/Physics/ColliderTriggerHelper.ts @@ -22,9 +22,7 @@ module es { for (let i = 0; i < colliders.length; i++) { let collider = colliders[i]; - let boxcastResult = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); - collider.bounds = boxcastResult.rect; - let neighbors = boxcastResult.colliders; + let neighbors = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers); for (let j = 0; j < neighbors.length; j++) { let neighbor = neighbors[j]; if (!collider.isTrigger && !neighbor.isTrigger) diff --git a/source/src/Physics/Physics.ts b/source/src/Physics/Physics.ts index 57be0921..7704aacd 100644 --- a/source/src/Physics/Physics.ts +++ b/source/src/Physics/Physics.ts @@ -17,15 +17,37 @@ module es { this._spatialHash.clear(); } + /** + * 获取位于指定圆内的所有碰撞器 + * @param center + * @param randius + * @param results + * @param layerMask + */ public static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask = -1){ + if (results.length == 0){ + console.error("An empty results array was passed in. No results will ever be returned."); + return; + } + return this._spatialHash.overlapCircle(center, randius, results, layerMask); } + /** + * 返回所有碰撞器与边界相交的碰撞器。bounds。请注意,这是一个broadphase检查,所以它只检查边界,不做单个碰撞到碰撞器的检查! + * @param rect + * @param layerMask + */ public static boxcastBroadphase(rect: Rectangle, layerMask: number = this.allLayers){ - let boxcastResult = this._spatialHash.aabbBroadphase(rect, null, layerMask); - return {colliders: boxcastResult.tempHashSet, rect: boxcastResult.bounds}; + return this._spatialHash.aabbBroadphase(rect, null, layerMask); } + /** + * 返回所有与边界相交的碰撞器,不包括传入的碰撞器(self)。如果您希望为其他查询自行创建扫过的边界,则此方法非常有用 + * @param collider + * @param rect + * @param layerMask + */ public static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask = this.allLayers){ return this._spatialHash.aabbBroadphase(rect, collider, layerMask); } diff --git a/source/src/Physics/Shapes/Box.ts b/source/src/Physics/Shapes/Box.ts index 27d98e3d..afcc3e54 100644 --- a/source/src/Physics/Shapes/Box.ts +++ b/source/src/Physics/Shapes/Box.ts @@ -66,15 +66,15 @@ module es { return super.overlaps(other); } - public collidesWithShape(other: Shape){ + public collidesWithShape(other: Shape, result: CollisionResult): boolean{ // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测 if (other instanceof Box && (other as Box).isUnrotated){ - return ShapeCollisions.boxToBox(this, other); + return ShapeCollisions.boxToBox(this, other, result); } // TODO: 让 minkowski 运行于 cricleToBox - return super.collidesWithShape(other); + return super.collidesWithShape(other, result); } public containsPoint(point: Vector2){ diff --git a/source/src/Physics/Shapes/Circle.ts b/source/src/Physics/Shapes/Circle.ts index 70e19752..f33f1a1c 100644 --- a/source/src/Physics/Shapes/Circle.ts +++ b/source/src/Physics/Shapes/Circle.ts @@ -34,6 +34,7 @@ module es { } public overlaps(other: Shape) { + let result: CollisionResult = new CollisionResult(); if (other instanceof Box && (other as Box).isUnrotated) return Collisions.isRectToCircle(other.bounds, this.position, this.radius); @@ -41,29 +42,29 @@ module es { return Collisions.isCircleToCircle(this.position, this.radius, other.position, (other as Circle).radius); if (other instanceof Polygon) - return ShapeCollisions.circleToPolygon(this, other); + return ShapeCollisions.circleToPolygon(this, other, result); throw new Error(`overlaps of circle to ${other} are not supported`); } - public collidesWithShape(other: Shape): CollisionResult { + public collidesWithShape(other: Shape, result: CollisionResult): boolean { if (other instanceof Box && (other as Box).isUnrotated) { - return ShapeCollisions.circleToBox(this, other); + return ShapeCollisions.circleToBox(this, other, result); } if (other instanceof Circle) { - return ShapeCollisions.circleToCircle(this, other); + return ShapeCollisions.circleToCircle(this, other, result); } if (other instanceof Polygon) { - return ShapeCollisions.circleToPolygon(this, other); + return ShapeCollisions.circleToPolygon(this, other, result); } throw new Error(`Collisions of Circle to ${other} are not supported`); } - public pointCollidesWithShape(point: Vector2): CollisionResult { - return ShapeCollisions.pointToCircle(point, this); + public pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean { + return ShapeCollisions.pointToCircle(point, this, result); } } } diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index 2904800f..3df91c4f 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -141,10 +141,12 @@ module es { * 点应该在多边形的空间中(点-多边形.位置) * @param points * @param point + * @param distanceSquared + * @param edgeNormal */ - public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { closestPoint, distanceSquared, edgeNormal } { - let distanceSquared = Number.MAX_VALUE; - let edgeNormal = new Vector2(0, 0); + public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2 { + distanceSquared = Number.MAX_VALUE; + edgeNormal = new Vector2(0, 0); let closestPoint = new Vector2(0, 0); let tempDistanceSquared; @@ -166,9 +168,9 @@ module es { } } - edgeNormal = Vector2.normalize(edgeNormal); + Vector2Ext.normalize(edgeNormal); - return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal }; + return closestPoint; } public recalculateBounds(collider: Collider){ @@ -221,13 +223,12 @@ module es { } public overlaps(other: Shape){ - let result: CollisionResult; + let result: CollisionResult = new CollisionResult(); if (other instanceof Polygon) - return ShapeCollisions.polygonToPolygon(this, other); + return ShapeCollisions.polygonToPolygon(this, other, result); if (other instanceof Circle){ - result = ShapeCollisions.circleToPolygon(other, this); - if (result){ + if (ShapeCollisions.circleToPolygon(other, this, result)){ result.invertResult(); return true; } @@ -238,20 +239,18 @@ module es { throw new Error(`overlaps of Pologon to ${other} are not supported`); } - public collidesWithShape(other: Shape){ - let result = new CollisionResult(); + public collidesWithShape(other: Shape, result: CollisionResult): boolean{ if (other instanceof Polygon){ - return ShapeCollisions.polygonToPolygon(this, other); + return ShapeCollisions.polygonToPolygon(this, other, result); } if (other instanceof Circle){ - result = ShapeCollisions.circleToPolygon(other, this); - if (result){ + if (ShapeCollisions.circleToPolygon(other, this, result)){ result.invertResult(); - return result; + return true; } - return null; + return false; } throw new Error(`overlaps of Polygon to ${other} are not supported`); @@ -278,8 +277,8 @@ module es { return isInside; } - public pointCollidesWithShape(point: Vector2): CollisionResult { - return ShapeCollisions.pointToPoly(point, this); + public pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean { + return ShapeCollisions.pointToPoly(point, this, result); } } } \ No newline at end of file diff --git a/source/src/Physics/Shapes/Shape.ts b/source/src/Physics/Shapes/Shape.ts index 9557753e..5c7b81e1 100644 --- a/source/src/Physics/Shapes/Shape.ts +++ b/source/src/Physics/Shapes/Shape.ts @@ -16,9 +16,9 @@ module es { public bounds: Rectangle; public abstract recalculateBounds(collider: Collider); - public abstract pointCollidesWithShape(point: Vector2): CollisionResult; - public abstract overlaps(other: Shape); - public abstract collidesWithShape(other: Shape): CollisionResult; + public abstract overlaps(other: Shape): boolean; + public abstract collidesWithShape(other: Shape, collisionResult: CollisionResult): boolean; + public abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean; public clone(): Shape{ return ObjectUtils.clone(this); diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts index fd6e5659..799b1695 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts @@ -4,9 +4,9 @@ module es { * 检查两个多边形之间的碰撞 * @param first * @param second + * @param result */ - public static polygonToPolygon(first: Polygon, second: Polygon) { - let result = new CollisionResult(); + public static polygonToPolygon(first: Polygon, second: Polygon, result: CollisionResult): boolean { let isIntersecting = true; let firstEdges = first.edgeNormals; @@ -54,7 +54,7 @@ module es { // 如果多边形不相交,也不会相交,退出循环 if (!isIntersecting) - return null; + return false; // 检查当前间隔距离是否为最小值。如果是,则存储间隔距离和当前距离。这将用于计算最小平移向量 intervalDist = Math.abs(intervalDist); @@ -71,7 +71,7 @@ module es { result.normal = translationAxis; result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance)); - return result; + return true; } /** @@ -115,20 +115,17 @@ module es { * * @param circle * @param polygon + * @param result */ - public static circleToPolygon(circle: Circle, polygon: Polygon) { - let result = new CollisionResult(); - + public static circleToPolygon(circle: Circle, polygon: Polygon, result: CollisionResult): boolean { let poly2Circle = Vector2.subtract(circle.position, polygon.position); - let gpp = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle); - let closestPoint: Vector2 = gpp.closestPoint; - let distanceSquared: number = gpp.distanceSquared; - result.normal = gpp.edgeNormal; + let distanceSquared = 0; + let closestPoint = Polygon.getClosestPointOnPolygonToPoint(polygon.points, poly2Circle, distanceSquared, result.normal); let circleCenterInsidePoly = polygon.containsPoint(circle.position); if (distanceSquared > circle.radius * circle.radius && !circleCenterInsidePoly) - return null; + return false; let mtv: Vector2; if (circleCenterInsidePoly) { @@ -145,17 +142,17 @@ module es { result.minimumTranslationVector = mtv; result.point = Vector2.add(closestPoint, polygon.position); - return result; + return true; } /** * 适用于圆心在方框内以及只与方框外圆心重叠的圆。 * @param circle * @param box + * @param result */ - public static circleToBox(circle: Circle, box: Box): CollisionResult { - let result = new CollisionResult(); - let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position).res; + public static circleToBox(circle: Circle, box: Box, result: CollisionResult): boolean { + let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); if (box.containsPoint(circle.position)) { result.point = closestPointOnBounds; @@ -163,7 +160,7 @@ module es { let safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); - return result; + return true; } let sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); @@ -172,23 +169,24 @@ module es { } else if (sqrDistance <= circle.radius * circle.radius) { result.normal = Vector2.subtract(circle.position, closestPointOnBounds); let depth = result.normal.length() - circle.radius; - result.normal = Vector2Ext.normalize(result.normal); + + result.point = closestPointOnBounds; + Vector2Ext.normalize(result.normal); result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); - return result; + return true; } - return null; + return false; } /** * * @param point * @param circle + * @param result */ - public static pointToCircle(point: Vector2, circle: Circle) { - let result = new CollisionResult(); - + public static pointToCircle(point: Vector2, circle: Circle, result: CollisionResult): boolean { let distanceSquared = Vector2.distanceSquared(point, circle.position); let sumOfRadii = 1 + circle.radius; let collided = distanceSquared < sumOfRadii * sumOfRadii; @@ -198,10 +196,10 @@ module es { result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth, -depth), result.normal); result.point = Vector2.add(circle.position, Vector2.multiply(result.normal, new Vector2(circle.radius, circle.radius))); - return result; + return true; } - return null; + return false; } /** @@ -210,7 +208,7 @@ module es { * @param lineB * @param closestTo */ - public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2) { + public static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2 { let v = Vector2.subtract(lineB, lineA); let w = Vector2.subtract(closestTo, lineA); let t = Vector2.dot(w, v) / Vector2.dot(v, v); @@ -223,24 +221,20 @@ module es { * * @param point * @param poly + * @param result */ - public static pointToPoly(point: Vector2, poly: Polygon) { - let result = new CollisionResult(); - + public static pointToPoly(point: Vector2, poly: Polygon, result: CollisionResult): boolean { if (poly.containsPoint(point)) { - let distanceSquared: number; - let gpp = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position)); - let closestPoint = gpp.closestPoint; - distanceSquared = gpp.distanceSquared; - result.normal = gpp.edgeNormal; + let distanceSquared: number = 0; + let closestPoint = Polygon.getClosestPointOnPolygonToPoint(poly.points, Vector2.subtract(point, poly.position), distanceSquared, result.normal); result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(Math.sqrt(distanceSquared), Math.sqrt(distanceSquared))); result.point = Vector2.add(closestPoint, poly.position); - return result; + return true; } - return null; + return false; } /** @@ -248,9 +242,7 @@ module es { * @param first * @param second */ - public static circleToCircle(first: Circle, second: Circle){ - let result = new CollisionResult(); - + public static circleToCircle(first: Circle, second: Circle, result: CollisionResult): boolean{ let distanceSquared = Vector2.distanceSquared(first.position, second.position); let sumOfRadii = first.radius + second.radius; let collided = distanceSquared < sumOfRadii * sumOfRadii; @@ -260,35 +252,34 @@ module es { result.minimumTranslationVector = Vector2.multiply(new Vector2(-depth), result.normal); result.point = Vector2.add(second.position, Vector2.multiply(result.normal, new Vector2(second.radius))); - return result; + return true; } - return null; + return false; } /** * * @param first * @param second + * @param result */ - public static boxToBox(first: Box, second: Box){ - let result = new CollisionResult(); - + public static boxToBox(first: Box, second: Box, result: CollisionResult): boolean{ let minkowskiDiff = this.minkowskiDifference(first, second); if (minkowskiDiff.contains(0, 0)){ // 计算MTV。如果它是零,我们就可以称它为非碰撞 result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin(); - if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0) - return null; + if (result.minimumTranslationVector.equals(Vector2.zero)) + return false; result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y); result.normal.normalize(); - return result; + return true; } - return null; + return false; } private static minkowskiDifference(first: Box, second: Box){ diff --git a/source/src/Physics/Verlet/SpatialHash.ts b/source/src/Physics/Verlet/SpatialHash.ts index 015c5786..0881afca 100644 --- a/source/src/Physics/Verlet/SpatialHash.ts +++ b/source/src/Physics/Verlet/SpatialHash.ts @@ -144,7 +144,7 @@ module es { * @param excludeCollider * @param layerMask */ - public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number) { + public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number) : Collider[]{ this._tempHashSet.length = 0; let p1 = this.cellCoords(bounds.x, bounds.y); @@ -172,7 +172,7 @@ module es { } } - return {tempHashSet: this._tempHashSet, bounds: bounds}; + return this._tempHashSet; } /** @@ -182,16 +182,14 @@ module es { * @param results * @param layerMask */ - public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask) { + public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask): number { let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; this._overlapTestCircle.position = circleCenter; let resultCounter = 0; - let aabbBroadphaseResult = this.aabbBroadphase(bounds, null, layerMask); - bounds = aabbBroadphaseResult.bounds; - let potentials = aabbBroadphaseResult.tempHashSet; + let potentials = this.aabbBroadphase(bounds, null, layerMask); for (let i = 0; i < potentials.length; i++) { let collider = potentials[i]; if (collider instanceof BoxCollider) { From 60921f703b34e3e77046e22b2f1544f6fef02a26 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Mon, 27 Jul 2020 17:27:32 +0800 Subject: [PATCH 14/15] =?UTF-8?q?#12=20fix=20addObserver=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.js | 10 ++- demo/libs/framework/framework.min.js | 2 +- source/bin/framework.js | 10 ++- source/bin/framework.min.js | 2 +- source/src/Extension.ts | 97 ++++++++++++++++------------ source/src/Utils/Emitter.ts | 2 +- 6 files changed, 71 insertions(+), 52 deletions(-) diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index 81b43a26..eb1699b9 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -214,7 +214,9 @@ Array.prototype.groupBy = function (keySelector) { var keys_1 = []; return array.reduce(function (groups, element, index) { var key = JSON.stringify(keySelector.call(arguments[1], element, index, array)); - var index2 = keys_1.findIndex(function (x) { return x === key; }); + var index2 = keys_1.findIndex(function (x) { + return x === key; + }); if (index2 < 0) { index2 = keys_1.push(key) - 1; } @@ -230,7 +232,9 @@ Array.prototype.groupBy = function (keySelector) { var keys = []; var _loop_1 = function (i, len) { var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array)); - var index = keys.findIndex(function (x) { return x === key; }); + var index = keys.findIndex(function (x) { + return x === key; + }); if (index < 0) { index = keys.push(key) - 1; } @@ -7056,7 +7060,7 @@ var es; list = []; this._messageTable.set(eventType, list); } - if (list.contains(handler)) + if (list.findIndex(function (funcPack) { return funcPack.func == handler; }) != -1) console.warn("您试图添加相同的观察者两次"); list.push(new FuncPack(handler, context)); }; diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 58777122..33a87cda 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/bin/framework.js b/source/bin/framework.js index 81b43a26..eb1699b9 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -214,7 +214,9 @@ Array.prototype.groupBy = function (keySelector) { var keys_1 = []; return array.reduce(function (groups, element, index) { var key = JSON.stringify(keySelector.call(arguments[1], element, index, array)); - var index2 = keys_1.findIndex(function (x) { return x === key; }); + var index2 = keys_1.findIndex(function (x) { + return x === key; + }); if (index2 < 0) { index2 = keys_1.push(key) - 1; } @@ -230,7 +232,9 @@ Array.prototype.groupBy = function (keySelector) { var keys = []; var _loop_1 = function (i, len) { var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array)); - var index = keys.findIndex(function (x) { return x === key; }); + var index = keys.findIndex(function (x) { + return x === key; + }); if (index < 0) { index = keys.push(key) - 1; } @@ -7056,7 +7060,7 @@ var es; list = []; this._messageTable.set(eventType, list); } - if (list.contains(handler)) + if (list.findIndex(function (funcPack) { return funcPack.func == handler; }) != -1) console.warn("您试图添加相同的观察者两次"); list.push(new FuncPack(handler, context)); }; diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 58777122..33a87cda 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),r.contains(n)&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/Extension.ts b/source/src/Extension.ts index aa988289..ce827664 100644 --- a/source/src/Extension.ts +++ b/source/src/Extension.ts @@ -4,84 +4,100 @@ declare interface Array { * @param predicate 表达式 */ findIndex(predicate: Function): number; + /** * 是否存在满足表达式的数组元素 * @param predicate 表达式 */ any(predicate: Function): boolean; + /** * 获取满足表达式的第一个或默认数组元素 * @param predicate 表达式 */ firstOrDefault(predicate: Function): T; + /** * 获取满足表达式的第一个数组元素 * @param predicate 表达式 */ find(predicate: Function): T; + /** * 筛选满足表达式的数组元素 * @param predicate 表达式 */ where(predicate: Function): Array; + /** * 获取满足表达式的数组元素的计数 * @param predicate 表达式 */ count(predicate: Function): number; + /** * 获取满足表达式的数组元素的数组 * @param predicate 表达式 */ findAll(predicate: Function): Array; + /** * 是否有获取满足表达式的数组元素 * @param value 值 */ contains(value): boolean; + /** * 移除满足表达式的数组元素 * @param predicate 表达式 */ removeAll(predicate: Function): void; + /** * 移除数组元素 * @param element 数组元素 */ remove(element: T): boolean; + /** * 移除特定索引数组元素 * @param index 索引 */ removeAt(index): void; + /** * 移除范围数组元素 * @param index 开始索引 * @param count 删除的个数 */ removeRange(index, count): void; + /** * 获取通过选择器转换的数组 * @param selector 选择器 */ select(selector: Function): Array; + /** * 排序(升序) * @param keySelector key选择器 * @param comparer 比较器 */ orderBy(keySelector: Function, comparer: Function): Array; + /** * 排序(降序) * @param keySelector key选择器 * @param comparer 比较器 */ orderByDescending(keySelector: Function, comparer: Function): Array; + /** * 分组 * @param keySelector key选择器 */ groupBy(keySelector: Function): Array; + /** * 求和 * @param selector 选择器 @@ -101,7 +117,7 @@ Array.prototype.findIndex = function (predicate) { } return findIndex(this, predicate); -} +}; Array.prototype.any = function (predicate) { function any(array, predicate) { @@ -109,7 +125,7 @@ Array.prototype.any = function (predicate) { } return any(this, predicate); -} +}; Array.prototype.firstOrDefault = function (predicate) { function firstOrDefault(array, predicate) { @@ -118,7 +134,7 @@ Array.prototype.firstOrDefault = function (predicate) { } return firstOrDefault(this, predicate); -} +}; Array.prototype.find = function (predicate) { function find(array, predicate) { @@ -126,7 +142,7 @@ Array.prototype.find = function (predicate) { } return find(this, predicate); -} +}; Array.prototype.where = function (predicate) { function where(array, predicate) { @@ -138,8 +154,7 @@ Array.prototype.where = function (predicate) { return ret; }, []); - } - else { + } else { let ret = []; for (let i = 0, len = array.length; i < len; i++) { let element = array[i]; @@ -153,7 +168,7 @@ Array.prototype.where = function (predicate) { } return where(this, predicate); -} +}; Array.prototype.count = function (predicate) { function count(array, predicate) { @@ -161,7 +176,7 @@ Array.prototype.count = function (predicate) { } return count(this, predicate); -} +}; Array.prototype.findAll = function (predicate) { function findAll(array, predicate) { @@ -169,7 +184,7 @@ Array.prototype.findAll = function (predicate) { } return findAll(this, predicate); -} +}; Array.prototype.contains = function (value) { function contains(array, value) { @@ -183,7 +198,7 @@ Array.prototype.contains = function (value) { } return contains(this, value); -} +}; Array.prototype.removeAll = function (predicate) { function removeAll(array, predicate) { @@ -198,7 +213,7 @@ Array.prototype.removeAll = function (predicate) { } removeAll(this, predicate); -} +}; Array.prototype.remove = function (element) { function remove(array, element) { @@ -209,14 +224,13 @@ Array.prototype.remove = function (element) { if (index >= 0) { array.splice(index, 1); return true; - } - else { + } else { return false; } } return remove(this, element); -} +}; Array.prototype.removeAt = function (index) { function removeAt(array, index) { @@ -224,7 +238,7 @@ Array.prototype.removeAt = function (index) { } return removeAt(this, index); -} +}; Array.prototype.removeRange = function (index, count) { function removeRange(array, index, count) { @@ -232,7 +246,7 @@ Array.prototype.removeRange = function (index, count) { } return removeRange(this, index, count); -} +}; Array.prototype.select = function (selector) { function select(array, selector) { @@ -241,8 +255,7 @@ Array.prototype.select = function (selector) { ret.push(selector.call(arguments[2], element, index, array)); return ret; }, []); - } - else { + } else { let ret = []; for (let i = 0, len = array.length; i < len; i++) { ret.push(selector.call(arguments[2], array[i], i, array)) @@ -253,17 +266,16 @@ Array.prototype.select = function (selector) { } return select(this, selector); -} +}; Array.prototype.orderBy = function (keySelector, comparer) { function orderBy(array, keySelector, comparer) { array.sort(function (x, y) { - let v1 = keySelector(x) - let v2 = keySelector(y) + let v1 = keySelector(x); + let v2 = keySelector(y); if (comparer) { return comparer(v1, v2); - } - else { + } else { return (v1 > v2) ? 1 : -1; } }); @@ -272,17 +284,16 @@ Array.prototype.orderBy = function (keySelector, comparer) { } return orderBy(this, keySelector, comparer); -} +}; Array.prototype.orderByDescending = function (keySelector, comparer) { function orderByDescending(array, keySelector, comparer) { array.sort(function (x, y) { - let v1 = keySelector(x) - let v2 = keySelector(y) + let v1 = keySelector(x); + let v2 = keySelector(y); if (comparer) { return -comparer(v1, v2); - } - else { + } else { return (v1 < v2) ? 1 : -1; } }); @@ -291,7 +302,7 @@ Array.prototype.orderByDescending = function (keySelector, comparer) { } return orderByDescending(this, keySelector, comparer); -} +}; Array.prototype.groupBy = function (keySelector) { function groupBy(array, keySelector) { @@ -299,7 +310,9 @@ Array.prototype.groupBy = function (keySelector) { let keys = []; return array.reduce(function (groups, element, index) { let key = JSON.stringify(keySelector.call(arguments[1], element, index, array)) - let index2 = keys.findIndex(function (x) { return x === key }); + let index2 = keys.findIndex(function (x) { + return x === key; + }); if (index2 < 0) { index2 = keys.push(key) - 1; @@ -312,13 +325,14 @@ Array.prototype.groupBy = function (keySelector) { groups[index2].push(element); return groups; }, []); - } - else { + } else { let groups = []; let keys = []; for (let i = 0, len = array.length; i < len; i++) { let key = JSON.stringify(keySelector.call(arguments[1], array[i], i, array)); - let index = keys.findIndex(function (x) { return x === key }); + let index = keys.findIndex(function (x) { + return x === key; + }); if (index < 0) { index = keys.push(key) - 1; @@ -336,7 +350,7 @@ Array.prototype.groupBy = function (keySelector) { } return groupBy(this, keySelector); -} +}; Array.prototype.sum = function (selector) { function sum(array, selector) { @@ -345,17 +359,14 @@ Array.prototype.sum = function (selector) { if (i == 0) { if (selector) { ret = selector.call(arguments[2], array[i], i, array); + } else { + ret = array[i]; } - else { - ret = array[i] - } - } - else { + } else { if (selector) { ret += selector.call(arguments[2], array[i], i, array); - } - else { - ret += array[i] + } else { + ret += array[i]; } } } @@ -364,4 +375,4 @@ Array.prototype.sum = function (selector) { } return sum(this, selector); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/source/src/Utils/Emitter.ts b/source/src/Utils/Emitter.ts index 521aa9b8..51e772cc 100644 --- a/source/src/Utils/Emitter.ts +++ b/source/src/Utils/Emitter.ts @@ -36,7 +36,7 @@ module es { this._messageTable.set(eventType, list); } - if (list.contains(handler)) + if (list.findIndex(funcPack => funcPack.func == handler) != -1) console.warn("您试图添加相同的观察者两次"); list.push(new FuncPack(handler, context)); } From d730851d97fe91a223022e14e5367980d8f9bfae Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Mon, 27 Jul 2020 18:16:19 +0800 Subject: [PATCH 15/15] =?UTF-8?q?=E4=BF=AE=E5=A4=8DcircleToBox=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=81=8F=E5=B7=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/libs/framework/framework.js | 25 ++++++++++--------- demo/libs/framework/framework.min.js | 2 +- source/bin/framework.js | 25 ++++++++++--------- source/bin/framework.min.js | 2 +- .../Components/Physics/Colliders/Collider.ts | 13 +++++----- source/src/ECS/Components/Physics/Mover.ts | 2 +- source/src/ECS/Components/SpriteRenderer.ts | 3 +++ source/src/Physics/Shapes/Polygon.ts | 4 +-- .../Shapes/ShapeCollisions/ShapeCollisions.ts | 7 ++++-- 9 files changed, 45 insertions(+), 38 deletions(-) diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index eb1699b9..01624ebc 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -2733,6 +2733,8 @@ var es; }; SpriteRenderer.prototype.render = function (camera) { this.sync(camera); + this.displayObject.x = this.entity.position.x - this.origin.x + this.localOffset.x - camera.position.x + camera.origin.x; + this.displayObject.y = this.entity.position.y - this.origin.y + this.localOffset.y - camera.position.y + camera.origin.y; }; return SpriteRenderer; }(es.RenderableComponent)); @@ -2995,7 +2997,7 @@ var es; continue; var _internalcollisionResult = new es.CollisionResult(); if (collider.collidesWith(neighbor, motion, _internalcollisionResult)) { - motion.subtract(_internalcollisionResult.minimumTranslationVector); + motion = motion.subtract(_internalcollisionResult.minimumTranslationVector); if (_internalcollisionResult.collider != null) { collisionResult = _internalcollisionResult; } @@ -3139,18 +3141,17 @@ var es; } var renderable = this.entity.getComponent(es.RenderableComponent); if (renderable) { - var bounds = renderable.bounds; - var width = bounds.width / this.entity.scale.x; - var height = bounds.height / this.entity.scale.y; + var renderableBounds = renderable.bounds; + var width = renderableBounds.width / this.entity.scale.x; + var height = renderableBounds.height / this.entity.scale.y; if (this instanceof es.CircleCollider) { - var circleCollider = this; - circleCollider.radius = Math.max(width, height) * 0.5; + this.radius = Math.max(width, height) * 0.5; } else { this.width = width; this.height = height; } - this.localOffset = es.Vector2.subtract(bounds.center, this.entity.transform.position); + this.localOffset = es.Vector2.subtract(renderableBounds.center, this.entity.transform.position); } else { console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); @@ -3202,7 +3203,7 @@ var es; }; Collider.prototype.collidesWith = function (collider, motion, result) { var oldPosition = this.entity.position; - this.entity.position.add(motion); + this.entity.position = this.entity.position.add(motion); var didCollide = this.shape.collidesWithShape(collider.shape, result); if (didCollide) result.collider = collider; @@ -6090,7 +6091,7 @@ var es; edgeNormal = new es.Vector2(-line.y, line.x); } } - es.Vector2Ext.normalize(edgeNormal); + edgeNormal = es.Vector2Ext.normalize(edgeNormal); return closestPoint; }; Polygon.prototype.recalculateBounds = function (collider) { @@ -6122,7 +6123,7 @@ var es; } this.position = es.Vector2.add(collider.entity.transform.position, this.center); this.bounds = es.Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = es.Vector2.add(this.bounds.location, this.position); + this.bounds.location = this.bounds.location.add(this.position); }; Polygon.prototype.overlaps = function (other) { var result = new es.CollisionResult(); @@ -6394,7 +6395,7 @@ var es; var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); if (box.containsPoint(circle.position)) { result.point = closestPointOnBounds; - var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.subtract(result.normal, new es.Vector2(circle.radius))); + var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius))); result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace); return true; } @@ -6406,7 +6407,7 @@ var es; result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds); var depth = result.normal.length() - circle.radius; result.point = closestPointOnBounds; - es.Vector2Ext.normalize(result.normal); + result.normal = es.Vector2Ext.normalize(result.normal); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal); return true; } diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 33a87cda..727c114c 100644 --- a/demo/libs/framework/framework.min.js +++ b/demo/libs/framework/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t),this.displayObject.x=this.entity.position.x-this.origin.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y-this.origin.y+this.localOffset.y-t.position.y+t.origin.y},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/bin/framework.js b/source/bin/framework.js index eb1699b9..01624ebc 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -2733,6 +2733,8 @@ var es; }; SpriteRenderer.prototype.render = function (camera) { this.sync(camera); + this.displayObject.x = this.entity.position.x - this.origin.x + this.localOffset.x - camera.position.x + camera.origin.x; + this.displayObject.y = this.entity.position.y - this.origin.y + this.localOffset.y - camera.position.y + camera.origin.y; }; return SpriteRenderer; }(es.RenderableComponent)); @@ -2995,7 +2997,7 @@ var es; continue; var _internalcollisionResult = new es.CollisionResult(); if (collider.collidesWith(neighbor, motion, _internalcollisionResult)) { - motion.subtract(_internalcollisionResult.minimumTranslationVector); + motion = motion.subtract(_internalcollisionResult.minimumTranslationVector); if (_internalcollisionResult.collider != null) { collisionResult = _internalcollisionResult; } @@ -3139,18 +3141,17 @@ var es; } var renderable = this.entity.getComponent(es.RenderableComponent); if (renderable) { - var bounds = renderable.bounds; - var width = bounds.width / this.entity.scale.x; - var height = bounds.height / this.entity.scale.y; + var renderableBounds = renderable.bounds; + var width = renderableBounds.width / this.entity.scale.x; + var height = renderableBounds.height / this.entity.scale.y; if (this instanceof es.CircleCollider) { - var circleCollider = this; - circleCollider.radius = Math.max(width, height) * 0.5; + this.radius = Math.max(width, height) * 0.5; } else { this.width = width; this.height = height; } - this.localOffset = es.Vector2.subtract(bounds.center, this.entity.transform.position); + this.localOffset = es.Vector2.subtract(renderableBounds.center, this.entity.transform.position); } else { console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); @@ -3202,7 +3203,7 @@ var es; }; Collider.prototype.collidesWith = function (collider, motion, result) { var oldPosition = this.entity.position; - this.entity.position.add(motion); + this.entity.position = this.entity.position.add(motion); var didCollide = this.shape.collidesWithShape(collider.shape, result); if (didCollide) result.collider = collider; @@ -6090,7 +6091,7 @@ var es; edgeNormal = new es.Vector2(-line.y, line.x); } } - es.Vector2Ext.normalize(edgeNormal); + edgeNormal = es.Vector2Ext.normalize(edgeNormal); return closestPoint; }; Polygon.prototype.recalculateBounds = function (collider) { @@ -6122,7 +6123,7 @@ var es; } this.position = es.Vector2.add(collider.entity.transform.position, this.center); this.bounds = es.Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = es.Vector2.add(this.bounds.location, this.position); + this.bounds.location = this.bounds.location.add(this.position); }; Polygon.prototype.overlaps = function (other) { var result = new es.CollisionResult(); @@ -6394,7 +6395,7 @@ var es; var closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); if (box.containsPoint(circle.position)) { result.point = closestPointOnBounds; - var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.subtract(result.normal, new es.Vector2(circle.radius))); + var safePlace = es.Vector2.add(closestPointOnBounds, es.Vector2.multiply(result.normal, new es.Vector2(circle.radius))); result.minimumTranslationVector = es.Vector2.subtract(circle.position, safePlace); return true; } @@ -6406,7 +6407,7 @@ var es; result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds); var depth = result.normal.length() - circle.radius; result.point = closestPointOnBounds; - es.Vector2Ext.normalize(result.normal); + result.normal = es.Vector2Ext.normalize(result.normal); result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal); return true; } diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 33a87cda..727c114c 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t)},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.subtract(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file +window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var transform,__awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return e.call(arguments[2],i,r,t)&&n.push(i),n},[]);for(var n=[],i=0,r=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,r){return n.push(e.call(arguments[2],i,r,t)),n},[]);for(var n=[],i=0,r=t.length;io?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var r=e(t),o=e(i);return n?-n(r,o):r0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},e.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},e}();t.AStarPathfinder=e;var n=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(t.PriorityQueueNode);t.AStarNode=n}(es||(es={})),function(t){var e=function(){function e(e,n){this.dirs=[new t.Vector2(1,0),new t.Vector2(0,-1),new t.Vector2(-1,0),new t.Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=e,this._height=n}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x=this._nodes.length?(console.error("node.QueueIndex has been corrupted. Did you change it manually? Or add this node to another queue?"),!1):this._nodes[t.queueIndex]==t:(console.error("node cannot be null"),!1)},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;t0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var r=this._nodes[i];this.hasHigherPriority(r,e)&&(e=r);var o=i+1;if(o<=this._numNodes){var s=this._nodes[o];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===c())break}return o?t.AStarPathfinder.recontructPath(a,n,i):null},e.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},e}();t.BreadthFirstPathfinder=e}(es||(es={})),function(t){var e=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}();t.UnweightedGraph=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(e,"zero",{get:function(){return e.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"one",{get:function(){return e.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitX",{get:function(){return e.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(e,"unitY",{get:function(){return e.unitYVector},enumerable:!0,configurable:!0}),e.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},e.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},e.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},e.prototype.subtract=function(t){return this.x-=t.x,this.y-=t.y,this},e.add=function(t,n){var i=new e(0,0);return i.x=t.x+n.x,i.y=t.y+n.y,i},e.divide=function(t,n){var i=new e(0,0);return i.x=t.x/n.x,i.y=t.y/n.y,i},e.multiply=function(t,n){var i=new e(0,0);return i.x=t.x*n.x,i.y=t.y*n.y,i},e.subtract=function(t,n){var i=new e(0,0);return i.x=t.x-n.x,i.y=t.y-n.y,i},e.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.prototype.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},e.dot=function(t,e){return t.x*e.x+t.y*e.y},e.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},e.clamp=function(n,i,r){return new e(t.MathHelper.clamp(n.x,i.x,r.x),t.MathHelper.clamp(n.y,i.y,r.y))},e.lerp=function(n,i,r){return new e(t.MathHelper.lerp(n.x,i.x,r),t.MathHelper.lerp(n.y,i.y,r))},e.transform=function(t,n){return new e(t.x*n.m11+t.y*n.m21+n.m31,t.x*n.m12+t.y*n.m22+n.m32)},e.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},e.negate=function(t){var n=new e;return n.x=-t.x,n.y=-t.y,n},e.prototype.equals=function(t){return t.x==this.x&&t.y==this.y},e.unitYVector=new e(0,1),e.unitXVector=new e(1,0),e.unitVector2=new e(1,1),e.zeroVector2=new e(0,0),e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(t,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=t,this._hegiht=n,this._dirs=i?e.COMPASS_DIRS:e.CARDINAL_DIRS}return e.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===u())break}return s?this.recontructPath(a,i,r):null},n.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},n.getKey=function(t,e){for(var n,i,r=t.keys(),o=t.values();n=r.next(),i=o.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},n.recontructPath=function(t,e,n){var i=[],r=n;for(i.push(n);r!=e;)r=this.getKey(t,r),i.push(r);return i.reverse(),i},n}();t.WeightedPathfinder=n}(es||(es={})),function(t){var e=function(){function e(){}return e.drawHollowRect=function(e,n,i){void 0===i&&(i=0),this._debugDrawItems.push(new t.DebugDrawItem(e,n,i))},e.render=function(){if(this._debugDrawItems.length>0){var e=new egret.Shape;t.Core.scene&&t.Core.scene.addChild(e);for(var n=this._debugDrawItems.length-1;n>=0;n--){this._debugDrawItems[n].draw(e)&&this._debugDrawItems.removeAt(n)}}},e._debugDrawItems=[],e}();t.Debug=e}(es||(es={})),function(t){var e=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}();t.DebugDefaults=e}(es||(es={})),function(t){var e;!function(t){t[t.line=0]="line",t[t.hollowRectangle=1]="hollowRectangle",t[t.pixel=2]="pixel",t[t.text=3]="text"}(e=t.DebugDrawType||(t.DebugDrawType={}));var n=function(){function n(t,n,i){this.rectangle=t,this.color=n,this.duration=i,this.drawType=e.hollowRectangle}return n.prototype.draw=function(n){switch(this.drawType){case e.line:t.DrawUtils.drawLine(n,this.start,this.end,this.color);break;case e.hollowRectangle:t.DrawUtils.drawHollowRect(n,this.rectangle,this.color);break;case e.pixel:t.DrawUtils.drawPixel(n,new t.Vector2(this.x,this.y),this.color,this.size);break;case e.text:}return this.duration-=t.Time.deltaTime,this.duration<0},n}();t.DebugDrawItem=n}(es||(es={})),function(t){var e=function(){function t(){this.updateInterval=1,this._enabled=!0,this._updateOrder=0}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}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.debugRender=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},t.prototype.setUpdateOrder=function(t){return this._updateOrder!=t&&(this._updateOrder=t),this},t.prototype.clone=function(){var t=ObjectUtils.clone(this);return t.entity=null,t},t}();t.Component=e}(es||(es={})),function(t){var e=function(e){function n(){var i=e.call(this)||this;return i._globalManagers=[],n._instance=i,n.emitter=new t.Emitter,n.content=new t.ContentManager,i.addEventListener(egret.Event.ADDED_TO_STAGE,i.onAddToStage,i),i}return __extends(n,e),Object.defineProperty(n,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(n,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(t){t?null==this._instance._scene?(this._instance._scene=t,this._instance.addChild(t),this._instance._scene.begin(),n.Instance.onSceneChanged()):this._instance._nextScene=t:console.error("场景不能为空")},enumerable:!0,configurable:!0}),n.prototype.onAddToStage=function(){n.graphicsDevice=new t.GraphicsDevice,this.addEventListener(egret.Event.RESIZE,this.onGraphicsDeviceReset,this),this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE,this.onOrientationChanged,this),this.addEventListener(egret.Event.ENTER_FRAME,this.update,this),t.Input.initialize(),this.initialize()},n.prototype.onOrientationChanged=function(){n.emitter.emit(t.CoreEvents.OrientationChanged)},n.prototype.onGraphicsDeviceReset=function(){n.emitter.emit(t.CoreEvents.GraphicsDeviceReset)},n.prototype.initialize=function(){},n.prototype.update=function(){return __awaiter(this,void 0,void 0,function(){var e;return __generator(this,function(n){switch(n.label){case 0:if(t.Time.update(egret.getTimer()),!this._scene)return[3,2];for(e=this._globalManagers.length-1;e>=0;e--)this._globalManagers[e].enabled&&this._globalManagers[e].update();return this._sceneTransition&&(!this._sceneTransition||this._sceneTransition.loadsNewScene&&!this._sceneTransition.isNewSceneLoaded)||this._scene.update(),this._nextScene?(this.removeChild(this._scene),this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this.addChild(this._scene),[4,this._scene.begin()]):[3,2];case 1:n.sent(),n.label=2;case 2:return[4,this.draw()];case 3:return n.sent(),[2]}})})},n.prototype.draw=function(){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return this._sceneTransition?(this._sceneTransition.preRender(),!this._scene||this._sceneTransition.hasPreviousSceneRender?[3,2]:(this._scene.render(),this._scene.postRender(),[4,this._sceneTransition.onBeginTransition()])):[3,4];case 1:return e.sent(),[3,3];case 2:this._sceneTransition&&(this._scene&&this._sceneTransition.isNewSceneLoaded&&(this._scene.render(),this._scene.postRender()),this._sceneTransition.render()),e.label=3;case 3:return[3,5];case 4:this._scene&&(this._scene.render(),t.Debug.render(),this._scene.postRender()),e.label=5;case 5:return[2]}})})},n.prototype.startDebugUpdate=function(){t.TimeRuler.Instance.startFrame(),t.TimeRuler.Instance.beginMark("update",65280)},n.prototype.endDebugUpdate=function(){t.TimeRuler.Instance.endMark("update")},n.prototype.onSceneChanged=function(){n.emitter.emit(t.CoreEvents.SceneChanged),t.Time.sceneChanged()},n.startSceneTransition=function(t){if(!this._instance._sceneTransition)return this._instance._sceneTransition=t,t;console.warn("在前一个场景完成之前,不能开始一个新的场景转换。")},n.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},n.unregisterGlobalManager=function(t){this._instance._globalManagers.remove(t),t.enabled=!1},n.getGlobalManager=function(t){for(var e=0;e=0;t--){this.transform.getChild(t).entity.destroy()}},e.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;te.x?-1:1,i=t.Vector2.normalize(t.Vector2.subtract(this.position,e));this.rotation=n*Math.acos(t.Vector2.dot(i,t.Vector2.unitY))},i.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=this._position.round()},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.clean&&(this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(this._translationMatrix=t.Matrix2D.create().translate(this._localPosition.x,this._localPosition.y),this._localPositionDirty=!1),this._localRotationDirty&&(this._rotationMatrix=t.Matrix2D.create().rotate(this._localRotation),this._localRotationDirty=!1),this._localScaleDirty&&(this._scaleMatrix=t.Matrix2D.create().scale(this._localScale.x,this._localScale.y),this._localScaleDirty=!1),this._localTransform=this._scaleMatrix.multiply(this._rotationMatrix),this._localTransform=this._localTransform.multiply(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=this._localTransform.multiply(this.parent._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=t.Vector2.multiply(this.parent._scale,this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=e.clean)},i.prototype.setDirty=function(e){if(0==(this.hierarchyDirty&e)){switch(this.hierarchyDirty|=e,e){case t.DirtyType.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case t.DirtyType.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case t.DirtyType.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}this._children||(this._children=[]);for(var n=0;nt&&(this._zoom=t),this._maximumZoom=t,this;console.error("maximumZoom must be greater than zero")},r.prototype.onEntityTransformChanged=function(t){this._areMatrixedDirty=!0},r.prototype.zoomIn=function(t){this.zoom+=t},r.prototype.zoomOut=function(t){this.zoom-=t},r.prototype.worldToScreenPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._transformMatrix)},r.prototype.screenToWorldPoint=function(e){return this.updateMatrixes(),e=t.Vector2.transform(e,this._inverseTransformMatrix)},r.prototype.mouseToWorldPoint=function(){return this.screenToWorldPoint(t.Input.touchPosition)},r.prototype.onAddedToEntity=function(){this.follow(this._targetEntity,this._cameraStyle)},r.prototype.update=function(){var e=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x*t.Core.scene.scaleX+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y*t.Core.scene.scaleY+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.position=t.Vector2.lerp(this.position,t.Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.transform.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.transform.roundPosition())},r.prototype.clampToMapSize=function(e){var n=t.Vector2.multiply(new t.Vector2(this.bounds.width,this.bounds.height),new t.Vector2(.5)),i=new t.Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return t.Vector2.clamp(e,n,i)},r.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==e.lockOn){var n=this._targetEntity.transform.position.x,i=this._targetEntity.transform.position.y;this._worldSpaceDeadZone.x>n?this._desiredPositionDelta.x=n-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xi&&(this._desiredPositionDelta.y=i-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this._targetEntity.getComponent(t.Collider),!this._targetCollider))return;var r=this._targetEntity.getComponent(t.Collider).bounds;this._worldSpaceDeadZone.containsRect(r)||(this._worldSpaceDeadZone.left>r.left?this._desiredPositionDelta.x=r.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightr.top&&(this._desiredPositionDelta.y=r.top-this._worldSpaceDeadZone.top))}},r.prototype.follow=function(n,i){switch(void 0===i&&(i=e.cameraWindow),this._targetEntity=n,this._cameraStyle=i,this._cameraStyle){case e.cameraWindow:var r=this.bounds.width/6,o=this.bounds.height/3;this.deadzone=new t.Rectangle((this.bounds.width-r)/2,(this.bounds.height-o)/2,r,o);break;case e.lockOn:this.deadzone=new t.Rectangle(this.bounds.width/2,this.bounds.height/2,10,10)}},r.prototype.setCenteredDeadzone=function(e,n){this.deadzone=new t.Rectangle((this.bounds.width-e)/2,(this.bounds.height-n)/2,e,n)},r}(t.Component);t.Camera=i}(es||(es={})),function(t){var e=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}();t.ComponentPool=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.compare=function(t,e){return t.updateOrder-e.updateOrder},t}();t.IUpdatableComparer=e}(es||(es={})),function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(t.Component);t.PooledComponent=e}(es||(es={})),function(t){var e=function(e){function n(){var n=null!==e&&e.apply(this,arguments)||this;return n.displayObject=new egret.DisplayObject,n.color=0,n._localOffset=t.Vector2.zero,n._renderLayer=0,n._bounds=new t.Rectangle,n._areBoundsDirty=!0,n}return __extends(n,e),Object.defineProperty(n.prototype,"width",{get:function(){return this.bounds.width},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){return this.bounds.height},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"bounds",{get:function(){return this._areBoundsDirty&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,t.Vector2.zero,this.entity.transform.scale,this.entity.transform.rotation,this.width,this.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"renderLayer",{get:function(){return this._renderLayer},set:function(t){},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"localOffset",{get:function(){return this._localOffset},set:function(t){this.setLocalOffset(t)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible!=t&&(this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible())},enumerable:!0,configurable:!0}),n.prototype.onEntityTransformChanged=function(t){this._areBoundsDirty=!0},n.prototype.onBecameVisible=function(){this.displayObject.visible=this.isVisible},n.prototype.onBecameInvisible=function(){this.displayObject.visible=this.isVisible},n.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.bounds.intersects(this.bounds),this.isVisible},n.prototype.setRenderLayer=function(t){if(t!=this._renderLayer){var e=this._renderLayer;this._renderLayer=t,this.entity&&this.entity.scene&&this.entity.scene.renderableComponents.updateRenderableRenderLayer(this,e,this._renderLayer)}return this},n.prototype.setColor=function(t){return this.color=t,this},n.prototype.setLocalOffset=function(t){return this._localOffset!=t&&(this._localOffset=t),this},n.prototype.sync=function(t){this.displayObject.x=this.entity.position.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y+this.localOffset.y-t.position.y+t.origin.y,this.displayObject.scaleX=this.entity.scale.x,this.displayObject.scaleY=this.entity.scale.y,this.displayObject.rotation=this.entity.rotation},n.prototype.toString=function(){return"[RenderableComponent] renderLayer: "+this.renderLayer},n}(t.Component);t.RenderableComponent=e}(es||(es={})),function(t){var e=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.reset=function(){},e.prototype.render=function(t){},e}(t.RenderableComponent);t.Mesh=e}(es||(es={})),function(t){var e=egret.Bitmap,n=function(n){function i(e){void 0===e&&(e=null);var i=n.call(this)||this;return e instanceof t.Sprite?i.setSprite(e):e instanceof egret.Texture&&i.setSprite(new t.Sprite(e)),i}return __extends(i,n),Object.defineProperty(i.prototype,"bounds",{get:function(){return this._areBoundsDirty&&this._sprite&&(this._bounds.calculateBounds(this.entity.transform.position,this._localOffset,this._origin,this.entity.transform.scale,this.entity.transform.rotation,this._sprite.sourceRect.width,this._sprite.sourceRect.height),this._areBoundsDirty=!1),this._bounds},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"originNormalized",{get:function(){return new t.Vector2(this._origin.x/this.width*this.entity.transform.scale.x,this._origin.y/this.height*this.entity.transform.scale.y)},set:function(e){this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y))},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),i.prototype.setSprite=function(t){return this._sprite=t,this._sprite&&(this._origin=this._sprite.origin,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y),this.displayObject=new e(t.texture2D),this},i.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t,this.displayObject.anchorOffsetX=this._origin.x,this.displayObject.anchorOffsetY=this._origin.y,this._areBoundsDirty=!0),this},i.prototype.setOriginNormalized=function(e){return this.setOrigin(new t.Vector2(e.x*this.width/this.entity.transform.scale.x,e.y*this.height/this.entity.transform.scale.y)),this},i.prototype.render=function(t){this.sync(t),this.displayObject.x=this.entity.position.x-this.origin.x+this.localOffset.x-t.position.x+t.origin.x,this.displayObject.y=this.entity.position.y-this.origin.y+this.localOffset.y-t.position.y+t.origin.y},i}(t.RenderableComponent);t.SpriteRenderer=n}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.leftTexture=new egret.Bitmap,n.rightTexture=new egret.Bitmap,n.leftTexture.texture=e.texture2D,n.rightTexture.texture=e.texture2D,n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},e}(t.SpriteRenderer);t.TiledSpriteRenderer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.scrollSpeedX=15,t.scroolSpeedY=0,t._scrollX=0,t._scrollY=0,t}return __extends(n,e),n.prototype.update=function(){this._scrollX+=this.scrollSpeedX*t.Time.deltaTime,this._scrollY+=this.scroolSpeedY*t.Time.deltaTime,this.sourceRect.x=this._scrollX,this.sourceRect.y=this._scrollY},n.prototype.render=function(t){if(this.sprite){e.prototype.render.call(this,t);var n=new egret.RenderTexture,i=new egret.DisplayObjectContainer;i.removeChildren(),i.addChild(this.leftTexture),i.addChild(this.rightTexture),this.leftTexture.x=this.sourceRect.x,this.rightTexture.x=this.sourceRect.x-this.sourceRect.width,this.leftTexture.y=this.sourceRect.y,this.rightTexture.y=this.sourceRect.y,i.cacheAsBitmap=!0,n.drawToTexture(i,new egret.Rectangle(0,0,this.sourceRect.width,this.sourceRect.height))}},n}(t.TiledSpriteRenderer);t.ScrollingSpriteRenderer=e}(es||(es={})),function(t){var e=function(){return function(e,n,i){void 0===n&&(n=new t.Rectangle(0,0,e.textureWidth,e.textureHeight)),void 0===i&&(i=n.getHalfSize()),this.uvs=new t.Rectangle,this.texture2D=e,this.sourceRect=n,this.center=new t.Vector2(.5*n.width,.5*n.height),this.origin=i;var r=1/e.textureWidth,o=1/e.textureHeight;this.uvs.x=n.x*r,this.uvs.y=n.y*o,this.uvs.width=n.width*r,this.uvs.height=n.height*o}}();t.Sprite=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.sprites=t,this.frameRate=e}}();t.SpriteAnimation=e}(es||(es={})),function(t){var e,n;!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(e=t.LoopMode||(t.LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(n=t.State||(t.State={}));var i=function(i){function r(t){var e=i.call(this,t)||this;return e.speed=1,e.animationState=n.none,e._animations=new Map,e._elapsedTime=0,e}return __extends(r,i),Object.defineProperty(r.prototype,"isRunning",{get:function(){return this.animationState==n.running},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"animations",{get:function(){return this._animations},enumerable:!0,configurable:!0}),r.prototype.update=function(){if(this.animationState==n.running&&this.currentAnimation){var i=this.currentAnimation,r=1/(i.frameRate*this.speed),o=r*i.sprites.length;this._elapsedTime+=t.Time.deltaTime;var s=Math.abs(this._elapsedTime);if(this._loopMode==e.once&&s>o||this._loopMode==e.pingPongOnce&&s>2*o)return this.animationState=n.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=i.sprites[this.currentFrame]);var a=Math.floor(s/r),c=i.sprites.length;if(c>2&&(this._loopMode==e.pingPong||this._loopMode==e.pingPongOnce)){var h=c-1;this.currentFrame=h-Math.abs(h-a%(2*h))}else this.currentFrame=a%c;this.sprite=i.sprites[this.currentFrame]}},r.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},r.prototype.play=function(t,i){void 0===i&&(i=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=n.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=i||e.loop},r.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},r.prototype.pause=function(){this.animationState=n.paused},r.prototype.unPause=function(){this.animationState=n.running},r.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=n.none},r}(t.SpriteRenderer);t.SpriteAnimator=i}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){if(!this.entity.getComponent(t.Collider)||!this._triggerHelper)return!1;for(var i=this.entity.getComponents(t.Collider),r=0;r>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var n=0;n0){n=0;for(var i=this._componentsToAdd.length;n0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t.removeFromTagList(e),t._entities.remove(e),e.onRemovedFromScene(),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.addToTagList(e),t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0,this._isEntityListUnsorted=!0}this._isEntityListUnsorted&&(this._entities.sort(),this._isEntityListUnsorted=!1),this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},e.prototype.findEntity=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},e.prototype.all=function(){for(var e=this,n=[],i=0;i0){for(var t=0,n=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function e(){}return e.convertImageToCanvas=function(e,n){this.sharedCanvas||(this.sharedCanvas=egret.sys.createCanvas(),this.sharedContext=this.sharedCanvas.getContext("2d"));var i=e.$getTextureWidth(),r=e.$getTextureHeight();n||((n=egret.$TempRectangle).x=0,n.y=0,n.width=i,n.height=r),n.x=Math.min(n.x,i-1),n.y=Math.min(n.y,r-1),n.width=Math.min(n.width,i-n.x),n.height=Math.min(n.height,r-n.y);var o=Math.floor(n.width),s=Math.floor(n.height),a=this.sharedCanvas;if(a.style.width=o+"px",a.style.height=s+"px",this.sharedCanvas.width=o,this.sharedCanvas.height=s,"webgl"==egret.Capabilities.renderMode){var c=void 0;e.$renderBuffer?c=e:(egret.sys.systemRenderer.renderClear&&egret.sys.systemRenderer.renderClear(),(c=new egret.RenderTexture).drawToTexture(new egret.Bitmap(e)));for(var h=c.$renderBuffer.getPixels(n.x,n.y,o,s),u=0,l=0,p=0;p=0?"png":"jpg"});return wx.getFileSystemManager().saveFile({tempFilePath:o,filePath:wx.env.USER_DATA_PATH+"/"+n,success:function(t){}}),o},e.getPixel32=function(t,e,n){return egret.$warn(1041,"getPixel32","getPixels"),t.getPixels(e,n)},e.getPixels=function(t,e,n,i,r){if(void 0===i&&(i=1),void 0===r&&(r=1),"webgl"==egret.Capabilities.renderMode){var o=void 0;return t.$renderBuffer?o=t:(o=new egret.RenderTexture).drawToTexture(new egret.Bitmap(t)),o.$renderBuffer.getPixels(e,n,i,r)}try{this.convertImageToCanvas(t);return this.sharedContext.getImageData(e,n,i,r).data}catch(t){egret.$error(1039)}},e}();t.TextureUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this._timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this._timeSinceSceneLoad=0},t.checkEvery=function(t){return this._timeSinceSceneLoad/t>(this._timeSinceSceneLoad-this.deltaTime)/t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,c=Math.floor(a)+1;if(53==c){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var h=n.getDay();if(0==h&&(h=7),e&&(!o||h<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(c>9?"":"0")+c)},t.diffDay=function(t,e,n){void 0===n&&(n=!1);var i=(t.getTime()-e.getTime())/864e5;return n?Math.ceil(i):Math.floor(i)},t.getFirstDayOfWeek=function(t){var e=(t=t||new Date).getDay()||7;return new Date(t.getFullYear(),t.getMonth(),t.getDate()+1-e,0,0,0,0)},t.getFirstOfDay=function(t){return(t=t||new Date).setHours(0,0,0,0),t},t.getNextFirstOfDay=function(t){return new Date(this.getFirstOfDay(t).getTime()+864e5)},t.formatDate=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();return e+"-"+n+"-"+(i=i<10?"0"+i:i)},t.formatDateTime=function(t){var e=t.getFullYear(),n=t.getMonth()+1;n=n<10?"0"+n:n;var i=t.getDate();i=i<10?"0"+i:i;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+n+"-"+i+" "+r+":"+o+":"+(s=s<10?"0"+s:s)},t.parseDate=function(t){var e=Date.parse(t);return isNaN(e)?new Date:new Date(Date.parse(t.replace(/-/g,"/")))},t.secondToTime=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===n&&(n=!0);var i=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=i.toString(),a=r.toString(),c=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(c="0"+c),n?s+e+a+e+c:a+e+c},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o-1?this.os="iOS":i.indexOf("android")>-1&&(this.os="Android");var r=n.language;r=r.indexOf("zh")>-1?"zh-CN":"en-US",this.language=r}},e}(egret.Capabilities);t.GraphicsCapabilities=e}(es||(es={})),function(t){var e=function(){function e(){this.setup(),this.graphicsCapabilities=new t.GraphicsCapabilities,this.graphicsCapabilities.initialize(this)}return Object.defineProperty(e.prototype,"viewport",{get:function(){return this._viewport},enumerable:!0,configurable:!0}),e.prototype.setup=function(){this._viewport=new t.Viewport(0,0,t.Core._instance.stage.stageWidth,t.Core._instance.stage.stageHeight)},e}();t.GraphicsDevice=e}(es||(es={})),function(t){var e=function(){function e(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i,this._minDepth=0,this._maxDepth=1}return Object.defineProperty(e.prototype,"height",{get:function(){return this._height},set:function(t){this._height=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"width",{get:function(){return this._width},set:function(t){this._width=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"aspectRatio",{get:function(){return 0!=this._height&&0!=this._width?this._width/this._height:0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new t.Rectangle(this._x,this._y,this._width,this._height)},set:function(t){this._x=t.x,this._y=t.y,this._width=t.width,this._height=t.height},enumerable:!0,configurable:!0}),e}();t.Viewport=e}(es||(es={})),function(t){var e=function(e){function n(){return e.call(this,t.PostProcessor.default_vert,n.blur_frag,{screenWidth:t.Core.graphicsDevice.viewport.width,screenHeight:t.Core.graphicsDevice.viewport.height})||this}return __extends(n,e),n.blur_frag="precision mediump float;\nuniform sampler2D uSampler;\nuniform float screenWidth;\nuniform float screenHeight;\nfloat normpdf(in float x, in float sigma)\n{\nreturn 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;\n}\nvoid main()\n{\nvec3 c = texture2D(uSampler, gl_FragCoord.xy / vec2(screenWidth, screenHeight).xy).rgb;\nconst int mSize = 11;\nconst int kSize = (mSize - 1)/2;\nfloat kernel[mSize];\nvec3 final_colour = vec3(0.0);\nfloat sigma = 7.0;\nfloat z = 0.0;\nfor (int j = 0; j <= kSize; ++j)\n{\nkernel[kSize+j] = kernel[kSize-j] = normpdf(float(j),sigma);\n}\nfor (int j = 0; j < mSize; ++j)\n{\nz += kernel[j];\n}\nfor (int i = -kSize; i <= kSize; ++i)\n{\nfor (int j = -kSize; j <= kSize; ++j)\n{\nfinal_colour += kernel[kSize+j]*kernel[kSize+i]*texture2D(uSampler, (gl_FragCoord.xy+vec2(float(i),float(j))) / vec2(screenWidth, screenHeight).xy).rgb;\n}\n}\ngl_FragColor = vec4(final_colour/(z*z), 1.0);\n}",n}(egret.CustomFilter);t.GaussianBlurEffect=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,e.vertSrc,e.fragmentSrc)||this}return __extends(e,t),e.vertSrc="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n}",e.fragmentSrc="precision lowp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\n#define SAMPLE_COUNT 15\nuniform vec2 _sampleOffsets[SAMPLE_COUNT];\nuniform float _sampleWeights[SAMPLE_COUNT];\nvoid main(void) {\nvec4 c = vec4(0, 0, 0, 0);\nfor( int i = 0; i < SAMPLE_COUNT; i++ )\n c += texture2D( uSampler, vTextureCoord + _sampleOffsets[i] ) * _sampleWeights[i];\ngl_FragColor = c;\n}",e}(egret.CustomFilter);t.PolygonLightEffect=e}(es||(es={})),function(t){var e=function(){function e(t){void 0===t&&(t=null),this.enabled=!0,this.effect=t}return e.prototype.onAddedToScene=function(e){this.scene=e,this.shape=new egret.Shape,this.shape.graphics.beginFill(16777215,1),this.shape.graphics.drawRect(0,0,t.Core.graphicsDevice.viewport.width,t.Core.graphicsDevice.viewport.height),this.shape.graphics.endFill(),e.addChild(this.shape)},e.prototype.process=function(){this.drawFullscreenQuad()},e.prototype.onSceneBackBufferSizeChanged=function(t,e){},e.prototype.drawFullscreenQuad=function(){this.scene.filters=[this.effect]},e.prototype.unload=function(){this.effect&&(this.effect=null),this.scene.removeChild(this.shape),this.scene=null},e.default_vert="attribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec2 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\ngl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\nvTextureCoord = aTextureCoord;\nvColor = vec4(aColor.x, aColor.x, aColor.x, aColor.x);\n}",e}();t.PostProcessor=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToScene=function(n){e.prototype.onAddedToScene.call(this,n),this.effect=new t.GaussianBlurEffect},n}(t.PostProcessor);t.GaussianBlurPostProcessor=e}(es||(es={})),function(t){var e=function(){function t(t,e){void 0===e&&(e=null),this.renderOrder=0,this.camera=e,this.renderOrder=t}return t.prototype.onAddedToScene=function(t){},t.prototype.unload=function(){},t.prototype.beginRender=function(t){},t.prototype.renderAfterStateCheck=function(t,e){t.render(e)},t.prototype.onSceneBackBufferSizeChanged=function(t,e){},t.prototype.compareTo=function(t){return this.renderOrder-t.renderOrder},t}();t.Renderer=e}(es||(es={})),function(t){var e=function(t){function e(){return t.call(this,0,null)||this}return __extends(e,t),e.prototype.render=function(t){var e=this.camera?this.camera:t.camera;this.beginRender(e);for(var n=0;nn?n:t},e.pointOnCirlce=function(n,i,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+n.x,Math.sin(o)*o+n.y)},e.isEven=function(t){return t%2==0},e.clamp01=function(t){return t<0?0:t>1?1:t},e.angleBetweenVectors=function(t,e){return Math.atan2(e.y-t.y,e.x-t.x)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e}();t.MathHelper=e}(es||(es={})),function(t){t.matrixPool=[];var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"m11",{get:function(){return this.a},set:function(t){this.a=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m12",{get:function(){return this.b},set:function(t){this.b=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m21",{get:function(){return this.c},set:function(t){this.c=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m22",{get:function(){return this.d},set:function(t){this.d=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m31",{get:function(){return this.tx},set:function(t){this.tx=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"m32",{get:function(){return this.ty},set:function(t){this.ty=t},enumerable:!0,configurable:!0}),n.create=function(){var e=t.matrixPool.pop();return e||(e=new n),e},n.prototype.identity=function(){return this.a=this.d=1,this.b=this.c=this.tx=this.ty=0,this},n.prototype.translate=function(t,e){return this.tx+=t,this.ty+=e,this},n.prototype.scale=function(t,e){return 1!==t&&(this.a*=t,this.c*=t,this.tx*=t),1!==e&&(this.b*=e,this.d*=e,this.ty*=e),this},n.prototype.rotate=function(t){if(0!==(t=+t)){t/=DEG_TO_RAD;var e=Math.cos(t),n=Math.sin(t),i=this.a,r=this.b,o=this.c,s=this.d,a=this.tx,c=this.ty;this.a=i*e-r*n,this.b=i*n+r*e,this.c=o*e-s*n,this.d=o*n+s*e,this.tx=a*e-c*n,this.ty=a*n+c*e}return this},n.prototype.invert=function(){return this.$invertInto(this),this},n.prototype.add=function(t){return this.m11+=t.m11,this.m12+=t.m12,this.m21+=t.m21,this.m22+=t.m22,this.m31+=t.m31,this.m32+=t.m32,this},n.prototype.substract=function(t){return this.m11-=t.m11,this.m12-=t.m12,this.m21-=t.m21,this.m22-=t.m22,this.m31-=t.m31,this.m32-=t.m32,this},n.prototype.divide=function(t){return this.m11/=t.m11,this.m12/=t.m12,this.m21/=t.m21,this.m22/=t.m22,this.m31/=t.m31,this.m32/=t.m32,this},n.prototype.multiply=function(t){var e=this.m11*t.m11+this.m12*t.m21,n=this.m11*t.m12+this.m12*t.m22,i=this.m21*t.m11+this.m22*t.m21,r=this.m21*t.m12+this.m22*t.m22,o=this.m31*t.m11+this.m32*t.m21+t.m31,s=this.m31*t.m12+this.m32*t.m22+t.m32;return this.m11=e,this.m12=n,this.m21=i,this.m22=r,this.m31=o,this.m32=s,this},n.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},n.prototype.release=function(e){e&&t.matrixPool.push(e)},n}(egret.Matrix);t.Matrix2D=e}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),Object.defineProperty(n.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"location",{get:function(){return new t.Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"size",{get:function(){return new t.Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),n.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},n}(egret.Rectangle);t.Rectangle=e}(es||(es={})),function(t){var e=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}();t.Vector3=e}(es||(es={})),function(t){var e=function(){function e(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return e.prototype.update=function(){for(var e=this._entity.getComponents(t.Collider),n=0;n1)return!1;var u=(c.x*o.y-c.y*o.x)/a;return!(u<0||u>1)},n.lineToLineIntersection=function(e,n,i,r){var o=new t.Vector2(0,0),s=t.Vector2.subtract(n,e),a=t.Vector2.subtract(r,i),c=s.x*a.y-s.y*a.x;if(0==c)return o;var h=t.Vector2.subtract(i,e),u=(h.x*a.y-h.y*a.x)/c;if(u<0||u>1)return o;var l=(h.x*s.y-h.y*s.x)/c;return l<0||l>1?o:o=t.Vector2.add(e,new t.Vector2(u*s.x,u*s.y))},n.closestPointOnLine=function(e,n,i){var r=t.Vector2.subtract(n,e),o=t.Vector2.subtract(i,e),s=t.Vector2.dot(o,r)/t.Vector2.dot(r,r);return s=t.MathHelper.clamp(s,0,1),t.Vector2.add(e,new t.Vector2(r.x*s,r.y*s))},n.isCircleToCircle=function(e,n,i,r){return t.Vector2.distanceSquared(e,i)<(n+r)*(n+r)},n.isCircleToLine=function(e,n,i,r){return t.Vector2.distanceSquared(e,this.closestPointOnLine(i,r,e))=t&&r.y>=e&&r.x=t+i&&(s|=e.right),o.y=n+r&&(s|=e.bottom),s},n}();t.Collisions=n}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize)},e.clear=function(){this._spatialHash.clear()},e.overlapCircleAll=function(t,e,n,i){if(void 0===i&&(i=-1),0!=n.length)return this._spatialHash.overlapCircle(t,e,n,i);console.error("An empty results array was passed in. No results will ever be returned.")},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},e.addCollider=function(t){e._spatialHash.register(t)},e.removeCollider=function(t){e._spatialHash.remove(t)},e.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},e.debugDraw=function(t){this._spatialHash.debugDraw(t,2)},e.spatialHashCellSize=100,e.allLayers=-1,e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(){}return t.prototype.clone=function(){return ObjectUtils.clone(this)},t}();t.Shape=e}(es||(es={})),function(t){var e=function(e){function n(t,n){var i=e.call(this)||this;return i._areEdgeNormalsDirty=!0,i.isUnrotated=!0,i.setPoints(t),i.isBox=n,i}return __extends(n,e),Object.defineProperty(n.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),n.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;e=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);o=t.Vector2.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;re.y!=this.points[r].y>e.y&&e.x<(this.points[r].x-this.points[i].x)*(e.y-this.points[i].y)/(this.points[r].y-this.points[i].y)+this.points[i].x&&(n=!n);return n},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisions.pointToPoly(e,this,n)},n}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function n(t,i){var r=e.call(this,n.buildBox(t,i),!0)||this;return r.width=t,r.height=i,r}return __extends(n,e),n.buildBox=function(e,n){var i=e/2,r=n/2,o=new Array(4);return o[0]=new t.Vector2(-i,-r),o[1]=new t.Vector2(i,-r),o[2]=new t.Vector2(i,r),o[3]=new t.Vector2(-i,r),o},n.prototype.updateBox=function(e,n){this.width=e,this.height=n;var i=e/2,r=n/2;this.points[0]=new t.Vector2(-i,-r),this.points[1]=new t.Vector2(i,-r),this.points[2]=new t.Vector2(i,r),this.points[3]=new t.Vector2(-i,r);for(var o=0;o0&&(o=!1),!o)return!1;(m=Math.abs(m))r&&(r=o);return{min:i,max:r}},e.circleToPolygon=function(e,n,i){var r,o=t.Vector2.subtract(e.position,n.position),s=t.Polygon.getClosestPointOnPolygonToPoint(n.points,o,0,i.normal),a=n.containsPoint(e.position);if(0>e.radius*e.radius&&!a)return!1;a?r=t.Vector2.multiply(i.normal,new t.Vector2(Math.sqrt(0)-e.radius)):r=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));return i.minimumTranslationVector=r,i.point=t.Vector2.add(s,n.position),!0},e.circleToBox=function(e,n,i){var r=n.bounds.getClosestPointOnRectangleBorderToPoint(e.position,i.normal);if(n.containsPoint(e.position)){i.point=r;var o=t.Vector2.add(r,t.Vector2.multiply(i.normal,new t.Vector2(e.radius)));return i.minimumTranslationVector=t.Vector2.subtract(e.position,o),!0}var s=t.Vector2.distanceSquared(r,e.position);if(0==s)i.minimumTranslationVector=t.Vector2.multiply(i.normal,new t.Vector2(e.radius));else if(s<=e.radius*e.radius){i.normal=t.Vector2.subtract(e.position,r);var a=i.normal.length()-e.radius;return i.point=r,i.normal=t.Vector2Ext.normalize(i.normal),i.minimumTranslationVector=t.Vector2.multiply(new t.Vector2(a),i.normal),!0}return!1},e.pointToCircle=function(e,n,i){var r=t.Vector2.distanceSquared(e,n.position),o=1+n.radius;if(r0&&this.debugDrawCellDetails(n,i,r.length,t,e)}},e.prototype.debugDrawCellDetails=function(t,e,n,i,r){void 0===i&&(i=.5),void 0===r&&(r=1)},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.length=0;for(var r=this.cellCoords(e.x,e.y),o=this.cellCoords(e.right,e.bottom),s=r.x;s<=o.x;s++)for(var a=r.y;a<=o.y;a++){var c=this.cellAtPosition(s,a);if(c)for(var h=0;hn;i--)if(t[i]0&&t[r-1]>i;r--)t[r]=t[r-1];t[r]=i}},t.binarySearch=function(t,e){for(var n=0,i=t.length,r=n+i>>1;n=t[r]&&(n=r+1),r=n+i>>1;return t[n]==e?n:-1},t.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},t.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},t.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i=new Object,r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},t.cloneList=function(t){return t?t.slice(0,t.length):null},t.equals=function(t,e){if(t==e)return!0;var n=t.length;if(n!=e.length)return!1;for(;n--;)if(t[n]!=e[n])return!1;return!0},t.insert=function(t,e,n){if(!t)return null;var i=t.length;if(e>i&&(e=i),e<0&&(e=0),e==i)t.push(n);else if(0==e)t.unshift(n);else{for(var r=i-1;r>=e;r-=1)t[r+1]=t[r];t[e]=n}return n},t}(),Base64Utils=function(){function t(){}return t._utf8_encode=function(t){t=t.replace(/\r\n/g,"\n");for(var e="",n=0;n127&&i<2048?(e+=String.fromCharCode(i>>6|192),e+=String.fromCharCode(63&i|128)):(e+=String.fromCharCode(i>>12|224),e+=String.fromCharCode(i>>6&63|128),e+=String.fromCharCode(63&i|128))}return e},t.decode=function(t,e){void 0===e&&(e=!0);var n,i,r,o,s,a,c="",h=0;for(t=(t=this.getConfKey(t)).replace(/[^A-Za-z0-9\+\/\=]/g,"");h>4,i=(15&o)<<4|(s=this._keyAll.indexOf(t.charAt(h++)))>>2,r=(3&s)<<6|(a=this._keyAll.indexOf(t.charAt(h++))),c+=String.fromCharCode(n),64!=s&&(0==i?e&&(c+=String.fromCharCode(i)):c+=String.fromCharCode(i)),64!=a&&(0==r?e&&(c+=String.fromCharCode(r)):c+=String.fromCharCode(r));return c=this._utf8_decode(c)},t._utf8_decode=function(t){for(var e="",n=0,i=0,r=0,o=0;n191&&i<224?(r=t.charCodeAt(n+1),e+=String.fromCharCode((31&i)<<6|63&r),n+=2):(r=t.charCodeAt(n+1),o=t.charCodeAt(n+2),e+=String.fromCharCode((15&i)<<12|(63&r)<<6|63&o),n+=3);return e},t.getConfKey=function(t){return t.slice(1,t.length)},t._keyNum="0123456789+/",t._keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",t._keyAll=t._keyNum+t._keyStr,t.encode=function(t){var e,n,i,r,o,s,a,c="",h=0;for(t=this._utf8_encode(t);h>2,o=(3&e)<<4|(n=t.charCodeAt(h++))>>4,s=(15&n)<<2|(i=t.charCodeAt(h++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),c=c+this._keyAll.charAt(r)+this._keyAll.charAt(o)+this._keyAll.charAt(s)+this._keyAll.charAt(a);return this._keyStr.charAt(Math.floor(Math.random()*this._keyStr.length))+c},t}();!function(t){var e=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,r){var o=n.loadedAssets.get(t);o?i(o):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),r(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}();t.ContentManager=e}(es||(es={})),function(t){var e=function(){function e(){}return e.drawLine=function(e,n,i,r,o){void 0===o&&(o=1),this.drawLineAngle(e,n,t.MathHelper.angleBetweenVectors(n,i),t.Vector2.distance(n,i),r,o)},e.drawLineAngle=function(t,e,n,i,r,o){void 0===o&&(o=1),t.graphics.beginFill(r),t.graphics.drawRect(e.x,e.y,1,1),t.graphics.endFill(),t.scaleX=i,t.scaleY=o,t.$anchorOffsetX=0,t.$anchorOffsetY=0,t.rotation=n},e.drawHollowRect=function(t,e,n,i){void 0===i&&(i=1),this.drawHollowRectR(t,e.x,e.y,e.width,e.height,n,i)},e.drawHollowRectR=function(e,n,i,r,o,s,a){void 0===a&&(a=1);var c=new t.Vector2(n,i).round(),h=new t.Vector2(n+r,i).round(),u=new t.Vector2(n+r,i+o).round(),l=new t.Vector2(n,i+o).round();this.drawLine(e,c,h,s,a),this.drawLine(e,h,u,s,a),this.drawLine(e,u,l,s,a),this.drawLine(e,l,c,s,a)},e.drawPixel=function(e,n,i,r){void 0===r&&(r=1);var o=new t.Rectangle(n.x,n.y,r,r);1!=r&&(o.x-=.5*r,o.y-=.5*r),e.graphics.beginFill(i),e.graphics.drawRect(o.x,o.y,o.width,o.height),e.graphics.endFill()},e.getColorMatrix=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];return e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255,new egret.ColorMatrixFilter(e)},e}();t.DrawUtils=e}(es||(es={})),function(t){var e=function(){return function(t,e){this.func=t,this.context=e}}();t.FuncPack=e;var n=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,n,i){var r=this._messageTable.get(t);r||(r=[],this._messageTable.set(t,r)),-1!=r.findIndex(function(t){return t.func==n})&&console.warn("您试图添加相同的观察者两次"),r.push(new e(n,i))},t.prototype.removeObserver=function(t,e){var n=this._messageTable.get(t),i=n.findIndex(function(t){return t.func==e});-1!=i&&n.removeAt(i)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i].func.call(n[i].context,e)},t}();t.Emitter=n}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t}();t.GlobalManager=e}(es||(es={})),function(t){var e=function(){function e(){this.x=0,this.y=0,this.touchPoint=-1,this.touchDown=!1}return Object.defineProperty(e.prototype,"position",{get:function(){return new t.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.x=0,this.y=0,this.touchDown=!1,this.touchPoint=-1},e}();t.TouchState=e;var n=function(){function n(){}return Object.defineProperty(n,"touchPosition",{get:function(){return this._gameTouchs[0]?this._gameTouchs[0].position:t.Vector2.zero},enumerable:!0,configurable:!0}),Object.defineProperty(n,"maxSupportedTouch",{get:function(){return t.Core._instance.stage.maxTouches},set:function(e){t.Core._instance.stage.maxTouches=e,this.initTouchCache()},enumerable:!0,configurable:!0}),Object.defineProperty(n,"resolutionScale",{get:function(){return this._resolutionScale},enumerable:!0,configurable:!0}),Object.defineProperty(n,"totalTouchCount",{get:function(){return this._totalTouchCount},enumerable:!0,configurable:!0}),Object.defineProperty(n,"gameTouchs",{get:function(){return this._gameTouchs},enumerable:!0,configurable:!0}),Object.defineProperty(n,"touchPositionDelta",{get:function(){var e=t.Vector2.subtract(this.touchPosition,this._previousTouchState.position);return e.length()>0&&this.setpreviousTouchState(this._gameTouchs[0]),e},enumerable:!0,configurable:!0}),n.initialize=function(){this._init||(this._init=!0,t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),t.Core._instance.stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},n.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={}));var THREAD_ID=Math.floor(1e3*Math.random())+"-"+Date.now(),setItem=egret.localStorage.setItem.bind(localStorage),getItem=egret.localStorage.getItem.bind(localStorage),removeItem=egret.localStorage.removeItem.bind(localStorage),nextTick=function(t){setTimeout(t,0)},LockUtils=function(){function t(t){this._keyX="mutex_key_"+t+"_X",this._keyY="mutex_key_"+t+"_Y"}return t.prototype.lock=function(){var t=this;return new Promise(function(e,n){var i=function(){setItem(t._keyX,THREAD_ID),null===!getItem(t._keyY)&&nextTick(i),setItem(t._keyY,THREAD_ID),getItem(t._keyX)!==THREAD_ID?setTimeout(function(){getItem(t._keyY)===THREAD_ID?(e(),removeItem(t._keyY)):nextTick(i)},10):(e(),removeItem(t._keyY))};i()})},t}();!function(t){var e=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}();t.Pair=e}(es||(es={}));var RandomUtils=function(){function t(){}return t.randrange=function(t,e,n){if(void 0===n&&(n=1),0==n)throw new Error("step 不能为 0");var i=e-t;if(0==i)throw new Error("没有可用的范围("+t+","+e+")");i<0&&(i=t-e);var r=Math.floor((i+n-1)/n);return Math.floor(this.random()*r)*n+Math.min(t,e)},t.randint=function(t,e){return(t=Math.floor(t))>(e=Math.floor(e))?t++:e++,this.randrange(t,e)},t.randnum=function(t,e){return this.random()*(e-t)+t},t.shuffle=function(t){return t.sort(this._randomCompare),t},t._randomCompare=function(t,e){return this.random()>.5?1:-1},t.choice=function(t){if(!t.hasOwnProperty("length"))throw new Error("无法对此对象执行此操作");var e=Math.floor(this.random()*t.length);return t instanceof String?String(t).charAt(e):t[e]},t.sample=function(t,e){var n=t.length;if(e<=0||n=0;)s=Math.floor(this.random()*n);i.push(t[s]),r.push(s)}return i},t.random=function(){return Math.random()},t.boolean=function(t){return void 0===t&&(t=.5),this.random()3&&o<500;){o++;var a=!0,c=n[this._triPrev[s]],h=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(c,h,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],c,h,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengtht.MathHelper.Epsilon?e=t.Vector2.divide(e,new t.Vector2(n)):e.x=e.y=0,e},e.transformA=function(t,e,n,i,r,o){for(var s=0;sthis.safeArea.right&&(s.x=this.safeArea.right-s.width),s.topthis.safeArea.bottom&&(s.y=this.safeArea.bottom-s.height),s},n}();t.Layout=n,function(t){t[t.none=0]="none",t[t.left=1]="left",t[t.right=2]="right",t[t.horizontalCenter=4]="horizontalCenter",t[t.top=8]="top",t[t.bottom=16]="bottom",t[t.verticalCenter=32]="verticalCenter",t[t.topLeft=9]="topLeft",t[t.topRight=10]="topRight",t[t.topCenter=12]="topCenter",t[t.bottomLeft=17]="bottomLeft",t[t.bottomRight=18]="bottomRight",t[t.bottomCenter=20]="bottomCenter",t[t.centerLeft=33]="centerLeft",t[t.centerRight=34]="centerRight",t[t.center=36]="center"}(e=t.Alignment||(t.Alignment={}))}(es||(es={})),function(t){var e,n=function(){function t(t){void 0===t&&(t=i),this.getSystemTime=t,this._stopDuration=0,this._completeSlices=[]}return t.prototype.getState=function(){return void 0===this._startSystemTime?e.IDLE:void 0===this._stopSystemTime?e.RUNNING:e.STOPPED},t.prototype.isIdle=function(){return this.getState()===e.IDLE},t.prototype.isRunning=function(){return this.getState()===e.RUNNING},t.prototype.isStopped=function(){return this.getState()===e.STOPPED},t.prototype.slice=function(){return this.recordPendingSlice()},t.prototype.getCompletedSlices=function(){return Array.from(this._completeSlices)},t.prototype.getCompletedAndPendingSlices=function(){return this._completeSlices.concat([this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},t.prototype.calculatePendingSlice=function(t){return void 0===this._pendingSliceStartStopwatchTime?Object.freeze({startTime:0,endTime:0,duration:0}):(void 0===t&&(t=this.getTime()),Object.freeze({startTime:this._pendingSliceStartStopwatchTime,endTime:t,duration:t-this._pendingSliceStartStopwatchTime}))},t.prototype.caculateStopwatchTime=function(t){return void 0===this._startSystemTime?0:(void 0===t&&(t=this.getSystemTimeOfCurrentStopwatchTime()),t-this._startSystemTime-this._stopDuration)},t.prototype.getSystemTimeOfCurrentStopwatchTime=function(){return void 0===this._stopSystemTime?this.getSystemTime():this._stopSystemTime},t.prototype.reset=function(){this._startSystemTime=this._pendingSliceStartStopwatchTime=this._stopSystemTime=void 0,this._stopDuration=0,this._completeSlices=[]},t.prototype.start=function(t){if(void 0===t&&(t=!1),t&&this.reset(),void 0!==this._stopSystemTime){var e=(n=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var n=this.getSystemTime();this._startSystemTime=n,this._pendingSliceStartStopwatchTime=0}},t.prototype.stop=function(t){if(void 0===t&&(t=!1),void 0===this._startSystemTime)return 0;var e=this.getSystemTimeOfCurrentStopwatchTime();return t&&this.recordPendingSlice(this.caculateStopwatchTime(e)),this._stopSystemTime=e,this.getTime()},t.prototype.recordPendingSlice=function(t){if(void 0!==this._pendingSliceStartStopwatchTime){void 0===t&&(t=this.getTime());var e=this.calculatePendingSlice(t);return this._pendingSliceStartStopwatchTime=e.endTime,this._completeSlices.push(e),e}return this.calculatePendingSlice()},t}();t.Stopwatch=n,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),i=t};var i=Date.now}(stopwatch||(stopwatch={})),function(t){var e=function(){function e(){this._frameKey="frame",this._logKey="log",this.markers=[],this.stopwacth=new stopwatch.Stopwatch,this._markerNameToIdMap=new Map,this.showLog=!1,this._logs=new Array(2);for(var e=0;e=e.logSnapDuration&&(l.logs[r].snapMin=l.logs[r].min,l.logs[r].snapMax=l.logs[r].max,l.logs[r].snapAvg=l.logs[r].avg,l.logs[r].samples=0)):(l.logs[r].min=h,l.logs[r].max=h,l.logs[r].avg=h,l.logs[r].initialized=!0)}s.markCount=o.nestCount,s.nestCount=o.nestCount}t.stopwacth.reset(),t.stopwacth.start()}})},e.prototype.beginMark=function(t,n,i){var r=this;void 0===i&&(i=0),new LockUtils(this._frameKey).lock().then(function(){if(i<0||i>=e.maxBars)throw new Error("barIndex argument out of range");var o=r._curLog.bars[i];if(o.markCount>=e.maxSamples)throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");if(o.nestCount>=e.maxNestCall)throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");var s=r._markerNameToIdMap.get(t);isNaN(s)&&(s=r.markers.length,r._markerNameToIdMap.set(t,s)),o.markerNests[o.nestCount++]=o.markCount,o.markers[o.markCount].markerId=s,o.markers[o.markCount].color=n,o.markers[o.markCount].beginTime=r.stopwacth.getTime(),o.markers[o.markCount].endTime=-1})},e.prototype.endMark=function(t,n){var i=this;void 0===n&&(n=0),new LockUtils(this._frameKey).lock().then(function(){if(n<0||n>=e.maxBars)throw new Error("barIndex argument out of range");var r=i._curLog.bars[n];if(r.nestCount<=0)throw new Error("call beginMark method before calling endMark method");var o=i._markerNameToIdMap.get(t);if(isNaN(o))throw new Error("Marker "+t+" is not registered. Make sure you specifed same name as you used for beginMark method");var s=r.markerNests[--r.nestCount];if(r.markers[s].markerId!=o)throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");r.markers[s].endTime=i.stopwacth.getTime()})},e.prototype.getAverageTime=function(t,n){if(t<0||t>=e.maxBars)throw new Error("barIndex argument out of range");var i=0,r=this._markerNameToIdMap.get(n);return r&&(i=this.markers[r].logs[t].avg),i},e.prototype.resetLog=function(){var t=this;new LockUtils(this._logKey).lock().then(function(){var e=parseInt(egret.localStorage.getItem(t._logKey),10);e+=1,egret.localStorage.setItem(t._logKey,e.toString()),t.markers.forEach(function(t){for(var e=0;e0&&(i+=e.barHeight+2*e.barPadding,r=Math.max(r,t.markers[t.markCount-1].endTime))});var o=this.sampleFrames*(1/60*1e3);this._frameAdjust=r>o?Math.max(0,this._frameAdjust)+1:Math.min(0,this._frameAdjust)-1,Math.max(this._frameAdjust)>e.autoAdjustDelay&&(this.sampleFrames=Math.min(e.maxSampleFrames,this.sampleFrames),this.sampleFrames=Math.max(this.targetSampleFrames,r/(1/60*1e3)+1),this._frameAdjust=0);t.y,e.barHeight}},e.maxBars=8,e.maxSamples=256,e.maxNestCall=32,e.barHeight=8,e.maxSampleFrames=4,e.logSnapDuration=120,e.barPadding=2,e.autoAdjustDelay=30,e}();t.TimeRuler=e;var n=function(){return function(){this.bars=new Array(e.maxBars),this.bars.fill(new i,0,e.maxBars)}}();t.FrameLog=n;var i=function(){return function(){this.markers=new Array(e.maxSamples),this.markCount=0,this.markerNests=new Array(e.maxNestCall),this.nestCount=0,this.markers.fill(new r,0,e.maxSamples),this.markerNests.fill(0,0,e.maxNestCall)}}();t.MarkerCollection=i;var r=function(){return function(){this.markerId=0,this.beginTime=0,this.endTime=0,this.color=0}}();t.Marker=r;var o=function(){return function(t){this.logs=new Array(e.maxBars),this.name=t,this.logs.fill(new s,0,e.maxBars)}}();t.MarkerInfo=o;var s=function(){return function(){this.snapMin=0,this.snapMax=0,this.snapAvg=0,this.min=0,this.max=0,this.avg=0,this.samples=0,this.color=0,this.initialized=!1}}();t.MarkerLog=s}(es||(es={})); \ No newline at end of file diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts index 416a3aa6..0f13b2cd 100644 --- a/source/src/ECS/Components/Physics/Colliders/Collider.ts +++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts @@ -124,22 +124,21 @@ module es { let renderable = this.entity.getComponent(RenderableComponent); if (renderable) { - let bounds = renderable.bounds; + let renderableBounds = renderable.bounds; // 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染 - let width = bounds.width / this.entity.scale.x; - let height = bounds.height / this.entity.scale.y; + let width = renderableBounds.width / this.entity.scale.x; + let height = renderableBounds.height / this.entity.scale.y; // 圆碰撞器需要特别注意原点 if (this instanceof CircleCollider) { - let circleCollider = this as CircleCollider; - circleCollider.radius = Math.max(width, height) * 0.5; + this.radius = Math.max(width, height) * 0.5; } else { this.width = width; this.height = height; } // 获取渲染的中心,将其转移到本地坐标,并使用它作为碰撞器的localOffset - this.localOffset = Vector2.subtract(bounds.center, this.entity.transform.position); + this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position); } else { console.warn("Collider has no shape and no RenderableComponent. Can't figure out how to size it."); } @@ -218,7 +217,7 @@ module es { public collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean { // 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠 let oldPosition = this.entity.position; - this.entity.position.add(motion); + this.entity.position = this.entity.position.add(motion); let didCollide = this.shape.collidesWithShape(collider.shape, result); if (didCollide) diff --git a/source/src/ECS/Components/Physics/Mover.ts b/source/src/ECS/Components/Physics/Mover.ts index c05f31c2..85461ecb 100644 --- a/source/src/ECS/Components/Physics/Mover.ts +++ b/source/src/ECS/Components/Physics/Mover.ts @@ -47,7 +47,7 @@ module es { let _internalcollisionResult: CollisionResult = new CollisionResult(); if (collider.collidesWith(neighbor, motion, _internalcollisionResult)){ // 如果碰撞 则退回之前的移动量 - motion.subtract(_internalcollisionResult.minimumTranslationVector); + motion = motion.subtract(_internalcollisionResult.minimumTranslationVector); // 如果我们碰到多个对象,为了简单起见,只取第一个。 if (_internalcollisionResult.collider != null){ diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts index 2e26ddff..baea0be7 100644 --- a/source/src/ECS/Components/SpriteRenderer.ts +++ b/source/src/ECS/Components/SpriteRenderer.ts @@ -121,6 +121,9 @@ module es { public render(camera: Camera) { this.sync(camera); + + this.displayObject.x = this.entity.position.x - this.origin.x + this.localOffset.x - camera.position.x + camera.origin.x; + this.displayObject.y = this.entity.position.y - this.origin.y + this.localOffset.y - camera.position.y + camera.origin.y; } } } diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index 3df91c4f..21c41595 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -168,7 +168,7 @@ module es { } } - Vector2Ext.normalize(edgeNormal); + edgeNormal = Vector2Ext.normalize(edgeNormal); return closestPoint; } @@ -219,7 +219,7 @@ module es { this.position = Vector2.add(collider.entity.transform.position, this.center); this.bounds = Rectangle.rectEncompassingPoints(this.points); - this.bounds.location = Vector2.add(this.bounds.location, this.position); + this.bounds.location = this.bounds.location.add(this.position); } public overlaps(other: Shape){ diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts index 799b1695..8c81309b 100644 --- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts +++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts @@ -154,16 +154,19 @@ module es { public static circleToBox(circle: Circle, box: Box, result: CollisionResult): boolean { let closestPointOnBounds = box.bounds.getClosestPointOnRectangleBorderToPoint(circle.position, result.normal); + // 处理那些中心在盒子里的圆,因为比较好操作, if (box.containsPoint(circle.position)) { result.point = closestPointOnBounds; - let safePlace = Vector2.add(closestPointOnBounds, Vector2.subtract(result.normal, new Vector2(circle.radius))); + // 计算mtv。找到安全的,没有碰撞的位置,然后从那里得到mtv + let safePlace = Vector2.add(closestPointOnBounds, Vector2.multiply(result.normal, new Vector2(circle.radius))); result.minimumTranslationVector = Vector2.subtract(circle.position, safePlace); return true; } let sqrDistance = Vector2.distanceSquared(closestPointOnBounds, circle.position); + // 看盒子上的点与圆的距离是否小于半径 if (sqrDistance == 0) { result.minimumTranslationVector = Vector2.multiply(result.normal, new Vector2(circle.radius)); } else if (sqrDistance <= circle.radius * circle.radius) { @@ -171,7 +174,7 @@ module es { let depth = result.normal.length() - circle.radius; result.point = closestPointOnBounds; - Vector2Ext.normalize(result.normal); + result.normal = Vector2Ext.normalize(result.normal); result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal); return true;