From 72fdabd099ea9796f1b62d8f5cfc09a72d98f3b3 Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Mon, 13 Mar 2023 14:51:38 +0800 Subject: [PATCH] =?UTF-8?q?mathHelper=E4=BC=98=E5=8C=96=E5=8F=8A=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E3=80=82=E4=BF=AE=E5=A4=8DpointCircle=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/bin/framework.d.ts | 358 +++++++----- source/bin/framework.js | 671 +++++++++++++++-------- source/bin/framework.min.js | 2 +- source/src/Math/MathHelper.ts | 778 +++++++++++++++++---------- source/src/Physics/Shapes/Circle.ts | 2 +- source/src/Physics/Shapes/Polygon.ts | 2 +- 6 files changed, 1166 insertions(+), 647 deletions(-) diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index ae85e1c7..944a0f2c 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -2546,12 +2546,13 @@ declare module es { */ static catmullRom(value1: number, value2: number, value3: number, value4: number, amount: number): number; /** - * 将值(在leftMin-leftMax范围内)映射到一个在rightMin-rightMax范围内的值 - * @param value - * @param leftMin - * @param leftMax - * @param rightMin - * @param rightMax + * 对给定值进行范围映射。 + * @param value 要映射的值。 + * @param leftMin 输入范围的最小值。 + * @param leftMax 输入范围的最大值。 + * @param rightMin 输出范围的最小值。 + * @param rightMax 输出范围的最大值。 + * @returns 映射后的值。 */ static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number; /** @@ -2563,8 +2564,7 @@ declare module es { */ static map01(value: number, min: number, max: number): number; /** - * 将值从某个任意范围映射到1到0范围 - * 这相当于map01的取反 + * 接收一个值value和两个边界min和max作为参数。它将value映射到0到1的范围内,然后返回1减去该结果的值,因此该函数的结果将在1到0之间 * @param value * @param min * @param max @@ -2572,10 +2572,11 @@ declare module es { */ static map10(value: number, min: number, max: number): number; /** - * 使用三次方程在两个值之间进行插值 - * @param value1 - * @param value2 - * @param amount + * 在两个值之间进行平滑的线性插值。与 lerp 相似,但具有平滑过渡的特点,当 t 在 0 和 1 之间时,返回 [value1, value2] 之间平滑插值后的结果。 + * @param value1 起始值 + * @param value2 结束值 + * @param amount 插值的程度,范围在 0 到 1 之间。 + * @returns 两个值之间进行平滑的线性插值后的结果。 */ static smoothStep(value1: number, value2: number, amount: number): number; /** @@ -2585,42 +2586,57 @@ declare module es { */ static wrapAngle(angle: number): number; /** - * 确定值是否以2为底 + * 判断给定的数值是否是2的幂 * @param value * @returns */ static isPowerOfTwo(value: number): boolean; - static lerp(from: number, to: number, t: number): number; - static betterLerp(a: number, b: number, t: number, epsilon: number): number; /** - * 使度数的角度在a和b之间 - * 用于处理360度环绕 - * @param a - * @param b + * 线性插值 + * @param from + * @param to * @param t * @returns */ + static lerp(from: number, to: number, t: number): number; + /** + * 线性插值前检查两个数的差是否小于一个给定的epsilon值,如果小于,则直接返回结束值b,否则执行线性插值并返回插值结果。 + * @param a 起始值 + * @param b 结束值 + * @param t 插值因子 + * @param epsilon 差值阈值,当两个数的差小于epsilon时直接返回结束值b。 + * @returns 如果a和b的差小于给定的epsilon值,则返回b,否则返回a到b的插值结果。 + */ + static betterLerp(a: number, b: number, t: number, epsilon: number): number; + /** + * 在两个角度之间进行插值,使用角度值表示角度 + * @param a 起始角度 + * @param b 结束角度 + * @param t 插值比例,范围[0, 1] + * @returns 两个角度之间插值后的角度,使用角度值表示 + */ static lerpAngle(a: number, b: number, t: number): number; /** - * 使弧度的角度在a和b之间 - * @param a - * @param b - * @param t - * @returns + * 在两个角度之间进行插值,使用弧度值表示角度 + * @param a 起始角度 + * @param b 结束角度 + * @param t 插值比例,范围[0, 1] + * @returns 两个角度之间插值后的角度,使用弧度值表示 */ static lerpAngleRadians(a: number, b: number, t: number): number; /** - * 循环t使其不大于长度且不小于0 - * @param t - * @param length - * @returns + * 指定长度上来回“弹跳”(ping-pong)一个变量 + * 因为弹跳的过程是来回循环的。最后,根据t在弹跳过程中相对于length的位置 + * @param t 变量的当前值 + * @param length 指定的长度 + * @returns 0到length之间变化的值 */ static pingPong(t: number, length: number): number; /** - * 如果value> = threshold返回其符号,否则返回0 - * @param value - * @param threshold - * @returns + * 当value的绝对值大于等于threshold时返回value的符号,否则返回0 + * @param value - 输入的值 + * @param threshold - 阈值 + * @returns value的符号或0 */ static signThreshold(value: number, threshold: number): number; /** @@ -2632,19 +2648,28 @@ declare module es { */ static inverseLerp(from: number, to: number, t: number): number; /** - * 在两个值之间线性插值 - * 此方法是MathHelper.Lerp的效率较低,更精确的版本。 + * 精确的线性插值,避免出现累积误差 + * @param value1 起始值 + * @param value2 结束值 + * @param amount 插值比例 + * @returns 两个值的线性插值结果 */ static lerpPrecise(value1: number, value2: number, amount: number): number; - static clamp(value: number, min: number, max: number): number; - static snap(value: number, increment: number): number; /** - * 给定圆心、半径和角度,得到圆周上的一个点。0度是3点钟。 - * @param circleCenter - * @param radius - * @param angleInDegrees + * 将给定值限制在指定范围内 + * @param value 需要被限制的值 + * @param min 最小值 + * @param max 最大值 + * @returns 限制后的值 */ - static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2; + static clamp(value: number, min: number, max: number): number; + /** + * 按照指定增量取整到最接近的整数倍数 + * @param value + * @param increment + * @returns + */ + static snap(value: number, increment: number): number; /** * 如果值为偶数,返回true * @param value @@ -2657,158 +2682,186 @@ declare module es { */ static isOdd(value: number): boolean; /** - * 将值四舍五入并返回它和四舍五入后的数值 - * @param value - * @param roundedAmount - * @returns + * 将数值四舍五入到最接近的整数,并计算四舍五入的数量 + * @param value 要四舍五入的数值 + * @param roundedAmount 用于存储四舍五入的数量的参数 + * @returns 四舍五入后的整数 */ static roundWithRoundedAmount(value: number, roundedAmount: Ref): number; /** - * 数值限定在0-1之间 - * @param value + * 将一个数值限制在 [0,1] 范围内 + * @param value 要限制的数值 + * @returns 限制后的数值 */ static clamp01(value: number): number; + /** + * 计算从一个向量到另一个向量之间的角度 + * @param from 起始向量 + * @param to 目标向量 + * @returns 两个向量之间的角度(弧度制) + */ static angleBetweenVectors(from: Vector2, to: Vector2): number; + /** + * 将极角和极径转换为向量坐标 + * @param angleRadians 极角弧度值 + * @param length 极径长度 + * @returns 对应向量坐标 + */ static angleToVector(angleRadians: number, length: number): Vector2; /** - * 增加t并确保它总是大于或等于0并且小于长度 - * @param t - * @param length + * 将一个数加上1,并在结果等于指定长度时将其设置为0 + * @param t 要加上1的数 + * @param length 指定长度 + * @returns 加上1后的结果,如果等于指定长度,则为0 */ static incrementWithWrap(t: number, length: number): number; /** - * 递减t并确保其始终大于或等于0且小于长度 - * @param t - * @param length - * @returns + * 将一个数减去1,并在结果小于0时将其设置为指定长度减去1 + * @param t 要减去1的数 + * @param length 指定长度 + * @returns 减去1后的结果,如果小于0,则为指定长度减去1 */ static decrementWithWrap(t: number, length: number): number; /** - * 返回sqrt(x * x + y * y) - * @param x - * @param y - * @returns + * 计算直角三角形斜边长度,即求两个数的欧几里得距离 + * @param x 直角三角形的一条直角边 + * @param y 直角三角形的另一条直角边 + * @returns 三角形斜边长度 */ static hypotenuse(x: number, y: number): number; + /** + * 计算大于给定数字的最小二次幂 + * @param x 给定数字 + * @returns 大于给定数字的最小二次幂 + */ static closestPowerOfTwoGreaterThan(x: number): number; /** - * 以roundToNearest为步长,将值舍入到最接近的数字。例如:在125中找到127到最近的5个结果 - * @param value - * @param roundToNearest + * 将数字舍入到最接近的指定值 + * @param value 需要被舍入的数字 + * @param roundToNearest 指定的舍入值 + * @returns 舍入后的结果 */ static roundToNearest(value: number, roundToNearest: number): number; /** - * 检查传递的值是否在某个阈值之下。对于小规模、精确的比较很有用 - * @param value - * @param ep + * 判断给定值是否接近于零 + * @param value 给定值 + * @param ep 阈值(可选,默认为Epsilon) + * @returns 如果接近于零,返回true,否则返回false */ static withinEpsilon(value: number, ep?: number): boolean; /** - * 由上移量向上移。start可以小于或大于end。例如:开始是2,结束是10,移位是4,结果是6 - * @param start - * @param end - * @param shift + * 逐渐逼近目标值 + * @param start 起始值 + * @param end 目标值 + * @param shift 逼近步长 + * @returns 逼近后的值 */ static approach(start: number, end: number, shift: number): number; /** - * 通过偏移量钳位结果并选择最短路径,将起始角度向终止角度移动,起始值可以小于或大于终止值。 - * 示例1:开始是30,结束是100,移位是25,结果为55 - * 示例2:开始是340,结束是30,移位是25,结果是5(365换为5) - * @param start - * @param end - * @param shift - * @returns + * 逐渐逼近目标角度 + * @param start 起始角度 + * @param end 目标角度 + * @param shift 逼近步长 + * @returns 最终角度 */ static approachAngle(start: number, end: number, shift: number): number; /** - * 将 Vector 投影到另一个 Vector 上 - * @param other + * 计算向量在另一个向量上的投影向量 + * @param self 要投影的向量 + * @param other 目标向量 + * @returns 投影向量 */ static project(self: Vector2, other: Vector2): Vector2; /** - * 通过将偏移量(全部以弧度为单位)夹住结果并选择最短路径,起始角度朝向终止角度。 - * 起始值可以小于或大于终止值。 - * 此方法的工作方式与“角度”方法非常相似,唯一的区别是使用弧度代替度,并以2 * Pi代替360。 - * @param start - * @param end - * @param shift - * @returns + * 逐渐接近目标角度 + * @param start 当前角度值(弧度制) + * @param end 目标角度值(弧度制) + * @param shift 每次逐渐接近目标角度的增量(弧度制) + * @returns 逐渐接近目标角度后的角度值(弧度制) */ static approachAngleRadians(start: number, end: number, shift: number): number; /** - * 使用可接受的检查公差检查两个值是否大致相同 - * @param value1 - * @param value2 - * @param tolerance - * @returns + * 判断两个数值是否在指定公差内近似相等 + * @param value1 第一个数值 + * @param value2 第二个数值 + * @param tolerance 指定公差,默认为 Epsilon 常量 + * @returns 是否在指定公差内近似相等 */ static approximately(value1: number, value2: number, tolerance?: number): boolean; /** - * 计算两个给定角之间的最短差值(度数) - * @param current - * @param target + * 计算两个角度值之间的角度差值 + * @param current 当前角度值 + * @param target 目标角度值 + * @returns 角度差值 */ static deltaAngle(current: number, target: number): number; /** - * 检查值是否介于最小值/最大值(包括最小值/最大值)之间 - * @param value - * @param min - * @param max - * @returns + * 判断给定数值是否在指定区间内 + * @param value 给定数值 + * @param min 区间最小值 + * @param max 区间最大值 + * @returns 是否在指定区间内 */ static between(value: number, min: number, max: number): boolean; /** - * 计算以弧度为单位的两个给定角度之间的最短差 - * @param current - * @param target - * @returns + * 计算两个弧度值之间的角度差值 + * @param current 当前弧度值 + * @param target 目标弧度值 + * @returns 角度差值 */ static deltaAngleRadians(current: number, target: number): number; /** - * 循环t,使其永远不大于长度,永远不小于0 - * @param t - * @param length + * 将给定的数值限定在一个循环范围内 + * @param t 给定的数值 + * @param length 循环范围长度 + * @returns 限定在循环范围内的数值 */ static repeat(t: number, length: number): number; + /** + * 将给定的浮点数向下取整为整数 + * @param f 给定的浮点数 + * @returns 向下取整后的整数 + */ static floorToInt(f: number): number; /** - * 将值绕一圈移动的助手 - * @param position - * @param speed - * @returns + * 绕着一个点旋转 + * @param position 原点坐标 + * @param speed 旋转速度 + * @returns 经过旋转后的点坐标 */ static rotateAround(position: Vector2, speed: number): Vector2; /** - * 旋转是相对于当前位置而不是总旋转。 - * 例如,如果您当前处于90度并且想要旋转到135度,则可以使用45度而不是135度的角度 - * @param point - * @param center - * @param angleIndegrees + * 绕给定中心点旋转指定角度后得到的新点坐标 + * @param point 要旋转的点的坐标 + * @param center 旋转中心点的坐标 + * @param angleIndegrees 旋转的角度,单位为度 + * @returns 旋转后的新点的坐标,返回值类型为Vector2 */ static rotateAround2(point: Vector2, center: Vector2, angleIndegrees: number): Vector2; /** - * 根据圆的中心,半径和角度在圆的圆周上得到一个点。 0度是3点钟方向 - * @param circleCenter - * @param radius - * @param angleInDegrees + * 计算以给定点为圆心、给定半径的圆上某一点的坐标 + * @param circleCenter 圆心坐标 + * @param radius 圆半径 + * @param angleInDegrees 角度值(度数制) + * @returns 计算出的圆上某一点的坐标 */ static pointOnCircle(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2; /** - * 根据圆的中心,半径和角度在圆的圆周上得到一个点。 0弧度是3点钟方向 - * @param circleCenter - * @param radius - * @param angleInRadians - * @returns + * 计算以给定点为圆心、给定半径的圆上某一点的坐标 + * @param circleCenter 圆心坐标 + * @param radius 圆半径 + * @param angleInRadians 角度值(弧度制) + * @returns 计算出的圆上某一点的坐标 */ static pointOnCircleRadians(circleCenter: Vector2, radius: number, angleInRadians: number): Vector2; /** - * lissajou曲线 - * @param xFrequency - * @param yFrequency - * @param xMagnitude - * @param yMagnitude - * @param phase - * @returns + * 生成一个Lissajous曲线上的点的坐标 + * @param xFrequency x方向上的频率,默认值为2 + * @param yFrequency y方向上的频率,默认值为3 + * @param xMagnitude x方向上的振幅,默认值为1 + * @param yMagnitude y方向上的振幅,默认值为1 + * @param phase 相位,默认值为0 + * @returns 在Lissajous曲线上的点的坐标,返回值类型为Vector2 */ static lissajou(xFrequency?: number, yFrequency?: number, xMagnitude?: number, yMagnitude?: number, phase?: number): Vector2; /** @@ -2833,27 +2886,58 @@ declare module es { */ static hermite(value1: number, tangent1: number, value2: number, tangent2: number, amount: number): number; /** - * 此函数用于确保数不是NaN或无穷大 + * 判断给定的数字是否有效 + * 如果输入的数字是 NaN 或正无穷大,该函数将返回 false;否则返回 true * @param x * @returns */ static isValid(x: number): boolean; + /** + * 平滑阻尼运动,将当前位置平滑过渡到目标位置,返回一个包含当前位置和当前速度的对象 + * @param current 当前位置 + * @param target 目标位置 + * @param currentVelocity 当前速度 + * @param smoothTime 平滑时间 + * @param maxSpeed 最大速度 + * @param deltaTime 时间增量 + * @returns 一个包含当前位置和当前速度的对象,类型为{ value: number; currentVelocity: number } + */ static smoothDamp(current: number, target: number, currentVelocity: number, smoothTime: number, maxSpeed: number, deltaTime: number): { value: number; currentVelocity: number; }; + /** + * 平滑插值两个二维向量 + * @param current 当前向量 + * @param target 目标向量 + * @param currentVelocity 当前速度向量 + * @param smoothTime 平滑插值时间 + * @param maxSpeed 最大速度 + * @param deltaTime 帧间隔时间 + * @returns 插值后的结果向量 + */ static smoothDampVector(current: Vector2, target: Vector2, currentVelocity: Vector2, smoothTime: number, maxSpeed: number, deltaTime: number): Vector2; /** - * 将值(在 leftMin - leftMax 范围内)映射到 rightMin - rightMax 范围内的值 - * @param value - * @param leftMin - * @param leftMax - * @param rightMin - * @param rightMax + * 将一个值从一个区间映射到另一个区间 + * @param value 需要映射的值 + * @param leftMin 所在区间的最小值 + * @param leftMax 所在区间的最大值 + * @param rightMin 需要映射到的目标区间的最小值 + * @param rightMax 需要映射到的目标区间的最大值 * @returns */ - static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: any): number; + static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number; + /** + * 返回一个给定角度的单位向量。角度被解释为弧度制。 + * @param angle - 给定角度,以弧度制表示。 + * @returns 一个新的已归一化的二维向量。 + */ static fromAngle(angle: number): Vector2; + /** + * 将一个数字转换为最接近的整数 + * @param val 需要被转换的数字 + * @returns 最接近的整数 + */ static toInt(val: number): number; } } diff --git a/source/bin/framework.js b/source/bin/framework.js index 8fa2b5ea..f0387a4d 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -6259,14 +6259,16 @@ var es; return p0 * amountCubed + p1 * amountSquared + p2 * amount + p3; }; /** - * 将值(在leftMin-leftMax范围内)映射到一个在rightMin-rightMax范围内的值 - * @param value - * @param leftMin - * @param leftMax - * @param rightMin - * @param rightMax + * 对给定值进行范围映射。 + * @param value 要映射的值。 + * @param leftMin 输入范围的最小值。 + * @param leftMax 输入范围的最大值。 + * @param rightMin 输出范围的最小值。 + * @param rightMax 输出范围的最大值。 + * @returns 映射后的值。 */ MathHelper.map = function (value, leftMin, leftMax, rightMin, rightMax) { + // 使用线性插值公式进行映射 return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); }; /** @@ -6280,26 +6282,29 @@ var es; return (value - min) * 1 / (max - min); }; /** - * 将值从某个任意范围映射到1到0范围 - * 这相当于map01的取反 + * 接收一个值value和两个边界min和max作为参数。它将value映射到0到1的范围内,然后返回1减去该结果的值,因此该函数的结果将在1到0之间 * @param value * @param min * @param max * @returns */ MathHelper.map10 = function (value, min, max) { - return 1 - this.map01(value, min, max); + // 将 value 映射到 0 到 1 的范围内 + var mappedValue = this.map01(value, min, max); + // 返回 1 减去 mappedValue 的值,结果将在 1 到 0 之间 + return 1 - mappedValue; }; /** - * 使用三次方程在两个值之间进行插值 - * @param value1 - * @param value2 - * @param amount + * 在两个值之间进行平滑的线性插值。与 lerp 相似,但具有平滑过渡的特点,当 t 在 0 和 1 之间时,返回 [value1, value2] 之间平滑插值后的结果。 + * @param value1 起始值 + * @param value2 结束值 + * @param amount 插值的程度,范围在 0 到 1 之间。 + * @returns 两个值之间进行平滑的线性插值后的结果。 */ MathHelper.smoothStep = function (value1, value2, amount) { - var result = this.clamp(amount, 0, 1); - result = MathHelper.hermite(value1, 0, value2, 0, result); - return result; + amount = this.clamp01(amount); // 将 amount 的值限制在 0 到 1 之间 + amount = this.hermite(value1, 0, value2, 0, amount); // 使用 hermite 函数进行平滑插值 + return amount; // 返回插值后的结果 }; /** * 将给定角度减小到π到-π之间的值 @@ -6318,67 +6323,98 @@ var es; } }; /** - * 确定值是否以2为底 + * 判断给定的数值是否是2的幂 * @param value * @returns */ MathHelper.isPowerOfTwo = function (value) { - return (value > 0) && ((value % (value - 1)) == 0); + // 确保值大于0 + if (value <= 0) { + return false; + } + // 检查是否为2的幂 + return (value & (value - 1)) == 0; }; + /** + * 线性插值 + * @param from + * @param to + * @param t + * @returns + */ MathHelper.lerp = function (from, to, t) { - return from + (to - from) * this.clamp01(t); + // 计算在 from 和 to 之间 t 所占的比例 + var clampedT = MathHelper.clamp01(t); + // 计算 from 到 to 的差值,再乘以比例,得到从 from 到 to 之间 t 所在的位置 + return from + (to - from) * clampedT; }; + /** + * 线性插值前检查两个数的差是否小于一个给定的epsilon值,如果小于,则直接返回结束值b,否则执行线性插值并返回插值结果。 + * @param a 起始值 + * @param b 结束值 + * @param t 插值因子 + * @param epsilon 差值阈值,当两个数的差小于epsilon时直接返回结束值b。 + * @returns 如果a和b的差小于给定的epsilon值,则返回b,否则返回a到b的插值结果。 + */ MathHelper.betterLerp = function (a, b, t, epsilon) { return Math.abs(a - b) < epsilon ? b : MathHelper.lerp(a, b, t); }; /** - * 使度数的角度在a和b之间 - * 用于处理360度环绕 - * @param a - * @param b - * @param t - * @returns + * 在两个角度之间进行插值,使用角度值表示角度 + * @param a 起始角度 + * @param b 结束角度 + * @param t 插值比例,范围[0, 1] + * @returns 两个角度之间插值后的角度,使用角度值表示 */ MathHelper.lerpAngle = function (a, b, t) { - var num = this.repeat(b - a, 360); - if (num > 180) - num -= 360; - return a + num * this.clamp01(t); + // 计算从a到b的差值,对于超过360的值,需要进行修正 + var deltaAngle = this.repeat(b - a, 360); + if (deltaAngle > 180) { + deltaAngle -= 360; + } + // 返回经过插值后的角度 + return a + deltaAngle * this.clamp01(t); }; /** - * 使弧度的角度在a和b之间 - * @param a - * @param b - * @param t - * @returns + * 在两个角度之间进行插值,使用弧度值表示角度 + * @param a 起始角度 + * @param b 结束角度 + * @param t 插值比例,范围[0, 1] + * @returns 两个角度之间插值后的角度,使用弧度值表示 */ MathHelper.lerpAngleRadians = function (a, b, t) { - var num = this.repeat(b - a, Math.PI * 2); - if (num > Math.PI) - num -= Math.PI * 2; - return a + num * this.clamp01(t); + // 计算从a到b的差值,对于超过2π的值,需要进行修正 + var deltaAngle = this.repeat(b - a, Math.PI * 2); + if (deltaAngle > Math.PI) { + deltaAngle -= Math.PI * 2; + } + // 返回经过插值后的角度 + return a + deltaAngle * this.clamp01(t); }; /** - * 循环t使其不大于长度且不小于0 - * @param t - * @param length - * @returns + * 指定长度上来回“弹跳”(ping-pong)一个变量 + * 因为弹跳的过程是来回循环的。最后,根据t在弹跳过程中相对于length的位置 + * @param t 变量的当前值 + * @param length 指定的长度 + * @returns 0到length之间变化的值 */ MathHelper.pingPong = function (t, length) { + // 将t的值限制在0到length*2的范围内 t = this.repeat(t, length * 2); + // 返回length和t-length的差的绝对值 return length - Math.abs(t - length); }; /** - * 如果value> = threshold返回其符号,否则返回0 - * @param value - * @param threshold - * @returns + * 当value的绝对值大于等于threshold时返回value的符号,否则返回0 + * @param value - 输入的值 + * @param threshold - 阈值 + * @returns value的符号或0 */ MathHelper.signThreshold = function (value, threshold) { - if (Math.abs(value) >= threshold) - return Math.sign(value); + if (Math.abs(value) >= threshold) // 如果绝对值大于等于阈值 + return Math.sign(value); // 返回value的符号 else - return 0; + return 0; // 否则返回0 }; /** * 计算t值在[from, to]区间内的插值比例 @@ -6398,31 +6434,42 @@ var es; return (t - from) / length; }; /** - * 在两个值之间线性插值 - * 此方法是MathHelper.Lerp的效率较低,更精确的版本。 + * 精确的线性插值,避免出现累积误差 + * @param value1 起始值 + * @param value2 结束值 + * @param amount 插值比例 + * @returns 两个值的线性插值结果 */ MathHelper.lerpPrecise = function (value1, value2, amount) { return ((1 - amount) * value1) + (value2 * amount); }; + /** + * 将给定值限制在指定范围内 + * @param value 需要被限制的值 + * @param min 最小值 + * @param max 最大值 + * @returns 限制后的值 + */ MathHelper.clamp = function (value, min, max) { - if (value < min) + if (value < min) { // 如果值小于最小值,则返回最小值 return min; - if (value > max) + } + else if (value > max) { // 如果值大于最大值,则返回最大值 return max; - return value; - }; - MathHelper.snap = function (value, increment) { - return Math.round(value / increment) * increment; + } + else { // 否则返回原始值 + return value; + } }; /** - * 给定圆心、半径和角度,得到圆周上的一个点。0度是3点钟。 - * @param circleCenter - * @param radius - * @param angleInDegrees + * 按照指定增量取整到最接近的整数倍数 + * @param value + * @param increment + * @returns */ - 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.snap = function (value, increment) { + // 将给定值除以增量取整后再乘以增量,得到最接近给定值的整数倍 + return Math.round(value / increment) * increment; }; /** * 如果值为偶数,返回true @@ -6440,10 +6487,10 @@ var es; return value % 2 != 0; }; /** - * 将值四舍五入并返回它和四舍五入后的数值 - * @param value - * @param roundedAmount - * @returns + * 将数值四舍五入到最接近的整数,并计算四舍五入的数量 + * @param value 要四舍五入的数值 + * @param roundedAmount 用于存储四舍五入的数量的参数 + * @returns 四舍五入后的整数 */ MathHelper.roundWithRoundedAmount = function (value, roundedAmount) { var rounded = Math.round(value); @@ -6451,8 +6498,9 @@ var es; return rounded; }; /** - * 数值限定在0-1之间 - * @param value + * 将一个数值限制在 [0,1] 范围内 + * @param value 要限制的数值 + * @returns 限制后的数值 */ MathHelper.clamp01 = function (value) { if (value < 0) @@ -6461,230 +6509,345 @@ var es; return 1; return value; }; + /** + * 计算从一个向量到另一个向量之间的角度 + * @param from 起始向量 + * @param to 目标向量 + * @returns 两个向量之间的角度(弧度制) + */ MathHelper.angleBetweenVectors = function (from, to) { + // 使用 Math.atan2() 方法计算出两个向量之间的夹角,返回的是弧度制角度 return Math.atan2(to.y - from.y, to.x - from.x); }; + /** + * 将极角和极径转换为向量坐标 + * @param angleRadians 极角弧度值 + * @param length 极径长度 + * @returns 对应向量坐标 + */ MathHelper.angleToVector = function (angleRadians, length) { - return new es.Vector2(Math.cos(angleRadians) * length, Math.sin(angleRadians) * length); + // 根据给定的极角弧度值,使用三角函数计算出向量的x坐标和y坐标 + var x = Math.cos(angleRadians) * length; + var y = Math.sin(angleRadians) * length; + // 使用上一步得到的坐标值创建一个新的Vector2对象并返回 + return new es.Vector2(x, y); }; /** - * 增加t并确保它总是大于或等于0并且小于长度 - * @param t - * @param length + * 将一个数加上1,并在结果等于指定长度时将其设置为0 + * @param t 要加上1的数 + * @param length 指定长度 + * @returns 加上1后的结果,如果等于指定长度,则为0 */ MathHelper.incrementWithWrap = function (t, length) { + // 将给定数t加上1。 t++; - if (t == length) + // 如果结果等于指定长度,则返回0。 + if (t == length) { return 0; + } + // 否则,返回结果。 return t; }; /** - * 递减t并确保其始终大于或等于0且小于长度 - * @param t - * @param length - * @returns + * 将一个数减去1,并在结果小于0时将其设置为指定长度减去1 + * @param t 要减去1的数 + * @param length 指定长度 + * @returns 减去1后的结果,如果小于0,则为指定长度减去1 */ MathHelper.decrementWithWrap = function (t, length) { + // 将给定数t减去1。 t--; - if (t < 0) + // 如果结果小于0,则返回指定长度减去1。 + if (t < 0) { return length - 1; + } + // 否则,返回结果。 return t; }; /** - * 返回sqrt(x * x + y * y) - * @param x - * @param y - * @returns + * 计算直角三角形斜边长度,即求两个数的欧几里得距离 + * @param x 直角三角形的一条直角边 + * @param y 直角三角形的另一条直角边 + * @returns 三角形斜边长度 */ MathHelper.hypotenuse = function (x, y) { - return Math.sqrt(x * x + y * y); + // 将x的平方与y的平方相加。 + var sumOfSquares = x * x + y * y; + // 对和进行平方根运算。 + var result = Math.sqrt(sumOfSquares); + // 返回结果。 + return result; }; + /** + * 计算大于给定数字的最小二次幂 + * @param x 给定数字 + * @returns 大于给定数字的最小二次幂 + */ MathHelper.closestPowerOfTwoGreaterThan = function (x) { - x--; - x |= (x >> 1); + x--; // 将给定数字减1,得到一个二进制数的掩码。 + x |= (x >> 1); // 将掩码的右侧一半全部设置为1。 x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); - x |= (x >> 16); - return (x + 1); + x |= (x >> 16); // 连续将掩码右移,并将右侧一半全部设置为1,直到得到一个全为1的掩码。 + return (x + 1); // 将全为1的掩码加1,得到的结果就是大于给定数字的最小二次幂。 }; /** - * 以roundToNearest为步长,将值舍入到最接近的数字。例如:在125中找到127到最近的5个结果 - * @param value - * @param roundToNearest + * 将数字舍入到最接近的指定值 + * @param value 需要被舍入的数字 + * @param roundToNearest 指定的舍入值 + * @returns 舍入后的结果 */ MathHelper.roundToNearest = function (value, roundToNearest) { - return Math.round(value / roundToNearest) * roundToNearest; + var quotient = value / roundToNearest; // 将数字除以指定值,得到商。 + var roundedQuotient = Math.round(quotient); // 将商四舍五入到最接近的整数。 + var result = roundedQuotient * roundToNearest; // 将舍入后的整数乘以指定值,得到最终结果。 + return result; }; /** - * 检查传递的值是否在某个阈值之下。对于小规模、精确的比较很有用 - * @param value - * @param ep + * 判断给定值是否接近于零 + * @param value 给定值 + * @param ep 阈值(可选,默认为Epsilon) + * @returns 如果接近于零,返回true,否则返回false */ MathHelper.withinEpsilon = function (value, ep) { if (ep === void 0) { ep = this.Epsilon; } + // 判断给定值的绝对值是否小于给定的阈值ep。 return Math.abs(value) < ep; }; /** - * 由上移量向上移。start可以小于或大于end。例如:开始是2,结束是10,移位是4,结果是6 - * @param start - * @param end - * @param shift + * 逐渐逼近目标值 + * @param start 起始值 + * @param end 目标值 + * @param shift 逼近步长 + * @returns 逼近后的值 */ MathHelper.approach = function (start, end, shift) { - if (start < end) + // 判断起始值是否小于目标值。 + if (start < end) { + // 如果是,返回起始值加上shift和目标值中的较小值。 return Math.min(start + shift, end); + } + // 如果不是,返回起始值减去shift和目标值中的较大值。 return Math.max(start - shift, end); }; /** - * 通过偏移量钳位结果并选择最短路径,将起始角度向终止角度移动,起始值可以小于或大于终止值。 - * 示例1:开始是30,结束是100,移位是25,结果为55 - * 示例2:开始是340,结束是30,移位是25,结果是5(365换为5) - * @param start - * @param end - * @param shift - * @returns + * 逐渐逼近目标角度 + * @param start 起始角度 + * @param end 目标角度 + * @param shift 逼近步长 + * @returns 最终角度 */ MathHelper.approachAngle = function (start, end, shift) { + // 调用this.deltaAngle()方法,获取起始角度和目标角度之间的夹角。 var deltaAngle = this.deltaAngle(start, end); - if (-shift < deltaAngle && deltaAngle < shift) + // 判断夹角是否小于等于shift,如果是,直接返回目标角度。 + if (-shift < deltaAngle && deltaAngle < shift) { return end; - return this.repeat(this.approach(start, start + deltaAngle, shift), 360); + } + // 如果夹角大于shift,则调用this.approach()方法,逐渐逼近目标角度。 + var newAngle = this.approach(start, start + deltaAngle, shift); + // 通过调用this.repeat()方法,将最终的角度限制在0到360度之间。 + newAngle = this.repeat(newAngle, 360); + // 返回最终的角度。 + return newAngle; }; /** - * 将 Vector 投影到另一个 Vector 上 - * @param other + * 计算向量在另一个向量上的投影向量 + * @param self 要投影的向量 + * @param other 目标向量 + * @returns 投影向量 */ MathHelper.project = function (self, other) { + // 通过调用Vector2.dot()方法,计算出self向量和other向量的点积。 var amt = self.dot(other) / other.lengthSquared(); + // 通过调用Vector2.lengthSquared()方法,计算出other向量的长度的平方。 + // 将点积除以长度的平方,得到self向量在other向量上的投影长度。 + // 通过调用Vector2.scale()方法,将投影长度与other向量的方向向量相乘,得到投影向量。 var vec = other.scale(amt); + // 返回投影向量。 return vec; }; /** - * 通过将偏移量(全部以弧度为单位)夹住结果并选择最短路径,起始角度朝向终止角度。 - * 起始值可以小于或大于终止值。 - * 此方法的工作方式与“角度”方法非常相似,唯一的区别是使用弧度代替度,并以2 * Pi代替360。 - * @param start - * @param end - * @param shift - * @returns + * 逐渐接近目标角度 + * @param start 当前角度值(弧度制) + * @param end 目标角度值(弧度制) + * @param shift 每次逐渐接近目标角度的增量(弧度制) + * @returns 逐渐接近目标角度后的角度值(弧度制) */ MathHelper.approachAngleRadians = function (start, end, shift) { + // 通过调用deltaAngleRadians()方法,计算出当前角度值和目标角度值之间的弧度差值。 var deltaAngleRadians = this.deltaAngleRadians(start, end); - if (-shift < deltaAngleRadians && deltaAngleRadians < shift) + // 如果弧度差值的绝对值小于shift,则返回目标角度值。 + if (-shift < deltaAngleRadians && deltaAngleRadians < shift) { return end; - return this.repeat(this.approach(start, start + deltaAngleRadians, shift), Math.PI * 2); + } + // 否则,通过调用approach()方法,逐渐将当前角度值接近目标角度值。 + var result = this.approach(start, start + deltaAngleRadians, shift); + // 将计算结果使用repeat()方法转换成[0, 2π)之间的角度值,并返回。 + return this.repeat(result, Math.PI * 2); }; /** - * 使用可接受的检查公差检查两个值是否大致相同 - * @param value1 - * @param value2 - * @param tolerance - * @returns + * 判断两个数值是否在指定公差内近似相等 + * @param value1 第一个数值 + * @param value2 第二个数值 + * @param tolerance 指定公差,默认为 Epsilon 常量 + * @returns 是否在指定公差内近似相等 */ MathHelper.approximately = function (value1, value2, tolerance) { if (tolerance === void 0) { tolerance = this.Epsilon; } + // 计算两个数值之差的绝对值是否小于等于指定公差。 return Math.abs(value1 - value2) <= tolerance; }; /** - * 计算两个给定角之间的最短差值(度数) - * @param current - * @param target + * 计算两个角度值之间的角度差值 + * @param current 当前角度值 + * @param target 目标角度值 + * @returns 角度差值 */ MathHelper.deltaAngle = function (current, target) { + // 通过调用repeat()方法,计算出当前角度值和目标角度值之间的差值。 var num = this.repeat(target - current, 360); - if (num > 180) + // 如果差值大于180度,则将差值减去360度,得到[-180度, 180度]之间的差值。 + if (num > 180) { num -= 360; + } + // 返回差值。 return num; }; /** - * 检查值是否介于最小值/最大值(包括最小值/最大值)之间 - * @param value - * @param min - * @param max - * @returns + * 判断给定数值是否在指定区间内 + * @param value 给定数值 + * @param min 区间最小值 + * @param max 区间最大值 + * @returns 是否在指定区间内 */ MathHelper.between = function (value, min, max) { + // 比较给定数值是否大于等于最小值并且小于等于最大值。 return value >= min && value <= max; }; /** - * 计算以弧度为单位的两个给定角度之间的最短差 - * @param current - * @param target - * @returns + * 计算两个弧度值之间的角度差值 + * @param current 当前弧度值 + * @param target 目标弧度值 + * @returns 角度差值 */ MathHelper.deltaAngleRadians = function (current, target) { + // 通过调用repeat()方法,计算出当前弧度值和目标弧度值之间的差值。 var num = this.repeat(target - current, 2 * Math.PI); - if (num > Math.PI) + // 如果差值大于π,则将差值减去2π,得到[-π, π]之间的差值。 + if (num > Math.PI) { num -= 2 * Math.PI; + } + // 返回差值。 return num; }; /** - * 循环t,使其永远不大于长度,永远不小于0 - * @param t - * @param length + * 将给定的数值限定在一个循环范围内 + * @param t 给定的数值 + * @param length 循环范围长度 + * @returns 限定在循环范围内的数值 */ MathHelper.repeat = function (t, length) { - return t - Math.floor(t / length) * length; - }; - MathHelper.floorToInt = function (f) { - return this.toInt(Math.floor(f)); + // 计算给定数值除以循环范围长度的整数部分,即循环次数。 + var num = Math.floor(t / length); + // 用给定数值减去循环次数乘以循环范围长度,得到限定在循环范围内的数值。 + var result = t - num * length; + // 返回限定后的数值。 + return result; }; /** - * 将值绕一圈移动的助手 - * @param position - * @param speed - * @returns + * 将给定的浮点数向下取整为整数 + * @param f 给定的浮点数 + * @returns 向下取整后的整数 + */ + MathHelper.floorToInt = function (f) { + // 使用Math.floor()方法,将给定的浮点数向下取整为最接近它的小于等于它的整数。 + var flooredValue = Math.floor(f); + // 调用toInt()方法,将结果转换为整数类型。 + return this.toInt(flooredValue); + }; + /** + * 绕着一个点旋转 + * @param position 原点坐标 + * @param speed 旋转速度 + * @returns 经过旋转后的点坐标 */ MathHelper.rotateAround = function (position, speed) { - var time = es.Time.totalTime * speed; - var x = Math.cos(time); - var y = Math.sin(time); - return new es.Vector2(position.x + x, position.y + y); - }; - /** - * 旋转是相对于当前位置而不是总旋转。 - * 例如,如果您当前处于90度并且想要旋转到135度,则可以使用45度而不是135度的角度 - * @param point - * @param center - * @param angleIndegrees - */ - MathHelper.rotateAround2 = function (point, center, angleIndegrees) { - angleIndegrees = this.toRadians(angleIndegrees); - var cos = Math.cos(angleIndegrees); - var sin = Math.sin(angleIndegrees); - var rotatedX = cos * (point.x - center.x) - sin * (point.y - center.y) + center.x; - var rotatedY = sin * (point.x - center.x) + cos * (point.y - center.y) + center.y; + // 计算旋转角度,使用当前时间与旋转速度的乘积作为参数进行计算。 + var angleInRadians = es.Time.totalTime * speed; + // 通过三角函数,计算出在当前时间下,距离原点为1的点在x轴和y轴上的坐标值。 + var cosValue = Math.cos(angleInRadians); + var sinValue = Math.sin(angleInRadians); + // 将计算出的x轴和y轴的坐标值加上原点的坐标值,得到旋转后的点的坐标值。 + var rotatedX = position.x + cosValue; + var rotatedY = position.y + sinValue; + // 创建一个新的Vector2对象,将上面得到的旋转后的点的坐标值作为参数,返回该对象。 return new es.Vector2(rotatedX, rotatedY); }; /** - * 根据圆的中心,半径和角度在圆的圆周上得到一个点。 0度是3点钟方向 - * @param circleCenter - * @param radius - * @param angleInDegrees + * 绕给定中心点旋转指定角度后得到的新点坐标 + * @param point 要旋转的点的坐标 + * @param center 旋转中心点的坐标 + * @param angleIndegrees 旋转的角度,单位为度 + * @returns 旋转后的新点的坐标,返回值类型为Vector2 + */ + MathHelper.rotateAround2 = function (point, center, angleIndegrees) { + var cx = center.x, cy = center.y; + var px = point.x, py = point.y; + var angleInRadians = this.toRadians(angleIndegrees); // 将角度值转换为弧度值 + var cos = Math.cos(angleInRadians); // 计算cos值 + var sin = Math.sin(angleInRadians); // 计算sin值 + var rotatedX = cos * (px - cx) - sin * (py - cy) + cx; // 计算旋转后的新点的x坐标 + var rotatedY = sin * (px - cx) + cos * (py - cy) + cy; // 计算旋转后的新点的y坐标 + return new es.Vector2(rotatedX, rotatedY); // 返回旋转后的新点的坐标 + }; + /** + * 计算以给定点为圆心、给定半径的圆上某一点的坐标 + * @param circleCenter 圆心坐标 + * @param radius 圆半径 + * @param angleInDegrees 角度值(度数制) + * @returns 计算出的圆上某一点的坐标 */ MathHelper.pointOnCircle = function (circleCenter, radius, angleInDegrees) { + // 将给定角度值转换为弧度值,以便使用三角函数计算坐标值。 var radians = this.toRadians(angleInDegrees); - return new es.Vector2(Math.cos(radians) * radius + circleCenter.x, Math.sin(radians) * radius + circleCenter.y); + // 根据弧度值,通过三角函数(cos和sin)计算出该角度对应的x和y坐标的值(其中x坐标对应cos值,y坐标对应sin值)。 + var x = Math.cos(radians) * radius; + var y = Math.sin(radians) * radius; + // 将x坐标值乘以半径,再加上圆心的x坐标,得到该点在x轴上的绝对坐标。 + var absoluteX = x + circleCenter.x; + // 将y坐标值乘以半径,再加上圆心的y坐标,得到该点在y轴上的绝对坐标。 + var absoluteY = y + circleCenter.y; + // 创建一个新的Vector2对象,将上面得到的x和y坐标作为参数,返回该对象。 + return new es.Vector2(absoluteX, absoluteY); }; /** - * 根据圆的中心,半径和角度在圆的圆周上得到一个点。 0弧度是3点钟方向 - * @param circleCenter - * @param radius - * @param angleInRadians - * @returns + * 计算以给定点为圆心、给定半径的圆上某一点的坐标 + * @param circleCenter 圆心坐标 + * @param radius 圆半径 + * @param angleInRadians 角度值(弧度制) + * @returns 计算出的圆上某一点的坐标 */ MathHelper.pointOnCircleRadians = function (circleCenter, radius, angleInRadians) { - return new es.Vector2(Math.cos(angleInRadians) * radius + circleCenter.x, Math.sin(angleInRadians) * radius + circleCenter.y); + // 根据给定角度值,通过三角函数(cos和sin)计算出该角度对应的x和y坐标的值(其中x坐标对应cos值,y坐标对应sin值)。 + var x = Math.cos(angleInRadians) * radius; + var y = Math.sin(angleInRadians) * radius; + // 将x坐标值乘以半径,再加上圆心的x坐标,得到该点在x轴上的绝对坐标。 + var absoluteX = x + circleCenter.x; + // 将y坐标值乘以半径,再加上圆心的y坐标,得到该点在y轴上的绝对坐标。 + var absoluteY = y + circleCenter.y; + // 创建一个新的Vector2对象,将上面得到的x和y坐标作为参数,返回该对象。 + return new es.Vector2(absoluteX, absoluteY); }; /** - * lissajou曲线 - * @param xFrequency - * @param yFrequency - * @param xMagnitude - * @param yMagnitude - * @param phase - * @returns + * 生成一个Lissajous曲线上的点的坐标 + * @param xFrequency x方向上的频率,默认值为2 + * @param yFrequency y方向上的频率,默认值为3 + * @param xMagnitude x方向上的振幅,默认值为1 + * @param yMagnitude y方向上的振幅,默认值为1 + * @param phase 相位,默认值为0 + * @returns 在Lissajous曲线上的点的坐标,返回值类型为Vector2 */ MathHelper.lissajou = function (xFrequency, yFrequency, xMagnitude, yMagnitude, phase) { if (xFrequency === void 0) { xFrequency = 2; } @@ -6692,9 +6855,9 @@ var es; if (xMagnitude === void 0) { xMagnitude = 1; } if (yMagnitude === void 0) { yMagnitude = 1; } if (phase === void 0) { phase = 0; } - var x = Math.sin(es.Time.totalTime * xFrequency + phase) * xMagnitude; - var y = Math.cos(es.Time.totalTime * yFrequency) * yMagnitude; - return new es.Vector2(x, y); + var x = Math.sin(es.Time.totalTime * xFrequency + phase) * xMagnitude; // 计算x方向上的坐标 + var y = Math.cos(es.Time.totalTime * yFrequency) * yMagnitude; // 计算y方向上的坐标 + return new es.Vector2(x, y); // 返回在Lissajous曲线上的点的坐标 }; /** * 生成阻尼的 Lissajous 曲线 @@ -6754,63 +6917,109 @@ var es; return result; }; /** - * 此函数用于确保数不是NaN或无穷大 + * 判断给定的数字是否有效 + * 如果输入的数字是 NaN 或正无穷大,该函数将返回 false;否则返回 true * @param x * @returns */ MathHelper.isValid = function (x) { + // 如果输入的数字是 NaN,返回 false if (Number.isNaN(x)) { return false; } - return x !== Infinity; - }; - MathHelper.smoothDamp = function (current, target, currentVelocity, smoothTime, maxSpeed, deltaTime) { - smoothTime = Math.max(0.0001, smoothTime); - var num = 2 / smoothTime; - var num2 = num * deltaTime; - var num3 = 1 / - (1 + (num2 + (0.48 * (num2 * num2) + 0.235 * (num2 * (num2 * num2))))); - var num4 = current - target; - var num5 = target; - var num6 = maxSpeed * smoothTime; - num4 = this.clamp(num4, num6 * -1, num6); - target = current - num4; - var num7 = (currentVelocity + num * num4) * deltaTime; - currentVelocity = (currentVelocity - num * num7) * num3; - var num8 = target + (num4 + num7) * num3; - if (num5 - current > 0 === num8 > num5) { - num8 = num5; - currentVelocity = (num8 - num5) / deltaTime; + // 如果输入的数字是正无穷大,返回 false + // 注意,负无穷大在这里被认为是有效的数字 + if (x === Infinity) { + return false; } - return { value: num8, currentVelocity: currentVelocity }; - }; - MathHelper.smoothDampVector = function (current, target, currentVelocity, smoothTime, maxSpeed, deltaTime) { - var v = es.Vector2.zero; - var resX = this.smoothDamp(current.x, target.x, currentVelocity.x, smoothTime, maxSpeed, deltaTime); - v.x = resX.value; - currentVelocity.x = resX.currentVelocity; - var resY = this.smoothDamp(current.y, target.y, currentVelocity.y, smoothTime, maxSpeed, deltaTime); - v.y = resY.value; - currentVelocity.y = resY.currentVelocity; - return v; + // 如果输入的数字既不是 NaN,也不是正无穷大,返回 true + return true; }; /** - * 将值(在 leftMin - leftMax 范围内)映射到 rightMin - rightMax 范围内的值 - * @param value - * @param leftMin - * @param leftMax - * @param rightMin - * @param rightMax + * 平滑阻尼运动,将当前位置平滑过渡到目标位置,返回一个包含当前位置和当前速度的对象 + * @param current 当前位置 + * @param target 目标位置 + * @param currentVelocity 当前速度 + * @param smoothTime 平滑时间 + * @param maxSpeed 最大速度 + * @param deltaTime 时间增量 + * @returns 一个包含当前位置和当前速度的对象,类型为{ value: number; currentVelocity: number } + */ + MathHelper.smoothDamp = function (current, target, currentVelocity, smoothTime, maxSpeed, deltaTime) { + smoothTime = Math.max(0.0001, smoothTime); // 平滑时间至少为0.0001,避免出现除以0的情况 + var omega = 2 / smoothTime; // 根据平滑时间计算阻尼系数 + var x = omega * deltaTime; // 计算阻尼系数与时间增量的乘积 + var exp = 1 / (1 + 0.48 * x + 0.235 * x * x); // 计算阻尼比 + var maxDelta = maxSpeed * smoothTime; // 计算最大速度与平滑时间的乘积 + var delta = current - target; // 计算当前位置与目标位置之间的距离 + delta = MathHelper.clamp(delta, -maxDelta, maxDelta); // 将距离限制在最大速度和最大速度的相反数之间 + target = current - delta; // 计算新的目标位置 + var temp = (currentVelocity + omega * delta) * deltaTime; // 计算当前速度和阻尼力的和乘以时间增量 + currentVelocity = (currentVelocity - omega * temp) * exp; // 计算新的当前速度 + var newValue = target + (delta + temp) * exp; // 计算新的当前位置 + if (current > target === newValue > target) { // 如果新的当前位置超过了目标位置,则将当前位置设置为目标位置,并计算新的当前速度 + newValue = target; + currentVelocity = (newValue - target) / deltaTime; + } + return { value: newValue, currentVelocity: currentVelocity }; // 返回包含当前位置和当前速度的对象 + }; + /** + * 平滑插值两个二维向量 + * @param current 当前向量 + * @param target 目标向量 + * @param currentVelocity 当前速度向量 + * @param smoothTime 平滑插值时间 + * @param maxSpeed 最大速度 + * @param deltaTime 帧间隔时间 + * @returns 插值后的结果向量 + */ + MathHelper.smoothDampVector = function (current, target, currentVelocity, smoothTime, maxSpeed, deltaTime) { + var v = es.Vector2.zero; // 创建一个初始向量v,其x和y坐标都为0。 + // 对当前向量的x和y坐标进行平滑插值,得到插值结果和当前速度。 + var resX = this.smoothDamp(current.x, target.x, currentVelocity.x, smoothTime, maxSpeed, deltaTime); + v.x = resX.value; // 将插值结果赋值给向量v的x坐标。 + currentVelocity.x = resX.currentVelocity; // 将当前速度赋值给向量currentVelocity的x坐标。 + var resY = this.smoothDamp(current.y, target.y, currentVelocity.y, smoothTime, maxSpeed, deltaTime); + v.y = resY.value; // 将插值结果赋值给向量v的y坐标。 + currentVelocity.y = resY.currentVelocity; // 将当前速度赋值给向量currentVelocity的y坐标。 + return v; // 返回向量v。 + }; + /** + * 将一个值从一个区间映射到另一个区间 + * @param value 需要映射的值 + * @param leftMin 所在区间的最小值 + * @param leftMax 所在区间的最大值 + * @param rightMin 需要映射到的目标区间的最小值 + * @param rightMax 需要映射到的目标区间的最大值 * @returns */ MathHelper.mapMinMax = function (value, leftMin, leftMax, rightMin, rightMax) { - return rightMin + ((MathHelper.clamp(value, leftMin, leftMax) - leftMin) * (rightMax - rightMin)) / (leftMax - leftMin); + // 先将 value 限制在 [leftMin, leftMax] 区间内 + var clampedValue = MathHelper.clamp(value, leftMin, leftMax); + // 计算映射到 [rightMin, rightMax] 区间内的值 + return rightMin + (clampedValue - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); }; + /** + * 返回一个给定角度的单位向量。角度被解释为弧度制。 + * @param angle - 给定角度,以弧度制表示。 + * @returns 一个新的已归一化的二维向量。 + */ MathHelper.fromAngle = function (angle) { + // 返回一个新的二维向量,其中x和y分别设置为给定角度的余弦和正弦值,然后进行归一化以产生单位向量。 return new es.Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual(); }; + /** + * 将一个数字转换为最接近的整数 + * @param val 需要被转换的数字 + * @returns 最接近的整数 + */ MathHelper.toInt = function (val) { - return val > 0 ? Math.floor(val) : Math.ceil(val); + if (val > 0) { // 如果数字大于0,则向下舍入为最接近的整数。 + return Math.floor(val); + } + else { // 如果数字小于等于0,则向上舍入为最接近的整数。 + return Math.ceil(val); + } }; MathHelper.Epsilon = 0.00001; MathHelper.Rad2Deg = 57.29578; @@ -9125,7 +9334,7 @@ var es; var offsetAngle = Math.atan2(collider.localOffset.y * collider.entity.transform.scale.y, collider.localOffset.x * collider.entity.transform.scale.x) * es.MathHelper.Rad2Deg; var offsetLength = hasUnitScale ? collider._localOffsetLength : collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); - this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); + this.center = es.MathHelper.pointOnCircle(es.Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); } es.Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y, tempMat); es.Matrix2D.multiply(combinedMatrix_1, tempMat, combinedMatrix_1); @@ -9334,7 +9543,7 @@ var es; // 为了处理偏移原点的旋转,我们只需要将圆心围绕(0,0)在一个圆上移动,我们的偏移量就是0角 var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg; var offsetLength = hasUnitScale ? collider._localOffsetLength : collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); - this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); + this.center = es.MathHelper.pointOnCircle(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); } } this.position = collider.transform.position.add(this.center); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 5c8afbf5..67c05f1c 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.es={};var __read=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}};!function(t){var e=function(){function e(n,i){void 0===n&&(n=!0),void 0===i&&(i=!0),this._globalManagers=[],this._coroutineManager=new t.CoroutineManager,this._timerManager=new t.TimerManager,this._frameCounterElapsedTime=0,this._frameCounter=0,this._totalMemory=0,e._instance=this,e.emitter=new t.Emitter,e.emitter.addObserver(t.CoreEvents.frameUpdated,this.update,this),e.registerGlobalManager(this._coroutineManager),e.registerGlobalManager(new t.TweenManager),e.registerGlobalManager(this._timerManager),e.entitySystemsEnabled=i,this.debug=n,this.initialize()}return Object.defineProperty(e,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(e,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(e){t.Insist.isNotNull(e,"场景不能为空"),null==this._instance._scene?(this._instance._scene=e,this._instance.onSceneChanged(),this._instance._scene.begin()):this._instance._nextScene=e},enumerable:!0,configurable:!0}),e.create=function(e){return void 0===e&&(e=!0),null==this._instance&&(this._instance=new t.Core(e)),this._instance},e.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},e.unregisterGlobalManager=function(e){new t.List(this._instance._globalManagers).remove(e),e.enabled=!1},e.getGlobalManager=function(t){for(var n=0,i=e._instance._globalManagers.length;n=1)){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.sceneChanged),t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(n){if(void 0===n&&(n=-1),!e.paused){if(t.Time.update(n,-1!=n),null!=this._scene){for(var i=this._globalManagers.length-1;i>=0;i--)this._globalManagers[i].enabled&&this._globalManagers[i].update();null!=this._sceneTransition&&(null==this._sceneTransition||this._sceneTransition._loadsNewScene&&!this._sceneTransition._isNewSceneLoaded)||this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.startDebugDraw(),this.draw()}},e.prototype.draw=function(){null!=this._sceneTransition&&this._sceneTransition.preRender(),null==this._sceneTransition||this._sceneTransition.hasPreviousSceneRender||(null!=this._scene&&e.startCoroutine(this._sceneTransition.onBeginTransition()),this._sceneTransition.render())},e.paused=!1,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){var e;!function(t){t[t.error=0]="error",t[t.warn=1]="warn",t[t.log=2]="log",t[t.info=3]="info",t[t.trace=4]="trace"}(e=t.LogType||(t.LogType={}));var n=function(){function n(){}return n.warnIf=function(t,n){for(var i=[],r=2;r=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t0?new e(this.x/t,this.y/t):new e(0,1)},e.prototype.normalizeEqual=function(){var t=this.distance();return t>0?(this.setTo(this.x/t,this.y/t),this):(this.setTo(0,1),this)},e.prototype.magnitude=function(){return this.distance()},e.prototype.distance=function(t){return t||(t=e.zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.getLength=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.prototype.angleBetween=function(e,n){var i=e.sub(this),r=n.sub(this);return t.Vector2Ext.angle(i,r)},e.prototype.getDistance=function(t){return Math.sqrt(this.getDistanceSquared(t))},e.prototype.getDistanceSquared=function(t){var e=t.x-this.x,n=t.y-this.y;return e*e+n*n},e.prototype.isBetween=function(t,e){var n=e.sub(t).cross(this.sub(t));return Math.abs(n)=0&&this.dot(t.sub(e))>=0},e.prototype.cross=function(t){return this.x*t.y-this.y*t.x},e.prototype.getAngle=function(){return Math.atan2(this.y,this.x)},e.prototype.equals=function(t,e){return void 0===e&&(e=.001),Math.abs(this.x-t.x)<=e&&Math.abs(this.y-t.y)<=e},e.prototype.isValid=function(){return t.MathHelper.isValid(this.x)&&t.MathHelper.isValid(this.y)},e.min=function(t,n){return new e(t.xn.x?t.x:n.x,t.y>n.y?t.y:n.y)},e.hermite=function(n,i,r,o,s){return new e(t.MathHelper.hermite(n.x,i.x,r.x,o.x,s),t.MathHelper.hermite(n.y,i.y,r.y,o.y,s))},e.unsignedAngle=function(e,n,i){void 0===i&&(i=!0),e.normalizeEqual(),n.normalizeEqual();var r=Math.acos(t.MathHelper.clamp(e.dot(n),-1,1))*t.MathHelper.Rad2Deg;return i?Math.round(r):r},e.fromAngle=function(t,n){return void 0===n&&(n=1),new e(n*Math.cos(t),n*Math.sin(t))},e.prototype.clone=function(){return new e(this.x,this.y)},e.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this.entities=new t.EntityList(this),this.entityProcessors=new t.EntityProcessorList,this.identifierPool=new t.IdentifierPool,this.initialize()}return e.prototype.initialize=function(){},e.prototype.onStart=function(){},e.prototype.unload=function(){},e.prototype.begin=function(){t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1,this.entities.removeAllEntities();for(var e=0;e=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},e.prototype.addSceneComponent=function(t){return t.scene=this,t.onEnabled(),this._sceneComponents.push(t),this._sceneComponents.sort(t.compare),t},e.prototype.getSceneComponent=function(t){for(var e=0;ee.x?-1:1,i=this.position.sub(e).normalize();this.rotation=n*Math.acos(i.dot(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(n.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,null!=this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this.setDirty(n.scaleDirty),this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(n.scaleDirty),this},i.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},i.prototype.updateTransform=function(){this.hierarchyDirty!=n.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y,this._translationMatrix),this._localPositionDirty=!1),this._localRotationDirty&&(t.Matrix2D.createRotation(this._localRotation,this._rotationMatrix),this._localRotationDirty=!1),this._localScaleDirty&&(t.Matrix2D.createScale(this._localScale.x,this._localScale.y,this._scaleMatrix),this._localScaleDirty=!1),t.Matrix2D.multiply(this._scaleMatrix,this._rotationMatrix,this._localTransform),t.Matrix2D.multiply(this._localTransform,this._translationMatrix,this._localTransform),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(t.Matrix2D.multiply(this._localTransform,this.parent._worldTransform,this._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=this.parent._scale.multiply(this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=n.clean)},i.prototype.setDirty=function(t){if(0==(this.hierarchyDirty&t)){switch(this.hierarchyDirty|=t,t){case n.positionDirty:this.entity.onTransformChanged(e.position);break;case n.rotationDirty:this.entity.onTransformChanged(e.rotation);break;case n.scaleDirty:this.entity.onTransformChanged(e.scale)}for(var i=0;i1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.setVelocity=function(t){return this.velocity=t,this},n.prototype.addImpulse=function(e){this.isImmovable||this.velocity.addEqual(e.scale(this._inverseMass*(t.Time.deltaTime*t.Time.deltaTime)*1e5))},n.prototype.onAddedToEntity=function(){this._collider=null;for(var e=0;e0)for(var i=0;i0&&(o=t.Vector2.zero);var a=this._friction;return s.lengthSquared()0&&this.collisionState.wasGroundedLastFrame&&(t=this.handleVerticalSlope(t)),0!==t.x&&(t=this.moveHorizontally(t)),0!==t.y&&(t=this.moveVertically(t)),this._player.setPosition(this._player.position.x+t.x,this._player.position.y+t.y),e>0&&(this.velocity.x=t.x/e,this.velocity.y=t.y/e),!this.collisionState.wasGroundedLastFrame&&this.collisionState.below&&(this.collisionState.becameGroundedThisFrame=!0),this._isGoingUpSlope&&(this.velocity.y=0),this._isWarpingToGround||this._triggerHelper.update();for(var n=0;n0&&(this.ignoreOneWayPlatformsTime-=e)},i.prototype.warpToGrounded=function(e){void 0===e&&(e=1e3),this.ignoreOneWayPlatformsTime=0,this._isWarpingToGround=!0;var n=0;do{if(n+=1,this.move(new t.Vector2(0,1),.02),n>e)break}while(!this.isGrounded);this._isWarpingToGround=!1},i.prototype.recalculateDistanceBetweenRays=function(){var t=this._collider.height*Math.abs(this._player.scale.y)-2*this._skinWidth;this._verticalDistanceBetweenRays=t/(this.totalHorizontalRays-1);var e=this._collider.width*Math.abs(this._player.scale.x)-2*this._skinWidth;this._horizontalDistanceBetweenRays=e/(this.totalVerticalRays-1)},i.prototype.primeRaycastOrigins=function(){var e=this._collider.bounds;this._raycastOrigins.topLeft=new t.Vector2(e.x+this._skinWidth,e.y+this._skinWidth),this._raycastOrigins.bottomRight=new t.Vector2(e.right-this._skinWidth,e.bottom-this._skinWidth),this._raycastOrigins.bottomLeft=new t.Vector2(e.x+this._skinWidth,e.bottom-this._skinWidth)},i.prototype.moveHorizontally=function(e){for(var n=e.x>0,i=Math.abs(e.x)+this._skinWidth*this.rayOriginSkinMutiplier,r=n?t.Vector2.right:t.Vector2.left,o=this._raycastOrigins.bottomLeft.y,s=n?this._raycastOrigins.bottomRight.x-this._skinWidth*(this.rayOriginSkinMutiplier-1):this._raycastOrigins.bottomLeft.x+this._skinWidth*(this.rayOriginSkinMutiplier-1),a=0;a0)&&(a&=~this.oneWayPlatformMask);for(var u=0;uthis.jumpingThreshold){var i=this.slopeSpeedMultiplier?this.slopeSpeedMultiplier.lerp(n):1;e.x*=i,e.y=Math.abs(Math.tan(n*t.MathHelper.Deg2Rad)*e.x);var r=e.x>0,o=r?this._raycastOrigins.bottomRight:this._raycastOrigins.bottomLeft,s=null;(s=this.supportSlopedOneWayPlatforms&&this.collisionState.wasGroundedLastFrame?t.Physics.linecast(o,o.add(e),this.platformMask,this.ignoredColliders):t.Physics.linecast(o,o.add(e),this.platformMask&~this.oneWayPlatformMask,this.ignoredColliders)).collider&&(e.x=s.point.x-o.x,e.y=s.point.y-o.y,r?e.x-=this._skinWidth:e.x+=this._skinWidth),this._isGoingUpSlope=!0,this.collisionState.below=!0}}else e.x=0;return!0},i}();t.CharacterController=i}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){if(e.components._components.length>0)for(var i=0;i0)for(var r=0;r0)for(r=0;r0)for(r=0;r0)for(var h=0;h0)for(var r=0;rn;n++){var i=t[n];this.processDelta(i,this.acc);var r=this.getRemainingDelay(i);r<=0?this.processExpired(i):this.offerDelay(r)}this.acc=0}else this.stop()},n.prototype.checkProcessing=function(){return!!this.running&&(this.acc+=t.Time.deltaTime,this.acc>=this.delay)},n.prototype.offerDelay=function(t){this.running?this.delay=Math.min(this.delay,t):(this.running=!0,this.delay=t)},n.prototype.getInitialTimeDelay=function(){return this.delay},n.prototype.getRemainingTimeUntilProcessing=function(){return this.running?this.delay-this.acc:0},n.prototype.isRunning=function(){return this.running},n.prototype.stop=function(){this.running=!1,this.acc=0},n}(t.EntitySystem);t.DelayedIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.enabled=!0,n}return __extends(e,t),e.prototype.lateProcessEntity=function(t){},e.prototype.process=function(t){if(0!=t.length)for(var e=0,n=t.length;e=this.interval&&(this.acc-=this.interval,this.intervalDelta=this.acc-this.intervalDelta,!0)},n.prototype.getIntervalDelta=function(){return this.interval+this.intervalDelta},n}(t.EntitySystem);t.IntervalSystem=e}(es||(es={})),function(t){var e=function(t){function e(e,n){return t.call(this,e,n)||this}return __extends(e,t),e.prototype.process=function(t){var e=this;t.forEach(function(t){return e.processEntity(t)})},e}(t.IntervalSystem);t.IntervalIteratingSystem=e}(es||(es={})),function(es){var JobSystem=function(_super){function JobSystem(t,e){var n=_super.call(this,t)||this;n._threads=e,n._jobs=new Array(e);for(var i=0;it.length&&(s=t.length);var a=o._jobs[n];if(a.set(t,r,s,o._executeStr,o),r!=s){var u=es.WorkerUtils.makeWorker(o.queueOnThread);es.WorkerUtils.workerMessage(u)(a).then(function(t){var n=t;e.resetJob(n),u.terminate()}).catch(function(t){a.err=t,u.terminate()})}},o=this,s=0;s-1?eval("(function(){return "+v+" })()"):v}),i=job.from;i0)for(var t=0,e=this._components.length;t0)for(var e=0,n=this._components.length;e0)for(var e=0,n=this._components.length;e0){for(var e=function(t,e){var i=n._componentsToRemoveList[t];n.handleRemove(i);var r=n._components.findIndex(function(t){return t.id==i.id});-1!=r&&n._components.splice(r,1),n.removeComponentsByType(i)},n=this,i=0,r=this._componentsToRemoveList.length;i0){for(i=0,r=this._componentsToAddList.length;i0){for(i=0,r=this._tempBufferList.length;i0){var n=this._updatableComponents.findIndex(function(t){return t.id==e.id});-1!=n&&this._updatableComponents.splice(n,1)}this.decreaseBits(e),this._entity.scene.entityProcessors.onComponentRemoved(this._entity),e.onRemovedFromEntity(),e.entity=null},e.prototype.removeComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsByType.set(t.TypeUtils.getType(e),n)},e.prototype.removeComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsToAddByType.set(t.TypeUtils.getType(e),n)},e.prototype.getComponent=function(t,e){var n=this.componentsByType.get(t);if(n&&n.length>0)return n[0];if(!e){var i=this.componentsToAddByType.get(t);if(i&&i.length>0)return i[0]}return null},e.prototype.getComponents=function(t,e){e||(e=[]);var n=this.componentsByType.get(t);n&&(e=e.concat(n));var i=this.componentsToAddByType.get(t);return i&&(e=e.concat(i)),e},e.prototype.update=function(){if(this.updateLists(),this._updatableComponents.length>0)for(var t=0,e=this._updatableComponents.length;t0)for(var e=0,n=this._components.length;e0)for(e=0,n=this._componentsToAddList.length;e0)for(var t=0,e=this._components.length;t0)for(var t=0,e=this._components.length;t0){for(var t=function(t,n){var i=e._entitiesToRemoveList[t];e.removeFromTagList(i);var r=e._entities.findIndex(function(t){return t.id==i.id});-1!=r&&e._entities.splice(r,1),i.onRemovedFromScene(),i.scene=null,e.scene.entityProcessors.onEntityRemoved(i)},e=this,n=0,i=this._entitiesToRemoveList.length;n0){for(n=0,i=this._entitiesToAddedList.length;n0)for(var e=0,n=this._entities.length;e0)for(e=0,n=this._entitiesToAddedList.length;e0)for(var e=0,n=this._entities.length;e0)try{for(var s=__values(r),a=s.next();!a.done;a=s.next()){var u=a.value;o.push(u)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return o},e.prototype.entityWithTag=function(t){var e,n,i=this.getTagList(t);if(i.size>0)try{for(var r=__values(i),o=r.next();!o.done;o=r.next()){return o.value}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return null},e.prototype.findComponentOfType=function(t){if(this._entities.length>0)for(var e=0,n=this._entities.length;e0)for(e=0;e0)for(var i=0,r=this._entities.length;i0)for(i=0,r=this._entitiesToAddedList.length;i0)for(var i=0,r=this._entities.length;i0)for(var s=0,a=t.length;s0)for(i=0,r=this._entitiesToAddedList.length;i0)for(s=0,a=t.length;s=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i0?this.ids.removeLast():this.nextAvailableId_++},e.prototype.checkIn=function(t){this.ids.add(t)},e}();t.IdentifierPool=e}(es||(es={})),function(t){var e=function(){function e(){this.allSet=[],this.exclusionSet=[],this.oneSet=[]}return e.empty=function(){return new e},e.prototype.getAllSet=function(){return this.allSet},e.prototype.getExclusionSet=function(){return this.exclusionSet},e.prototype.getOneSet=function(){return this.oneSet},e.prototype.isInterestedEntity=function(t){return this.isInterested(t.componentBits)},e.prototype.isInterested=function(e){if(0!=this.allSet.length)for(var n=0,i=this.allSet.length;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}();t.StringUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.update=function(t,e){var n=0;e?n=t:(-1==t&&(t=Date.now()),-1==this._lastTime&&(this._lastTime=t),n=(t-this._lastTime)/1e3),n>this.maxDeltaTime&&(n=this.maxDeltaTime),this.totalTime+=n,this.deltaTime=n*this.timeScale,this.unscaledDeltaTime=n,this.timeSinceSceneLoad+=n,this.frameCount++,this._lastTime=t},e.sceneChanged=function(){this.timeSinceSceneLoad=0},e.checkEvery=function(e){return t.MathHelper.toInt(this.timeSinceSceneLoad/e)>t.MathHelper.toInt((this.timeSinceSceneLoad-this.deltaTime)/e)},e.totalTime=0,e.unscaledDeltaTime=0,e.deltaTime=0,e.timeScale=1,e.maxDeltaTime=Number.MAX_VALUE,e.frameCount=0,e.timeSinceSceneLoad=0,e._lastTime=-1,e}();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,u=Math.floor(a)+1;if(53==u){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var c=n.getDay();if(0==c&&(c=7),e&&(!o||c<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(u>9?"":"0")+u)},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(),u=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(u="0"+u),n?s+e+a+e+u:a+e+u},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o=1?(e=1,n.range=this._points.length-4):(e=t.MathHelper.clamp01(e)*this._curveCount,n.range=t.MathHelper.toInt(e),e-=n.range,n.range*=3),n.time=e,n},e.prototype.setControlPoint=function(t,e){if(t%3==0){var n=e.sub(this._points[t]);t>0&&this._points[t-1].addEqual(n),t+1Math.PI?e-2*Math.PI:e},e.isPowerOfTwo=function(t){return t>0&&t%(t-1)==0},e.lerp=function(t,e,n){return t+(e-t)*this.clamp01(n)},e.betterLerp=function(t,n,i,r){return Math.abs(t-n)180&&(i-=360),t+i*this.clamp01(n)},e.lerpAngleRadians=function(t,e,n){var i=this.repeat(e-t,2*Math.PI);return i>Math.PI&&(i-=2*Math.PI),t+i*this.clamp01(n)},e.pingPong=function(t,e){return t=this.repeat(t,2*e),e-Math.abs(t-e)},e.signThreshold=function(t,e){return Math.abs(t)>=e?Math.sign(t):0},e.inverseLerp=function(t,e,n){var i=e-t;return 0===i?0:(n-t)/i},e.lerpPrecise=function(t,e,n){return(1-n)*t+e*n},e.clamp=function(t,e,n){return tn?n:t},e.snap=function(t,e){return Math.round(t/e)*e},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.isOdd=function(t){return t%2!=0},e.roundWithRoundedAmount=function(t,e){var n=Math.round(t);return e.value=t-n*Math.round(t/n),n},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.angleToVector=function(e,n){return new t.Vector2(Math.cos(e)*n,Math.sin(e)*n)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.decrementWithWrap=function(t,e){return--t<0?e-1:t},e.hypotenuse=function(t,e){return Math.sqrt(t*t+e*e)},e.closestPowerOfTwoGreaterThan=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,(t|=t>>16)+1},e.roundToNearest=function(t,e){return Math.round(t/e)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.between=function(t,e,n){return t>=e&&t<=n},e.deltaAngleRadians=function(t,e){var n=this.repeat(e-t,2*Math.PI);return n>Math.PI&&(n-=2*Math.PI),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.floorToInt=function(t){return this.toInt(Math.floor(t))},e.rotateAround=function(e,n){var i=t.Time.totalTime*n,r=Math.cos(i),o=Math.sin(i);return new t.Vector2(e.x+r,e.y+o)},e.rotateAround2=function(e,n,i){i=this.toRadians(i);var r=Math.cos(i),o=Math.sin(i),s=r*(e.x-n.x)-o*(e.y-n.y)+n.x,a=o*(e.x-n.x)+r*(e.y-n.y)+n.y;return new t.Vector2(s,a)},e.pointOnCircle=function(e,n,i){var r=this.toRadians(i);return new t.Vector2(Math.cos(r)*n+e.x,Math.sin(r)*n+e.y)},e.pointOnCircleRadians=function(e,n,i){return new t.Vector2(Math.cos(i)*n+e.x,Math.sin(i)*n+e.y)},e.lissajou=function(e,n,i,r,o){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=0);var s=Math.sin(t.Time.totalTime*e+o)*i,a=Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(s,a)},e.lissajouDamped=function(e,n,i,r,o,s,a){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=.5),void 0===s&&(s=0),void 0===a&&(a=5);var u=this.pingPong(t.Time.totalTime,a),c=Math.pow(Math.E,-s*u),h=c*Math.sin(t.Time.totalTime*e+o)*i,l=c*Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(h,l)},e.hermite=function(t,e,n,i,r){if(0===r)return t;if(1===r)return n;return(2*t-2*n+i+e)*(r*r*r)+(3*n-3*t-2*e-i)*(r*r)+e*r+t},e.isValid=function(t){return!Number.isNaN(t)&&t!==1/0},e.smoothDamp=function(t,e,n,i,r,o){var s=2/(i=Math.max(1e-4,i)),a=s*o,u=1/(1+(a+(a*a*.48+a*(a*a)*.235))),c=t-e,h=e,l=r*i,p=(n+s*(c=this.clamp(c,-1*l,l)))*o;n=(n-s*p)*u;var f=(e=t-c)+(c+p)*u;return h-t>0==f>h&&(n=((f=h)-h)/o),{value:f,currentVelocity:n}},e.smoothDampVector=function(e,n,i,r,o,s){var a=t.Vector2.zero,u=this.smoothDamp(e.x,n.x,i.x,r,o,s);a.x=u.value,i.x=u.currentVelocity;var c=this.smoothDamp(e.y,n.y,i.y,r,o,s);return a.y=c.value,i.y=c.currentVelocity,a},e.mapMinMax=function(t,n,i,r,o){return r+(e.clamp(t,n,i)-n)*(o-r)/(i-n)},e.fromAngle=function(e){return new t.Vector2(Math.cos(e),Math.sin(e)).normalizeEqual()},e.toInt=function(t){return t>0?Math.floor(t):Math.ceil(t)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(t,e,n,i,r,o,s,a,u,c,h,l,p,f,d,m){this.m11=t,this.m12=e,this.m13=n,this.m14=i,this.m21=r,this.m22=o,this.m23=s,this.m24=a,this.m31=u,this.m32=c,this.m33=h,this.m34=l,this.m41=p,this.m42=f,this.m43=d,this.m44=m}return Object.defineProperty(t,"Identity",{get:function(){return this.identity},enumerable:!0,configurable:!0}),t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.createTranslation=function(t,e){e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=t.x,e.m42=t.y,e.m43=0,e.m44=1},t.createRotationZ=function(e,n){n=t.Identity;var i=Math.cos(e),r=Math.sin(e);n.m11=i,n.m12=r,n.m21=-r,n.m22=i},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,u=e.m21*n.m11+e.m22*n.m21+e.m23*n.m31+e.m24*n.m41,c=e.m21*n.m12+e.m22*n.m22+e.m23*n.m32+e.m24*n.m42,h=e.m21*n.m13+e.m22*n.m23+e.m23*n.m33+e.m24*n.m43,l=e.m21*n.m14+e.m22*n.m24+e.m23*n.m34+e.m24*n.m44,p=e.m31*n.m11+e.m32*n.m21+e.m33*n.m31+e.m34*n.m41,f=e.m31*n.m12+e.m32*n.m22+e.m33*n.m32+e.m34*n.m42,d=e.m31*n.m13+e.m32*n.m23+e.m33*n.m33+e.m34*n.m43,m=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,y=e.m41*n.m11+e.m42*n.m21+e.m43*n.m31+e.m44*n.m41,g=e.m41*n.m12+e.m42*n.m22+e.m43*n.m32+e.m44*n.m42,_=e.m41*n.m13+e.m42*n.m23+e.m43*n.m33+e.m44*n.m43,v=e.m41*n.m14+e.m42*n.m24+e.m43*n.m34+e.m44*n.m44;i.m11=r,i.m12=o,i.m13=s,i.m14=a,i.m21=u,i.m22=c,i.m23=h,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=m,i.m41=y,i.m42=g,i.m43=_,i.m44=v},t.identity=new t(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0}return Object.defineProperty(e,"identity",{get:function(){return(new e).setIdentity()},enumerable:!0,configurable:!0}),e.prototype.setIdentity=function(){return this.setValues(1,0,0,1,0,0)},e.prototype.setValues=function(t,e,n,i,r,o){return this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=r,this.m32=o,this},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.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t,e){e.setIdentity();var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-1*i,e.m22=n},e.createRotationOut=function(t,e){var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-i,e.m22=n},e.createScale=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createScaleOut=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createTranslation=function(t,e,n){return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.createTranslationOut=function(t,e){e.m11=1,e.m12=0,e.m21=0,e.m22=1,e.m31=t.x,e.m32=t.y},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},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.multiply=function(t,e,n){var i=t.m11*e.m11+t.m12*e.m21,r=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,s=t.m21*e.m12+t.m22*e.m22,a=t.m31*e.m11+t.m32*e.m21+e.m31,u=t.m31*e.m12+t.m32*e.m22+e.m32;n.m11=i,n.m12=r,n.m21=o,n.m22=s,n.m31=a,n.m32=u},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=new e;return e.createTranslation(n,i,r),t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.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,u=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=u,i.m32=c}else"number"==typeof n&&(i.m11=e.m11*n,i.m12=e.m12*n,i.m21=e.m21*n,i.m22=e.m22*n,i.m31=e.m31*n,i.m32=e.m32*n);return i},e.subtract=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11-n.m11,i.m12=e.m12-n.m12,i.m21=e.m21-n.m21,i.m22=e.m22-n.m22,i.m31=e.m31-n.m31,i.m32=e.m32-n.m32,i},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(e,n,i,r){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),void 0===r&&(r=0),this.x=0,this.y=0,this.width=0,this.height=0,this._tempMat=new t.Matrix2D,this._transformMat=new t.Matrix2D,this.x=e,this.y=n,this.width=i,this.height=r}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.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(e.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}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return e}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.distance=Math.max(r,e.distance),n=Math.min(o,n),e.distance>n)return e}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return e}else{var a=1/t.direction.y,u=(this.y-t.start.y)*a,c=(this.y+this.height-t.start.y)*a;if(u>c){var h=u;u=c,c=h}if(e.distance=Math.max(u,e.distance),n=Math.max(c,n),e.distance>n)return e}return e.intersected=!0,e},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(h)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=h>0?p-h:-p-h;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return Math.trunc(this.x)^Math.trunc(this.y)^Math.trunc(this.width)^Math.trunc(this.height)},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.PairSet,this._previousTriggerIntersections=new t.PairSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){var e=[],n=this.getColliders();if(n.length>0)for(var i=0;i=t.Collider.lateSortOrder?e.push(u):this.notifyTriggerListeners(u,!0)),this._activeTriggerIntersections.add(u)}}if(e.length>0)for(i=0;i0)for(var n=0;n0)for(var i=0;i0)for(var o=0;o1)return!1;var c=(a.x*r.y-a.y*r.x)/s;return!(c<0||c>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=t.Vector2.zero),o.x=0,o.y=0;var s=n.sub(e),a=r.sub(i),u=s.x*a.y-s.y*a.x;if(0==u)return!1;var c=i.sub(e),h=(c.x*a.y-c.y*a.x)/u;if(h<0||h>1)return!1;var l=(c.x*s.y-c.y*s.x)/u;if(l<0||l>1)return!1;var p=e.add(s.scale(h));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scale(o))},n.circleToCircle=function(e,n,i,r){return t.Vector2.sqrDistance(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.sqrDistance(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(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setAllValues=function(t,e,n,i,r){this.collider=t,this.fraction=e,this.distance=n,this.point=i,this.normal=r},e.prototype.setValues=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.clone=function(){var t=new e;return t.setAllValues(this.collider,this.fraction,this.distance,this.point,this.normal),t},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.overlapCircle=function(t,n,i){return void 0===i&&(i=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapCircle(t,n,this._colliderArray,i),this._colliderArray[0]},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=this.allLayers),this._spatialHash.overlapCircle(t,e,n,i)},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.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds;return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},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.linecast=function(t,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._hitArray[0].reset(),e.linecastAll(t,n,this._hitArray,i,r),this._hitArray[0]},e.linecastAll=function(t,e,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._spatialHash.linecast(t,e,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,-300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e.debugRender=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(t,e){this._start=t.clone(),this._end=e.clone(),this._direction=this._end.sub(this._start)}return Object.defineProperty(t.prototype,"start",{get:function(){return this._start},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"end",{get:function(){return this._end},enumerable:!0,configurable:!0}),t}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(e){for(var n=e.registeredPhysicsBounds.clone(),i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom),o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){var a=this.cellAtPosition(o,s);t.Insist.isNotNull(a,"从不存在碰撞器的单元格中移除碰撞器: ["+e+"]"),null!=a&&new t.List(a).remove(e)}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();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 u=this.cellAtPosition(s,a);if(u&&u.length>0)for(var c=0;c0)for(var u=0;u=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;ri&&(i=o,n=r)}return t[n]},n.getClosestPointOnPolygonToPoint=function(e,n){for(var i={distanceSquared:Number.MAX_VALUE,edgeNormal:t.Vector2.zero,closestPoint:t.Vector2.zero},r=0,o=0;ot.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},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.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;oi&&(n.copyFrom(r),i=o),r.setTo(-this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),r.setTo(this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),n},n}(t.Polygon);t.Box=e}(es||(es={})),function(t){var e=function(e){function n(t){var n=e.call(this)||this;return n.radius=t,n._originalRadius=t,n}return __extends(n,e),n.prototype.recalculateBounds=function(e){if(this.center=e.localOffset,e.shouldColliderScaleAndRotateWithTransform){var n=e.entity.transform.scale,i=1===n.x&&1===n.y,r=Math.max(n.x,n.y);if(this.radius=this._originalRadius*r,0!==e.entity.transform.rotation){var o=Math.atan2(e.localOffset.y,e.localOffset.x)*t.MathHelper.Rad2Deg,s=i?e._localOffsetLength:e.localOffset.multiply(e.entity.transform.scale).magnitude();this.center=t.MathHelper.pointOnCirlce(t.Vector2.zero,s,e.entity.transform.rotation+o)}}this.position=e.transform.position.add(this.center),this.bounds=new t.Rectangle(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},n.prototype.overlaps=function(e){var i=new t.Out;if(e instanceof t.Box&&e.isUnrotated)return t.Collisions.rectToCircle(e.bounds,this.position,this.radius);if(e instanceof n)return t.Collisions.circleToCircle(this.position,this.radius,e.position,e.radius);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("overlaps of circle to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,i){if(e instanceof t.Box&&e.isUnrotated)return t.ShapeCollisionsCircle.circleToBox(this,e,i);if(e instanceof n)return t.ShapeCollisionsCircle.circleToCircle(this,e,i);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("Collisions of Circle to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){return t.ShapeCollisionsLine.lineToCircle(e,n,this,i)},n.prototype.getPointAlongEdge=function(e){return new t.Vector2(this.position.x+this.radius*Math.cos(e),this.position.y+this.radius*Math.sin(e))},n.prototype.containsPoint=function(t){return t.sub(this.position).lengthSquared()<=this.radius*this.radius},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToCircle(e,this,n)},n}(t.Shape);t.Circle=e}(es||(es={})),function(t){var e=function(){function e(){this.normal=t.Vector2.zero,this.minimumTranslationVector=t.Vector2.zero,this.point=t.Vector2.zero}return e.prototype.reset=function(){this.collider=null,this.normal.setTo(0,0),this.minimumTranslationVector.setTo(0,0),this.point&&this.point.setTo(0,0)},e.prototype.cloneTo=function(e){e.collider=this.collider,e.normal.setTo(this.normal.x,this.normal.y),e.minimumTranslationVector.setTo(this.minimumTranslationVector.x,this.minimumTranslationVector.y),this.point&&(e.point||(e.point=new t.Vector2(0,0)),e.point.setTo(this.point.x,this.point.y))},e.prototype.removeHorizontalTranslation=function(e){if(Math.sign(this.normal.x)!==Math.sign(e.x)||0===e.x&&0!==this.normal.x){var n=this.minimumTranslationVector.magnitude()/this.normal.y;1!=Math.abs(this.normal.x)&&Math.abs(n)this.end.dot(t)?this.start:this.end},e.prototype.getClosestPoint=function(t,e){var n=e.copyFrom(this.end).sub(this.start),i=t.sub(this.start).dot(n)/n.lengthSquared();return i<0?e.copyFrom(this.start):i>1?e.copyFrom(this.end):e.copyFrom(n).multiplyScaler(i).add(this.start)},e}();t.Line=e}(es||(es={})),function(t){var e=function(){function t(){this.min=Number.MAX_VALUE,this.max=-Number.MAX_VALUE}return t.prototype.project=function(t,e){for(var n=e.points,i=t.dot(n[0]),r=i,o=1;or&&(r=a)}this.min=i,this.max=r},t.prototype.overlap=function(t){return this.max>=t.min&&t.max>=this.min},t.prototype.getOverlap=function(t){return Math.min(this.max,t.max)-Math.max(this.min,t.min)},t}();t.Projection=e}(es||(es={})),function(t){var e=function(){function e(){}return e.intersectMovingCircleBox=function(e,n,i,r){var o=n.bounds;o.inflate(e.radius,e.radius);var s=new t.Ray2D(e.position.sub(i),e.position),a=o.rayIntersects(s);if(!a.intersected&&a.distance>1)return!1;var u,c=s.start.add(s.direction.scale(r)),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var l=u+h;return 3==l&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=t.Vector2.zero;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(t,e,n){var i=e.bounds.getClosestPointOnRectangleToPoint(t.position).sub(t.position);return i.dot(i)<=t.radius*t.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(e){function n(t,n,i,r){var o=e.call(this)||this;return o.center=t,o.radius=n,o.startAngle=i,o.endAngle=r,o.angle=r-i,o.radiusSquared=n*n,o.points=o.getPoints(),o.calculateProperties(),o}return __extends(n,e),Object.defineProperty(n.prototype,"sectorAngle",{get:function(){var t=this.endAngle-this.startAngle;return t<0&&(t+=360),t},enumerable:!0,configurable:!0}),n.prototype.getCentroid=function(){var e=(Math.cos(this.startAngle)+Math.cos(this.endAngle))*this.radius/3,n=(Math.sin(this.startAngle)+Math.sin(this.endAngle))*this.radius/3;return new t.Vector2(e+this.center.x,n+this.center.y)},n.prototype.getAngle=function(){return this.startAngle},n.prototype.recalculateBounds=function(e){var n=this.center.add(e.localOffset),i=n.x-this.radius,r=n.y-this.radius,o=2*this.radius,s=2*this.radius,a=new t.Rectangle(i,r,o,s);this.bounds=a,this.center=n},n.prototype.overlaps=function(e){var n=new t.Out;if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return!!t.ShapeCollisionSector.sectorToCircle(this,e,n)&&(n.value.invertResult(),!0);throw new Error("overlaps of Sector to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,n){if(e instanceof t.Box)return t.ShapeCollisionSector.sectorToBox(this,e,n);if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return t.ShapeCollisionSector.sectorToCircle(this,e,n);throw new Error("overlaps of Polygon to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){var r=e.sub(this.center),o=n.sub(this.center),s=r.getAngle(),a=o.getAngle()-s;if(a>Math.PI?a-=2*Math.PI:a<-Math.PI&&(a+=2*Math.PI),a>=this.startAngle&&a<=this.endAngle){var u=r.getLength(),c=this.startAngle-s,h=u*Math.cos(c),l=u*Math.sin(c),p=new t.Vector2(h,l);if(p.isBetween(e,n)){var f=p.sub(e).getLength(),d=f/e.getDistance(n),m=p.sub(this.center).normalize(),y=p.add(this.center),g=new t.RaycastHit;return g.setValues(d,f,y,m),i.value=g,!0}}return!1},n.prototype.containsPoint=function(t){var e=t.sub(this.center);if(e.lengthSquared()>this.radiusSquared)return!1;var n=e.getAngle(),i=this.startAngle,r=(this.angle,n-i);return r<0&&(r+=2*Math.PI),!(r>this.angle)},n.prototype.pointCollidesWithShape=function(e,n){return this.containsPoint(e)?(n&&(n.value=new t.CollisionResult,n.value.normal=e.sub(this.center).normalize(),n.value.minimumTranslationVector=n.value.normal.scale(this.radius-e.sub(this.center).getLength()),n.value.point=e),!0):(n&&(n.value=null),!1)},n.prototype.getPoints=function(){for(var e=new Array(this.numberOfPoints),n=0;nn&&(n=o,i.copyFrom(this.points[r]))}return i},n}(t.Shape);t.Sector=e}(es||(es={})),function(t){var e=function(){function e(){}return e.sectorToPolygon=function(e,n,i){for(var r=n.points.length,o=!1,s=new t.Vector2,a=new t.Vector2,u=new t.Out,c=0;c0)return!1;i.value&&Math.abs(c)e.radius*e.radius&&!a)return!1;if(a)s=i.value.normal.scale(Math.sqrt(o.distanceSquared)-e.radius);else if(0===o.distanceSquared)s=i.value.normal.scale(e.radius);else{var u=Math.sqrt(o.distanceSquared);s=r.sub(o.closestPoint).scale((e.radius-u)/u*-1)}return i.value.minimumTranslationVector=s,i.value.point=o.closestPoint.add(n.position),!0},e.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scaleEqual(o))},e}();t.ShapeCollisionsCircle=e}(es||(es={})),function(t){var e=function(){function e(){}return e.lineToPoly=function(n,i,r,o){o.value=new t.RaycastHit;for(var s=t.Vector2.zero,a=t.Vector2.zero,u=Number.MAX_VALUE,c=!1,h=r.points.length-1,l=0;l1)return!1;var h=(u.x*o.y-u.y*o.x)/a;if(h<0||h>1)return!1;var l=t.add(o.scale(c));return r.x=l.x,r.y=l.y,!0},e.lineToCircle=function(e,n,i,r){r.value=new t.RaycastHit;var o=t.Vector2.distance(e,n),s=t.Vector2.divideScaler(n.sub(e),o),a=e.sub(i.position),u=a.dot(s),c=a.dot(a)-i.radius*i.radius;if(c>0&&u>0)return!1;var h=u*u-c;return!(h<0)&&(r.value.fraction=-u-Math.sqrt(h),r.value.fraction<0&&(r.value.fraction=0),r.value.point=e.add(s.scale(r.value.fraction)),r.value.distance=t.Vector2.distance(e,r.value.point),r.value.normal=r.value.point.sub(i.position).normalize(),r.value.fraction=r.value.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,n,i){i.value=new t.CollisionResult;var r=t.Vector2.sqrDistance(e,n.position),o=1+n.radius;if(r0&&(o=!1),!o)return!1;(p=Math.abs(p))i.max&&(i.max=n);return i},e.intervalDistance=function(t,e,n,i){return t=this._duration?(i=this._elapsedTime-this._duration,this._elapsedTime=this._duration,this._tweenState=n.complete):this._isRunningInReverse&&this._elapsedTime<=0&&(i=0-this._elapsedTime,this._elapsedTime=0,this._tweenState=n.complete),this._elapsedTime>=0&&this._elapsedTime<=this._duration&&this.updateValue(),this._loopType!=e.none&&this._tweenState==n.complete&&0!=this._loops&&this.handleLooping(i);var r=this._isTimeScaleIndependent?t.Time.unscaledDeltaTime:t.Time.deltaTime;return r*=this._timeScale,this._isRunningInReverse?this._elapsedTime-=r:this._elapsedTime+=r,this._tweenState==n.complete&&(this._completionHandler&&this._completionHandler(this),null!=this._nextTween&&(this._nextTween.start(),this._nextTween=null),!0)},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null)},i.prototype.isRunning=function(){return this._tweenState==n.running},i.prototype.start=function(){this._isFromValueOverridden||(this._fromValue=this._target.getTweenedValue()),this._tweenState==n.complete&&(this._tweenState=n.running,t.TweenManager.addTween(this))},i.prototype.pause=function(){this._tweenState=n.paused},i.prototype.resume=function(){this._tweenState=n.running},i.prototype.stop=function(i){void 0===i&&(i=!1),this._tweenState=n.complete,i?(this._elapsedTime=this._isRunningInReverse?0:this._duration,this._loopType=e.none,this._loops=0):t.TweenManager.removeTween(this)},i.prototype.jumpToElapsedTime=function(e){this._elapsedTime=t.MathHelper.clamp(e,0,this._duration),this.updateValue()},i.prototype.reverseTween=function(){this._isRunningInReverse=!this._isRunningInReverse},i.prototype.waitForCompletion=function(){return __generator(this,function(t){switch(t.label){case 0:return this._tweenState==n.complete?[3,2]:[4,null];case 1:return t.sent(),[3,0];case 2:return[2]}})},i.prototype.getTargetObject=function(){return this._target.getTargetObject()},i.prototype.resetState=function(){this.context=null,this._completionHandler=this._loopCompleteHandler=null,this._isFromValueOverridden=!1,this._isTimeScaleIndependent=!1,this._tweenState=n.complete,this._isRelative=!1,this._easeType=t.TweenManager.defaultEaseType,null!=this._nextTween&&(this._nextTween.recycleSelf(),this._nextTween=null),this._delay=0,this._duration=0,this._timeScale=1,this._elapsedTime=0,this._loopType=e.none,this._delayBetweenLoops=0,this._loops=0,this._isRunningInReverse=!1},i.prototype.initialize=function(t,e,n){this.resetState(),this._target=t,this._toValue=e,this._duration=n},i.prototype.handleLooping=function(t){this._loops--,this._loopType==e.pingpong&&this.reverseTween(),this._loopType!=e.restartFromBeginning&&this._loops%2!=0||this._loopCompleteHandler&&this._completionHandler(this),0!=this._loops&&(this._tweenState=n.running,this._loopType==e.restartFromBeginning?this._elapsedTime=t-this._delayBetweenLoops:this._isRunningInReverse?this._elapsedTime+=this._delayBetweenLoops-t:this._elapsedTime=t-this._delayBetweenLoops,0==this._delayBetweenLoops&&t>0&&this.updateValue())},i}();t.Tween=i}(es||(es={})),function(t){var e=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheNumberTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue+=this._fromValue,this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheNumberTweens&&t.Pool.free(n,this)},n}(t.Tween);t.NumberTween=e;var n=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheVector2Tweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue.add(this._fromValue),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheVector2Tweens&&t.Pool.free(n,this)},n}(t.Tween);t.Vector2Tween=n;var i=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheRectTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue=new t.Rectangle(this._toValue.x+this._fromValue.x,this._toValue.y+this._fromValue.y,this._toValue.width+this._fromValue.width,this._toValue.height+this._fromValue.height),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheRectTweens&&t.Pool.free(n,this)},n}(t.Tween);t.RectangleTween=i}(es||(es={})),function(t){var e;!function(t){t[t.position=0]="position",t[t.localPosition=1]="localPosition",t[t.scale=2]="scale",t[t.localScale=3]="localScale",t[t.rotationDegrees=4]="rotationDegrees",t[t.localRotationDegrees=5]="localRotationDegrees"}(e=t.TransformTargetType||(t.TransformTargetType={}));var n=function(n){function i(){return null!==n&&n.apply(this,arguments)||this}return __extends(i,n),i.prototype.setTweenedValue=function(t){switch(this._targetType){case e.position:this._transform.position=t;break;case e.localPosition:this._transform.localPosition=t;break;case e.scale:this._transform.scale=t;break;case e.localScale:this._transform.localScale=t;break;case e.rotationDegrees:this._transform.rotationDegrees=t.x;case e.localRotationDegrees:this._transform.localRotationDegrees=t.x}},i.prototype.getTweenedValue=function(){switch(this._targetType){case e.position:return this._transform.position;case e.localPosition:return this._transform.localPosition;case e.scale:return this._transform.scale;case e.localScale:return this._transform.localScale;case e.rotationDegrees:return new t.Vector2(this._transform.rotationDegrees,this._transform.rotationDegrees);case e.localRotationDegrees:return new t.Vector2(this._transform.localRotationDegrees,0)}},i.prototype.getTargetObject=function(){return this._transform},i.prototype.setTargetAndType=function(t,e){this._transform=t,this._targetType=e},i.prototype.updateValue=function(){this._targetType!=e.rotationDegrees&&this._targetType!=e.localRotationDegrees||this._isRelative?this.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration)):this.setTweenedValue(t.Lerps.easeAngle(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null,this._transform=null,t.Pool.free(t.Vector2Tween,this))},i}(t.Vector2Tween);t.TransformVector2Tween=n}(es||(es={})),function(t){var e;!function(t){t[t.linear=0]="linear",t[t.sineIn=1]="sineIn",t[t.sineOut=2]="sineOut",t[t.sineInOut=3]="sineInOut",t[t.quadIn=4]="quadIn",t[t.quadOut=5]="quadOut",t[t.quadInOut=6]="quadInOut",t[t.quintIn=7]="quintIn",t[t.quintOut=8]="quintOut",t[t.quintInOut=9]="quintInOut",t[t.cubicIn=10]="cubicIn",t[t.cubicOut=11]="cubicOut",t[t.cubicInOut=12]="cubicInOut",t[t.quartIn=13]="quartIn",t[t.quartOut=14]="quartOut",t[t.quartInOut=15]="quartInOut",t[t.expoIn=16]="expoIn",t[t.expoOut=17]="expoOut",t[t.expoInOut=18]="expoInOut",t[t.circleIn=19]="circleIn",t[t.circleOut=20]="circleOut",t[t.circleInOut=21]="circleInOut",t[t.elasticIn=22]="elasticIn",t[t.elasticOut=23]="elasticOut",t[t.elasticInOut=24]="elasticInOut",t[t.punch=25]="punch",t[t.backIn=26]="backIn",t[t.backOut=27]="backOut",t[t.backInOut=28]="backInOut",t[t.bounceIn=29]="bounceIn",t[t.bounceOut=30]="bounceOut",t[t.bounceInOut=31]="bounceInOut"}(e=t.EaseType||(t.EaseType={}));var n=function(){function n(){}return n.oppositeEaseType=function(t){switch(t){case e.linear:return t;case e.backIn:return e.backOut;case e.backOut:return e.backIn;case e.backInOut:return t;case e.bounceIn:return e.bounceOut;case e.bounceOut:return e.bounceIn;case e.bounceInOut:return t;case e.circleIn:return e.circleOut;case e.circleOut:return e.circleIn;case e.circleInOut:return t;case e.cubicIn:return e.cubicOut;case e.cubicOut:return e.cubicIn;case e.circleInOut:case e.punch:return t;case e.expoIn:return e.expoOut;case e.expoOut:return e.expoIn;case e.expoInOut:return t;case e.quadIn:return e.quadOut;case e.quadOut:return e.quadIn;case e.quadInOut:return t;case e.quartIn:return e.quadOut;case e.quartOut:return e.quartIn;case e.quadInOut:return t;case e.sineIn:return e.sineOut;case e.sineOut:return e.sineIn;case e.sineInOut:default:return t}},n.ease=function(n,i,r){switch(n){case e.linear:return t.Easing.Linear.easeNone(i,r);case e.backIn:return t.Easing.Back.easeIn(i,r);case e.backOut:return t.Easing.Back.easeOut(i,r);case e.backInOut:return t.Easing.Back.easeInOut(i,r);case e.bounceIn:return t.Easing.Bounce.easeIn(i,r);case e.bounceOut:return t.Easing.Bounce.easeOut(i,r);case e.bounceInOut:return t.Easing.Bounce.easeInOut(i,r);case e.circleIn:return t.Easing.Circular.easeIn(i,r);case e.circleOut:return t.Easing.Circular.easeOut(i,r);case e.circleInOut:return t.Easing.Circular.easeInOut(i,r);case e.cubicIn:return t.Easing.Cubic.easeIn(i,r);case e.cubicOut:return t.Easing.Cubic.easeOut(i,r);case e.cubicInOut:return t.Easing.Cubic.easeInOut(i,r);case e.elasticIn:return t.Easing.Elastic.easeIn(i,r);case e.elasticOut:return t.Easing.Elastic.easeOut(i,r);case e.elasticInOut:return t.Easing.Elastic.easeInOut(i,r);case e.punch:return t.Easing.Elastic.punch(i,r);case e.expoIn:return t.Easing.Exponential.easeIn(i,r);case e.expoOut:return t.Easing.Exponential.easeOut(i,r);case e.expoInOut:return t.Easing.Exponential.easeInOut(i,r);case e.quadIn:return t.Easing.Quadratic.easeIn(i,r);case e.quadOut:return t.Easing.Quadratic.easeOut(i,r);case e.quadInOut:return t.Easing.Quadratic.easeInOut(i,r);case e.quintIn:return t.Easing.Quintic.easeIn(i,r);case e.quintOut:return t.Easing.Quintic.easeOut(i,r);case e.quintInOut:return t.Easing.Quintic.easeInOut(i,r);case e.sineIn:return t.Easing.Sinusoidal.easeIn(i,r);case e.sineOut:return t.Easing.Sinusoidal.easeOut(i,r);case e.sineInOut:return t.Easing.Sinusoidal.easeInOut(i,r);default:return t.Easing.Linear.easeNone(i,r)}},n}();t.EaseHelper=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(e){function n(){var t=e.call(this)||this;return t._activeTweens=[],t._tempTweens=[],n._instance=t,t}return __extends(n,e),Object.defineProperty(n,"activeTweens",{get:function(){return this._instance._activeTweens},enumerable:!0,configurable:!0}),n.prototype.update=function(){this._isUpdating=!0;for(var e=this._activeTweens.length-1;e>=0;--e){var n=this._activeTweens[e];n.tick()&&this._tempTweens.push(n)}this._isUpdating=!1;for(e=0;e=0;--e)n._instance._activeTweens[e].stop(t)},n.allTweensWithContext=function(t){for(var e=[],i=0;i=0;--i)n._instance._activeTweens[i].context==t&&n._instance._activeTweens[i].stop(e)},n.allTweenWithTarget=function(t){for(var e=[],i=0;i=0;--i)if(n._instance._activeTweens[i]){var r=n._instance._activeTweens[i];r.getTargetObject()==t&&r.stop(e)}},n.defaultEaseType=t.EaseType.quartIn,n.removeAllTweensOnLevelLoad=!1,n.cacheNumberTweens=!0,n.cacheVector2Tweens=!0,n.cacheColorTweens=!0,n.cacheRectTweens=!1,n}(t.GlobalManager);t.TweenManager=e}(es||(es={})),function(t){!function(t){var e=function(){function t(){}return t.easeNone=function(t,e){return t/e},t}();t.Linear=e;var n=function(){function t(){}return t.easeIn=function(t,e){return(t/=e)*t},t.easeOut=function(t,e){return-1*(t/=e)*(t-2)},t.easeInOut=function(t,e){return(t/=e/2)<1?.5*t*t:-.5*(--t*(t-2)-1)},t}();t.Quadratic=n;var i=function(){function t(){}return t.easeIn=function(t,e){return(t/=e)*t*(2.70158*t-1.70158)},t.easeOut=function(t,e){return(t=t/e-1)*t*(2.70158*t+1.70158)+1},t.easeInOut=function(t,e){var n=1.70158;return(t/=e/2)<1?t*t*((1+(n*=1.525))*t-n)*.5:.5*((t-=2)*t*((1+(n*=1.525))*t+n)+2)},t}();t.Back=i;var r=function(){function t(){}return t.easeOut=function(t,e){return(t/=e)<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},t.easeIn=function(t,e){return 1-this.easeOut(e-t,e)},t.easeInOut=function(t,e){return t= 2");if(t.sort(function(t,e){return t.t-e.t}),0!==t[0].t)throw new Error("curve must start with 0");if(1!==t[t.length-1].t)throw new Error("curve must end with 1");this._points=t}return Object.defineProperty(e.prototype,"points",{get:function(){return this._points},enumerable:!0,configurable:!0}),e.prototype.lerp=function(e){for(var n=1;n=0;o--)(e=r[o].func).call.apply(e,__spread([r[o].context],n))},n}();t.Emitter=n}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){function t(){this._listeners=[]}return t.prototype.addListener=function(t,e){-1===this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t})&&this._listeners.push({caller:t,callback:e})},t.prototype.removeListener=function(t,e){var n=this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t});n>=0&&this._listeners.splice(n,1)},t.prototype.clearListener=function(){this._listeners=[]},t.prototype.clearListenerWithCaller=function(t){for(var e=this._listeners.length-1;e>=0;e--){this._listeners[e].caller===t&&this._listeners.splice(e,1)}},t.prototype.notify=function(){for(var t,e=[],n=0;n=0;i--){var r=this._listeners[i];r.caller?(t=r.callback).call.apply(t,__spread([r.caller],e)):r.callback.apply(r,__spread(e))}},t}();t.Observable=e;var n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e){t.prototype.notify.call(this,e)},e}(e);t.ObservableT=n;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e,n){t.prototype.notify.call(this,e,n)},e}(e);t.ObservableTT=i;var r=function(){function t(t,n){this.bindAction(t,n),this._onExec=new e}return t.prototype.bindAction=function(t,e){this._caller=t,this._action=e},t.prototype.dispatch=function(){for(var t,e=[],n=0;n3&&o<500;){o++;var a=!0,u=n[this._triPrev[s]],c=n[s],h=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(u,c,h)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],u,c,h)){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.length>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&n]+e[n>>8&255]+"-"+e[n>>16&15|64]+e[n>>24&255]+"-"+e[63&i|128]+e[i>>8&255]+"-"+e[i>>16&255]+e[i>>24&255]+e[255&r]+e[r>>8&255]+e[r>>16&255]+e[r>>24&255]},t}();t.UUID=n}(es||(es={})),function(t){t.getClassName=function(t){return t.className||t.name}}(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 __spread(this._completeSlices,[this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},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.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.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}(es||(es={})),function(t){var e=function(){function t(t){void 0===t&&(t=64),this.size_=0,this.length=0,this.array=[],this.length=t}return t.prototype.removeAt=function(t){var e=this.array[t];return this.array[t]=this.array[--this.size_],this.array[this.size_]=null,e},t.prototype.remove=function(t){var e,n=this.size_;for(e=0;e0){var t=this.array[--this.size_];return this.array[this.size_]=null,t}return null},t.prototype.contains=function(t){var e,n;for(e=0,n=this.size_;n>e;e++)if(t===this.array[e])return!0;return!1},t.prototype.removeAll=function(t){var e,n,i,r,o=!1;for(e=0,i=t.size();e=this.length)throw new Error("ArrayIndexOutOfBoundsException");return this.array[t]},t.prototype.safeGet=function(t){return t>=this.length&&this.grow(7*t/4+1),this.array[t]},t.prototype.size=function(){return this.size_},t.prototype.getCapacity=function(){return this.length},t.prototype.isIndexWithinBounds=function(t){return t=this.length&&this.grow(2*t),this.size_=t+1,this.array[t]=e},t.prototype.grow=function(t){void 0===t&&(t=1+~~(3*this.length/2)),this.length=~~t},t.prototype.ensureCapacity=function(t){t>=this.length&&this.grow(2*t)},t.prototype.clear=function(){var t,e;for(t=0,e=this.size_;te;e++)this.add(t.get(e))},t}();t.Bag=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=1),this._freeValueCellIndex=0,this._collisions=0,this._valuesInfo=new Array(e),this._values=new Array(e),this._buckets=new Array(t.HashHelpers.getPrime(e))}return e.prototype.getValuesArray=function(t){return t.value=this._freeValueCellIndex,this._values},Object.defineProperty(e.prototype,"valuesArray",{get:function(){return this._values},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"count",{get:function(){return this._freeValueCellIndex},enumerable:!0,configurable:!0}),e.prototype.add=function(t,e){if(!this.addValue(t,e,{value:0}))throw new Error("key 已经存在")},e.prototype.addValue=function(i,r,o){var s=t.HashHelpers.getHashCode(i),a=e.reduce(s,this._buckets.length);if(this._freeValueCellIndex==this._values.length){var u=t.HashHelpers.expandPrime(this._freeValueCellIndex);this._values.length=u,this._valuesInfo.length=u}var c=t.NumberExtension.toNumber(this._buckets[a])-1;if(-1==c)this._valuesInfo[this._freeValueCellIndex]=new n(i,s);else{var h=c;do{if(this._valuesInfo[h].hashcode==s&&this._valuesInfo[h].key==i)return this._values[h]=r,o.value=h,!1;h=this._valuesInfo[h].previous}while(-1!=h);this._collisions++,this._valuesInfo[this._freeValueCellIndex]=new n(i,s,c),this._valuesInfo[c].next=this._freeValueCellIndex}if(this._buckets[a]=this._freeValueCellIndex+1,this._values[this._freeValueCellIndex]=r,o.value=this._freeValueCellIndex,this._freeValueCellIndex++,this._collisions>this._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function n(t,e){return t===e}t.Node=e,t.defaultEquals=n;var i=function(){function t(t){void 0===t&&(t=n),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var n,i=new e(t);if(null==this.head)this.head=i;else{for(n=this.head;null!=n.next;)n=n.next;n.next=i}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,n=0;n=0&&n<=this.count){var i=new e(t);if(0===n)i.next=this.head,this.head=i;else{var r=this.getElementAt(n-1);i.next=r.next,r.next=i}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,n=0;n0)for(var n=0;nthis._objectQueue.get(t).length;)this._objectQueue.get(t).splice(0,1)},t.clearCache=function(t){this.checkCreate(t),this._objectQueue.get(t).length=0},t.obtain=function(t){return this.checkCreate(t),this._objectQueue.get(t).length>0?this._objectQueue.get(t).shift():[]},t.free=function(t,e){this.checkCreate(t),this._objectQueue.get(t).push(e),e.length=0},t.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},t._objectQueue=new Map,t}();t.ListPool=e}(es||(es={})),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={})),function(t){var e=function(){function t(){this._all=new Array}return Object.defineProperty(t.prototype,"all",{get:function(){return this._all},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return this._all.findIndex(function(e){return e.equals(t)})>-1},t.prototype.add=function(t){this.has(t)||this._all.push(t)},t.prototype.remove=function(t){var e=this._all.findIndex(function(e){return e.equals(t)});if(e>-1){var n=this._all[e];this._all[e]=this._all[this._all.length-1],this._all[this._all.length-1]=n,this._all=this._all.slice(0,this._all.length-1)}},t.prototype.clear=function(){this._all=[]},t.prototype.union=function(t){var e=t.all;if(e.length>0)for(var n=0;n0)for(var n=0;n0)for(var n=0;nthis._objectQueue.get(t).length;)this._objectQueue.get(t).splice(0,1)},e.clearCache=function(t){this.checkCreate(t),this._objectQueue.get(t).length=0},e.obtain=function(t){return this.checkCreate(t),this._objectQueue.get(t).length>0?this._objectQueue.get(t).shift():new t},e.free=function(e,n){this.checkCreate(e),this._objectQueue.get(e).push(n),t.isIPoolable(n)&&n.reset()},e.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},e._objectQueue=new Map,e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(){function t(){}return t.waitForSeconds=function(t){return n.waiter.wait(t)},t}();t.Coroutine=e;var n=function(){function t(){this.waitTime=0}return t.prototype.wait=function(e){return t.waiter.waitTime=e,t.waiter},t.waiter=new t,t}();t.WaitForSeconds=n}(es||(es={})),function(t){var e=function(){function t(){this.waitTimer=0,this.useUnscaledDeltaTime=!1}return t.prototype.stop=function(){this.isDone=!0},t.prototype.setUseUnscaledDeltaTime=function(t){return this.useUnscaledDeltaTime=t,this},t.prototype.prepareForUse=function(){this.isDone=!1},t.prototype.reset=function(){this.isDone=!0,this.waitTimer=0,this.waitForCoroutine=null,this.enumerator=null,this.useUnscaledDeltaTime=!1},t}();t.CoroutineImpl=e;var n=function(n){function i(){var t=null!==n&&n.apply(this,arguments)||this;return t._unblockedCoroutines=[],t._shouldRunNextFrame=[],t}return __extends(i,n),i.prototype.clearAllCoroutines=function(){for(var n=0;n0?(i.waitTimer-=i.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(i)):this.tickCoroutine(i)&&this._shouldRunNextFrame.push(i)}}var r=new t.List(this._unblockedCoroutines);r.clear(),r.addRange(this._shouldRunNextFrame),this._shouldRunNextFrame.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next();return i.done||n.isDone?(t.Pool.free(e,n),!1):null==i.value||(i.value instanceof t.WaitForSeconds?(n.waitTimer=i.value.waitTime,!0):"number"==typeof i.value?(n.waitTimer=i.value,!0):"string"==typeof i.value?"break"!=i.value||(t.Pool.free(e,n),!1):"function"==typeof i.value?(n.waitForCoroutine=this.startCoroutine(i.value),!0):!(i.value instanceof e)||(n.waitForCoroutine=i.value,!0))},i}(t.GlobalManager);t.CoroutineManager=n}(es||(es={})),function(t){var e=function(){function e(t,e,n){void 0===n&&(n=!0),this.binWidth=0,this.binHeight=0,this.usedRectangles=[],this.freeRectangles=[],this.init(t,e,n)}return e.prototype.init=function(e,n,i){void 0===i&&(i=!0),this.binWidth=e,this.binHeight=n,this.allowRotations=i;var r=new t.Rectangle;r.x=0,r.y=0,r.width=e,r.height=n,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(r)},e.prototype.insert=function(e,n){var i=new t.Rectangle,r=new t.Ref(0),o=new t.Ref(0);if(0==(i=this.findPositionForNewNodeBestAreaFit(e,n,r,o)).height)return i;for(var s=this.freeRectangles.length,a=0;a=e&&this.freeRectangles[s].height>=n){var u=Math.abs(this.freeRectangles[s].width-e),c=Math.abs(this.freeRectangles[s].height-n),h=Math.min(u,c);(a=n&&this.freeRectangles[s].height>=e){u=Math.abs(this.freeRectangles[s].width-n),c=Math.abs(this.freeRectangles[s].height-e),h=Math.min(u,c);(a=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y)return!1;if(e.xt.x){if(e.y>t.y&&e.yt.y){var n;if(e.x>t.x&&e.x=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height},e}();t.MaxRectsBinPack=e}(es||(es={})),function(t){var e=function(){function e(){}return e.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}},e.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},e.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},e.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},e.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},e.cloneList=function(t){return t?t.slice(0,t.length):null},e.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},e.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},e.shuffle=function(e){for(var n=e.length;n>1;){n--;var i=t.RandomUtils.randint(0,n+1),r=e[i];e[i]=e[n],e[n]=r}},e.addIfNotPresent=function(e,n){return!new t.List(e).contains(n)&&(e.push(n),!0)},e.lastItem=function(t){return t[t.length-1]},e.randomItem=function(e){return e[t.RandomUtils.randint(0,e.length-1)]},e.randomItems=function(e,n,i){for(var r=new Set;r.size!=i;){var o=this.randomItem(n);r.has(o)||r.add(o)}var s=t.ListPool.obtain(e);return r.forEach(function(t){return s.push(t)}),s},e}();t.ArrayUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],u=0;u>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(u++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(u++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,u=[],c=0;c>2,o=(3&e)<<4|(n=t.charCodeAt(c++))>>4,s=(15&n)<<2|(i=t.charCodeAt(c++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),u.push(this._keyStr.charAt(r)),u.push(this._keyStr.charAt(o)),u.push(this._keyStr.charAt(s)),u.push(this._keyStr.charAt(a));return u=u.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i(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.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().5?1:-1},t}();t.RandomUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(h)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=h>0?p-h:-p-h;return new t.Vector2(f,d)},e.getClosestPointOnBoundsToOrigin=function(e){var n=this.getMax(e),i=Math.abs(e.location.x),r=new t.Vector2(e.location.x,0);return Math.abs(n.x)r&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(t.MathHelper.toInt(n),t.MathHelper.toInt(i)),new t.Vector2(t.MathHelper.toInt(r),t.MathHelper.toInt(o)))},e.calculateBounds=function(e,n,i,r,o,s,a,u){if(0==s)e.x=t.MathHelper.toInt(n.x+i.x-r.x*o.x),e.y=t.MathHelper.toInt(n.y+i.y-r.y*o.y),e.width=t.MathHelper.toInt(a*o.x),e.height=t.MathHelper.toInt(u*o.y);else{var c=n.x+i.x,h=n.y+i.y,l=new t.Matrix2D;t.Matrix2D.createTranslation(-c-r.x,-h-r.y,l),t.Matrix2D.createScale(o.x,o.y,void 0),l=l.multiply(void 0),t.Matrix2D.createRotation(s,void 0),l=l.multiply(void 0),t.Matrix2D.createTranslation(c,h,void 0),l=l.multiply(void 0);var p=new t.Vector2(c,h),f=new t.Vector2(c+a,h),d=new t.Vector2(c,h+u),m=new t.Vector2(c+a,h+u);t.Vector2Ext.transformR(p,l,p),t.Vector2Ext.transformR(f,l,f),t.Vector2Ext.transformR(d,l,d),t.Vector2Ext.transformR(m,l,m);var y=t.MathHelper.toInt(Math.min(p.x,m.x,f.x,d.x)),g=t.MathHelper.toInt(Math.max(p.x,m.x,f.x,d.x)),_=t.MathHelper.toInt(Math.min(p.y,m.y,f.y,d.y)),v=t.MathHelper.toInt(Math.max(p.y,m.y,f.y,d.y));e.location=new t.Vector2(y,_),e.width=t.MathHelper.toInt(g-y),e.height=t.MathHelper.toInt(v-_)}},e.scale=function(e,n){e.x=t.MathHelper.toInt(e.x*n.x),e.y=t.MathHelper.toInt(e.y*n.y),e.width=t.MathHelper.toInt(e.width*n.x),e.height=t.MathHelper.toInt(e.height*n.y)},e.translate=function(t,e){t.location.addEqual(e)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divideScaler(n):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){return this.sum(t)/this.count(t)},e.prototype.cast=function(){return new e(this._elements)},e.prototype.clear=function(){this._elements.length=0},e.prototype.concat=function(t){return new e(this._elements.concat(t.toArray()))},e.prototype.contains=function(t){return this.any(function(e){return e===t})},e.prototype.count=function(t){return t?this.where(t).count():this._elements.length},e.prototype.defaultIfEmpty=function(t){return this.count()?this:new e([t])},e.prototype.distinctBy=function(t){var n=this.groupBy(t);return Object.keys(n).reduce(function(t,e){return t.add(n[e][0]),t},new e)},e.prototype.elementAt=function(t){if(t=0)return this._elements[t];throw new Error("ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.")},e.prototype.elementAtOrDefault=function(t){return t=0?this._elements[t]:void 0},e.prototype.except=function(t){return this.where(function(e){return!t.contains(e)})},e.prototype.first=function(t){if(this.count())return t?this.where(t).first():this._elements[0];throw new Error("InvalidOperationException: The source sequence is empty.")},e.prototype.firstOrDefault=function(t){return this.count(t)?this.first(t):void 0},e.prototype.forEach=function(t){return this._elements.forEach(t)},e.prototype.groupBy=function(t,e){void 0===e&&(e=function(t){return t});return this.aggregate(function(n,i){var r=t(i),o=n[r],s=e(i);return o?o.push(s):n[r]=[s],n},{})},e.prototype.groupJoin=function(t,e,n,i){return this.select(function(r){return i(r,t.where(function(t){return e(r)===n(t)}))})},e.prototype.indexOf=function(t){return this._elements.indexOf(t)},e.prototype.insert=function(t,e){if(t<0||t>this._elements.length)throw new Error("Index is out of range.");this._elements.splice(t,0,e)},e.prototype.intersect=function(t){return this.where(function(e){return t.contains(e)})},e.prototype.join=function(t,e,n,i){return this.selectMany(function(r){return t.where(function(t){return n(t)===e(r)}).select(function(t){return i(r,t)})})},e.prototype.last=function(t){if(this.count())return t?this.where(t).last():this._elements[this.count()-1];throw Error("InvalidOperationException: The source sequence is empty.")},e.prototype.lastOrDefault=function(t){return this.count(t)?this.last(t):void 0},e.prototype.max=function(t){return Math.max.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.min=function(t){return Math.min.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.ofType=function(t){var e;switch(t){case Number:e="number";break;case String:e="string";break;case Boolean:e=typeof!0;break;case Function:e="function";break;default:e=null}return null===e?this.where(function(e){return e instanceof t}).cast():this.where(function(t){return typeof t===e}).cast()},e.prototype.orderBy=function(e,i){return void 0===i&&(i=t.keyComparer(e,!1)),new n(this._elements,i)},e.prototype.orderByDescending=function(e,i){return void 0===i&&(i=t.keyComparer(e,!0)),new n(this._elements,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){return-1!==this.indexOf(t)&&(this.removeAt(this.indexOf(t)),!0)},e.prototype.removeAll=function(e){return this.where(t.negate(e))},e.prototype.removeAt=function(t){this._elements.splice(t,1)},e.prototype.reverse=function(){return new e(this._elements.reverse())},e.prototype.select=function(t){return new e(this._elements.map(t))},e.prototype.selectMany=function(t){var n=this;return this.aggregate(function(e,i,r){return e.addRange(n.select(t).elementAt(r).toArray()),e},new e)},e.prototype.sequenceEqual=function(t){return this.all(function(e){return t.contains(e)})},e.prototype.single=function(t){if(1!==this.count(t))throw new Error("The collection does not contain exactly one element.");return this.first(t)},e.prototype.singleOrDefault=function(t){return this.count(t)?this.single(t):void 0},e.prototype.skip=function(t){return new e(this._elements.slice(Math.max(0,t)))},e.prototype.skipLast=function(t){return new e(this._elements.slice(0,-Math.max(0,t)))},e.prototype.skipWhile=function(t){var e=this;return this.skip(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.sum=function(t){return t?this.select(t).sum():this.aggregate(function(t,e){return t+ +e},0)},e.prototype.take=function(t){return new e(this._elements.slice(0,Math.max(0,t)))},e.prototype.takeLast=function(t){return new e(this._elements.slice(-Math.max(0,t)))},e.prototype.takeWhile=function(t){var e=this;return this.take(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,n){var i=this;return this.aggregate(function(e,r,o){return e[i.select(t).elementAt(o).toString()]=n?i.select(n).elementAt(o):r,e.add({Key:i.select(t).elementAt(o),Value:n?i.select(n).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){var t,e,n=new Set;try{for(var i=__values(this._elements),r=i.next();!r.done;r=i.next()){var o=r.value;n.add(o)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return n},e.prototype.toList=function(){return this},e.prototype.toLookup=function(t,e){return this.groupBy(t,e)},e.prototype.where=function(t){return new e(this._elements.filter(t))},e.prototype.zip=function(t,e){var n=this;return t.count()e.angle?1:t.angleMath.PI&&(o-=2*Math.PI),r.p1.begin=o>0,r.p2.begin=!r.p1.begin}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}this._isSpotLight&&(this._spotStartAngle=this._segments[0].p2.angle,this._spotEndAngle=this._segments[1].p2.angle)},e._cornerCache=[],e._openSegments=new t.LinkedList,e}();t.VisibilityComputer=e}(es||(es={})),function(t){var e=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}return e.prototype.getContext=function(){return this.context},e.prototype.reset=function(){this._elapsedTime=0},e.prototype.stop=function(){this._isDone=!0},e.prototype.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i.bind(n)},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.splice(t,1))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file +window.es={};var __read=this&&this.__read||function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}};!function(t){var e=function(){function e(n,i){void 0===n&&(n=!0),void 0===i&&(i=!0),this._globalManagers=[],this._coroutineManager=new t.CoroutineManager,this._timerManager=new t.TimerManager,this._frameCounterElapsedTime=0,this._frameCounter=0,this._totalMemory=0,e._instance=this,e.emitter=new t.Emitter,e.emitter.addObserver(t.CoreEvents.frameUpdated,this.update,this),e.registerGlobalManager(this._coroutineManager),e.registerGlobalManager(new t.TweenManager),e.registerGlobalManager(this._timerManager),e.entitySystemsEnabled=i,this.debug=n,this.initialize()}return Object.defineProperty(e,"Instance",{get:function(){return this._instance},enumerable:!0,configurable:!0}),Object.defineProperty(e,"scene",{get:function(){return this._instance?this._instance._scene:null},set:function(e){t.Insist.isNotNull(e,"场景不能为空"),null==this._instance._scene?(this._instance._scene=e,this._instance.onSceneChanged(),this._instance._scene.begin()):this._instance._nextScene=e},enumerable:!0,configurable:!0}),e.create=function(e){return void 0===e&&(e=!0),null==this._instance&&(this._instance=new t.Core(e)),this._instance},e.registerGlobalManager=function(t){this._instance._globalManagers.push(t),t.enabled=!0},e.unregisterGlobalManager=function(e){new t.List(this._instance._globalManagers).remove(e),e.enabled=!1},e.getGlobalManager=function(t){for(var n=0,i=e._instance._globalManagers.length;n=1)){var e=window.performance.memory;null!=e&&(this._totalMemory=Number((e.totalJSHeapSize/1048576).toFixed(2))),this._titleMemory&&this._titleMemory(this._totalMemory,this._frameCounter),this._frameCounter=0,this._frameCounterElapsedTime-=1}},e.prototype.onSceneChanged=function(){e.emitter.emit(t.CoreEvents.sceneChanged),t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(n){if(void 0===n&&(n=-1),!e.paused){if(t.Time.update(n,-1!=n),null!=this._scene){for(var i=this._globalManagers.length-1;i>=0;i--)this._globalManagers[i].enabled&&this._globalManagers[i].update();null!=this._sceneTransition&&(null==this._sceneTransition||this._sceneTransition._loadsNewScene&&!this._sceneTransition._isNewSceneLoaded)||this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}this.startDebugDraw(),this.draw()}},e.prototype.draw=function(){null!=this._sceneTransition&&this._sceneTransition.preRender(),null==this._sceneTransition||this._sceneTransition.hasPreviousSceneRender||(null!=this._scene&&e.startCoroutine(this._sceneTransition.onBeginTransition()),this._sceneTransition.render())},e.paused=!1,e.debugRenderEndabled=!1,e}();t.Core=e}(es||(es={})),function(t){var e;!function(t){t[t.error=0]="error",t[t.warn=1]="warn",t[t.log=2]="log",t[t.info=3]="info",t[t.trace=4]="trace"}(e=t.LogType||(t.LogType={}));var n=function(){function n(){}return n.warnIf=function(t,n){for(var i=[],r=2;r=0;t--){this.transform.getChild(t).entity.destroy()}},n.prototype.detachFromScene=function(){this.scene.entities.remove(this),this.components.deregisterAllComponents();for(var t=0;t0?new e(this.x/t,this.y/t):new e(0,1)},e.prototype.normalizeEqual=function(){var t=this.distance();return t>0?(this.setTo(this.x/t,this.y/t),this):(this.setTo(0,1),this)},e.prototype.magnitude=function(){return this.distance()},e.prototype.distance=function(t){return t||(t=e.zero),Math.sqrt(Math.pow(this.x-t.x,2)+Math.pow(this.y-t.y,2))},e.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},e.prototype.getLength=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.prototype.angleBetween=function(e,n){var i=e.sub(this),r=n.sub(this);return t.Vector2Ext.angle(i,r)},e.prototype.getDistance=function(t){return Math.sqrt(this.getDistanceSquared(t))},e.prototype.getDistanceSquared=function(t){var e=t.x-this.x,n=t.y-this.y;return e*e+n*n},e.prototype.isBetween=function(t,e){var n=e.sub(t).cross(this.sub(t));return Math.abs(n)=0&&this.dot(t.sub(e))>=0},e.prototype.cross=function(t){return this.x*t.y-this.y*t.x},e.prototype.getAngle=function(){return Math.atan2(this.y,this.x)},e.prototype.equals=function(t,e){return void 0===e&&(e=.001),Math.abs(this.x-t.x)<=e&&Math.abs(this.y-t.y)<=e},e.prototype.isValid=function(){return t.MathHelper.isValid(this.x)&&t.MathHelper.isValid(this.y)},e.min=function(t,n){return new e(t.xn.x?t.x:n.x,t.y>n.y?t.y:n.y)},e.hermite=function(n,i,r,o,s){return new e(t.MathHelper.hermite(n.x,i.x,r.x,o.x,s),t.MathHelper.hermite(n.y,i.y,r.y,o.y,s))},e.unsignedAngle=function(e,n,i){void 0===i&&(i=!0),e.normalizeEqual(),n.normalizeEqual();var r=Math.acos(t.MathHelper.clamp(e.dot(n),-1,1))*t.MathHelper.Rad2Deg;return i?Math.round(r):r},e.fromAngle=function(t,n){return void 0===n&&(n=1),new e(n*Math.cos(t),n*Math.sin(t))},e.prototype.clone=function(){return new e(this.x,this.y)},e.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this.entities=new t.EntityList(this),this.entityProcessors=new t.EntityProcessorList,this.identifierPool=new t.IdentifierPool,this.initialize()}return e.prototype.initialize=function(){},e.prototype.onStart=function(){},e.prototype.unload=function(){},e.prototype.begin=function(){t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1,this.entities.removeAllEntities();for(var e=0;e=0;t--)this._sceneComponents[t].enabled&&this._sceneComponents[t].update();null!=this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),null!=this.entityProcessors&&this.entityProcessors.lateUpdate()},e.prototype.addSceneComponent=function(t){return t.scene=this,t.onEnabled(),this._sceneComponents.push(t),this._sceneComponents.sort(t.compare),t},e.prototype.getSceneComponent=function(t){for(var e=0;ee.x?-1:1,i=this.position.sub(e).normalize();this.rotation=n*Math.acos(i.dot(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(n.rotationDirty),this},i.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},i.prototype.setScale=function(e){return this._scale=e,null!=this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this.setDirty(n.scaleDirty),this},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(n.scaleDirty),this},i.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},i.prototype.updateTransform=function(){this.hierarchyDirty!=n.clean&&(null!=this.parent&&this.parent.updateTransform(),this._localDirty&&(this._localPositionDirty&&(t.Matrix2D.createTranslation(this._localPosition.x,this._localPosition.y,this._translationMatrix),this._localPositionDirty=!1),this._localRotationDirty&&(t.Matrix2D.createRotation(this._localRotation,this._rotationMatrix),this._localRotationDirty=!1),this._localScaleDirty&&(t.Matrix2D.createScale(this._localScale.x,this._localScale.y,this._scaleMatrix),this._localScaleDirty=!1),t.Matrix2D.multiply(this._scaleMatrix,this._rotationMatrix,this._localTransform),t.Matrix2D.multiply(this._localTransform,this._translationMatrix,this._localTransform),null==this.parent&&(this._worldTransform=this._localTransform,this._rotation=this._localRotation,this._scale=this._localScale,this._worldInverseDirty=!0),this._localDirty=!1),null!=this.parent&&(t.Matrix2D.multiply(this._localTransform,this.parent._worldTransform,this._worldTransform),this._rotation=this._localRotation+this.parent._rotation,this._scale=this.parent._scale.multiply(this._localScale),this._worldInverseDirty=!0),this._worldToLocalDirty=!0,this._positionDirty=!0,this.hierarchyDirty=n.clean)},i.prototype.setDirty=function(t){if(0==(this.hierarchyDirty&t)){switch(this.hierarchyDirty|=t,t){case n.positionDirty:this.entity.onTransformChanged(e.position);break;case n.rotationDirty:this.entity.onTransformChanged(e.rotation);break;case n.scaleDirty:this.entity.onTransformChanged(e.scale)}for(var i=0;i1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},n.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},n.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},n.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},n.prototype.setVelocity=function(t){return this.velocity=t,this},n.prototype.addImpulse=function(e){this.isImmovable||this.velocity.addEqual(e.scale(this._inverseMass*(t.Time.deltaTime*t.Time.deltaTime)*1e5))},n.prototype.onAddedToEntity=function(){this._collider=null;for(var e=0;e0)for(var i=0;i0&&(o=t.Vector2.zero);var a=this._friction;return s.lengthSquared()0&&this.collisionState.wasGroundedLastFrame&&(t=this.handleVerticalSlope(t)),0!==t.x&&(t=this.moveHorizontally(t)),0!==t.y&&(t=this.moveVertically(t)),this._player.setPosition(this._player.position.x+t.x,this._player.position.y+t.y),e>0&&(this.velocity.x=t.x/e,this.velocity.y=t.y/e),!this.collisionState.wasGroundedLastFrame&&this.collisionState.below&&(this.collisionState.becameGroundedThisFrame=!0),this._isGoingUpSlope&&(this.velocity.y=0),this._isWarpingToGround||this._triggerHelper.update();for(var n=0;n0&&(this.ignoreOneWayPlatformsTime-=e)},i.prototype.warpToGrounded=function(e){void 0===e&&(e=1e3),this.ignoreOneWayPlatformsTime=0,this._isWarpingToGround=!0;var n=0;do{if(n+=1,this.move(new t.Vector2(0,1),.02),n>e)break}while(!this.isGrounded);this._isWarpingToGround=!1},i.prototype.recalculateDistanceBetweenRays=function(){var t=this._collider.height*Math.abs(this._player.scale.y)-2*this._skinWidth;this._verticalDistanceBetweenRays=t/(this.totalHorizontalRays-1);var e=this._collider.width*Math.abs(this._player.scale.x)-2*this._skinWidth;this._horizontalDistanceBetweenRays=e/(this.totalVerticalRays-1)},i.prototype.primeRaycastOrigins=function(){var e=this._collider.bounds;this._raycastOrigins.topLeft=new t.Vector2(e.x+this._skinWidth,e.y+this._skinWidth),this._raycastOrigins.bottomRight=new t.Vector2(e.right-this._skinWidth,e.bottom-this._skinWidth),this._raycastOrigins.bottomLeft=new t.Vector2(e.x+this._skinWidth,e.bottom-this._skinWidth)},i.prototype.moveHorizontally=function(e){for(var n=e.x>0,i=Math.abs(e.x)+this._skinWidth*this.rayOriginSkinMutiplier,r=n?t.Vector2.right:t.Vector2.left,o=this._raycastOrigins.bottomLeft.y,s=n?this._raycastOrigins.bottomRight.x-this._skinWidth*(this.rayOriginSkinMutiplier-1):this._raycastOrigins.bottomLeft.x+this._skinWidth*(this.rayOriginSkinMutiplier-1),a=0;a0)&&(a&=~this.oneWayPlatformMask);for(var u=0;uthis.jumpingThreshold){var i=this.slopeSpeedMultiplier?this.slopeSpeedMultiplier.lerp(n):1;e.x*=i,e.y=Math.abs(Math.tan(n*t.MathHelper.Deg2Rad)*e.x);var r=e.x>0,o=r?this._raycastOrigins.bottomRight:this._raycastOrigins.bottomLeft,s=null;(s=this.supportSlopedOneWayPlatforms&&this.collisionState.wasGroundedLastFrame?t.Physics.linecast(o,o.add(e),this.platformMask,this.ignoredColliders):t.Physics.linecast(o,o.add(e),this.platformMask&~this.oneWayPlatformMask,this.ignoredColliders)).collider&&(e.x=s.point.x-o.x,e.y=s.point.y-o.y,r?e.x-=this._skinWidth:e.x+=this._skinWidth),this._isGoingUpSlope=!0,this.collisionState.below=!0}}else e.x=0;return!0},i}();t.CharacterController=i}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,n){if(e.components._components.length>0)for(var i=0;i0)for(var r=0;r0)for(r=0;r0)for(r=0;r0)for(var h=0;h0)for(var r=0;rn;n++){var i=t[n];this.processDelta(i,this.acc);var r=this.getRemainingDelay(i);r<=0?this.processExpired(i):this.offerDelay(r)}this.acc=0}else this.stop()},n.prototype.checkProcessing=function(){return!!this.running&&(this.acc+=t.Time.deltaTime,this.acc>=this.delay)},n.prototype.offerDelay=function(t){this.running?this.delay=Math.min(this.delay,t):(this.running=!0,this.delay=t)},n.prototype.getInitialTimeDelay=function(){return this.delay},n.prototype.getRemainingTimeUntilProcessing=function(){return this.running?this.delay-this.acc:0},n.prototype.isRunning=function(){return this.running},n.prototype.stop=function(){this.running=!1,this.acc=0},n}(t.EntitySystem);t.DelayedIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(e){var n=t.call(this,e)||this;return n.enabled=!0,n}return __extends(e,t),e.prototype.lateProcessEntity=function(t){},e.prototype.process=function(t){if(0!=t.length)for(var e=0,n=t.length;e=this.interval&&(this.acc-=this.interval,this.intervalDelta=this.acc-this.intervalDelta,!0)},n.prototype.getIntervalDelta=function(){return this.interval+this.intervalDelta},n}(t.EntitySystem);t.IntervalSystem=e}(es||(es={})),function(t){var e=function(t){function e(e,n){return t.call(this,e,n)||this}return __extends(e,t),e.prototype.process=function(t){var e=this;t.forEach(function(t){return e.processEntity(t)})},e}(t.IntervalSystem);t.IntervalIteratingSystem=e}(es||(es={})),function(es){var JobSystem=function(_super){function JobSystem(t,e){var n=_super.call(this,t)||this;n._threads=e,n._jobs=new Array(e);for(var i=0;it.length&&(s=t.length);var a=o._jobs[n];if(a.set(t,r,s,o._executeStr,o),r!=s){var u=es.WorkerUtils.makeWorker(o.queueOnThread);es.WorkerUtils.workerMessage(u)(a).then(function(t){var n=t;e.resetJob(n),u.terminate()}).catch(function(t){a.err=t,u.terminate()})}},o=this,s=0;s-1?eval("(function(){return "+v+" })()"):v}),i=job.from;i0)for(var t=0,e=this._components.length;t0)for(var e=0,n=this._components.length;e0)for(var e=0,n=this._components.length;e0){for(var e=function(t,e){var i=n._componentsToRemoveList[t];n.handleRemove(i);var r=n._components.findIndex(function(t){return t.id==i.id});-1!=r&&n._components.splice(r,1),n.removeComponentsByType(i)},n=this,i=0,r=this._componentsToRemoveList.length;i0){for(i=0,r=this._componentsToAddList.length;i0){for(i=0,r=this._tempBufferList.length;i0){var n=this._updatableComponents.findIndex(function(t){return t.id==e.id});-1!=n&&this._updatableComponents.splice(n,1)}this.decreaseBits(e),this._entity.scene.entityProcessors.onComponentRemoved(this._entity),e.onRemovedFromEntity(),e.entity=null},e.prototype.removeComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsByType=function(e){var n=this.componentsByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsByType.set(t.TypeUtils.getType(e),n)},e.prototype.removeComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e)),i=n.findIndex(function(t){return t.id==e.id});-1!=i&&n.splice(i,1)},e.prototype.addComponentsToAddByType=function(e){var n=this.componentsToAddByType.get(t.TypeUtils.getType(e));n||(n=[]),n.push(e),this.componentsToAddByType.set(t.TypeUtils.getType(e),n)},e.prototype.getComponent=function(t,e){var n=this.componentsByType.get(t);if(n&&n.length>0)return n[0];if(!e){var i=this.componentsToAddByType.get(t);if(i&&i.length>0)return i[0]}return null},e.prototype.getComponents=function(t,e){e||(e=[]);var n=this.componentsByType.get(t);n&&(e=e.concat(n));var i=this.componentsToAddByType.get(t);return i&&(e=e.concat(i)),e},e.prototype.update=function(){if(this.updateLists(),this._updatableComponents.length>0)for(var t=0,e=this._updatableComponents.length;t0)for(var e=0,n=this._components.length;e0)for(e=0,n=this._componentsToAddList.length;e0)for(var t=0,e=this._components.length;t0)for(var t=0,e=this._components.length;t0){for(var t=function(t,n){var i=e._entitiesToRemoveList[t];e.removeFromTagList(i);var r=e._entities.findIndex(function(t){return t.id==i.id});-1!=r&&e._entities.splice(r,1),i.onRemovedFromScene(),i.scene=null,e.scene.entityProcessors.onEntityRemoved(i)},e=this,n=0,i=this._entitiesToRemoveList.length;n0){for(n=0,i=this._entitiesToAddedList.length;n0)for(var e=0,n=this._entities.length;e0)for(e=0,n=this._entitiesToAddedList.length;e0)for(var e=0,n=this._entities.length;e0)try{for(var s=__values(r),a=s.next();!a.done;a=s.next()){var u=a.value;o.push(u)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return o},e.prototype.entityWithTag=function(t){var e,n,i=this.getTagList(t);if(i.size>0)try{for(var r=__values(i),o=r.next();!o.done;o=r.next()){return o.value}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return null},e.prototype.findComponentOfType=function(t){if(this._entities.length>0)for(var e=0,n=this._entities.length;e0)for(e=0;e0)for(var i=0,r=this._entities.length;i0)for(i=0,r=this._entitiesToAddedList.length;i0)for(var i=0,r=this._entities.length;i0)for(var s=0,a=t.length;s0)for(i=0,r=this._entitiesToAddedList.length;i0)for(s=0,a=t.length;s=t)return n}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,n=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return n;for(var i=0;i0?this.ids.removeLast():this.nextAvailableId_++},e.prototype.checkIn=function(t){this.ids.add(t)},e}();t.IdentifierPool=e}(es||(es={})),function(t){var e=function(){function e(){this.allSet=[],this.exclusionSet=[],this.oneSet=[]}return e.empty=function(){return new e},e.prototype.getAllSet=function(){return this.allSet},e.prototype.getExclusionSet=function(){return this.exclusionSet},e.prototype.getOneSet=function(){return this.oneSet},e.prototype.isInterestedEntity=function(t){return this.isInterested(t.componentBits)},e.prototype.isInterested=function(e){if(0!=this.allSet.length)for(var n=0,i=this.allSet.length;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}();t.StringUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.update=function(t,e){var n=0;e?n=t:(-1==t&&(t=Date.now()),-1==this._lastTime&&(this._lastTime=t),n=(t-this._lastTime)/1e3),n>this.maxDeltaTime&&(n=this.maxDeltaTime),this.totalTime+=n,this.deltaTime=n*this.timeScale,this.unscaledDeltaTime=n,this.timeSinceSceneLoad+=n,this.frameCount++,this._lastTime=t},e.sceneChanged=function(){this.timeSinceSceneLoad=0},e.checkEvery=function(e){return t.MathHelper.toInt(this.timeSinceSceneLoad/e)>t.MathHelper.toInt((this.timeSinceSceneLoad-this.deltaTime)/e)},e.totalTime=0,e.unscaledDeltaTime=0,e.deltaTime=0,e.timeScale=1,e.maxDeltaTime=Number.MAX_VALUE,e.frameCount=0,e.timeSinceSceneLoad=0,e._lastTime=-1,e}();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,u=Math.floor(a)+1;if(53==u){n.setTime(t.getTime()),n.setDate(n.getDate()-1);var c=n.getDay();if(0==c&&(c=7),e&&(!o||c<4))return n.setFullYear(n.getFullYear()+1),n.setDate(1),n.setMonth(0),this.weekId(n,!1)}return parseInt(i+"00"+(u>9?"":"0")+u)},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(),u=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(u="0"+u),n?s+e+a+e+u:a+e+u},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o=1?(e=1,n.range=this._points.length-4):(e=t.MathHelper.clamp01(e)*this._curveCount,n.range=t.MathHelper.toInt(e),e-=n.range,n.range*=3),n.time=e,n},e.prototype.setControlPoint=function(t,e){if(t%3==0){var n=e.sub(this._points[t]);t>0&&this._points[t-1].addEqual(n),t+1Math.PI?e-2*Math.PI:e},e.isPowerOfTwo=function(t){return!(t<=0)&&0==(t&t-1)},e.lerp=function(t,n,i){return t+(n-t)*e.clamp01(i)},e.betterLerp=function(t,n,i,r){return Math.abs(t-n)180&&(i-=360),t+i*this.clamp01(n)},e.lerpAngleRadians=function(t,e,n){var i=this.repeat(e-t,2*Math.PI);return i>Math.PI&&(i-=2*Math.PI),t+i*this.clamp01(n)},e.pingPong=function(t,e){return t=this.repeat(t,2*e),e-Math.abs(t-e)},e.signThreshold=function(t,e){return Math.abs(t)>=e?Math.sign(t):0},e.inverseLerp=function(t,e,n){var i=e-t;return 0===i?0:(n-t)/i},e.lerpPrecise=function(t,e,n){return(1-n)*t+e*n},e.clamp=function(t,e,n){return tn?n:t},e.snap=function(t,e){return Math.round(t/e)*e},e.isEven=function(t){return t%2==0},e.isOdd=function(t){return t%2!=0},e.roundWithRoundedAmount=function(t,e){var n=Math.round(t);return e.value=t-n*Math.round(t/n),n},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.angleToVector=function(e,n){var i=Math.cos(e)*n,r=Math.sin(e)*n;return new t.Vector2(i,r)},e.incrementWithWrap=function(t,e){return++t==e?0:t},e.decrementWithWrap=function(t,e){return--t<0?e-1:t},e.hypotenuse=function(t,e){var n=t*t+e*e;return Math.sqrt(n)},e.closestPowerOfTwoGreaterThan=function(t){return t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,(t|=t>>16)+1},e.roundToNearest=function(t,e){var n=t/e;return Math.round(n)*e},e.withinEpsilon=function(t,e){return void 0===e&&(e=this.Epsilon),Math.abs(t)180&&(n-=360),n},e.between=function(t,e,n){return t>=e&&t<=n},e.deltaAngleRadians=function(t,e){var n=this.repeat(e-t,2*Math.PI);return n>Math.PI&&(n-=2*Math.PI),n},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.floorToInt=function(t){var e=Math.floor(t);return this.toInt(e)},e.rotateAround=function(e,n){var i=t.Time.totalTime*n,r=Math.cos(i),o=Math.sin(i),s=e.x+r,a=e.y+o;return new t.Vector2(s,a)},e.rotateAround2=function(e,n,i){var r=n.x,o=n.y,s=e.x,a=e.y,u=this.toRadians(i),c=Math.cos(u),h=Math.sin(u),l=c*(s-r)-h*(a-o)+r,p=h*(s-r)+c*(a-o)+o;return new t.Vector2(l,p)},e.pointOnCircle=function(e,n,i){var r=this.toRadians(i),o=Math.cos(r)*n,s=Math.sin(r)*n,a=o+e.x,u=s+e.y;return new t.Vector2(a,u)},e.pointOnCircleRadians=function(e,n,i){var r=Math.cos(i)*n,o=Math.sin(i)*n,s=r+e.x,a=o+e.y;return new t.Vector2(s,a)},e.lissajou=function(e,n,i,r,o){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=0);var s=Math.sin(t.Time.totalTime*e+o)*i,a=Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(s,a)},e.lissajouDamped=function(e,n,i,r,o,s,a){void 0===e&&(e=2),void 0===n&&(n=3),void 0===i&&(i=1),void 0===r&&(r=1),void 0===o&&(o=.5),void 0===s&&(s=0),void 0===a&&(a=5);var u=this.pingPong(t.Time.totalTime,a),c=Math.pow(Math.E,-s*u),h=c*Math.sin(t.Time.totalTime*e+o)*i,l=c*Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(h,l)},e.hermite=function(t,e,n,i,r){if(0===r)return t;if(1===r)return n;return(2*t-2*n+i+e)*(r*r*r)+(3*n-3*t-2*e-i)*(r*r)+e*r+t},e.isValid=function(t){return!Number.isNaN(t)&&t!==1/0},e.smoothDamp=function(t,n,i,r,o,s){var a=2/(r=Math.max(1e-4,r)),u=a*s,c=1/(1+.48*u+.235*u*u),h=o*r,l=t-n,p=(i+a*(l=e.clamp(l,-h,h)))*s;i=(i-a*p)*c;var f=(n=t-l)+(l+p)*c;return t>n==f>n&&(i=((f=n)-n)/s),{value:f,currentVelocity:i}},e.smoothDampVector=function(e,n,i,r,o,s){var a=t.Vector2.zero,u=this.smoothDamp(e.x,n.x,i.x,r,o,s);a.x=u.value,i.x=u.currentVelocity;var c=this.smoothDamp(e.y,n.y,i.y,r,o,s);return a.y=c.value,i.y=c.currentVelocity,a},e.mapMinMax=function(t,n,i,r,o){return r+(e.clamp(t,n,i)-n)*(o-r)/(i-n)},e.fromAngle=function(e){return new t.Vector2(Math.cos(e),Math.sin(e)).normalizeEqual()},e.toInt=function(t){return t>0?Math.floor(t):Math.ceil(t)},e.Epsilon=1e-5,e.Rad2Deg=57.29578,e.Deg2Rad=.0174532924,e.PiOver2=Math.PI/2,e}();t.MathHelper=e}(es||(es={})),function(t){var e=function(){function t(t,e,n,i,r,o,s,a,u,c,h,l,p,f,d,m){this.m11=t,this.m12=e,this.m13=n,this.m14=i,this.m21=r,this.m22=o,this.m23=s,this.m24=a,this.m31=u,this.m32=c,this.m33=h,this.m34=l,this.m41=p,this.m42=f,this.m43=d,this.m44=m}return Object.defineProperty(t,"Identity",{get:function(){return this.identity},enumerable:!0,configurable:!0}),t.createOrthographicOffCenter=function(e,n,i,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(n-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-i),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+n)/(e-n),a.m42=(r+i)/(i-r),a.m43=o/(o-s),a.m44=1},t.createTranslation=function(t,e){e.m11=1,e.m12=0,e.m13=0,e.m14=0,e.m21=0,e.m22=1,e.m23=0,e.m24=0,e.m31=0,e.m32=0,e.m33=1,e.m34=0,e.m41=t.x,e.m42=t.y,e.m43=0,e.m44=1},t.createRotationZ=function(e,n){n=t.Identity;var i=Math.cos(e),r=Math.sin(e);n.m11=i,n.m12=r,n.m21=-r,n.m22=i},t.multiply=function(e,n,i){void 0===i&&(i=new t);var r=e.m11*n.m11+e.m12*n.m21+e.m13*n.m31+e.m14*n.m41,o=e.m11*n.m12+e.m12*n.m22+e.m13*n.m32+e.m14*n.m42,s=e.m11*n.m13+e.m12*n.m23+e.m13*n.m33+e.m14*n.m43,a=e.m11*n.m14+e.m12*n.m24+e.m13*n.m34+e.m14*n.m44,u=e.m21*n.m11+e.m22*n.m21+e.m23*n.m31+e.m24*n.m41,c=e.m21*n.m12+e.m22*n.m22+e.m23*n.m32+e.m24*n.m42,h=e.m21*n.m13+e.m22*n.m23+e.m23*n.m33+e.m24*n.m43,l=e.m21*n.m14+e.m22*n.m24+e.m23*n.m34+e.m24*n.m44,p=e.m31*n.m11+e.m32*n.m21+e.m33*n.m31+e.m34*n.m41,f=e.m31*n.m12+e.m32*n.m22+e.m33*n.m32+e.m34*n.m42,d=e.m31*n.m13+e.m32*n.m23+e.m33*n.m33+e.m34*n.m43,m=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,y=e.m41*n.m11+e.m42*n.m21+e.m43*n.m31+e.m44*n.m41,g=e.m41*n.m12+e.m42*n.m22+e.m43*n.m32+e.m44*n.m42,_=e.m41*n.m13+e.m42*n.m23+e.m43*n.m33+e.m44*n.m43,v=e.m41*n.m14+e.m42*n.m24+e.m43*n.m34+e.m44*n.m44;i.m11=r,i.m12=o,i.m13=s,i.m14=a,i.m21=u,i.m22=c,i.m23=h,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=m,i.m41=y,i.m42=g,i.m43=_,i.m44=v},t.identity=new t(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),t}();t.Matrix=e}(es||(es={})),function(t){var e=function(){function e(){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0}return Object.defineProperty(e,"identity",{get:function(){return(new e).setIdentity()},enumerable:!0,configurable:!0}),e.prototype.setIdentity=function(){return this.setValues(1,0,0,1,0,0)},e.prototype.setValues=function(t,e,n,i,r,o){return this.m11=t,this.m12=e,this.m21=n,this.m22=i,this.m31=r,this.m32=o,this},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.m22=t.y},enumerable:!0,configurable:!0}),e.createRotation=function(t,e){e.setIdentity();var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-1*i,e.m22=n},e.createRotationOut=function(t,e){var n=Math.cos(t),i=Math.sin(t);e.m11=n,e.m12=i,e.m21=-i,e.m22=n},e.createScale=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createScaleOut=function(t,e,n){n.m11=t,n.m12=0,n.m21=0,n.m22=e,n.m31=0,n.m32=0},e.createTranslation=function(t,e,n){return n.m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=t,n.m32=e,n},e.createTranslationOut=function(t,e){e.m11=1,e.m12=0,e.m21=0,e.m22=1,e.m31=t.x,e.m32=t.y},e.invert=function(t){var e=1/t.determinant(),n=this.identity;return n.m11=t.m22*e,n.m12=-t.m12*e,n.m21=-t.m21*e,n.m22=t.m11*e,n.m31=(t.m32*t.m21-t.m31*t.m22)*e,n.m32=-(t.m32*t.m11-t.m31*t.m12)*e,n},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.multiply=function(t,e,n){var i=t.m11*e.m11+t.m12*e.m21,r=t.m11*e.m12+t.m12*e.m22,o=t.m21*e.m11+t.m22*e.m21,s=t.m21*e.m12+t.m22*e.m22,a=t.m31*e.m11+t.m32*e.m21+e.m31,u=t.m31*e.m12+t.m32*e.m22+e.m32;n.m11=i,n.m12=r,n.m21=o,n.m22=s,n.m31=a,n.m32=u},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,n){return t.m11=t.m11+(e.m11-t.m11)*n,t.m12=t.m12+(e.m12-t.m12)*n,t.m21=t.m21+(e.m21-t.m21)*n,t.m22=t.m22+(e.m22-t.m22)*n,t.m31=t.m31+(e.m31-t.m31)*n,t.m32=t.m32+(e.m32-t.m32)*n,t},e.transpose=function(t){var e=this.identity;return e.m11=t.m11,e.m12=t.m21,e.m21=t.m12,e.m22=t.m22,e.m31=0,e.m32=0,e},e.prototype.mutiplyTranslation=function(n,i){var r=new e;return e.createTranslation(n,i,r),t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var n=new t.Matrix;return n.m11=e.m11,n.m12=e.m12,n.m13=0,n.m14=0,n.m21=e.m21,n.m22=e.m22,n.m23=0,n.m24=0,n.m31=0,n.m32=0,n.m33=1,n.m34=0,n.m41=e.m31,n.m42=e.m32,n.m43=0,n.m44=1,n},e.prototype.toString=function(){return"{m11:"+this.m11+" m12:"+this.m12+" m21:"+this.m21+" m22:"+this.m22+" m31:"+this.m31+" m32:"+this.m32+"}"},e}();t.Matrix2D=e}(es||(es={})),function(t){var e=function(){function e(){}return e.add=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11+n.m11,i.m12=e.m12+n.m12,i.m21=e.m21+n.m21,i.m22=e.m22+n.m22,i.m31=e.m31+n.m31,i.m32=e.m32+n.m32,i},e.divide=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11/n.m11,i.m12=e.m12/n.m12,i.m21=e.m21/n.m21,i.m22=e.m22/n.m22,i.m31=e.m31/n.m31,i.m32=e.m32/n.m32,i},e.mutiply=function(e,n){var i=t.Matrix2D.identity;if(n instanceof t.Matrix2D){var r=e.m11*n.m11+e.m12*n.m21,o=n.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,u=e.m31*n.m11+e.m32*n.m21+n.m31,c=e.m31*n.m12+e.m32*n.m22+n.m32;i.m11=r,i.m12=o,i.m21=s,i.m22=a,i.m31=u,i.m32=c}else"number"==typeof n&&(i.m11=e.m11*n,i.m12=e.m12*n,i.m21=e.m21*n,i.m22=e.m22*n,i.m31=e.m31*n,i.m32=e.m32*n);return i},e.subtract=function(e,n){var i=t.Matrix2D.identity;return i.m11=e.m11-n.m11,i.m12=e.m12-n.m12,i.m21=e.m21-n.m21,i.m22=e.m22-n.m22,i.m31=e.m31-n.m31,i.m32=e.m32-n.m32,i},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(e,n,i,r){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),void 0===r&&(r=0),this.x=0,this.y=0,this.width=0,this.height=0,this._tempMat=new t.Matrix2D,this._transformMat=new t.Matrix2D,this.x=e,this.y=n,this.width=i,this.height=r}return Object.defineProperty(e,"empty",{get:function(){return new e},enumerable:!0,configurable:!0}),Object.defineProperty(e,"maxRect",{get:function(){return new e(Number.MIN_VALUE/2,Number.MIN_VALUE/2,Number.MAX_VALUE,Number.MAX_VALUE)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"max",{get:function(){return new t.Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),e.prototype.isEmpty=function(){return 0==this.width&&0==this.height&&0==this.x&&0==this.y},Object.defineProperty(e.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(e.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}),Object.defineProperty(e.prototype,"center",{get:function(){return new t.Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),e.fromMinMax=function(t,n,i,r){return new e(t,n,i-t,r-n)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,n=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;oi&&(i=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,n,i,r)},e.prototype.getSide=function(e){switch(e){case t.Edge.top:return this.top;case t.Edge.bottom:return this.bottom;case t.Edge.left:return this.left;case t.Edge.right:return this.right;default:throw new Error("Argument Out Of Range")}},e.prototype.contains=function(t,e){return this.x<=t&&tthis.x+this.width)return e}else{var i=1/t.direction.x,r=(this.x-t.start.x)*i,o=(this.x+this.width-t.start.x)*i;if(r>o){var s=r;r=o,o=s}if(e.distance=Math.max(r,e.distance),n=Math.min(o,n),e.distance>n)return e}if(Math.abs(t.direction.y)<1e-6){if(t.start.ythis.y+this.height)return e}else{var a=1/t.direction.y,u=(this.y-t.start.y)*a,c=(this.y+this.height-t.start.y)*a;if(u>c){var h=u;u=c,c=h}if(e.distance=Math.max(u,e.distance),n=Math.max(c,n),e.distance>n)return e}return e.intersected=!0,e},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,i.y=n>0?this.y:this.y+n,i.width=t>0?t+this.width:this.width-t,i.height=n>0?n+this.height:this.height-n,i},e.prototype.collisionCheck=function(t,e,n){e.value=n.value=0;var i=t.x-(this.x+this.width),r=t.x+t.width-this.x,o=t.y-(this.y+this.height),s=t.y+t.height-this.y;return!(i>0||r<0||o>0||s<0)&&(e.value=Math.abs(i)=l||Math.abs(h)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=h>0?p-h:-p-h;return new t.Vector2(f,d)},e.prototype.equals=function(t){return this===t},e.prototype.getHashCode=function(){return Math.trunc(this.x)^Math.trunc(this.y)^Math.trunc(this.width)^Math.trunc(this.height)},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e}();t.Rectangle=e}(es||(es={})),function(t){var e=function(){function t(){this.remainder=0}return t.prototype.update=function(t){this.remainder+=t;var e=Math.trunc(this.remainder);return this.remainder-=e,t=e},t.prototype.reset=function(){this.remainder=0},t}();t.SubpixelFloat=e}(es||(es={})),function(t){var e=function(){function e(){this._x=new t.SubpixelFloat,this._y=new t.SubpixelFloat}return e.prototype.update=function(t){t.x=this._x.update(t.x),t.y=this._y.update(t.y)},e.prototype.reset=function(){this._x.reset(),this._y.reset()},e}();t.SubpixelVector2=e}(es||(es={})),function(t){var e=function(){function e(e){this._activeTriggerIntersections=new t.PairSet,this._previousTriggerIntersections=new t.PairSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){var e=[],n=this.getColliders();if(n.length>0)for(var i=0;i=t.Collider.lateSortOrder?e.push(u):this.notifyTriggerListeners(u,!0)),this._activeTriggerIntersections.add(u)}}if(e.length>0)for(i=0;i0)for(var n=0;n0)for(var i=0;i0)for(var o=0;o1)return!1;var c=(a.x*r.y-a.y*r.x)/s;return!(c<0||c>1)},n.lineToLineIntersection=function(e,n,i,r,o){void 0===o&&(o=t.Vector2.zero),o.x=0,o.y=0;var s=n.sub(e),a=r.sub(i),u=s.x*a.y-s.y*a.x;if(0==u)return!1;var c=i.sub(e),h=(c.x*a.y-c.y*a.x)/u;if(h<0||h>1)return!1;var l=(c.x*s.y-c.y*s.x)/u;if(l<0||l>1)return!1;var p=e.add(s.scale(h));return o.x=p.x,o.y=p.y,!0},n.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scale(o))},n.circleToCircle=function(e,n,i,r){return t.Vector2.sqrDistance(e,i)<(n+r)*(n+r)},n.circleToLine=function(e,n,i,r){return t.Vector2.sqrDistance(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(e,n,i,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=n,this.distance=i,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setAllValues=function(t,e,n,i,r){this.collider=t,this.fraction=e,this.distance=n,this.point=i,this.normal=r},e.prototype.setValues=function(t,e,n,i){this.fraction=t,this.distance=e,this.point=n,this.normal=i},e.prototype.reset=function(){this.collider=null,this.fraction=this.distance=0},e.prototype.clone=function(){var t=new e;return t.setAllValues(this.collider,this.fraction,this.distance,this.point,this.normal),t},e.prototype.toString=function(){return"[RaycastHit] fraction: "+this.fraction+", distance: "+this.distance+", normal: "+this.normal+", centroid: "+this.centroid+", point: "+this.point},e}();t.RaycastHit=e}(es||(es={})),function(t){var e=function(){function e(){}return e.reset=function(){this._spatialHash=new t.SpatialHash(this.spatialHashCellSize),this._hitArray[0].reset(),this._colliderArray[0]=null},e.clear=function(){this._spatialHash.clear()},e.overlapCircle=function(t,n,i){return void 0===i&&(i=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapCircle(t,n,this._colliderArray,i),this._colliderArray[0]},e.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=this.allLayers),this._spatialHash.overlapCircle(t,e,n,i)},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.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var n=t.bounds;return this._spatialHash.aabbBroadphase(n,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,n,i,r){void 0===r&&(r=e.allLayers);var o=t.bounds.getSweptBroadphaseBounds(n,i);return this._spatialHash.aabbBroadphase(o,t,r)},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.linecast=function(t,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._hitArray[0].reset(),e.linecastAll(t,n,this._hitArray,i,r),this._hitArray[0]},e.linecastAll=function(t,e,n,i,r){return void 0===i&&(i=this.allLayers),void 0===r&&(r=null),this._spatialHash.linecast(t,e,n,i,r)},e.overlapRectangle=function(t,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,n),this._colliderArray[0]},e.overlapRectangleAll=function(t,n,i){return void 0===i&&(i=e.allLayers),0==n.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,n,i)},e.gravity=new t.Vector2(0,-300),e.spatialHashCellSize=100,e.allLayers=-1,e.raycastsHitTriggers=!1,e.raycastsStartInColliders=!1,e.debugRender=!1,e._hitArray=[new t.RaycastHit],e._colliderArray=[null],e}();t.Physics=e}(es||(es={})),function(t){var e=function(){function t(t,e){this._start=t.clone(),this._end=e.clone(),this._direction=this._end.sub(this._start)}return Object.defineProperty(t.prototype,"start",{get:function(){return this._start},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"direction",{get:function(){return this._direction},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"end",{get:function(){return this._end},enumerable:!0,configurable:!0}),t}();t.Ray2D=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=100),this.gridBounds=new t.Rectangle,this._overlapTestBox=new t.Box(0,0),this._overlapTestCircle=new t.Circle(0),this._cellDict=new n,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new i}return e.prototype.register=function(e){var n=e.bounds.clone();e.registeredPhysicsBounds=n;var i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom);this.gridBounds.contains(i.x,i.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,i)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(e){for(var n=e.registeredPhysicsBounds.clone(),i=this.cellCoords(n.x,n.y),r=this.cellCoords(n.right,n.bottom),o=i.x;o<=r.x;o++)for(var s=i.y;s<=r.y;s++){var a=this.cellAtPosition(o,s);t.Insist.isNotNull(a,"从不存在碰撞器的单元格中移除碰撞器: ["+e+"]"),null!=a&&new t.List(a).remove(e)}},e.prototype.removeWithBruteForce=function(t){this._cellDict.remove(t)},e.prototype.clear=function(){this._cellDict.clear()},e.prototype.aabbBroadphase=function(e,n,i){this._tempHashSet.clear();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 u=this.cellAtPosition(s,a);if(u&&u.length>0)for(var c=0;c0)for(var u=0;u=this.points.length?this.points[0]:this.points[i+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[i]=o}},n.buildSymmetricalPolygon=function(e,n){for(var i=new Array(e),r=0;ri&&(i=o,n=r)}return t[n]},n.getClosestPointOnPolygonToPoint=function(e,n){for(var i={distanceSquared:Number.MAX_VALUE,edgeNormal:t.Vector2.zero,closestPoint:t.Vector2.zero},r=0,o=0;ot.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},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.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;oi&&(n.copyFrom(r),i=o),r.setTo(-this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),r.setTo(this.width/2,-this.height/2),(o=r.dot(e))>i&&(n.copyFrom(r),i=o),n},n}(t.Polygon);t.Box=e}(es||(es={})),function(t){var e=function(e){function n(t){var n=e.call(this)||this;return n.radius=t,n._originalRadius=t,n}return __extends(n,e),n.prototype.recalculateBounds=function(e){if(this.center=e.localOffset,e.shouldColliderScaleAndRotateWithTransform){var n=e.entity.transform.scale,i=1===n.x&&1===n.y,r=Math.max(n.x,n.y);if(this.radius=this._originalRadius*r,0!==e.entity.transform.rotation){var o=Math.atan2(e.localOffset.y,e.localOffset.x)*t.MathHelper.Rad2Deg,s=i?e._localOffsetLength:e.localOffset.multiply(e.entity.transform.scale).magnitude();this.center=t.MathHelper.pointOnCircle(t.Vector2.zero,s,e.entity.transform.rotation+o)}}this.position=e.transform.position.add(this.center),this.bounds=new t.Rectangle(this.position.x-this.radius,this.position.y-this.radius,2*this.radius,2*this.radius)},n.prototype.overlaps=function(e){var i=new t.Out;if(e instanceof t.Box&&e.isUnrotated)return t.Collisions.rectToCircle(e.bounds,this.position,this.radius);if(e instanceof n)return t.Collisions.circleToCircle(this.position,this.radius,e.position,e.radius);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("overlaps of circle to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,i){if(e instanceof t.Box&&e.isUnrotated)return t.ShapeCollisionsCircle.circleToBox(this,e,i);if(e instanceof n)return t.ShapeCollisionsCircle.circleToCircle(this,e,i);if(e instanceof t.Polygon)return t.ShapeCollisionsCircle.circleToPolygon(this,e,i);throw new Error("Collisions of Circle to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){return t.ShapeCollisionsLine.lineToCircle(e,n,this,i)},n.prototype.getPointAlongEdge=function(e){return new t.Vector2(this.position.x+this.radius*Math.cos(e),this.position.y+this.radius*Math.sin(e))},n.prototype.containsPoint=function(t){return t.sub(this.position).lengthSquared()<=this.radius*this.radius},n.prototype.pointCollidesWithShape=function(e,n){return t.ShapeCollisionsPoint.pointToCircle(e,this,n)},n}(t.Shape);t.Circle=e}(es||(es={})),function(t){var e=function(){function e(){this.normal=t.Vector2.zero,this.minimumTranslationVector=t.Vector2.zero,this.point=t.Vector2.zero}return e.prototype.reset=function(){this.collider=null,this.normal.setTo(0,0),this.minimumTranslationVector.setTo(0,0),this.point&&this.point.setTo(0,0)},e.prototype.cloneTo=function(e){e.collider=this.collider,e.normal.setTo(this.normal.x,this.normal.y),e.minimumTranslationVector.setTo(this.minimumTranslationVector.x,this.minimumTranslationVector.y),this.point&&(e.point||(e.point=new t.Vector2(0,0)),e.point.setTo(this.point.x,this.point.y))},e.prototype.removeHorizontalTranslation=function(e){if(Math.sign(this.normal.x)!==Math.sign(e.x)||0===e.x&&0!==this.normal.x){var n=this.minimumTranslationVector.magnitude()/this.normal.y;1!=Math.abs(this.normal.x)&&Math.abs(n)this.end.dot(t)?this.start:this.end},e.prototype.getClosestPoint=function(t,e){var n=e.copyFrom(this.end).sub(this.start),i=t.sub(this.start).dot(n)/n.lengthSquared();return i<0?e.copyFrom(this.start):i>1?e.copyFrom(this.end):e.copyFrom(n).multiplyScaler(i).add(this.start)},e}();t.Line=e}(es||(es={})),function(t){var e=function(){function t(){this.min=Number.MAX_VALUE,this.max=-Number.MAX_VALUE}return t.prototype.project=function(t,e){for(var n=e.points,i=t.dot(n[0]),r=i,o=1;or&&(r=a)}this.min=i,this.max=r},t.prototype.overlap=function(t){return this.max>=t.min&&t.max>=this.min},t.prototype.getOverlap=function(t){return Math.min(this.max,t.max)-Math.max(this.min,t.min)},t}();t.Projection=e}(es||(es={})),function(t){var e=function(){function e(){}return e.intersectMovingCircleBox=function(e,n,i,r){var o=n.bounds;o.inflate(e.radius,e.radius);var s=new t.Ray2D(e.position.sub(i),e.position),a=o.rayIntersects(s);if(!a.intersected&&a.distance>1)return!1;var u,c=s.start.add(s.direction.scale(r)),h=0;c.xn.bounds.right&&(h|=1),c.yn.bounds.bottom&&(h|=2);var l=u+h;return 3==l&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,n){var i=t.Vector2.zero;return i.x=0==(1&n)?e.right:e.left,i.y=0==(1&n)?e.bottom:e.top,i},e.testCircleBox=function(t,e,n){var i=e.bounds.getClosestPointOnRectangleToPoint(t.position).sub(t.position);return i.dot(i)<=t.radius*t.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(e){function n(t,n,i,r){var o=e.call(this)||this;return o.center=t,o.radius=n,o.startAngle=i,o.endAngle=r,o.angle=r-i,o.radiusSquared=n*n,o.points=o.getPoints(),o.calculateProperties(),o}return __extends(n,e),Object.defineProperty(n.prototype,"sectorAngle",{get:function(){var t=this.endAngle-this.startAngle;return t<0&&(t+=360),t},enumerable:!0,configurable:!0}),n.prototype.getCentroid=function(){var e=(Math.cos(this.startAngle)+Math.cos(this.endAngle))*this.radius/3,n=(Math.sin(this.startAngle)+Math.sin(this.endAngle))*this.radius/3;return new t.Vector2(e+this.center.x,n+this.center.y)},n.prototype.getAngle=function(){return this.startAngle},n.prototype.recalculateBounds=function(e){var n=this.center.add(e.localOffset),i=n.x-this.radius,r=n.y-this.radius,o=2*this.radius,s=2*this.radius,a=new t.Rectangle(i,r,o,s);this.bounds=a,this.center=n},n.prototype.overlaps=function(e){var n=new t.Out;if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return!!t.ShapeCollisionSector.sectorToCircle(this,e,n)&&(n.value.invertResult(),!0);throw new Error("overlaps of Sector to "+e+" are not supported")},n.prototype.collidesWithShape=function(e,n){if(e instanceof t.Box)return t.ShapeCollisionSector.sectorToBox(this,e,n);if(e instanceof t.Polygon)return t.ShapeCollisionSector.sectorToPolygon(this,e,n);if(e instanceof t.Circle)return t.ShapeCollisionSector.sectorToCircle(this,e,n);throw new Error("overlaps of Polygon to "+e+" are not supported")},n.prototype.collidesWithLine=function(e,n,i){var r=e.sub(this.center),o=n.sub(this.center),s=r.getAngle(),a=o.getAngle()-s;if(a>Math.PI?a-=2*Math.PI:a<-Math.PI&&(a+=2*Math.PI),a>=this.startAngle&&a<=this.endAngle){var u=r.getLength(),c=this.startAngle-s,h=u*Math.cos(c),l=u*Math.sin(c),p=new t.Vector2(h,l);if(p.isBetween(e,n)){var f=p.sub(e).getLength(),d=f/e.getDistance(n),m=p.sub(this.center).normalize(),y=p.add(this.center),g=new t.RaycastHit;return g.setValues(d,f,y,m),i.value=g,!0}}return!1},n.prototype.containsPoint=function(t){var e=t.sub(this.center);if(e.lengthSquared()>this.radiusSquared)return!1;var n=e.getAngle(),i=this.startAngle,r=(this.angle,n-i);return r<0&&(r+=2*Math.PI),!(r>this.angle)},n.prototype.pointCollidesWithShape=function(e,n){return this.containsPoint(e)?(n&&(n.value=new t.CollisionResult,n.value.normal=e.sub(this.center).normalize(),n.value.minimumTranslationVector=n.value.normal.scale(this.radius-e.sub(this.center).getLength()),n.value.point=e),!0):(n&&(n.value=null),!1)},n.prototype.getPoints=function(){for(var e=new Array(this.numberOfPoints),n=0;nn&&(n=o,i.copyFrom(this.points[r]))}return i},n}(t.Shape);t.Sector=e}(es||(es={})),function(t){var e=function(){function e(){}return e.sectorToPolygon=function(e,n,i){for(var r=n.points.length,o=!1,s=new t.Vector2,a=new t.Vector2,u=new t.Out,c=0;c0)return!1;i.value&&Math.abs(c)e.radius*e.radius&&!a)return!1;if(a)s=i.value.normal.scale(Math.sqrt(o.distanceSquared)-e.radius);else if(0===o.distanceSquared)s=i.value.normal.scale(e.radius);else{var u=Math.sqrt(o.distanceSquared);s=r.sub(o.closestPoint).scale((e.radius-u)/u*-1)}return i.value.minimumTranslationVector=s,i.value.point=o.closestPoint.add(n.position),!0},e.closestPointOnLine=function(e,n,i){var r=n.sub(e),o=i.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scaleEqual(o))},e}();t.ShapeCollisionsCircle=e}(es||(es={})),function(t){var e=function(){function e(){}return e.lineToPoly=function(n,i,r,o){o.value=new t.RaycastHit;for(var s=t.Vector2.zero,a=t.Vector2.zero,u=Number.MAX_VALUE,c=!1,h=r.points.length-1,l=0;l1)return!1;var h=(u.x*o.y-u.y*o.x)/a;if(h<0||h>1)return!1;var l=t.add(o.scale(c));return r.x=l.x,r.y=l.y,!0},e.lineToCircle=function(e,n,i,r){r.value=new t.RaycastHit;var o=t.Vector2.distance(e,n),s=t.Vector2.divideScaler(n.sub(e),o),a=e.sub(i.position),u=a.dot(s),c=a.dot(a)-i.radius*i.radius;if(c>0&&u>0)return!1;var h=u*u-c;return!(h<0)&&(r.value.fraction=-u-Math.sqrt(h),r.value.fraction<0&&(r.value.fraction=0),r.value.point=e.add(s.scale(r.value.fraction)),r.value.distance=t.Vector2.distance(e,r.value.point),r.value.normal=r.value.point.sub(i.position).normalize(),r.value.fraction=r.value.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,n,i){i.value=new t.CollisionResult;var r=t.Vector2.sqrDistance(e,n.position),o=1+n.radius;if(r0&&(o=!1),!o)return!1;(p=Math.abs(p))i.max&&(i.max=n);return i},e.intervalDistance=function(t,e,n,i){return t=this._duration?(i=this._elapsedTime-this._duration,this._elapsedTime=this._duration,this._tweenState=n.complete):this._isRunningInReverse&&this._elapsedTime<=0&&(i=0-this._elapsedTime,this._elapsedTime=0,this._tweenState=n.complete),this._elapsedTime>=0&&this._elapsedTime<=this._duration&&this.updateValue(),this._loopType!=e.none&&this._tweenState==n.complete&&0!=this._loops&&this.handleLooping(i);var r=this._isTimeScaleIndependent?t.Time.unscaledDeltaTime:t.Time.deltaTime;return r*=this._timeScale,this._isRunningInReverse?this._elapsedTime-=r:this._elapsedTime+=r,this._tweenState==n.complete&&(this._completionHandler&&this._completionHandler(this),null!=this._nextTween&&(this._nextTween.start(),this._nextTween=null),!0)},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null)},i.prototype.isRunning=function(){return this._tweenState==n.running},i.prototype.start=function(){this._isFromValueOverridden||(this._fromValue=this._target.getTweenedValue()),this._tweenState==n.complete&&(this._tweenState=n.running,t.TweenManager.addTween(this))},i.prototype.pause=function(){this._tweenState=n.paused},i.prototype.resume=function(){this._tweenState=n.running},i.prototype.stop=function(i){void 0===i&&(i=!1),this._tweenState=n.complete,i?(this._elapsedTime=this._isRunningInReverse?0:this._duration,this._loopType=e.none,this._loops=0):t.TweenManager.removeTween(this)},i.prototype.jumpToElapsedTime=function(e){this._elapsedTime=t.MathHelper.clamp(e,0,this._duration),this.updateValue()},i.prototype.reverseTween=function(){this._isRunningInReverse=!this._isRunningInReverse},i.prototype.waitForCompletion=function(){return __generator(this,function(t){switch(t.label){case 0:return this._tweenState==n.complete?[3,2]:[4,null];case 1:return t.sent(),[3,0];case 2:return[2]}})},i.prototype.getTargetObject=function(){return this._target.getTargetObject()},i.prototype.resetState=function(){this.context=null,this._completionHandler=this._loopCompleteHandler=null,this._isFromValueOverridden=!1,this._isTimeScaleIndependent=!1,this._tweenState=n.complete,this._isRelative=!1,this._easeType=t.TweenManager.defaultEaseType,null!=this._nextTween&&(this._nextTween.recycleSelf(),this._nextTween=null),this._delay=0,this._duration=0,this._timeScale=1,this._elapsedTime=0,this._loopType=e.none,this._delayBetweenLoops=0,this._loops=0,this._isRunningInReverse=!1},i.prototype.initialize=function(t,e,n){this.resetState(),this._target=t,this._toValue=e,this._duration=n},i.prototype.handleLooping=function(t){this._loops--,this._loopType==e.pingpong&&this.reverseTween(),this._loopType!=e.restartFromBeginning&&this._loops%2!=0||this._loopCompleteHandler&&this._completionHandler(this),0!=this._loops&&(this._tweenState=n.running,this._loopType==e.restartFromBeginning?this._elapsedTime=t-this._delayBetweenLoops:this._isRunningInReverse?this._elapsedTime+=this._delayBetweenLoops-t:this._elapsedTime=t-this._delayBetweenLoops,0==this._delayBetweenLoops&&t>0&&this.updateValue())},i}();t.Tween=i}(es||(es={})),function(t){var e=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheNumberTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue+=this._fromValue,this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheNumberTweens&&t.Pool.free(n,this)},n}(t.Tween);t.NumberTween=e;var n=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheVector2Tweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue.add(this._fromValue),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheVector2Tweens&&t.Pool.free(n,this)},n}(t.Tween);t.Vector2Tween=n;var i=function(e){function n(t,n,i){var r=e.call(this)||this;return r.initialize(t,n,i),r}return __extends(n,e),n.create=function(){return t.TweenManager.cacheRectTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue=new t.Rectangle(this._toValue.x+this._fromValue.x,this._toValue.y+this._fromValue.y,this._toValue.width+this._fromValue.width,this._toValue.height+this._fromValue.height),this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.recycleSelf=function(){e.prototype.recycleSelf.call(this),this._shouldRecycleTween&&t.TweenManager.cacheRectTweens&&t.Pool.free(n,this)},n}(t.Tween);t.RectangleTween=i}(es||(es={})),function(t){var e;!function(t){t[t.position=0]="position",t[t.localPosition=1]="localPosition",t[t.scale=2]="scale",t[t.localScale=3]="localScale",t[t.rotationDegrees=4]="rotationDegrees",t[t.localRotationDegrees=5]="localRotationDegrees"}(e=t.TransformTargetType||(t.TransformTargetType={}));var n=function(n){function i(){return null!==n&&n.apply(this,arguments)||this}return __extends(i,n),i.prototype.setTweenedValue=function(t){switch(this._targetType){case e.position:this._transform.position=t;break;case e.localPosition:this._transform.localPosition=t;break;case e.scale:this._transform.scale=t;break;case e.localScale:this._transform.localScale=t;break;case e.rotationDegrees:this._transform.rotationDegrees=t.x;case e.localRotationDegrees:this._transform.localRotationDegrees=t.x}},i.prototype.getTweenedValue=function(){switch(this._targetType){case e.position:return this._transform.position;case e.localPosition:return this._transform.localPosition;case e.scale:return this._transform.scale;case e.localScale:return this._transform.localScale;case e.rotationDegrees:return new t.Vector2(this._transform.rotationDegrees,this._transform.rotationDegrees);case e.localRotationDegrees:return new t.Vector2(this._transform.localRotationDegrees,0)}},i.prototype.getTargetObject=function(){return this._transform},i.prototype.setTargetAndType=function(t,e){this._transform=t,this._targetType=e},i.prototype.updateValue=function(){this._targetType!=e.rotationDegrees&&this._targetType!=e.localRotationDegrees||this._isRelative?this.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration)):this.setTweenedValue(t.Lerps.easeAngle(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},i.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._target=null,this._nextTween=null,this._transform=null,t.Pool.free(t.Vector2Tween,this))},i}(t.Vector2Tween);t.TransformVector2Tween=n}(es||(es={})),function(t){var e;!function(t){t[t.linear=0]="linear",t[t.sineIn=1]="sineIn",t[t.sineOut=2]="sineOut",t[t.sineInOut=3]="sineInOut",t[t.quadIn=4]="quadIn",t[t.quadOut=5]="quadOut",t[t.quadInOut=6]="quadInOut",t[t.quintIn=7]="quintIn",t[t.quintOut=8]="quintOut",t[t.quintInOut=9]="quintInOut",t[t.cubicIn=10]="cubicIn",t[t.cubicOut=11]="cubicOut",t[t.cubicInOut=12]="cubicInOut",t[t.quartIn=13]="quartIn",t[t.quartOut=14]="quartOut",t[t.quartInOut=15]="quartInOut",t[t.expoIn=16]="expoIn",t[t.expoOut=17]="expoOut",t[t.expoInOut=18]="expoInOut",t[t.circleIn=19]="circleIn",t[t.circleOut=20]="circleOut",t[t.circleInOut=21]="circleInOut",t[t.elasticIn=22]="elasticIn",t[t.elasticOut=23]="elasticOut",t[t.elasticInOut=24]="elasticInOut",t[t.punch=25]="punch",t[t.backIn=26]="backIn",t[t.backOut=27]="backOut",t[t.backInOut=28]="backInOut",t[t.bounceIn=29]="bounceIn",t[t.bounceOut=30]="bounceOut",t[t.bounceInOut=31]="bounceInOut"}(e=t.EaseType||(t.EaseType={}));var n=function(){function n(){}return n.oppositeEaseType=function(t){switch(t){case e.linear:return t;case e.backIn:return e.backOut;case e.backOut:return e.backIn;case e.backInOut:return t;case e.bounceIn:return e.bounceOut;case e.bounceOut:return e.bounceIn;case e.bounceInOut:return t;case e.circleIn:return e.circleOut;case e.circleOut:return e.circleIn;case e.circleInOut:return t;case e.cubicIn:return e.cubicOut;case e.cubicOut:return e.cubicIn;case e.circleInOut:case e.punch:return t;case e.expoIn:return e.expoOut;case e.expoOut:return e.expoIn;case e.expoInOut:return t;case e.quadIn:return e.quadOut;case e.quadOut:return e.quadIn;case e.quadInOut:return t;case e.quartIn:return e.quadOut;case e.quartOut:return e.quartIn;case e.quadInOut:return t;case e.sineIn:return e.sineOut;case e.sineOut:return e.sineIn;case e.sineInOut:default:return t}},n.ease=function(n,i,r){switch(n){case e.linear:return t.Easing.Linear.easeNone(i,r);case e.backIn:return t.Easing.Back.easeIn(i,r);case e.backOut:return t.Easing.Back.easeOut(i,r);case e.backInOut:return t.Easing.Back.easeInOut(i,r);case e.bounceIn:return t.Easing.Bounce.easeIn(i,r);case e.bounceOut:return t.Easing.Bounce.easeOut(i,r);case e.bounceInOut:return t.Easing.Bounce.easeInOut(i,r);case e.circleIn:return t.Easing.Circular.easeIn(i,r);case e.circleOut:return t.Easing.Circular.easeOut(i,r);case e.circleInOut:return t.Easing.Circular.easeInOut(i,r);case e.cubicIn:return t.Easing.Cubic.easeIn(i,r);case e.cubicOut:return t.Easing.Cubic.easeOut(i,r);case e.cubicInOut:return t.Easing.Cubic.easeInOut(i,r);case e.elasticIn:return t.Easing.Elastic.easeIn(i,r);case e.elasticOut:return t.Easing.Elastic.easeOut(i,r);case e.elasticInOut:return t.Easing.Elastic.easeInOut(i,r);case e.punch:return t.Easing.Elastic.punch(i,r);case e.expoIn:return t.Easing.Exponential.easeIn(i,r);case e.expoOut:return t.Easing.Exponential.easeOut(i,r);case e.expoInOut:return t.Easing.Exponential.easeInOut(i,r);case e.quadIn:return t.Easing.Quadratic.easeIn(i,r);case e.quadOut:return t.Easing.Quadratic.easeOut(i,r);case e.quadInOut:return t.Easing.Quadratic.easeInOut(i,r);case e.quintIn:return t.Easing.Quintic.easeIn(i,r);case e.quintOut:return t.Easing.Quintic.easeOut(i,r);case e.quintInOut:return t.Easing.Quintic.easeInOut(i,r);case e.sineIn:return t.Easing.Sinusoidal.easeIn(i,r);case e.sineOut:return t.Easing.Sinusoidal.easeOut(i,r);case e.sineInOut:return t.Easing.Sinusoidal.easeInOut(i,r);default:return t.Easing.Linear.easeNone(i,r)}},n}();t.EaseHelper=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(e){function n(){var t=e.call(this)||this;return t._activeTweens=[],t._tempTweens=[],n._instance=t,t}return __extends(n,e),Object.defineProperty(n,"activeTweens",{get:function(){return this._instance._activeTweens},enumerable:!0,configurable:!0}),n.prototype.update=function(){this._isUpdating=!0;for(var e=this._activeTweens.length-1;e>=0;--e){var n=this._activeTweens[e];n.tick()&&this._tempTweens.push(n)}this._isUpdating=!1;for(e=0;e=0;--e)n._instance._activeTweens[e].stop(t)},n.allTweensWithContext=function(t){for(var e=[],i=0;i=0;--i)n._instance._activeTweens[i].context==t&&n._instance._activeTweens[i].stop(e)},n.allTweenWithTarget=function(t){for(var e=[],i=0;i=0;--i)if(n._instance._activeTweens[i]){var r=n._instance._activeTweens[i];r.getTargetObject()==t&&r.stop(e)}},n.defaultEaseType=t.EaseType.quartIn,n.removeAllTweensOnLevelLoad=!1,n.cacheNumberTweens=!0,n.cacheVector2Tweens=!0,n.cacheColorTweens=!0,n.cacheRectTweens=!1,n}(t.GlobalManager);t.TweenManager=e}(es||(es={})),function(t){!function(t){var e=function(){function t(){}return t.easeNone=function(t,e){return t/e},t}();t.Linear=e;var n=function(){function t(){}return t.easeIn=function(t,e){return(t/=e)*t},t.easeOut=function(t,e){return-1*(t/=e)*(t-2)},t.easeInOut=function(t,e){return(t/=e/2)<1?.5*t*t:-.5*(--t*(t-2)-1)},t}();t.Quadratic=n;var i=function(){function t(){}return t.easeIn=function(t,e){return(t/=e)*t*(2.70158*t-1.70158)},t.easeOut=function(t,e){return(t=t/e-1)*t*(2.70158*t+1.70158)+1},t.easeInOut=function(t,e){var n=1.70158;return(t/=e/2)<1?t*t*((1+(n*=1.525))*t-n)*.5:.5*((t-=2)*t*((1+(n*=1.525))*t+n)+2)},t}();t.Back=i;var r=function(){function t(){}return t.easeOut=function(t,e){return(t/=e)<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},t.easeIn=function(t,e){return 1-this.easeOut(e-t,e)},t.easeInOut=function(t,e){return t= 2");if(t.sort(function(t,e){return t.t-e.t}),0!==t[0].t)throw new Error("curve must start with 0");if(1!==t[t.length-1].t)throw new Error("curve must end with 1");this._points=t}return Object.defineProperty(e.prototype,"points",{get:function(){return this._points},enumerable:!0,configurable:!0}),e.prototype.lerp=function(e){for(var n=1;n=0;o--)(e=r[o].func).call.apply(e,__spread([r[o].context],n))},n}();t.Emitter=n}(es||(es={})),function(t){!function(t){t[t.top=0]="top",t[t.bottom=1]="bottom",t[t.left=2]="left",t[t.right=3]="right"}(t.Edge||(t.Edge={}))}(es||(es={})),function(t){var e=function(){function t(){}return t.default=function(){return new t},t.prototype.equals=function(t,e){return"function"==typeof t.equals?t.equals(e):t===e},t.prototype.getHashCode=function(t){var e=this;if("number"==typeof t)return this._getHashCodeForNumber(t);if("string"==typeof t)return this._getHashCodeForString(t);var n=385229220;return this.forOwn(t,function(t){"number"==typeof t?n+=e._getHashCodeForNumber(t):"string"==typeof t?n+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){n+=e.getHashCode(t)})}),n},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,n=0;n>7,n+=n<<3,n^=n>>17,n+=n<<5},t}();t.Hash=e}(es||(es={})),function(t){var e=function(){function t(){this._listeners=[]}return t.prototype.addListener=function(t,e){-1===this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t})&&this._listeners.push({caller:t,callback:e})},t.prototype.removeListener=function(t,e){var n=this._listeners.findIndex(function(n){return n.callback===e&&n.caller===t});n>=0&&this._listeners.splice(n,1)},t.prototype.clearListener=function(){this._listeners=[]},t.prototype.clearListenerWithCaller=function(t){for(var e=this._listeners.length-1;e>=0;e--){this._listeners[e].caller===t&&this._listeners.splice(e,1)}},t.prototype.notify=function(){for(var t,e=[],n=0;n=0;i--){var r=this._listeners[i];r.caller?(t=r.callback).call.apply(t,__spread([r.caller],e)):r.callback.apply(r,__spread(e))}},t}();t.Observable=e;var n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e){t.prototype.notify.call(this,e)},e}(e);t.ObservableT=n;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,n){t.prototype.addListener.call(this,e,n)},e.prototype.removeListener=function(e,n){t.prototype.removeListener.call(this,e,n)},e.prototype.notify=function(e,n){t.prototype.notify.call(this,e,n)},e}(e);t.ObservableTT=i;var r=function(){function t(t,n){this.bindAction(t,n),this._onExec=new e}return t.prototype.bindAction=function(t,e){this._caller=t,this._action=e},t.prototype.dispatch=function(){for(var t,e=[],n=0;n3&&o<500;){o++;var a=!0,u=n[this._triPrev[s]],c=n[s],h=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(u,c,h)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],u,c,h)){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.length>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&n]+e[n>>8&255]+"-"+e[n>>16&15|64]+e[n>>24&255]+"-"+e[63&i|128]+e[i>>8&255]+"-"+e[i>>16&255]+e[i>>24&255]+e[255&r]+e[r>>8&255]+e[r>>16&255]+e[r>>24&255]},t}();t.UUID=n}(es||(es={})),function(t){t.getClassName=function(t){return t.className||t.name}}(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 __spread(this._completeSlices,[this.getPendingSlice()])},t.prototype.getPendingSlice=function(){return this.calculatePendingSlice()},t.prototype.getTime=function(){return this.caculateStopwatchTime()},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.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.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}(es||(es={})),function(t){var e=function(){function t(t){void 0===t&&(t=64),this.size_=0,this.length=0,this.array=[],this.length=t}return t.prototype.removeAt=function(t){var e=this.array[t];return this.array[t]=this.array[--this.size_],this.array[this.size_]=null,e},t.prototype.remove=function(t){var e,n=this.size_;for(e=0;e0){var t=this.array[--this.size_];return this.array[this.size_]=null,t}return null},t.prototype.contains=function(t){var e,n;for(e=0,n=this.size_;n>e;e++)if(t===this.array[e])return!0;return!1},t.prototype.removeAll=function(t){var e,n,i,r,o=!1;for(e=0,i=t.size();e=this.length)throw new Error("ArrayIndexOutOfBoundsException");return this.array[t]},t.prototype.safeGet=function(t){return t>=this.length&&this.grow(7*t/4+1),this.array[t]},t.prototype.size=function(){return this.size_},t.prototype.getCapacity=function(){return this.length},t.prototype.isIndexWithinBounds=function(t){return t=this.length&&this.grow(2*t),this.size_=t+1,this.array[t]=e},t.prototype.grow=function(t){void 0===t&&(t=1+~~(3*this.length/2)),this.length=~~t},t.prototype.ensureCapacity=function(t){t>=this.length&&this.grow(2*t)},t.prototype.clear=function(){var t,e;for(t=0,e=this.size_;te;e++)this.add(t.get(e))},t}();t.Bag=e}(es||(es={})),function(t){var e=function(){function e(e){void 0===e&&(e=1),this._freeValueCellIndex=0,this._collisions=0,this._valuesInfo=new Array(e),this._values=new Array(e),this._buckets=new Array(t.HashHelpers.getPrime(e))}return e.prototype.getValuesArray=function(t){return t.value=this._freeValueCellIndex,this._values},Object.defineProperty(e.prototype,"valuesArray",{get:function(){return this._values},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"count",{get:function(){return this._freeValueCellIndex},enumerable:!0,configurable:!0}),e.prototype.add=function(t,e){if(!this.addValue(t,e,{value:0}))throw new Error("key 已经存在")},e.prototype.addValue=function(i,r,o){var s=t.HashHelpers.getHashCode(i),a=e.reduce(s,this._buckets.length);if(this._freeValueCellIndex==this._values.length){var u=t.HashHelpers.expandPrime(this._freeValueCellIndex);this._values.length=u,this._valuesInfo.length=u}var c=t.NumberExtension.toNumber(this._buckets[a])-1;if(-1==c)this._valuesInfo[this._freeValueCellIndex]=new n(i,s);else{var h=c;do{if(this._valuesInfo[h].hashcode==s&&this._valuesInfo[h].key==i)return this._values[h]=r,o.value=h,!1;h=this._valuesInfo[h].previous}while(-1!=h);this._collisions++,this._valuesInfo[this._freeValueCellIndex]=new n(i,s,c),this._valuesInfo[c].next=this._freeValueCellIndex}if(this._buckets[a]=this._freeValueCellIndex+1,this._values[this._freeValueCellIndex]=r,o.value=this._freeValueCellIndex,this._freeValueCellIndex++,this._collisions>this._buckets.length){this._buckets=new Array(t.HashHelpers.expandPrime(this._collisions)),this._collisions=0;for(var l=0;l=e?t%e:t},e}();t.FasterDictionary=e;var n=function(){return function(t,e,n){void 0===n&&(n=-1),this.key=t,this.hashcode=e,this.previous=n,this.next=-1}}();t.FastNode=n}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function n(t,e){return t===e}t.Node=e,t.defaultEquals=n;var i=function(){function t(t){void 0===t&&(t=n),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var n,i=new e(t);if(null==this.head)this.head=i;else{for(n=this.head;null!=n.next;)n=n.next;n.next=i}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,n=0;n=0&&n<=this.count){var i=new e(t);if(0===n)i.next=this.head,this.head=i;else{var r=this.getElementAt(n-1);i.next=r.next,r.next=i}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,n=0;n0)for(var n=0;nthis._objectQueue.get(t).length;)this._objectQueue.get(t).splice(0,1)},t.clearCache=function(t){this.checkCreate(t),this._objectQueue.get(t).length=0},t.obtain=function(t){return this.checkCreate(t),this._objectQueue.get(t).length>0?this._objectQueue.get(t).shift():[]},t.free=function(t,e){this.checkCreate(t),this._objectQueue.get(t).push(e),e.length=0},t.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},t._objectQueue=new Map,t}();t.ListPool=e}(es||(es={})),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={})),function(t){var e=function(){function t(){this._all=new Array}return Object.defineProperty(t.prototype,"all",{get:function(){return this._all},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return this._all.findIndex(function(e){return e.equals(t)})>-1},t.prototype.add=function(t){this.has(t)||this._all.push(t)},t.prototype.remove=function(t){var e=this._all.findIndex(function(e){return e.equals(t)});if(e>-1){var n=this._all[e];this._all[e]=this._all[this._all.length-1],this._all[this._all.length-1]=n,this._all=this._all.slice(0,this._all.length-1)}},t.prototype.clear=function(){this._all=[]},t.prototype.union=function(t){var e=t.all;if(e.length>0)for(var n=0;n0)for(var n=0;n0)for(var n=0;nthis._objectQueue.get(t).length;)this._objectQueue.get(t).splice(0,1)},e.clearCache=function(t){this.checkCreate(t),this._objectQueue.get(t).length=0},e.obtain=function(t){return this.checkCreate(t),this._objectQueue.get(t).length>0?this._objectQueue.get(t).shift():new t},e.free=function(e,n){this.checkCreate(e),this._objectQueue.get(e).push(n),t.isIPoolable(n)&&n.reset()},e.checkCreate=function(t){this._objectQueue.has(t)||this._objectQueue.set(t,[])},e._objectQueue=new Map,e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(){function t(){}return t.waitForSeconds=function(t){return n.waiter.wait(t)},t}();t.Coroutine=e;var n=function(){function t(){this.waitTime=0}return t.prototype.wait=function(e){return t.waiter.waitTime=e,t.waiter},t.waiter=new t,t}();t.WaitForSeconds=n}(es||(es={})),function(t){var e=function(){function t(){this.waitTimer=0,this.useUnscaledDeltaTime=!1}return t.prototype.stop=function(){this.isDone=!0},t.prototype.setUseUnscaledDeltaTime=function(t){return this.useUnscaledDeltaTime=t,this},t.prototype.prepareForUse=function(){this.isDone=!1},t.prototype.reset=function(){this.isDone=!0,this.waitTimer=0,this.waitForCoroutine=null,this.enumerator=null,this.useUnscaledDeltaTime=!1},t}();t.CoroutineImpl=e;var n=function(n){function i(){var t=null!==n&&n.apply(this,arguments)||this;return t._unblockedCoroutines=[],t._shouldRunNextFrame=[],t}return __extends(i,n),i.prototype.clearAllCoroutines=function(){for(var n=0;n0?(i.waitTimer-=i.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(i)):this.tickCoroutine(i)&&this._shouldRunNextFrame.push(i)}}var r=new t.List(this._unblockedCoroutines);r.clear(),r.addRange(this._shouldRunNextFrame),this._shouldRunNextFrame.length=0,this._isInUpdate=!1},i.prototype.tickCoroutine=function(n){var i=n.enumerator.next();return i.done||n.isDone?(t.Pool.free(e,n),!1):null==i.value||(i.value instanceof t.WaitForSeconds?(n.waitTimer=i.value.waitTime,!0):"number"==typeof i.value?(n.waitTimer=i.value,!0):"string"==typeof i.value?"break"!=i.value||(t.Pool.free(e,n),!1):"function"==typeof i.value?(n.waitForCoroutine=this.startCoroutine(i.value),!0):!(i.value instanceof e)||(n.waitForCoroutine=i.value,!0))},i}(t.GlobalManager);t.CoroutineManager=n}(es||(es={})),function(t){var e=function(){function e(t,e,n){void 0===n&&(n=!0),this.binWidth=0,this.binHeight=0,this.usedRectangles=[],this.freeRectangles=[],this.init(t,e,n)}return e.prototype.init=function(e,n,i){void 0===i&&(i=!0),this.binWidth=e,this.binHeight=n,this.allowRotations=i;var r=new t.Rectangle;r.x=0,r.y=0,r.width=e,r.height=n,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(r)},e.prototype.insert=function(e,n){var i=new t.Rectangle,r=new t.Ref(0),o=new t.Ref(0);if(0==(i=this.findPositionForNewNodeBestAreaFit(e,n,r,o)).height)return i;for(var s=this.freeRectangles.length,a=0;a=e&&this.freeRectangles[s].height>=n){var u=Math.abs(this.freeRectangles[s].width-e),c=Math.abs(this.freeRectangles[s].height-n),h=Math.min(u,c);(a=n&&this.freeRectangles[s].height>=e){u=Math.abs(this.freeRectangles[s].width-n),c=Math.abs(this.freeRectangles[s].height-e),h=Math.min(u,c);(a=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y)return!1;if(e.xt.x){if(e.y>t.y&&e.yt.y){var n;if(e.x>t.x&&e.x=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height},e}();t.MaxRectsBinPack=e}(es||(es={})),function(t){var e=function(){function e(){}return e.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}},e.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},e.findElementIndex=function(t,e){for(var n=t.length,i=0;it[e]&&(e=i);return e},e.getMinElementIndex=function(t){for(var e=0,n=t.length,i=1;i=0;--r)n.unshift(e[r]);return n},e.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var n=t.concat(e),i={},r=[],o=n.length,s=0;s=0;e-=1)t.splice(e,1)},e.cloneList=function(t){return t?t.slice(0,t.length):null},e.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},e.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},e.shuffle=function(e){for(var n=e.length;n>1;){n--;var i=t.RandomUtils.randint(0,n+1),r=e[i];e[i]=e[n],e[n]=r}},e.addIfNotPresent=function(e,n){return!new t.List(e).contains(n)&&(e.push(n),!0)},e.lastItem=function(t){return t[t.length-1]},e.randomItem=function(e){return e[t.RandomUtils.randint(0,e.length-1)]},e.randomItems=function(e,n,i){for(var r=new Set;r.size!=i;){var o=this.randomItem(n);r.has(o)||r.add(o)}var s=t.ListPool.obtain(e);return r.forEach(function(t){return s.push(t)}),s},e}();t.ArrayUtils=e}(es||(es={})),function(t){var e=function(){function t(){}return Object.defineProperty(t,"nativeBase64",{get:function(){return"function"==typeof window.atob},enumerable:!0,configurable:!0}),t.decode=function(t){if(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),this.nativeBase64)return window.atob(t);for(var e,n,i,r,o,s,a=[],u=0;u>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(u++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(u++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(n)),64!==s&&a.push(String.fromCharCode(i));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,n,i,r,o,s,a,u=[],c=0;c>2,o=(3&e)<<4|(n=t.charCodeAt(c++))>>4,s=(15&n)<<2|(i=t.charCodeAt(c++))>>6,a=63&i,isNaN(n)?s=a=64:isNaN(i)&&(a=64),u.push(this._keyStr.charAt(r)),u.push(this._keyStr.charAt(o)),u.push(this._keyStr.charAt(s)),u.push(this._keyStr.charAt(a));return u=u.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,n){n=n||1;var i,r,o,s=t.decode(e),a=new Uint32Array(s.length/n);for(i=0,o=s.length/n;i=0;--r)a[i]+=s.charCodeAt(i*n+r)<<(r<<3);return a},t.decompress=function(t,e,n){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),n=[],i=0;i(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.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().5?1:-1},t}();t.RandomUtils=e}(es||(es={})),function(t){var e=function(){function e(){}return e.getSide=function(e,n){switch(n){case t.Edge.top:return e.top;case t.Edge.bottom:return e.bottom;case t.Edge.left:return e.left;case t.Edge.right:return e.right}},e.union=function(e,n){var i=new t.Rectangle(n.x,n.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,i.x),r.y=Math.min(e.y,i.y),r.width=Math.max(e.right,i.right)-r.x,r.height=Math.max(e.bottom,i.bottom)-r.y,r},e.getHalfRect=function(e,n){switch(n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,e.height/2);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height/2,e.width,e.height/2);case t.Edge.left:return new t.Rectangle(e.x,e.y,e.width/2,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width/2,e.y,e.width/2,e.height)}},e.getRectEdgePortion=function(e,n,i){switch(void 0===i&&(i=1),n){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,i);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-i,e.width,i);case t.Edge.left:return new t.Rectangle(e.x,e.y,i,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-i,e.y,i,e.height)}},e.expandSide=function(e,n,i){switch(i=Math.abs(i),n){case t.Edge.top:e.y-=i,e.height+=i;break;case t.Edge.bottom:e.height+=i;break;case t.Edge.left:e.x-=i,e.width+=i;break;case t.Edge.right:e.width+=i}},e.contract=function(t,e,n){t.x+=e,t.y+=n,t.width-=2*e,t.height-=2*n},e.boundsFromPolygonVector=function(e){for(var n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY,s=0;sr&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(n,i),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,n){return new t.Rectangle(e.x,e.y,n.x-e.x,n.y-e.y)},e.getSweptBroadphaseBounds=function(e,n,i){var r=t.Rectangle.empty;return r.x=n>0?e.x:e.x+n,r.y=i>0?e.y:e.y+i,r.width=n>0?n+e.width:e.width-n,r.height=i>0?i+e.height:e.height-i,r},e.prototype.collisionCheck=function(t,e,n,i){n.value=i.value=0;var r=e.x-(t.x+t.width),o=e.x+e.width-t.x,s=e.y-(t.y+t.height),a=e.y+e.height-t.y;return!(r>0||o<0||s>0||a<0)&&(n.value=Math.abs(r)=l||Math.abs(h)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=h>0?p-h:-p-h;return new t.Vector2(f,d)},e.getClosestPointOnBoundsToOrigin=function(e){var n=this.getMax(e),i=Math.abs(e.location.x),r=new t.Vector2(e.location.x,0);return Math.abs(n.x)r&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(t.MathHelper.toInt(n),t.MathHelper.toInt(i)),new t.Vector2(t.MathHelper.toInt(r),t.MathHelper.toInt(o)))},e.calculateBounds=function(e,n,i,r,o,s,a,u){if(0==s)e.x=t.MathHelper.toInt(n.x+i.x-r.x*o.x),e.y=t.MathHelper.toInt(n.y+i.y-r.y*o.y),e.width=t.MathHelper.toInt(a*o.x),e.height=t.MathHelper.toInt(u*o.y);else{var c=n.x+i.x,h=n.y+i.y,l=new t.Matrix2D;t.Matrix2D.createTranslation(-c-r.x,-h-r.y,l),t.Matrix2D.createScale(o.x,o.y,void 0),l=l.multiply(void 0),t.Matrix2D.createRotation(s,void 0),l=l.multiply(void 0),t.Matrix2D.createTranslation(c,h,void 0),l=l.multiply(void 0);var p=new t.Vector2(c,h),f=new t.Vector2(c+a,h),d=new t.Vector2(c,h+u),m=new t.Vector2(c+a,h+u);t.Vector2Ext.transformR(p,l,p),t.Vector2Ext.transformR(f,l,f),t.Vector2Ext.transformR(d,l,d),t.Vector2Ext.transformR(m,l,m);var y=t.MathHelper.toInt(Math.min(p.x,m.x,f.x,d.x)),g=t.MathHelper.toInt(Math.max(p.x,m.x,f.x,d.x)),_=t.MathHelper.toInt(Math.min(p.y,m.y,f.y,d.y)),v=t.MathHelper.toInt(Math.max(p.y,m.y,f.y,d.y));e.location=new t.Vector2(y,_),e.width=t.MathHelper.toInt(g-y),e.height=t.MathHelper.toInt(v-_)}},e.scale=function(e,n){e.x=t.MathHelper.toInt(e.x*n.x),e.y=t.MathHelper.toInt(e.y*n.y),e.width=t.MathHelper.toInt(e.width*n.x),e.height=t.MathHelper.toInt(e.height*n.y)},e.translate=function(t,e){t.location.addEqual(e)},e}();t.RectangleExt=e}(es||(es={})),function(t){var e=function(){function t(){}return t.premultiplyAlpha=function(t){for(var e=t[0],n=0;nt.MathHelper.Epsilon?e.divideScaler(n):e.x=e.y=0},e.transformA=function(t,e,n,i,r,o){for(var s=0;so?e?-1:1:r0},e.prototype.average=function(t){return this.sum(t)/this.count(t)},e.prototype.cast=function(){return new e(this._elements)},e.prototype.clear=function(){this._elements.length=0},e.prototype.concat=function(t){return new e(this._elements.concat(t.toArray()))},e.prototype.contains=function(t){return this.any(function(e){return e===t})},e.prototype.count=function(t){return t?this.where(t).count():this._elements.length},e.prototype.defaultIfEmpty=function(t){return this.count()?this:new e([t])},e.prototype.distinctBy=function(t){var n=this.groupBy(t);return Object.keys(n).reduce(function(t,e){return t.add(n[e][0]),t},new e)},e.prototype.elementAt=function(t){if(t=0)return this._elements[t];throw new Error("ArgumentOutOfRangeException: index is less than 0 or greater than or equal to the number of elements in source.")},e.prototype.elementAtOrDefault=function(t){return t=0?this._elements[t]:void 0},e.prototype.except=function(t){return this.where(function(e){return!t.contains(e)})},e.prototype.first=function(t){if(this.count())return t?this.where(t).first():this._elements[0];throw new Error("InvalidOperationException: The source sequence is empty.")},e.prototype.firstOrDefault=function(t){return this.count(t)?this.first(t):void 0},e.prototype.forEach=function(t){return this._elements.forEach(t)},e.prototype.groupBy=function(t,e){void 0===e&&(e=function(t){return t});return this.aggregate(function(n,i){var r=t(i),o=n[r],s=e(i);return o?o.push(s):n[r]=[s],n},{})},e.prototype.groupJoin=function(t,e,n,i){return this.select(function(r){return i(r,t.where(function(t){return e(r)===n(t)}))})},e.prototype.indexOf=function(t){return this._elements.indexOf(t)},e.prototype.insert=function(t,e){if(t<0||t>this._elements.length)throw new Error("Index is out of range.");this._elements.splice(t,0,e)},e.prototype.intersect=function(t){return this.where(function(e){return t.contains(e)})},e.prototype.join=function(t,e,n,i){return this.selectMany(function(r){return t.where(function(t){return n(t)===e(r)}).select(function(t){return i(r,t)})})},e.prototype.last=function(t){if(this.count())return t?this.where(t).last():this._elements[this.count()-1];throw Error("InvalidOperationException: The source sequence is empty.")},e.prototype.lastOrDefault=function(t){return this.count(t)?this.last(t):void 0},e.prototype.max=function(t){return Math.max.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.min=function(t){return Math.min.apply(Math,__spread(this._elements.map(t||function(t){return t})))},e.prototype.ofType=function(t){var e;switch(t){case Number:e="number";break;case String:e="string";break;case Boolean:e=typeof!0;break;case Function:e="function";break;default:e=null}return null===e?this.where(function(e){return e instanceof t}).cast():this.where(function(t){return typeof t===e}).cast()},e.prototype.orderBy=function(e,i){return void 0===i&&(i=t.keyComparer(e,!1)),new n(this._elements,i)},e.prototype.orderByDescending=function(e,i){return void 0===i&&(i=t.keyComparer(e,!0)),new n(this._elements,i)},e.prototype.thenBy=function(t){return this.orderBy(t)},e.prototype.thenByDescending=function(t){return this.orderByDescending(t)},e.prototype.remove=function(t){return-1!==this.indexOf(t)&&(this.removeAt(this.indexOf(t)),!0)},e.prototype.removeAll=function(e){return this.where(t.negate(e))},e.prototype.removeAt=function(t){this._elements.splice(t,1)},e.prototype.reverse=function(){return new e(this._elements.reverse())},e.prototype.select=function(t){return new e(this._elements.map(t))},e.prototype.selectMany=function(t){var n=this;return this.aggregate(function(e,i,r){return e.addRange(n.select(t).elementAt(r).toArray()),e},new e)},e.prototype.sequenceEqual=function(t){return this.all(function(e){return t.contains(e)})},e.prototype.single=function(t){if(1!==this.count(t))throw new Error("The collection does not contain exactly one element.");return this.first(t)},e.prototype.singleOrDefault=function(t){return this.count(t)?this.single(t):void 0},e.prototype.skip=function(t){return new e(this._elements.slice(Math.max(0,t)))},e.prototype.skipLast=function(t){return new e(this._elements.slice(0,-Math.max(0,t)))},e.prototype.skipWhile=function(t){var e=this;return this.skip(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.sum=function(t){return t?this.select(t).sum():this.aggregate(function(t,e){return t+ +e},0)},e.prototype.take=function(t){return new e(this._elements.slice(0,Math.max(0,t)))},e.prototype.takeLast=function(t){return new e(this._elements.slice(-Math.max(0,t)))},e.prototype.takeWhile=function(t){var e=this;return this.take(this.aggregate(function(n){return t(e.elementAt(n))?++n:n},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,n){var i=this;return this.aggregate(function(e,r,o){return e[i.select(t).elementAt(o).toString()]=n?i.select(n).elementAt(o):r,e.add({Key:i.select(t).elementAt(o),Value:n?i.select(n).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){var t,e,n=new Set;try{for(var i=__values(this._elements),r=i.next();!r.done;r=i.next()){var o=r.value;n.add(o)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=i.return)&&e.call(i)}finally{if(t)throw t.error}}return n},e.prototype.toList=function(){return this},e.prototype.toLookup=function(t,e){return this.groupBy(t,e)},e.prototype.where=function(t){return new e(this._elements.filter(t))},e.prototype.zip=function(t,e){var n=this;return t.count()e.angle?1:t.angleMath.PI&&(o-=2*Math.PI),r.p1.begin=o>0,r.p2.begin=!r.p1.begin}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}this._isSpotLight&&(this._spotStartAngle=this._segments[0].p2.angle,this._spotEndAngle=this._segments[1].p2.angle)},e._cornerCache=[],e._openSegments=new t.LinkedList,e}();t.VisibilityComputer=e}(es||(es={})),function(t){var e=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}return e.prototype.getContext=function(){return this.context},e.prototype.reset=function(){this._elapsedTime=0},e.prototype.stop=function(){this._isDone=!0},e.prototype.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=t.Time.deltaTime,this._isDone},e.prototype.initialize=function(t,e,n,i){this._timeInSeconds=t,this._repeats=e,this.context=n,this._onTime=i.bind(n)},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(n,e),n.prototype.update=function(){for(var t=this._timers.length-1;t>=0;t--)this._timers[t].tick()&&(this._timers[t].unload(),this._timers.splice(t,1))},n.prototype.schedule=function(e,n,i,r){var o=new t.Timer;return o.initialize(e,n,i,r),this._timers.push(o),o},n}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file diff --git a/source/src/Math/MathHelper.ts b/source/src/Math/MathHelper.ts index a5a7e701..5f0cd4a4 100644 --- a/source/src/Math/MathHelper.ts +++ b/source/src/Math/MathHelper.ts @@ -67,14 +67,16 @@ module es { } /** - * 将值(在leftMin-leftMax范围内)映射到一个在rightMin-rightMax范围内的值 - * @param value - * @param leftMin - * @param leftMax - * @param rightMin - * @param rightMax + * 对给定值进行范围映射。 + * @param value 要映射的值。 + * @param leftMin 输入范围的最小值。 + * @param leftMax 输入范围的最大值。 + * @param rightMin 输出范围的最小值。 + * @param rightMax 输出范围的最大值。 + * @returns 映射后的值。 */ public static map(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number) { + // 使用线性插值公式进行映射 return rightMin + (value - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); } @@ -90,28 +92,30 @@ module es { } /** - * 将值从某个任意范围映射到1到0范围 - * 这相当于map01的取反 + * 接收一个值value和两个边界min和max作为参数。它将value映射到0到1的范围内,然后返回1减去该结果的值,因此该函数的结果将在1到0之间 * @param value * @param min * @param max * @returns */ public static map10(value: number, min: number, max: number) { - return 1 - this.map01(value, min, max); + // 将 value 映射到 0 到 1 的范围内 + const mappedValue = this.map01(value, min, max); + // 返回 1 减去 mappedValue 的值,结果将在 1 到 0 之间 + return 1 - mappedValue; } /** - * 使用三次方程在两个值之间进行插值 - * @param value1 - * @param value2 - * @param amount + * 在两个值之间进行平滑的线性插值。与 lerp 相似,但具有平滑过渡的特点,当 t 在 0 和 1 之间时,返回 [value1, value2] 之间平滑插值后的结果。 + * @param value1 起始值 + * @param value2 结束值 + * @param amount 插值的程度,范围在 0 到 1 之间。 + * @returns 两个值之间进行平滑的线性插值后的结果。 */ - public static smoothStep(value1: number, value2: number, amount: number) { - let result = this.clamp(amount, 0, 1); - result = MathHelper.hermite(value1, 0, value2, 0, result); - - return result; + public static smoothStep(value1: number, value2: number, amount: number): number { + amount = this.clamp01(amount); // 将 amount 的值限制在 0 到 1 之间 + amount = this.hermite(value1, 0, value2, 0, amount); // 使用 hermite 函数进行平滑插值 + return amount; // 返回插值后的结果 } /** @@ -132,75 +136,107 @@ module es { } /** - * 确定值是否以2为底 + * 判断给定的数值是否是2的幂 * @param value * @returns */ public static isPowerOfTwo(value: number) { - return (value > 0) && ((value % (value - 1)) == 0); + // 确保值大于0 + if (value <= 0) { + return false; + } + + // 检查是否为2的幂 + return (value & (value - 1)) == 0; } - public static lerp(from: number, to: number, t: number) { - return from + (to - from) * this.clamp01(t); + /** + * 线性插值 + * @param from + * @param to + * @param t + * @returns + */ + public static lerp(from: number, to: number, t: number): number { + // 计算在 from 和 to 之间 t 所占的比例 + const clampedT = MathHelper.clamp01(t); + // 计算 from 到 to 的差值,再乘以比例,得到从 from 到 to 之间 t 所在的位置 + return from + (to - from) * clampedT; } + /** + * 线性插值前检查两个数的差是否小于一个给定的epsilon值,如果小于,则直接返回结束值b,否则执行线性插值并返回插值结果。 + * @param a 起始值 + * @param b 结束值 + * @param t 插值因子 + * @param epsilon 差值阈值,当两个数的差小于epsilon时直接返回结束值b。 + * @returns 如果a和b的差小于给定的epsilon值,则返回b,否则返回a到b的插值结果。 + */ public static betterLerp(a: number, b: number, t: number, epsilon: number): number { return Math.abs(a - b) < epsilon ? b : MathHelper.lerp(a, b, t); } /** - * 使度数的角度在a和b之间 - * 用于处理360度环绕 - * @param a - * @param b - * @param t - * @returns + * 在两个角度之间进行插值,使用角度值表示角度 + * @param a 起始角度 + * @param b 结束角度 + * @param t 插值比例,范围[0, 1] + * @returns 两个角度之间插值后的角度,使用角度值表示 */ - public static lerpAngle(a: number, b: number, t: number) { - let num = this.repeat(b - a, 360); - if (num > 180) - num -= 360; + public static lerpAngle(a: number, b: number, t: number): number { + // 计算从a到b的差值,对于超过360的值,需要进行修正 + let deltaAngle = this.repeat(b - a, 360); + if (deltaAngle > 180) { + deltaAngle -= 360; + } - return a + num * this.clamp01(t); + // 返回经过插值后的角度 + return a + deltaAngle * this.clamp01(t); } /** - * 使弧度的角度在a和b之间 - * @param a - * @param b - * @param t - * @returns + * 在两个角度之间进行插值,使用弧度值表示角度 + * @param a 起始角度 + * @param b 结束角度 + * @param t 插值比例,范围[0, 1] + * @returns 两个角度之间插值后的角度,使用弧度值表示 */ - public static lerpAngleRadians(a: number, b: number, t: number) { - let num = this.repeat(b - a, Math.PI * 2); - if (num > Math.PI) - num -= Math.PI * 2; + public static lerpAngleRadians(a: number, b: number, t: number): number { + // 计算从a到b的差值,对于超过2π的值,需要进行修正 + let deltaAngle = this.repeat(b - a, Math.PI * 2); + if (deltaAngle > Math.PI) { + deltaAngle -= Math.PI * 2; + } - return a + num * this.clamp01(t); + // 返回经过插值后的角度 + return a + deltaAngle * this.clamp01(t); } /** - * 循环t使其不大于长度且不小于0 - * @param t - * @param length - * @returns + * 指定长度上来回“弹跳”(ping-pong)一个变量 + * 因为弹跳的过程是来回循环的。最后,根据t在弹跳过程中相对于length的位置 + * @param t 变量的当前值 + * @param length 指定的长度 + * @returns 0到length之间变化的值 */ public static pingPong(t: number, length: number) { + // 将t的值限制在0到length*2的范围内 t = this.repeat(t, length * 2); + // 返回length和t-length的差的绝对值 return length - Math.abs(t - length); } /** - * 如果value> = threshold返回其符号,否则返回0 - * @param value - * @param threshold - * @returns + * 当value的绝对值大于等于threshold时返回value的符号,否则返回0 + * @param value - 输入的值 + * @param threshold - 阈值 + * @returns value的符号或0 */ public static signThreshold(value: number, threshold: number) { - if (Math.abs(value) >= threshold) - return Math.sign(value); + if (Math.abs(value) >= threshold) // 如果绝对值大于等于阈值 + return Math.sign(value); // 返回value的符号 else - return 0; + return 0; // 否则返回0 } /** @@ -223,38 +259,43 @@ module es { return (t - from) / length; } - /** - * 在两个值之间线性插值 - * 此方法是MathHelper.Lerp的效率较低,更精确的版本。 + /** + * 精确的线性插值,避免出现累积误差 + * @param value1 起始值 + * @param value2 结束值 + * @param amount 插值比例 + * @returns 两个值的线性插值结果 */ public static lerpPrecise(value1: number, value2: number, amount: number) { return ((1 - amount) * value1) + (value2 * amount); } - public static clamp(value: number, min: number, max: number) { - if (value < min) + /** + * 将给定值限制在指定范围内 + * @param value 需要被限制的值 + * @param min 最小值 + * @param max 最大值 + * @returns 限制后的值 + */ + public static clamp(value: number, min: number, max: number): number { + if (value < min) { // 如果值小于最小值,则返回最小值 return min; - - if (value > max) + } else if (value > max) { // 如果值大于最大值,则返回最大值 return max; - - return value; - } - - public static snap(value: number, increment: number) { - return Math.round(value / increment) * increment; + } else { // 否则返回原始值 + return value; + } } /** - * 给定圆心、半径和角度,得到圆周上的一个点。0度是3点钟。 - * @param circleCenter - * @param radius - * @param angleInDegrees + * 按照指定增量取整到最接近的整数倍数 + * @param value + * @param increment + * @returns */ - 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); + public static snap(value: number, increment: number) { + // 将给定值除以增量取整后再乘以增量,得到最接近给定值的整数倍 + return Math.round(value / increment) * increment; } /** @@ -275,22 +316,23 @@ module es { } /** - * 将值四舍五入并返回它和四舍五入后的数值 - * @param value - * @param roundedAmount - * @returns + * 将数值四舍五入到最接近的整数,并计算四舍五入的数量 + * @param value 要四舍五入的数值 + * @param roundedAmount 用于存储四舍五入的数量的参数 + * @returns 四舍五入后的整数 */ - public static roundWithRoundedAmount(value: number, roundedAmount: Ref) { + public static roundWithRoundedAmount(value: number, roundedAmount: Ref): number { let rounded = Math.round(value); roundedAmount.value = value - (rounded * Math.round(value / rounded)); return rounded; } /** - * 数值限定在0-1之间 - * @param value + * 将一个数值限制在 [0,1] 范围内 + * @param value 要限制的数值 + * @returns 限制后的数值 */ - public static clamp01(value: number) { + public static clamp01(value: number): number { if (value < 0) return 0; @@ -300,267 +342,406 @@ module es { return value; } - public static angleBetweenVectors(from: Vector2, to: Vector2) { + /** + * 计算从一个向量到另一个向量之间的角度 + * @param from 起始向量 + * @param to 目标向量 + * @returns 两个向量之间的角度(弧度制) + */ + public static angleBetweenVectors(from: Vector2, to: Vector2): number { + // 使用 Math.atan2() 方法计算出两个向量之间的夹角,返回的是弧度制角度 return Math.atan2(to.y - from.y, to.x - from.x); } - public static angleToVector(angleRadians: number, length: number) { - return new Vector2(Math.cos(angleRadians) * length, Math.sin(angleRadians) * length); + /** + * 将极角和极径转换为向量坐标 + * @param angleRadians 极角弧度值 + * @param length 极径长度 + * @returns 对应向量坐标 + */ + public static angleToVector(angleRadians: number, length: number): Vector2 { + // 根据给定的极角弧度值,使用三角函数计算出向量的x坐标和y坐标 + const x = Math.cos(angleRadians) * length; + const y = Math.sin(angleRadians) * length; + + // 使用上一步得到的坐标值创建一个新的Vector2对象并返回 + return new Vector2(x, y); } /** - * 增加t并确保它总是大于或等于0并且小于长度 - * @param t - * @param length + * 将一个数加上1,并在结果等于指定长度时将其设置为0 + * @param t 要加上1的数 + * @param length 指定长度 + * @returns 加上1后的结果,如果等于指定长度,则为0 */ - public static incrementWithWrap(t: number, length: number) { + public static incrementWithWrap(t: number, length: number): number { + // 将给定数t加上1。 t++; - if (t == length) + + // 如果结果等于指定长度,则返回0。 + if (t == length) { return 0; + } + // 否则,返回结果。 return t; } /** - * 递减t并确保其始终大于或等于0且小于长度 - * @param t - * @param length - * @returns + * 将一个数减去1,并在结果小于0时将其设置为指定长度减去1 + * @param t 要减去1的数 + * @param length 指定长度 + * @returns 减去1后的结果,如果小于0,则为指定长度减去1 */ - public static decrementWithWrap(t: number, length: number) { + public static decrementWithWrap(t: number, length: number): number { + // 将给定数t减去1。 t--; - if (t < 0) - return length - 1; + // 如果结果小于0,则返回指定长度减去1。 + if (t < 0) { + return length - 1; + } + + // 否则,返回结果。 return t; } /** - * 返回sqrt(x * x + y * y) - * @param x - * @param y - * @returns + * 计算直角三角形斜边长度,即求两个数的欧几里得距离 + * @param x 直角三角形的一条直角边 + * @param y 直角三角形的另一条直角边 + * @returns 三角形斜边长度 */ - public static hypotenuse(x: number, y: number) { - return Math.sqrt(x * x + y * y); + public static hypotenuse(x: number, y: number): number { + // 将x的平方与y的平方相加。 + let sumOfSquares = x * x + y * y; + + // 对和进行平方根运算。 + let result = Math.sqrt(sumOfSquares); + + // 返回结果。 + return result; } - public static closestPowerOfTwoGreaterThan(x: number) { - x--; - x |= (x >> 1); + /** + * 计算大于给定数字的最小二次幂 + * @param x 给定数字 + * @returns 大于给定数字的最小二次幂 + */ + public static closestPowerOfTwoGreaterThan(x: number): number { + x--; // 将给定数字减1,得到一个二进制数的掩码。 + x |= (x >> 1); // 将掩码的右侧一半全部设置为1。 x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); - x |= (x >> 16); - - return (x + 1); + x |= (x >> 16); // 连续将掩码右移,并将右侧一半全部设置为1,直到得到一个全为1的掩码。 + return (x + 1); // 将全为1的掩码加1,得到的结果就是大于给定数字的最小二次幂。 } /** - * 以roundToNearest为步长,将值舍入到最接近的数字。例如:在125中找到127到最近的5个结果 - * @param value - * @param roundToNearest + * 将数字舍入到最接近的指定值 + * @param value 需要被舍入的数字 + * @param roundToNearest 指定的舍入值 + * @returns 舍入后的结果 */ - public static roundToNearest(value: number, roundToNearest: number) { - return Math.round(value / roundToNearest) * roundToNearest; + public static roundToNearest(value: number, roundToNearest: number): number { + const quotient: number = value / roundToNearest; // 将数字除以指定值,得到商。 + const roundedQuotient: number = Math.round(quotient); // 将商四舍五入到最接近的整数。 + const result: number = roundedQuotient * roundToNearest; // 将舍入后的整数乘以指定值,得到最终结果。 + return result; } /** - * 检查传递的值是否在某个阈值之下。对于小规模、精确的比较很有用 - * @param value - * @param ep + * 判断给定值是否接近于零 + * @param value 给定值 + * @param ep 阈值(可选,默认为Epsilon) + * @returns 如果接近于零,返回true,否则返回false */ - public static withinEpsilon(value: number, ep: number = this.Epsilon) { + public static withinEpsilon(value: number, ep: number = this.Epsilon): boolean { + // 判断给定值的绝对值是否小于给定的阈值ep。 return Math.abs(value) < ep; } /** - * 由上移量向上移。start可以小于或大于end。例如:开始是2,结束是10,移位是4,结果是6 - * @param start - * @param end - * @param shift + * 逐渐逼近目标值 + * @param start 起始值 + * @param end 目标值 + * @param shift 逼近步长 + * @returns 逼近后的值 */ public static approach(start: number, end: number, shift: number): number { - if (start < end) + // 判断起始值是否小于目标值。 + if (start < end) { + // 如果是,返回起始值加上shift和目标值中的较小值。 return Math.min(start + shift, end); + } + // 如果不是,返回起始值减去shift和目标值中的较大值。 return Math.max(start - shift, end); } /** - * 通过偏移量钳位结果并选择最短路径,将起始角度向终止角度移动,起始值可以小于或大于终止值。 - * 示例1:开始是30,结束是100,移位是25,结果为55 - * 示例2:开始是340,结束是30,移位是25,结果是5(365换为5) - * @param start - * @param end - * @param shift - * @returns + * 逐渐逼近目标角度 + * @param start 起始角度 + * @param end 目标角度 + * @param shift 逼近步长 + * @returns 最终角度 */ - public static approachAngle(start: number, end: number, shift: number) { - let deltaAngle = this.deltaAngle(start, end); - if (-shift < deltaAngle && deltaAngle < shift) - return end; + public static approachAngle(start: number, end: number, shift: number): number { + // 调用this.deltaAngle()方法,获取起始角度和目标角度之间的夹角。 + let deltaAngle: number = this.deltaAngle(start, end); - return this.repeat(this.approach(start, start + deltaAngle, shift), 360); + // 判断夹角是否小于等于shift,如果是,直接返回目标角度。 + if (-shift < deltaAngle && deltaAngle < shift) { + return end; + } + + // 如果夹角大于shift,则调用this.approach()方法,逐渐逼近目标角度。 + let newAngle: number = this.approach(start, start + deltaAngle, shift); + + // 通过调用this.repeat()方法,将最终的角度限制在0到360度之间。 + newAngle = this.repeat(newAngle, 360); + + // 返回最终的角度。 + return newAngle; } /** - * 将 Vector 投影到另一个 Vector 上 - * @param other + * 计算向量在另一个向量上的投影向量 + * @param self 要投影的向量 + * @param other 目标向量 + * @returns 投影向量 */ - public static project(self: Vector2, other: Vector2) { - let amt = self.dot(other) / other.lengthSquared(); - let vec = other.scale(amt); + public static project(self: Vector2, other: Vector2): Vector2 { + // 通过调用Vector2.dot()方法,计算出self向量和other向量的点积。 + let amt: number = self.dot(other) / other.lengthSquared(); + + // 通过调用Vector2.lengthSquared()方法,计算出other向量的长度的平方。 + // 将点积除以长度的平方,得到self向量在other向量上的投影长度。 + // 通过调用Vector2.scale()方法,将投影长度与other向量的方向向量相乘,得到投影向量。 + let vec: Vector2 = other.scale(amt); + + // 返回投影向量。 return vec; } /** - * 通过将偏移量(全部以弧度为单位)夹住结果并选择最短路径,起始角度朝向终止角度。 - * 起始值可以小于或大于终止值。 - * 此方法的工作方式与“角度”方法非常相似,唯一的区别是使用弧度代替度,并以2 * Pi代替360。 - * @param start - * @param end - * @param shift - * @returns + * 逐渐接近目标角度 + * @param start 当前角度值(弧度制) + * @param end 目标角度值(弧度制) + * @param shift 每次逐渐接近目标角度的增量(弧度制) + * @returns 逐渐接近目标角度后的角度值(弧度制) */ - public static approachAngleRadians(start: number, end: number, shift: number) { - let deltaAngleRadians = this.deltaAngleRadians(start, end); - if (-shift < deltaAngleRadians && deltaAngleRadians < shift) - return end; + public static approachAngleRadians(start: number, end: number, shift: number): number { + // 通过调用deltaAngleRadians()方法,计算出当前角度值和目标角度值之间的弧度差值。 + let deltaAngleRadians: number = this.deltaAngleRadians(start, end); - return this.repeat(this.approach(start, start + deltaAngleRadians, shift), Math.PI * 2); + // 如果弧度差值的绝对值小于shift,则返回目标角度值。 + if (-shift < deltaAngleRadians && deltaAngleRadians < shift) { + return end; + } + + // 否则,通过调用approach()方法,逐渐将当前角度值接近目标角度值。 + let result: number = this.approach(start, start + deltaAngleRadians, shift); + + // 将计算结果使用repeat()方法转换成[0, 2π)之间的角度值,并返回。 + return this.repeat(result, Math.PI * 2); } /** - * 使用可接受的检查公差检查两个值是否大致相同 - * @param value1 - * @param value2 - * @param tolerance - * @returns + * 判断两个数值是否在指定公差内近似相等 + * @param value1 第一个数值 + * @param value2 第二个数值 + * @param tolerance 指定公差,默认为 Epsilon 常量 + * @returns 是否在指定公差内近似相等 */ - public static approximately(value1: number, value2: number, tolerance: number = this.Epsilon) { + public static approximately(value1: number, value2: number, tolerance: number = this.Epsilon): boolean { + // 计算两个数值之差的绝对值是否小于等于指定公差。 return Math.abs(value1 - value2) <= tolerance; } /** - * 计算两个给定角之间的最短差值(度数) - * @param current - * @param target + * 计算两个角度值之间的角度差值 + * @param current 当前角度值 + * @param target 目标角度值 + * @returns 角度差值 */ - public static deltaAngle(current: number, target: number) { - let num = this.repeat(target - current, 360); - if (num > 180) - num -= 360; + public static deltaAngle(current: number, target: number): number { + // 通过调用repeat()方法,计算出当前角度值和目标角度值之间的差值。 + let num: number = this.repeat(target - current, 360); + // 如果差值大于180度,则将差值减去360度,得到[-180度, 180度]之间的差值。 + if (num > 180) { + num -= 360; + } + + // 返回差值。 return num; } /** - * 检查值是否介于最小值/最大值(包括最小值/最大值)之间 - * @param value - * @param min - * @param max - * @returns + * 判断给定数值是否在指定区间内 + * @param value 给定数值 + * @param min 区间最小值 + * @param max 区间最大值 + * @returns 是否在指定区间内 */ - public static between(value: number, min: number, max: number) { + public static between(value: number, min: number, max: number): boolean { + // 比较给定数值是否大于等于最小值并且小于等于最大值。 return value >= min && value <= max; } /** - * 计算以弧度为单位的两个给定角度之间的最短差 - * @param current - * @param target - * @returns + * 计算两个弧度值之间的角度差值 + * @param current 当前弧度值 + * @param target 目标弧度值 + * @returns 角度差值 */ - public static deltaAngleRadians(current: number, target: number) { - let num = this.repeat(target - current, 2 * Math.PI); - if (num > Math.PI) - num -= 2 * Math.PI; + public static deltaAngleRadians(current: number, target: number): number { + // 通过调用repeat()方法,计算出当前弧度值和目标弧度值之间的差值。 + let num: number = this.repeat(target - current, 2 * Math.PI); + // 如果差值大于π,则将差值减去2π,得到[-π, π]之间的差值。 + if (num > Math.PI) { + num -= 2 * Math.PI; + } + + // 返回差值。 return num; } /** - * 循环t,使其永远不大于长度,永远不小于0 - * @param t - * @param length + * 将给定的数值限定在一个循环范围内 + * @param t 给定的数值 + * @param length 循环范围长度 + * @returns 限定在循环范围内的数值 */ - public static repeat(t: number, length: number) { - return t - Math.floor(t / length) * length; - } + public static repeat(t: number, length: number): number { + // 计算给定数值除以循环范围长度的整数部分,即循环次数。 + const num: number = Math.floor(t / length); - public static floorToInt(f: number) { - return this.toInt(Math.floor(f)); + // 用给定数值减去循环次数乘以循环范围长度,得到限定在循环范围内的数值。 + const result: number = t - num * length; + + // 返回限定后的数值。 + return result; } /** - * 将值绕一圈移动的助手 - * @param position - * @param speed - * @returns + * 将给定的浮点数向下取整为整数 + * @param f 给定的浮点数 + * @returns 向下取整后的整数 */ - public static rotateAround(position: Vector2, speed: number) { - let time = Time.totalTime * speed; + public static floorToInt(f: number): number { + // 使用Math.floor()方法,将给定的浮点数向下取整为最接近它的小于等于它的整数。 + const flooredValue: number = Math.floor(f); - let x = Math.cos(time); - let y = Math.sin(time); - - return new Vector2(position.x + x, position.y + y); + // 调用toInt()方法,将结果转换为整数类型。 + return this.toInt(flooredValue); } /** - * 旋转是相对于当前位置而不是总旋转。 - * 例如,如果您当前处于90度并且想要旋转到135度,则可以使用45度而不是135度的角度 - * @param point - * @param center - * @param angleIndegrees + * 绕着一个点旋转 + * @param position 原点坐标 + * @param speed 旋转速度 + * @returns 经过旋转后的点坐标 */ - public static rotateAround2(point: Vector2, center: Vector2, angleIndegrees: number) { - angleIndegrees = this.toRadians(angleIndegrees); - let cos = Math.cos(angleIndegrees); - let sin = Math.sin(angleIndegrees); - let rotatedX = cos * (point.x - center.x) - sin * (point.y - center.y) + center.x; - let rotatedY = sin * (point.x - center.x) + cos * (point.y - center.y) + center.y; + public static rotateAround(position: Vector2, speed: number): Vector2 { + // 计算旋转角度,使用当前时间与旋转速度的乘积作为参数进行计算。 + const angleInRadians: number = Time.totalTime * speed; + // 通过三角函数,计算出在当前时间下,距离原点为1的点在x轴和y轴上的坐标值。 + const cosValue: number = Math.cos(angleInRadians); + const sinValue: number = Math.sin(angleInRadians); + + // 将计算出的x轴和y轴的坐标值加上原点的坐标值,得到旋转后的点的坐标值。 + const rotatedX: number = position.x + cosValue; + const rotatedY: number = position.y + sinValue; + + // 创建一个新的Vector2对象,将上面得到的旋转后的点的坐标值作为参数,返回该对象。 return new Vector2(rotatedX, rotatedY); } /** - * 根据圆的中心,半径和角度在圆的圆周上得到一个点。 0度是3点钟方向 - * @param circleCenter - * @param radius - * @param angleInDegrees + * 绕给定中心点旋转指定角度后得到的新点坐标 + * @param point 要旋转的点的坐标 + * @param center 旋转中心点的坐标 + * @param angleIndegrees 旋转的角度,单位为度 + * @returns 旋转后的新点的坐标,返回值类型为Vector2 */ - public static pointOnCircle(circleCenter: Vector2, radius: number, angleInDegrees: number) { - let radians = this.toRadians(angleInDegrees); - return new Vector2(Math.cos(radians) * radius + circleCenter.x, Math.sin(radians) * radius + circleCenter.y); + public static rotateAround2(point: Vector2, center: Vector2, angleIndegrees: number) { + const { x: cx, y: cy } = center; + const { x: px, y: py } = point; + + const angleInRadians = this.toRadians(angleIndegrees); // 将角度值转换为弧度值 + const cos = Math.cos(angleInRadians); // 计算cos值 + const sin = Math.sin(angleInRadians); // 计算sin值 + + const rotatedX = cos * (px - cx) - sin * (py - cy) + cx; // 计算旋转后的新点的x坐标 + const rotatedY = sin * (px - cx) + cos * (py - cy) + cy; // 计算旋转后的新点的y坐标 + + return new Vector2(rotatedX, rotatedY); // 返回旋转后的新点的坐标 } /** - * 根据圆的中心,半径和角度在圆的圆周上得到一个点。 0弧度是3点钟方向 - * @param circleCenter - * @param radius - * @param angleInRadians - * @returns + * 计算以给定点为圆心、给定半径的圆上某一点的坐标 + * @param circleCenter 圆心坐标 + * @param radius 圆半径 + * @param angleInDegrees 角度值(度数制) + * @returns 计算出的圆上某一点的坐标 */ - public static pointOnCircleRadians(circleCenter: Vector2, radius: number, angleInRadians: number) { - return new Vector2(Math.cos(angleInRadians) * radius + circleCenter.x, Math.sin(angleInRadians) * radius + circleCenter.y); + public static pointOnCircle(circleCenter: Vector2, radius: number, angleInDegrees: number): Vector2 { + // 将给定角度值转换为弧度值,以便使用三角函数计算坐标值。 + const radians: number = this.toRadians(angleInDegrees); + + // 根据弧度值,通过三角函数(cos和sin)计算出该角度对应的x和y坐标的值(其中x坐标对应cos值,y坐标对应sin值)。 + const x: number = Math.cos(radians) * radius; + const y: number = Math.sin(radians) * radius; + + // 将x坐标值乘以半径,再加上圆心的x坐标,得到该点在x轴上的绝对坐标。 + const absoluteX: number = x + circleCenter.x; + // 将y坐标值乘以半径,再加上圆心的y坐标,得到该点在y轴上的绝对坐标。 + const absoluteY: number = y + circleCenter.y; + + // 创建一个新的Vector2对象,将上面得到的x和y坐标作为参数,返回该对象。 + return new Vector2(absoluteX, absoluteY); } /** - * lissajou曲线 - * @param xFrequency - * @param yFrequency - * @param xMagnitude - * @param yMagnitude - * @param phase - * @returns + * 计算以给定点为圆心、给定半径的圆上某一点的坐标 + * @param circleCenter 圆心坐标 + * @param radius 圆半径 + * @param angleInRadians 角度值(弧度制) + * @returns 计算出的圆上某一点的坐标 */ - public static lissajou(xFrequency: number = 2, yFrequency: number = 3, xMagnitude: number = 1, yMagnitude: number = 1, phase: number = 0) { - let x = Math.sin(Time.totalTime * xFrequency + phase) * xMagnitude; - let y = Math.cos(Time.totalTime * yFrequency) * yMagnitude; + public static pointOnCircleRadians(circleCenter: Vector2, radius: number, angleInRadians: number): Vector2 { + // 根据给定角度值,通过三角函数(cos和sin)计算出该角度对应的x和y坐标的值(其中x坐标对应cos值,y坐标对应sin值)。 + const x: number = Math.cos(angleInRadians) * radius; + const y: number = Math.sin(angleInRadians) * radius; + + // 将x坐标值乘以半径,再加上圆心的x坐标,得到该点在x轴上的绝对坐标。 + const absoluteX: number = x + circleCenter.x; + // 将y坐标值乘以半径,再加上圆心的y坐标,得到该点在y轴上的绝对坐标。 + const absoluteY: number = y + circleCenter.y; - return new Vector2(x, y); + // 创建一个新的Vector2对象,将上面得到的x和y坐标作为参数,返回该对象。 + return new Vector2(absoluteX, absoluteY); + } + + /** + * 生成一个Lissajous曲线上的点的坐标 + * @param xFrequency x方向上的频率,默认值为2 + * @param yFrequency y方向上的频率,默认值为3 + * @param xMagnitude x方向上的振幅,默认值为1 + * @param yMagnitude y方向上的振幅,默认值为1 + * @param phase 相位,默认值为0 + * @returns 在Lissajous曲线上的点的坐标,返回值类型为Vector2 + */ + public static lissajou(xFrequency = 2, yFrequency = 3, xMagnitude = 1, yMagnitude = 1, phase = 0) { + const x = Math.sin(Time.totalTime * xFrequency + phase) * xMagnitude; // 计算x方向上的坐标 + const y = Math.cos(Time.totalTime * yFrequency) * yMagnitude; // 计算y方向上的坐标 + + return new Vector2(x, y); // 返回在Lissajous曲线上的点的坐标 } /** @@ -630,43 +811,70 @@ module es { } /** - * 此函数用于确保数不是NaN或无穷大 + * 判断给定的数字是否有效 + * 如果输入的数字是 NaN 或正无穷大,该函数将返回 false;否则返回 true * @param x * @returns */ - public static isValid(x: number) { + public static isValid(x: number): boolean { + // 如果输入的数字是 NaN,返回 false if (Number.isNaN(x)) { return false; } - - return x !== Infinity; - } - - public static smoothDamp(current: number, target: number, currentVelocity: number, smoothTime: number, maxSpeed: number, deltaTime: number): { value: number; currentVelocity: number } { - smoothTime = Math.max(0.0001, smoothTime); - const num: number = 2 / smoothTime; - const num2: number = num * deltaTime; - const num3: number = - 1 / - (1 + (num2 + (0.48 * (num2 * num2) + 0.235 * (num2 * (num2 * num2))))); - let num4: number = current - target; - const num5: number = target; - const num6: number = maxSpeed * smoothTime; - num4 = this.clamp(num4, num6 * -1, num6); - target = current - num4; - const num7: number = (currentVelocity + num * num4) * deltaTime; - currentVelocity = (currentVelocity - num * num7) * num3; - let num8: number = target + (num4 + num7) * num3; - if (num5 - current > 0 === num8 > num5) { - num8 = num5; - currentVelocity = (num8 - num5) / deltaTime; + + // 如果输入的数字是正无穷大,返回 false + // 注意,负无穷大在这里被认为是有效的数字 + if (x === Infinity) { + return false; } - return { value: num8, currentVelocity }; + + // 如果输入的数字既不是 NaN,也不是正无穷大,返回 true + return true; } - public static smoothDampVector(current: Vector2, target: Vector2, currentVelocity: Vector2, smoothTime: number, maxSpeed: number, deltaTime: number): Vector2 { - const v = Vector2.zero; + /** + * 平滑阻尼运动,将当前位置平滑过渡到目标位置,返回一个包含当前位置和当前速度的对象 + * @param current 当前位置 + * @param target 目标位置 + * @param currentVelocity 当前速度 + * @param smoothTime 平滑时间 + * @param maxSpeed 最大速度 + * @param deltaTime 时间增量 + * @returns 一个包含当前位置和当前速度的对象,类型为{ value: number; currentVelocity: number } + */ + public static smoothDamp(current: number, target: number, currentVelocity: number, smoothTime: number, maxSpeed: number, deltaTime: number): { value: number; currentVelocity: number } { + smoothTime = Math.max(0.0001, smoothTime); // 平滑时间至少为0.0001,避免出现除以0的情况 + const omega: number = 2 / smoothTime; // 根据平滑时间计算阻尼系数 + const x: number = omega * deltaTime; // 计算阻尼系数与时间增量的乘积 + const exp: number = 1 / (1 + 0.48 * x + 0.235 * x * x); // 计算阻尼比 + const maxDelta: number = maxSpeed * smoothTime; // 计算最大速度与平滑时间的乘积 + let delta: number = current - target; // 计算当前位置与目标位置之间的距离 + delta = MathHelper.clamp(delta, -maxDelta, maxDelta); // 将距离限制在最大速度和最大速度的相反数之间 + target = current - delta; // 计算新的目标位置 + const temp: number = (currentVelocity + omega * delta) * deltaTime; // 计算当前速度和阻尼力的和乘以时间增量 + currentVelocity = (currentVelocity - omega * temp) * exp; // 计算新的当前速度 + let newValue: number = target + (delta + temp) * exp; // 计算新的当前位置 + if (current > target === newValue > target) { // 如果新的当前位置超过了目标位置,则将当前位置设置为目标位置,并计算新的当前速度 + newValue = target; + currentVelocity = (newValue - target) / deltaTime; + } + return { value: newValue, currentVelocity }; // 返回包含当前位置和当前速度的对象 + } + /** + * 平滑插值两个二维向量 + * @param current 当前向量 + * @param target 目标向量 + * @param currentVelocity 当前速度向量 + * @param smoothTime 平滑插值时间 + * @param maxSpeed 最大速度 + * @param deltaTime 帧间隔时间 + * @returns 插值后的结果向量 + */ + public static smoothDampVector(current: Vector2, target: Vector2, currentVelocity: Vector2, smoothTime: number, maxSpeed: number, deltaTime: number): Vector2 { + const v = Vector2.zero; // 创建一个初始向量v,其x和y坐标都为0。 + + // 对当前向量的x和y坐标进行平滑插值,得到插值结果和当前速度。 const resX = this.smoothDamp( current.x, target.x, @@ -675,8 +883,8 @@ module es { maxSpeed, deltaTime ); - v.x = resX.value; - currentVelocity.x = resX.currentVelocity; + v.x = resX.value; // 将插值结果赋值给向量v的x坐标。 + currentVelocity.x = resX.currentVelocity; // 将当前速度赋值给向量currentVelocity的x坐标。 const resY = this.smoothDamp( current.y, @@ -686,31 +894,49 @@ module es { maxSpeed, deltaTime ); - v.y = resY.value; - currentVelocity.y = resY.currentVelocity; + v.y = resY.value; // 将插值结果赋值给向量v的y坐标。 + currentVelocity.y = resY.currentVelocity; // 将当前速度赋值给向量currentVelocity的y坐标。 - return v; + return v; // 返回向量v。 } /** - * 将值(在 leftMin - leftMax 范围内)映射到 rightMin - rightMax 范围内的值 - * @param value - * @param leftMin - * @param leftMax - * @param rightMin - * @param rightMax + * 将一个值从一个区间映射到另一个区间 + * @param value 需要映射的值 + * @param leftMin 所在区间的最小值 + * @param leftMax 所在区间的最大值 + * @param rightMin 需要映射到的目标区间的最小值 + * @param rightMax 需要映射到的目标区间的最大值 * @returns */ - public static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax): number { - return rightMin + ((MathHelper.clamp(value, leftMin, leftMax) - leftMin) * (rightMax - rightMin)) / (leftMax - leftMin); + public static mapMinMax(value: number, leftMin: number, leftMax: number, rightMin: number, rightMax: number): number { + // 先将 value 限制在 [leftMin, leftMax] 区间内 + let clampedValue = MathHelper.clamp(value, leftMin, leftMax); + // 计算映射到 [rightMin, rightMax] 区间内的值 + return rightMin + (clampedValue - leftMin) * (rightMax - rightMin) / (leftMax - leftMin); } + /** + * 返回一个给定角度的单位向量。角度被解释为弧度制。 + * @param angle - 给定角度,以弧度制表示。 + * @returns 一个新的已归一化的二维向量。 + */ public static fromAngle(angle: number) { + // 返回一个新的二维向量,其中x和y分别设置为给定角度的余弦和正弦值,然后进行归一化以产生单位向量。 return new Vector2(Math.cos(angle), Math.sin(angle)).normalizeEqual(); } - public static toInt(val: number){ - return val>0 ? Math.floor(val):Math.ceil(val); + /** + * 将一个数字转换为最接近的整数 + * @param val 需要被转换的数字 + * @returns 最接近的整数 + */ + public static toInt(val: number): number { + if (val > 0) { // 如果数字大于0,则向下舍入为最接近的整数。 + return Math.floor(val); + } else { // 如果数字小于等于0,则向上舍入为最接近的整数。 + return Math.ceil(val); + } } } } diff --git a/source/src/Physics/Shapes/Circle.ts b/source/src/Physics/Shapes/Circle.ts index b687bb38..ffdd63af 100644 --- a/source/src/Physics/Shapes/Circle.ts +++ b/source/src/Physics/Shapes/Circle.ts @@ -25,7 +25,7 @@ module es { // 为了处理偏移原点的旋转,我们只需要将圆心围绕(0,0)在一个圆上移动,我们的偏移量就是0角 const offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg; const offsetLength = hasUnitScale ? collider._localOffsetLength : collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); + this.center = MathHelper.pointOnCircle(Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle); } } diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index 25027603..9f8539eb 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -257,7 +257,7 @@ module es { const offsetAngle = Math.atan2(collider.localOffset.y * collider.entity.transform.scale.y, collider.localOffset.x * collider.entity.transform.scale.x) * MathHelper.Rad2Deg; const offsetLength = hasUnitScale ? collider._localOffsetLength : collider.localOffset.multiply(collider.entity.transform.scale).magnitude(); - this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, + this.center = MathHelper.pointOnCircle(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle); }