From dc3d6398244ccab9c7f723ec0c01850ebaddbebc Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Sat, 3 Jul 2021 12:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E7=BD=AEtween=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 3 - README.md | 5 +- extensions/ecs-tween | 1 - source/bin/framework.d.ts | 648 +++++++- source/bin/framework.js | 1473 ++++++++++++++++- source/bin/framework.min.js | 2 +- source/src/Core.ts | 1 + .../Renderables/RenderableComponent.ts | 62 +- source/src/ECS/Entity.ts | 60 + source/src/Math/Bezier.ts | 16 +- .../Verlet/Constraints/AngleConstraint.ts | 2 +- source/src/Tween/AbstractTweenable.ts | 51 + source/src/Tween/Easing/EaseType.ts | 207 +++ source/src/Tween/Easing/Easing.ts | 230 +++ source/src/Tween/Easing/Lerps.ts | 84 + source/src/Tween/Interfaces/ITween.ts | 79 + source/src/Tween/Interfaces/ITweenControl.ts | 24 + source/src/Tween/Interfaces/ITweenTarget.ts | 19 + source/src/Tween/Interfaces/ITweenable.ts | 34 + source/src/Tween/PropertyTweens.ts | 44 + source/src/Tween/RenderableColorTween.ts | 38 + source/src/Tween/TransformSpringTween.ts | 100 ++ source/src/Tween/TransformVector2Tween.ts | 90 + source/src/Tween/Tween.ts | 319 ++++ source/src/Tween/TweenManager.ts | 152 ++ source/src/Tween/Tweens.ts | 117 ++ 26 files changed, 3719 insertions(+), 142 deletions(-) delete mode 160000 extensions/ecs-tween create mode 100644 source/src/Tween/AbstractTweenable.ts create mode 100644 source/src/Tween/Easing/EaseType.ts create mode 100644 source/src/Tween/Easing/Easing.ts create mode 100644 source/src/Tween/Easing/Lerps.ts create mode 100644 source/src/Tween/Interfaces/ITween.ts create mode 100644 source/src/Tween/Interfaces/ITweenControl.ts create mode 100644 source/src/Tween/Interfaces/ITweenTarget.ts create mode 100644 source/src/Tween/Interfaces/ITweenable.ts create mode 100644 source/src/Tween/PropertyTweens.ts create mode 100644 source/src/Tween/RenderableColorTween.ts create mode 100644 source/src/Tween/TransformSpringTween.ts create mode 100644 source/src/Tween/TransformVector2Tween.ts create mode 100644 source/src/Tween/Tween.ts create mode 100644 source/src/Tween/TweenManager.ts create mode 100644 source/src/Tween/Tweens.ts diff --git a/.gitmodules b/.gitmodules index dade3a79..8d608a8a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,6 +10,3 @@ [submodule "extensions/behaviourTree-ai"] path = extensions/behaviourTree-ai url = https://github.com/esengine/BehaviourTree-ai -[submodule "extensions/ecs-tween"] - path = extensions/ecs-tween - url = https://github.com/esengine/ecs-tween diff --git a/README.md b/README.md index a6ecf8e9..3fd6405b 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,10 @@ ecs-framework 的目标是成为功能强大的框架。它为您构建游戏提 - AABB,圆和多边形碰撞/触发检测 - 高效的协程,可在多个帧或动画定时中分解大型任务(Core.startCoroutine) - 通过Astar和广度优先搜索提供寻路支持,以查找图块地图或您自己的自定义格式 ( 参见 https://github.com/esengine/ecs-astar ) -- tween系统。任何number / Vector / 矩形/字段或属性都可以tween。 (参见 https://github.com/esengine/ecs-tween) +- tween系统。任何number / Vector / 矩形/字段或属性都可以tween。 - 针对核心事件的优化的事件发射器(发射器类),您也可以将其添加到自己的任何类中 - 延迟和重复任务的调度程序(核心调度方法) -## 关于ECS-FRAMEWORK -该项目由Nez项目由C#转为Typescript。感谢该项目提供的思路:https://github.com/prime31/Nez - ## 交流群 点击链接加入群聊【ecs游戏框架交流】:https://jq.qq.com/?_wv=1027&k=29w1Nud6 diff --git a/extensions/ecs-tween b/extensions/ecs-tween deleted file mode 160000 index 2154498b..00000000 --- a/extensions/ecs-tween +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2154498b2f8100be178d66d7a6334b7032e41c96 diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index a7c7b188..95581e8d 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -423,6 +423,14 @@ declare module es { * 从实体中删除所有组件 */ removeAllComponents(): void; + tweenPositionTo(to: Vector2, duration?: number): ITween; + tweenLocalPositionTo(to: Vector2, duration?: number): ITween; + tweenScaleTo(to: Vector2, duration?: number): any; + tweenScaleTo(to: number, duration?: number): any; + tweenLocalScaleTo(to: Vector2, duration?: any): any; + tweenLocalScaleTo(to: number, duration?: any): any; + tweenRotationDegreesTo(to: number, duration?: number): TransformVector2Tween; + tweenLocalRotationDegreesTo(to: number, duration?: number): TransformVector2Tween; compareTo(other: Entity): number; equals(other: Entity): boolean; getHashCode(): number; @@ -1506,6 +1514,7 @@ declare module es { getbounds(): es.Rectangle; readonly bounds: Rectangle; protected _areBoundsDirty: boolean; + color: Color; renderLayer: number; protected _renderLayer: number; onEntityTransformChanged(comp: transform.Component): void; @@ -1521,6 +1530,7 @@ declare module es { setRenderLayer(renderLayer: number): RenderableComponent; isVisibleFromCamera(cam: ICamera): boolean; debugRender(batcher: IBatcher): void; + tweenColorTo(to: Color, duration: number): RenderableColorTween; } } declare module es { @@ -4224,6 +4234,612 @@ declare module es { debugRender(batcher: IBatcher): void; } } +declare module es { + /** + * AbstractTweenable作为你可能想做的任何可以执行的自定义类的基础。 + * 这些类不同于ITweens,因为他们没有实现ITweenT接口。 + * 它只是说一个AbstractTweenable不仅仅是将一个值从开始移动到结束。 + * 它可以做任何需要每帧执行的事情。 + */ + abstract class AbstractTweenable implements ITweenable { + protected _isPaused: boolean; + /** + * abstractTweenable在完成后往往会被保留下来。 + * 这个标志可以让它们在内部知道自己当前是否被TweenManager盯上了,以便在必要时可以重新添加自己。 + */ + protected _isCurrentlyManagedByTweenManager: boolean; + abstract tick(): boolean; + recycleSelf(): void; + isRunning(): boolean; + start(): void; + pause(): void; + resume(): void; + stop(bringToCompletion?: boolean): void; + } +} +declare module es { + class PropertyTweens { + static NumberPropertyTo(self: any, memberName: string, to: number, duration: number): ITween; + static Vector2PropertyTo(self: any, memeberName: string, to: Vector2, duration: number): ITween; + } +} +declare module es { + enum LoopType { + none = 0, + restartFromBeginning = 1, + pingpong = 2 + } + enum TweenState { + running = 0, + paused = 1, + complete = 2 + } + abstract class Tween implements ITweenable, ITween { + protected _target: ITweenTarget; + protected _isFromValueOverridden: boolean; + protected _fromValue: T; + protected _toValue: T; + protected _easeType: EaseType; + protected _shouldRecycleTween: boolean; + protected _isRelative: boolean; + protected _completionHandler: (tween: ITween) => void; + protected _loopCompleteHandler: (tween: ITween) => void; + protected _nextTween: ITweenable; + protected _tweenState: TweenState; + private _isTimeScaleIndependent; + protected _delay: number; + protected _duration: number; + protected _timeScale: number; + protected _elapsedTime: number; + protected _loopType: LoopType; + protected _loops: number; + protected _delayBetweenLoops: number; + private _isRunningInReverse; + context: any; + setEaseType(easeType: EaseType): ITween; + setDelay(delay: number): ITween; + setDuration(duration: number): ITween; + setTimeScale(timeSclae: number): ITween; + setIsTimeScaleIndependent(): ITween; + setCompletionHandler(completeHandler: (tween: ITween) => void): ITween; + setLoops(loopType: LoopType, loops?: number, delayBetweenLoops?: number): ITween; + setLoopCompletionHanlder(loopCompleteHandler: (tween: ITween) => void): ITween; + setFrom(from: T): ITween; + prepareForReuse(from: T, to: T, duration: number): ITween; + setRecycleTween(shouldRecycleTween: boolean): ITween; + abstract setIsRelative(): ITween; + setContext(context: any): ITween; + setNextTween(nextTween: ITweenable): ITween; + tick(): boolean; + recycleSelf(): void; + isRunning(): boolean; + start(): void; + pause(): void; + resume(): void; + stop(bringToCompletion?: boolean): void; + jumpToElapsedTime(elapsedTime: any): void; + /** + * 反转当前的tween,如果是向前走,就会向后走,反之亦然 + */ + reverseTween(): void; + /** + * 当通过StartCoroutine调用时,这将一直持续到tween完成 + */ + waitForCompletion(): IterableIterator; + getTargetObject(): any; + private resetState; + /** + * 将所有状态重置为默认值,并根据传入的参数设置初始状态。 + * 这个方法作为一个切入点,这样Tween子类就可以调用它,这样tweens就可以被回收。 + * 当回收时,构造函数不会再被调用,所以这个方法封装了构造函数要做的事情 + * @param target + * @param to + * @param duration + */ + initialize(target: ITweenTarget, to: T, duration: number): void; + /** + * 处理循环逻辑 + * @param elapsedTimeExcess + */ + private handleLooping; + protected abstract updateValue(): any; + } +} +declare module es { + class NumberTween extends Tween { + static create(): NumberTween; + constructor(target?: ITweenTarget, to?: number, duration?: number); + setIsRelative(): ITween; + protected updateValue(): void; + recycleSelf(): void; + } + class Vector2Tween extends Tween { + static create(): Vector2Tween; + constructor(target?: ITweenTarget, to?: Vector2, duration?: number); + setIsRelative(): ITween; + protected updateValue(): void; + recycleSelf(): void; + } + class RectangleTween extends Tween { + static create(): RectangleTween; + constructor(target?: ITweenTarget, to?: Rectangle, duration?: number); + setIsRelative(): ITween; + protected updateValue(): void; + recycleSelf(): void; + } + class ColorTween extends Tween { + static create(): ColorTween; + constructor(target?: ITweenTarget, to?: Color, duration?: number); + setIsRelative(): this; + protected updateValue(): void; + } +} +declare module es { + class RenderableColorTween extends ColorTween implements ITweenTarget { + _renderable: RenderableComponent; + setTweenedValue(value: Color): void; + getTweenedValue(): Color; + getTargetObject(): RenderableComponent; + updateValue(): void; + setTarget(renderable: RenderableComponent): void; + recycleSelf(): void; + } +} +declare module es { + class TransformSpringTween extends AbstractTweenable { + readonly targetType: TransformTargetType; + private _transform; + private _targetType; + private _targetValue; + private _velocity; + /** + * 值越低,阻尼越小,值越高,阻尼越大,导致弹簧度越小,应在0.01-1之间,以避免系统不稳定 + */ + dampingRatio: number; + /** + * 角频率为2pi(弧度/秒)意味着振荡在一秒钟内完成一个完整的周期,即1Hz.应小于35左右才能保持稳定角频率 + */ + angularFrequency: number; + constructor(transform: Transform, targetType: TransformTargetType, targetValue: Vector2); + /** + * 你可以在任何时候调用setTargetValue来重置目标值到一个新的Vector2。 + * 如果你没有调用start来添加spring tween,它会为你调用 + * @param targetValue + */ + setTargetValue(targetValue: Vector2): void; + /** + * lambda应该是振荡幅度减少50%时的理想持续时间 + * @param lambda + */ + updateDampingRatioWithHalfLife(lambda: number): void; + tick(): boolean; + private setTweenedValue; + private getCurrentValueOfTweenedTargetType; + } +} +declare module es { + /** + * 对任何与Transform相关的属性tweens都是有用的枚举 + */ + enum TransformTargetType { + position = 0, + localPosition = 1, + scale = 2, + localScale = 3, + rotationDegrees = 4, + localRotationDegrees = 5 + } + /** + * 这是一个特殊的情况,因为Transform是迄今为止最被ween的对象。 + * 我们将Tween和ITweenTarget封装在一个单一的、可缓存的类中 + */ + class TransformVector2Tween extends Vector2Tween implements ITweenTarget { + private _transform; + private _targetType; + setTweenedValue(value: Vector2): void; + getTweenedValue(): Vector2; + getTargetObject(): Transform; + setTargetAndType(transform: Transform, targetType: TransformTargetType): void; + protected updateValue(): void; + recycleSelf(): void; + } +} +declare module es { + enum EaseType { + linear = 0, + sineIn = 1, + sineOut = 2, + sineInOut = 3, + quadIn = 4, + quadOut = 5, + quadInOut = 6, + quintIn = 7, + quintOut = 8, + quintInOut = 9, + cubicIn = 10, + cubicOut = 11, + cubicInOut = 12, + quartIn = 13, + quartOut = 14, + quartInOut = 15, + expoIn = 16, + expoOut = 17, + expoInOut = 18, + circleIn = 19, + circleOut = 20, + circleInOut = 21, + elasticIn = 22, + elasticOut = 23, + elasticInOut = 24, + punch = 25, + backIn = 26, + backOut = 27, + backInOut = 28, + bounceIn = 29, + bounceOut = 30, + bounceInOut = 31 + } + /** + * 助手的一个方法,它接收一个EaseType,并通过给定的持续时间和时间参数来应用该Ease方程。 + * 我们这样做是为了避免传来传去的Funcs为垃圾收集器制造大量垃圾 + */ + class EaseHelper { + /** + * 返回 easeType 的相反 EaseType + * @param easeType + */ + static oppositeEaseType(easeType: EaseType): EaseType.linear | EaseType.sineIn | EaseType.sineOut | EaseType.sineInOut | EaseType.quadIn | EaseType.quadOut | EaseType.quadInOut | EaseType.quintIn | EaseType.quintOut | EaseType.quintInOut | EaseType.cubicIn | EaseType.cubicOut | EaseType.cubicInOut | EaseType.quartIn | EaseType.quartInOut | EaseType.expoIn | EaseType.expoOut | EaseType.expoInOut | EaseType.circleIn | EaseType.circleOut | EaseType.circleInOut | EaseType.elasticIn | EaseType.elasticOut | EaseType.elasticInOut | EaseType.punch | EaseType.backIn | EaseType.backOut | EaseType.backInOut | EaseType.bounceIn | EaseType.bounceOut | EaseType.bounceInOut; + static ease(easeType: EaseType, t: number, duration: number): number; + } +} +declare module es { + class GlobalManager { + _enabled: boolean; + /** + * 如果true则启用了GlobalManager。 + * 状态的改变会导致调用OnEnabled/OnDisable + */ + /** + * 如果true则启用了GlobalManager。 + * 状态的改变会导致调用OnEnabled/OnDisable + * @param value + */ + enabled: boolean; + /** + * 启用/禁用这个GlobalManager + * @param isEnabled + */ + setEnabled(isEnabled: boolean): void; + /** + * 此GlobalManager启用时调用 + */ + onEnabled(): void; + /** + * 此GlobalManager禁用时调用 + */ + onDisabled(): void; + /** + * 在frame .update之前调用每一帧 + */ + update(): void; + } +} +declare module es { + class TweenManager extends GlobalManager { + static defaultEaseType: EaseType; + /** + * 如果为真,当加载新关卡时,活动的tween列表将被清除 + */ + static removeAllTweensOnLevelLoad: boolean; + /** + * 这里支持各种类型的自动缓存。请 + * 注意,只有在使用扩展方法启动tweens时,或者在做自定义tweens时从缓存中获取tween时,缓存才会起作用。 + * 关于如何获取缓存的tween,请参见扩展方法的实现 + */ + static cacheNumberTweens: boolean; + static cacheVector2Tweens: boolean; + static cacheColorTweens: boolean; + static cacheRectTweens: boolean; + /** + * 当前所有活跃用户的内部列表 + */ + private _activeTweens; + private _tempTweens; + /** + * 标志表示tween更新循环正在运行 + */ + private _isUpdating; + /** + * 便于暴露一个静态的API以方便访问 + */ + private static _instance; + constructor(); + update(): void; + /** + * 将一个tween添加到活动tweens列表中 + * @param tween + */ + static addTween(tween: ITweenable): void; + /** + * 从当前的tweens列表中删除一个tween + * @param tween + */ + static removeTween(tween: ITweenable): void; + /** + * 停止所有的tween并选择地把他们全部完成 + * @param bringToCompletion + */ + static stopAllTweens(bringToCompletion?: boolean): void; + /** + * 返回具有特定上下文的所有tweens。 + * Tweens以ITweenable的形式返回,因为这就是TweenManager所知道的所有内容 + * @param context + */ + static allTweensWithContext(context: any): ITweenable[]; + /** + * 停止所有给定上下文的tweens + * @param context + * @param bringToCompletion + */ + static stopAllTweensWithContext(context: any, bringToCompletion?: boolean): void; + /** + * 返回具有特定目标的所有tweens。 + * Tweens以ITweenControl的形式返回,因为TweenManager只知道这些 + * @param target + */ + static allTweenWithTarget(target: any): ITweenable[]; + /** + * 停止所有具有TweenManager知道的特定目标的tweens + * @param target + * @param bringToCompletion + */ + static stopAllTweensWithTarget(target: any, bringToCompletion?: boolean): void; + } +} +declare module es { + /** + * 标准缓和方程通过将b和c参数(起始值和变化值)用0和1替换,然后进行简化。 + * 这样做的目的是为了让我们可以得到一个0 - 1之间的原始值(除了弹性/反弹故意超过界限),然后用这个值来lerp任何东西 + */ + module Easing { + class Linear { + static easeNone(t: number, d: number): number; + } + class Quadratic { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Back { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Bounce { + static easeOut(t: number, d: number): number; + static easeIn(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Circular { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Cubic { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Elastic { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + static punch(t: number, d: number): number; + } + class Exponential { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Quartic { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Quintic { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + class Sinusoidal { + static easeIn(t: number, d: number): number; + static easeOut(t: number, d: number): number; + static easeInOut(t: number, d: number): number; + } + } +} +declare module es { + /** + * 一系列静态方法来处理所有常见的tween类型结构,以及它们的unclamped lerps.unclamped lerps对于超过0-1范围的bounce、elastic或其他tweens是必需的 + */ + class Lerps { + static lerp(from: Color, to: Color, t: number): any; + static lerp(from: number, to: number, t: number): any; + static lerp(from: Rectangle, to: Rectangle, t: number): any; + static lerp(from: Vector2, to: Vector2, t: number): any; + static angleLerp(from: Vector2, to: Vector2, t: number): Vector2; + static ease(easeType: EaseType, from: Rectangle, to: Rectangle, t: number, duration: number): any; + static ease(easeType: EaseType, from: Vector2, to: Vector2, t: number, duration: number): any; + static ease(easeType: EaseType, from: number, to: number, t: number, duration: number): any; + static ease(easeType: EaseType, from: Color, to: Color, t: number, duration: number): any; + static easeAngle(easeType: EaseType, from: Vector2, to: Vector2, t: number, duration: number): Vector2; + /** + * 使用半隐式欧拉方法。速度较慢,但总是很稳定。见 + * http://allenchou.net/2015/04/game-math-more-on-numeric-springing/ + * @param currentValue + * @param targetValue + * @param velocity Velocity的引用。如果在两次调用之间改变targetValue,请务必将其重置为0 + * @param dampingRatio 值越低,阻尼越小,值越高,阻尼越大,导致弹簧度越小,应在0.01-1之间,以避免系统不稳定 + * @param angularFrequency 角频率为2pi(弧度/秒)意味着振荡在一秒钟内完成一个完整的周期,即1Hz.应小于35左右才能保持稳定 + */ + static fastSpring(currentValue: Vector2, targetValue: Vector2, velocity: Vector2, dampingRatio: number, angularFrequency: number): Vector2; + } +} +declare module es { + /** + * 一系列强类型、可链式的方法来设置各种tween属性 + */ + interface ITween extends ITweenControl { + /** + * 设置该tween的易用性类型 + * @param easeType + */ + setEaseType(easeType: EaseType): ITween; + /** + * 设置启动tween前的延迟 + * @param delay + */ + setDelay(delay: number): ITween; + /** + * 设置tween的持续时间 + * @param duration + */ + setDuration(duration: number): ITween; + /** + * 设置这个tween使用的timeScale。 + * TimeScale将与Time.deltaTime/Time.unscaledDeltaTime相乘,从而得到tween实际使用的delta时间 + * @param timeScale + */ + setTimeScale(timeScale: number): ITween; + /** + * 设置tween使用Time.unscaledDeltaTime代替Time.deltaTime + */ + setIsTimeScaleIndependent(): ITween; + /** + * 设置当tween完成时应该调用的动作 + * @param completionHandler + */ + setCompletionHandler(completionHandler: (tween: ITween) => void): ITween; + /** + * 设置tween的循环类型。一个pingpong循环意味着从开始-结束-开始 + * @param loopType + * @param loops + * @param delayBetweenLoops + */ + setLoops(loopType: LoopType, loops: number, delayBetweenLoops: number): ITween; + /** + * 设置tween的起始位置 + * @param from + */ + setFrom(from: T): ITween; + /** + * 通过重置tween的from/to值和持续时间,为重复使用tween做准备。 + * @param from + * @param to + * @param duration + */ + prepareForReuse(from: T, to: T, duration: number): ITween; + /** + * 如果为true(默认值),tween将在使用后被回收。 + * 如果在TweenManager类中进行了配置,所有的Tween子类都有自己相关的自动缓存 + * @param shouldRecycleTween + */ + setRecycleTween(shouldRecycleTween: boolean): ITween; + /** + * 帮助程序,只是将tween的to值设置为相对于其当前值的+从使tween + */ + setIsRelative(): ITween; + /** + * 允许你通过tween.context.context来设置任何可检索的对象引用。 + * 这对于避免完成处理程序方法的闭包分配是很方便的。 + * 你也可以在TweenManager中搜索具有特定上下文的所有tweens + * @param context + */ + setContext(context: any): ITween; + /** + * 允许你添加一个tween,这个tween完成后会被运行。 + * 注意 nextTween 必须是一个 ITweenable! 同时注意,所有的ITweenT都是ITweenable + * @param nextTween + */ + setNextTween(nextTween: ITweenable): ITween; + } +} +declare module es { + /** + * 更多具体的Tween播放控制在这里 + */ + interface ITweenControl extends ITweenable { + /** + * 当使用匿名方法时,您可以在任何回调(如完成处理程序)中使用该属性来避免分配 + */ + context: any; + /** + * 将tween扭曲为elapsedTime,并将其限制在0和duration之间,无论tween对象是暂停、完成还是运行,都会立即更新 + * @param elapsedTime 所用时间 + */ + jumpToElapsedTime(elapsedTime: number): any; + /** + * 当从StartCoroutine调用时,它将直到tween完成 + */ + waitForCompletion(): any; + /** + * 获取tween的目标,如果TweenTargets不一定都是一个对象,则为null,它的唯一真正用途是让TweenManager按目标查找tweens的列表 + */ + getTargetObject(): any; + } +} +declare module es { + /** + * 任何想要被weened的对象都需要实现这个功能。 + * TweenManager内部喜欢做一个简单的对象来实现这个接口,并存储一个对被tweened对象的引用 + */ + interface ITweenTarget { + /** + * 在你选择的对象上设置最终的tweened值 + * @param value + */ + setTweenedValue(value: T): any; + getTweenedValue(): T; + /** + * 获取tween的目标,如果TweenTargets不一定都是一个对象,则为null,它的唯一真正用途是让TweenManager按目标查找tweens的列表 + */ + getTargetObject(): any; + } +} +declare module es { + interface ITweenable { + /** + * 就像内部的Update一样,每一帧都被TweenManager调用 + */ + tick(): boolean; + /** + * 当一个tween被移除时,由TweenManager调用。子 + * 类可以选择自己回收。子类应该首先在其实现中检查_shouldRecycleTween bool! + */ + recycleSelf(): any; + /** + * 检查是否有tween在运行 + */ + isRunning(): boolean; + /** + * 启动tween + */ + start(): any; + /** + * 暂停 + */ + pause(): any; + /** + * 暂停后恢复tween + */ + resume(): any; + /** + * 停止tween,并可选择将其完成 + * @param bringToCompletion + */ + stop(bringToCompletion: boolean): any; + } +} declare module es { interface IAnimFrame { t: number; @@ -4293,38 +4909,6 @@ declare module es { private forOwn; } } -declare module es { - class GlobalManager { - _enabled: boolean; - /** - * 如果true则启用了GlobalManager。 - * 状态的改变会导致调用OnEnabled/OnDisable - */ - /** - * 如果true则启用了GlobalManager。 - * 状态的改变会导致调用OnEnabled/OnDisable - * @param value - */ - enabled: boolean; - /** - * 启用/禁用这个GlobalManager - * @param isEnabled - */ - setEnabled(isEnabled: boolean): void; - /** - * 此GlobalManager启用时调用 - */ - onEnabled(): void; - /** - * 此GlobalManager禁用时调用 - */ - onDisabled(): void; - /** - * 在frame .update之前调用每一帧 - */ - update(): void; - } -} declare module es { class Hash { /** diff --git a/source/bin/framework.js b/source/bin/framework.js index 1ff0fc6c..41934fe6 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -96,6 +96,7 @@ var es; Core.emitter = new es.Emitter(); Core.emitter.addObserver(es.CoreEvents.frameUpdated, this.update, this); Core.registerGlobalManager(this._coroutineManager); + Core.registerGlobalManager(new es.TweenManager()); Core.registerGlobalManager(this._timerManager); Core.entitySystemsEnabled = enableEntitySystems; this.debug = debug; @@ -1053,6 +1054,54 @@ var es; this.removeComponent(this.components.buffer[i]); } }; + Entity.prototype.tweenPositionTo = function (to, duration) { + if (duration === void 0) { duration = 0.3; } + var tween = es.Pool.obtain(es.TransformVector2Tween); + tween.setTargetAndType(this.transform, es.TransformTargetType.position); + tween.initialize(tween, to, duration); + return tween; + }; + Entity.prototype.tweenLocalPositionTo = function (to, duration) { + if (duration === void 0) { duration = 0.3; } + var tween = es.Pool.obtain(es.TransformVector2Tween); + tween.setTargetAndType(this.transform, es.TransformTargetType.localPosition); + tween.initialize(tween, to, duration); + return tween; + }; + Entity.prototype.tweenScaleTo = function (to, duration) { + if (duration === void 0) { duration = 0.3; } + if (typeof (to) == 'number') { + return this.tweenScaleTo(new es.Vector2(to, to), duration); + } + var tween = es.Pool.obtain(es.TransformVector2Tween); + tween.setTargetAndType(this.transform, es.TransformTargetType.scale); + tween.initialize(tween, to, duration); + return tween; + }; + Entity.prototype.tweenLocalScaleTo = function (to, duration) { + if (duration === void 0) { duration = 0.3; } + if (typeof (to) == 'number') { + return this.tweenLocalScaleTo(new es.Vector2(to, to), duration); + } + var tween = es.Pool.obtain(es.TransformVector2Tween); + tween.setTargetAndType(this.transform, es.TransformTargetType.localScale); + tween.initialize(tween, to, duration); + return tween; + }; + Entity.prototype.tweenRotationDegreesTo = function (to, duration) { + if (duration === void 0) { duration = 0.3; } + var tween = es.Pool.obtain(es.TransformVector2Tween); + tween.setTargetAndType(this.transform, es.TransformTargetType.rotationDegrees); + tween.initialize(tween, new es.Vector2(to, to), duration); + return tween; + }; + Entity.prototype.tweenLocalRotationDegreesTo = function (to, duration) { + if (duration === void 0) { duration = 0.3; } + var tween = es.Pool.obtain(es.TransformVector2Tween); + tween.setTargetAndType(this.transform, es.TransformTargetType.localRotationDegrees); + tween.initialize(tween, new es.Vector2(to, to), duration); + return tween; + }; Entity.prototype.compareTo = function (other) { var compare = this._updateOrder - other._updateOrder; if (compare == 0) @@ -3683,6 +3732,7 @@ var es; var _this = _super !== null && _super.apply(this, arguments) || this; _this._bounds = new es.Rectangle(); _this._areBoundsDirty = true; + _this.color = es.Color.White; _this._renderLayer = 0; _this.debugRenderEnabled = true; _this._isVisible = false; @@ -3792,6 +3842,12 @@ var es; batcher.drawPixel(es.Vector2.add(this.entity.transform.position, this._localOffset), new es.Color(153, 50, 204), 4); batcher.end(); }; + RenderableComponent.prototype.tweenColorTo = function (to, duration) { + var tween = es.Pool.obtain(es.RenderableColorTween); + tween.setTarget(this); + tween.initialize(tween, to, duration); + return tween; + }; return RenderableComponent; }(es.Component)); es.RenderableComponent = RenderableComponent; @@ -6437,9 +6493,9 @@ var es; Bezier.getPoint = function (p0, p1, p2, t) { t = es.MathHelper.clamp01(t); var oneMinusT = 1 - t; - return new es.Vector2(oneMinusT * oneMinusT).multiply(p0) - .addEqual(new es.Vector2(2 * oneMinusT * t).multiply(p1)) - .addEqual(new es.Vector2(t * t).multiply(p2)); + return p0.scale(oneMinusT * oneMinusT) + .addEqual(p1.scale(2 * oneMinusT * t)) + .addEqual(p2.scale(t * t)); }; /** * 求解一个立方体曲率 @@ -6452,10 +6508,10 @@ var es; Bezier.getPointThree = function (start, firstControlPoint, secondControlPoint, end, t) { t = es.MathHelper.clamp01(t); var oneMinusT = 1 - t; - return new es.Vector2(oneMinusT * oneMinusT * oneMinusT).multiply(start) - .addEqual(new es.Vector2(3 * oneMinusT * oneMinusT * t).multiply(firstControlPoint)) - .addEqual(new es.Vector2(3 * oneMinusT * t * t).multiply(secondControlPoint)) - .addEqual(new es.Vector2(t * t * t).multiply(end)); + return start.scale(oneMinusT * oneMinusT * oneMinusT) + .addEqual(firstControlPoint.scale(3 * oneMinusT * oneMinusT * t)) + .addEqual(secondControlPoint.scale(3 * oneMinusT * t * t)) + .addEqual(end.scale(t * t * t)); }; /** * 得到二次贝塞尔函数的一阶导数 @@ -10880,6 +10936,1351 @@ var es; es.DistanceConstraint = DistanceConstraint; })(es || (es = {})); var es; +(function (es) { + /** + * AbstractTweenable作为你可能想做的任何可以执行的自定义类的基础。 + * 这些类不同于ITweens,因为他们没有实现ITweenT接口。 + * 它只是说一个AbstractTweenable不仅仅是将一个值从开始移动到结束。 + * 它可以做任何需要每帧执行的事情。 + */ + var AbstractTweenable = /** @class */ (function () { + function AbstractTweenable() { + } + AbstractTweenable.prototype.recycleSelf = function () { + }; + AbstractTweenable.prototype.isRunning = function () { + return this._isCurrentlyManagedByTweenManager && !this._isPaused; + }; + AbstractTweenable.prototype.start = function () { + if (this._isCurrentlyManagedByTweenManager) { + this._isPaused = false; + return; + } + es.TweenManager.addTween(this); + this._isCurrentlyManagedByTweenManager = true; + this._isPaused = false; + }; + AbstractTweenable.prototype.pause = function () { + this._isPaused = true; + }; + AbstractTweenable.prototype.resume = function () { + this._isPaused = false; + }; + AbstractTweenable.prototype.stop = function (bringToCompletion) { + if (bringToCompletion === void 0) { bringToCompletion = false; } + es.TweenManager.removeTween(this); + this._isCurrentlyManagedByTweenManager = false; + this._isPaused = true; + }; + return AbstractTweenable; + }()); + es.AbstractTweenable = AbstractTweenable; +})(es || (es = {})); +var es; +(function (es) { + /** + * 通用ITweenTarget用于所有属性tweens。 + */ + var PropertyTarget = /** @class */ (function () { + function PropertyTarget(target, propertyName) { + this._target = target; + this._propertyName = propertyName; + } + PropertyTarget.prototype.getTargetObject = function () { + return this._target; + }; + PropertyTarget.prototype.setTweenedValue = function (value) { + this._target[this._propertyName] = value; + }; + PropertyTarget.prototype.getTweenedValue = function () { + return this._target[this._propertyName]; + }; + return PropertyTarget; + }()); + var PropertyTweens = /** @class */ (function () { + function PropertyTweens() { + } + PropertyTweens.NumberPropertyTo = function (self, memberName, to, duration) { + var tweenTarget = new PropertyTarget(self, memberName); + var tween = es.TweenManager.cacheNumberTweens ? es.Pool.obtain(es.NumberTween) : new es.NumberTween(); + tween.initialize(tweenTarget, to, duration); + return tween; + }; + PropertyTweens.Vector2PropertyTo = function (self, memeberName, to, duration) { + var tweenTarget = new PropertyTarget(self, memeberName); + var tween = es.TweenManager.cacheVector2Tweens ? es.Pool.obtain(es.Vector2Tween) : new es.Vector2Tween(); + tween.initialize(tweenTarget, to, duration); + return tween; + }; + return PropertyTweens; + }()); + es.PropertyTweens = PropertyTweens; +})(es || (es = {})); +var es; +(function (es) { + var LoopType; + (function (LoopType) { + LoopType[LoopType["none"] = 0] = "none"; + LoopType[LoopType["restartFromBeginning"] = 1] = "restartFromBeginning"; + LoopType[LoopType["pingpong"] = 2] = "pingpong"; + })(LoopType = es.LoopType || (es.LoopType = {})); + var TweenState; + (function (TweenState) { + TweenState[TweenState["running"] = 0] = "running"; + TweenState[TweenState["paused"] = 1] = "paused"; + TweenState[TweenState["complete"] = 2] = "complete"; + })(TweenState = es.TweenState || (es.TweenState = {})); + var Tween = /** @class */ (function () { + function Tween() { + this._shouldRecycleTween = true; + this._tweenState = TweenState.complete; + this._timeScale = 1; + } + Tween.prototype.setEaseType = function (easeType) { + this._easeType = easeType; + return this; + }; + Tween.prototype.setDelay = function (delay) { + this._delay = delay; + this._elapsedTime = -this._delay; + return this; + }; + Tween.prototype.setDuration = function (duration) { + this._duration = duration; + return this; + }; + Tween.prototype.setTimeScale = function (timeSclae) { + this._timeScale = timeSclae; + return this; + }; + Tween.prototype.setIsTimeScaleIndependent = function () { + this._isTimeScaleIndependent = true; + return this; + }; + Tween.prototype.setCompletionHandler = function (completeHandler) { + this._completionHandler = completeHandler; + return this; + }; + Tween.prototype.setLoops = function (loopType, loops, delayBetweenLoops) { + if (loops === void 0) { loops = 1; } + if (delayBetweenLoops === void 0) { delayBetweenLoops = 0; } + this._loopType = loopType; + this._delayBetweenLoops = delayBetweenLoops; + if (loops < 0) + loops = -1; + if (loopType == LoopType.pingpong) + loops = loops * 2; + this._loops = loops; + return this; + }; + Tween.prototype.setLoopCompletionHanlder = function (loopCompleteHandler) { + this._loopCompleteHandler = loopCompleteHandler; + return this; + }; + Tween.prototype.setFrom = function (from) { + this._isFromValueOverridden = true; + this._fromValue = from; + return this; + }; + Tween.prototype.prepareForReuse = function (from, to, duration) { + this.initialize(this._target, to, duration); + return this; + }; + Tween.prototype.setRecycleTween = function (shouldRecycleTween) { + this._shouldRecycleTween = shouldRecycleTween; + return this; + }; + Tween.prototype.setContext = function (context) { + this.context = context; + return this; + }; + Tween.prototype.setNextTween = function (nextTween) { + this._nextTween = nextTween; + return this; + }; + Tween.prototype.tick = function () { + if (this._tweenState == TweenState.paused) + return false; + // 当我们进行循环时,我们会在0和持续时间之间限制数值 + var elapsedTimeExcess = 0; + if (!this._isRunningInReverse && this._elapsedTime >= this._duration) { + elapsedTimeExcess = this._elapsedTime - this._duration; + this._elapsedTime = this._duration; + this._tweenState = TweenState.complete; + } + else if (this._isRunningInReverse && this._elapsedTime <= 0) { + elapsedTimeExcess = 0 - this._elapsedTime; + this._elapsedTime = 0; + this._tweenState = TweenState.complete; + } + // 当我们延迟开始tween的时候,经过的时间会是负数,所以不要更新这个值。 + if (this._elapsedTime >= 0 && this._elapsedTime <= this._duration) { + this.updateValue(); + } + // 如果我们有一个loopType,并且我们是Complete(意味着我们达到了0或持续时间)处理循环。 + // handleLooping将采取任何多余的elapsedTime,并将其因子化,并在必要时调用udpateValue来保持tween的完美准确性 + if (this._loopType != LoopType.none && this._tweenState == TweenState.complete && this._loops != 0) { + this.handleLooping(elapsedTimeExcess); + } + var deltaTime = this._isTimeScaleIndependent ? es.Time.unscaledDeltaTime : es.Time.deltaTime; + deltaTime *= this._timeScale; + // 我们需要减去deltaTime + if (this._isRunningInReverse) + this._elapsedTime -= deltaTime; + else + this._elapsedTime += deltaTime; + if (this._tweenState == TweenState.complete) { + this._completionHandler && this._completionHandler(this); + // 如果我们有一个nextTween,把它添加到TweenManager中,这样它就可以开始运行了 + if (this._nextTween != null) { + this._nextTween.start(); + this._nextTween = null; + } + return true; + } + return false; + }; + Tween.prototype.recycleSelf = function () { + if (this._shouldRecycleTween) { + this._target = null; + this._nextTween = null; + } + }; + Tween.prototype.isRunning = function () { + return this._tweenState == TweenState.running; + }; + Tween.prototype.start = function () { + if (!this._isFromValueOverridden) + this._fromValue = this._target.getTargetObject(); + if (this._tweenState == TweenState.complete) { + this._tweenState = TweenState.running; + es.TweenManager.addTween(this); + } + }; + Tween.prototype.pause = function () { + this._tweenState = TweenState.paused; + }; + Tween.prototype.resume = function () { + this._tweenState = TweenState.running; + }; + Tween.prototype.stop = function (bringToCompletion) { + if (bringToCompletion === void 0) { bringToCompletion = false; } + this._tweenState = TweenState.complete; + if (bringToCompletion) { + // 如果我们逆向运行,我们在0处结束,否则我们进入持续时间 + this._elapsedTime = this._isRunningInReverse ? 0 : this._duration; + this._loopType = LoopType.none; + this._loops = 0; + // TweenManager将在下一个tick上进行删除处理 + } + else { + es.TweenManager.removeTween(this); + } + }; + Tween.prototype.jumpToElapsedTime = function (elapsedTime) { + this._elapsedTime = es.MathHelper.clamp(elapsedTime, 0, this._duration); + this.updateValue(); + }; + /** + * 反转当前的tween,如果是向前走,就会向后走,反之亦然 + */ + Tween.prototype.reverseTween = function () { + this._isRunningInReverse = !this._isRunningInReverse; + }; + /** + * 当通过StartCoroutine调用时,这将一直持续到tween完成 + */ + Tween.prototype.waitForCompletion = function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this._tweenState != TweenState.complete)) return [3 /*break*/, 2]; + return [4 /*yield*/, null]; + case 1: + _a.sent(); + return [3 /*break*/, 0]; + case 2: return [2 /*return*/]; + } + }); + }; + Tween.prototype.getTargetObject = function () { + return this._target.getTargetObject(); + }; + Tween.prototype.resetState = function () { + this.context = null; + this._completionHandler = this._loopCompleteHandler = null; + this._isFromValueOverridden = false; + this._isTimeScaleIndependent = false; + this._tweenState = TweenState.complete; + // TODO: 我认为在没有得到用户同意的情况下,我们绝对不应该从_shouldRecycleTween=false。需要研究和思考 + // this._shouldRecycleTween = true; + this._isRelative = false; + this._easeType = es.TweenManager.defaultEaseType; + if (this._nextTween != null) { + this._nextTween.recycleSelf(); + this._nextTween = null; + } + this._delay = 0; + this._duration = 0; + this._timeScale = 1; + this._elapsedTime = 0; + this._loopType = LoopType.none; + this._delayBetweenLoops = 0; + this._loops = 0; + this._isRunningInReverse = false; + }; + /** + * 将所有状态重置为默认值,并根据传入的参数设置初始状态。 + * 这个方法作为一个切入点,这样Tween子类就可以调用它,这样tweens就可以被回收。 + * 当回收时,构造函数不会再被调用,所以这个方法封装了构造函数要做的事情 + * @param target + * @param to + * @param duration + */ + Tween.prototype.initialize = function (target, to, duration) { + // 重置状态,以防我们被回收 + this.resetState(); + this._target = target; + this._toValue = to; + this._duration = duration; + }; + /** + * 处理循环逻辑 + * @param elapsedTimeExcess + */ + Tween.prototype.handleLooping = function (elapsedTimeExcess) { + this._loops--; + if (this._loopType == LoopType.pingpong) { + this.reverseTween(); + } + if (this._loopType == LoopType.restartFromBeginning || this._loops % 2 == 0) { + this._loopCompleteHandler && this._completionHandler(this); + } + // 如果我们还有循环要处理,就把我们的状态重置为Running,这样我们就可以继续处理它们了 + if (this._loops != 0) { + this._tweenState = TweenState.running; + // 现在,我们需要设置我们的经过时间,并考虑到我们的elapsedTimeExcess + if (this._loopType == LoopType.restartFromBeginning) { + this._elapsedTime = elapsedTimeExcess - this._delayBetweenLoops; + } + else { + if (this._isRunningInReverse) + this._elapsedTime += this._delayBetweenLoops - elapsedTimeExcess; + else + this._elapsedTime = elapsedTimeExcess - this._delayBetweenLoops; + } + // 如果我们有一个elapsedTimeExcess,并且没有delayBetweenLoops,则更新该值 + if (this._delayBetweenLoops == 0 && elapsedTimeExcess > 0) { + this.updateValue(); + } + } + }; + return Tween; + }()); + es.Tween = Tween; +})(es || (es = {})); +/// +var es; +/// +(function (es) { + var NumberTween = /** @class */ (function (_super) { + __extends(NumberTween, _super); + function NumberTween(target, to, duration) { + var _this = _super.call(this) || this; + _this.initialize(target, to, duration); + return _this; + } + NumberTween.create = function () { + return es.TweenManager.cacheNumberTweens ? es.Pool.obtain(NumberTween) : new NumberTween(); + }; + NumberTween.prototype.setIsRelative = function () { + this._isRelative = true; + this._toValue += this._fromValue; + return this; + }; + NumberTween.prototype.updateValue = function () { + this._target.setTweenedValue(es.Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + }; + NumberTween.prototype.recycleSelf = function () { + _super.prototype.recycleSelf.call(this); + if (this._shouldRecycleTween && es.TweenManager.cacheNumberTweens) + es.Pool.free(this); + }; + return NumberTween; + }(es.Tween)); + es.NumberTween = NumberTween; + var Vector2Tween = /** @class */ (function (_super) { + __extends(Vector2Tween, _super); + function Vector2Tween(target, to, duration) { + var _this = _super.call(this) || this; + _this.initialize(target, to, duration); + return _this; + } + Vector2Tween.create = function () { + return es.TweenManager.cacheVector2Tweens ? es.Pool.obtain(Vector2Tween) : new Vector2Tween(); + }; + Vector2Tween.prototype.setIsRelative = function () { + this._isRelative = true; + this._toValue.add(this._fromValue); + return this; + }; + Vector2Tween.prototype.updateValue = function () { + this._target.setTweenedValue(es.Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + }; + Vector2Tween.prototype.recycleSelf = function () { + _super.prototype.recycleSelf.call(this); + if (this._shouldRecycleTween && es.TweenManager.cacheVector2Tweens) + es.Pool.free(this); + }; + return Vector2Tween; + }(es.Tween)); + es.Vector2Tween = Vector2Tween; + var RectangleTween = /** @class */ (function (_super) { + __extends(RectangleTween, _super); + function RectangleTween(target, to, duration) { + var _this = _super.call(this) || this; + _this.initialize(target, to, duration); + return _this; + } + RectangleTween.create = function () { + return es.TweenManager.cacheRectTweens ? es.Pool.obtain(RectangleTween) : new RectangleTween(); + }; + RectangleTween.prototype.setIsRelative = function () { + this._isRelative = true; + this._toValue = new es.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); + return this; + }; + RectangleTween.prototype.updateValue = function () { + this._target.setTweenedValue(es.Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + }; + RectangleTween.prototype.recycleSelf = function () { + _super.prototype.recycleSelf.call(this); + if (this._shouldRecycleTween && es.TweenManager.cacheRectTweens) + es.Pool.free(this); + }; + return RectangleTween; + }(es.Tween)); + es.RectangleTween = RectangleTween; + var ColorTween = /** @class */ (function (_super) { + __extends(ColorTween, _super); + function ColorTween(target, to, duration) { + var _this = _super.call(this) || this; + _this.initialize(target, to, duration); + return _this; + } + ColorTween.create = function () { + return es.TweenManager.cacheColorTweens ? es.Pool.obtain(ColorTween) : new ColorTween(); + }; + ColorTween.prototype.setIsRelative = function () { + this._isRelative = true; + this._toValue.r += this._fromValue.r; + this._toValue.g += this._fromValue.g; + this._toValue.b += this._fromValue.b; + this._toValue.a += this._fromValue.a; + return this; + }; + ColorTween.prototype.updateValue = function () { + this._target.setTweenedValue(es.Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + }; + return ColorTween; + }(es.Tween)); + es.ColorTween = ColorTween; +})(es || (es = {})); +/// +var es; +/// +(function (es) { + var RenderableColorTween = /** @class */ (function (_super) { + __extends(RenderableColorTween, _super); + function RenderableColorTween() { + return _super !== null && _super.apply(this, arguments) || this; + } + RenderableColorTween.prototype.setTweenedValue = function (value) { + this._renderable.color = value; + }; + RenderableColorTween.prototype.getTweenedValue = function () { + return this._renderable.color; + }; + RenderableColorTween.prototype.getTargetObject = function () { + return this._renderable; + }; + RenderableColorTween.prototype.updateValue = function () { + this.setTweenedValue(es.Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + }; + RenderableColorTween.prototype.setTarget = function (renderable) { + this._renderable = renderable; + }; + RenderableColorTween.prototype.recycleSelf = function () { + if (this._shouldRecycleTween) { + this._renderable = null; + this._target = null; + this._nextTween = null; + } + if (this._shouldRecycleTween && es.TweenManager.cacheColorTweens) { + es.Pool.free(this); + } + }; + return RenderableColorTween; + }(es.ColorTween)); + es.RenderableColorTween = RenderableColorTween; +})(es || (es = {})); +var es; +(function (es) { + var TransformSpringTween = /** @class */ (function (_super) { + __extends(TransformSpringTween, _super); + function TransformSpringTween(transform, targetType, targetValue) { + var _this = _super.call(this) || this; + // 阻尼比(dampingRatio)和角频率(angularFrequency)的配置是公开的,以便于在设计时进行调整 + /** + * 值越低,阻尼越小,值越高,阻尼越大,导致弹簧度越小,应在0.01-1之间,以避免系统不稳定 + */ + _this.dampingRatio = 0.23; + /** + * 角频率为2pi(弧度/秒)意味着振荡在一秒钟内完成一个完整的周期,即1Hz.应小于35左右才能保持稳定角频率 + */ + _this.angularFrequency = 25; + _this._transform = transform; + _this._targetType = targetType; + _this.setTargetValue(targetValue); + return _this; + } + Object.defineProperty(TransformSpringTween.prototype, "targetType", { + get: function () { + return this._targetType; + }, + enumerable: true, + configurable: true + }); + /** + * 你可以在任何时候调用setTargetValue来重置目标值到一个新的Vector2。 + * 如果你没有调用start来添加spring tween,它会为你调用 + * @param targetValue + */ + TransformSpringTween.prototype.setTargetValue = function (targetValue) { + this._velocity = es.Vector2.zero; + this._targetValue = targetValue; + if (!this._isCurrentlyManagedByTweenManager) + this.start(); + }; + /** + * lambda应该是振荡幅度减少50%时的理想持续时间 + * @param lambda + */ + TransformSpringTween.prototype.updateDampingRatioWithHalfLife = function (lambda) { + this.dampingRatio = (-lambda / this.angularFrequency) * Math.log(0.5); + }; + TransformSpringTween.prototype.tick = function () { + if (!this._isPaused) + this.setTweenedValue(es.Lerps.fastSpring(this.getCurrentValueOfTweenedTargetType(), this._targetValue, this._velocity, this.dampingRatio, this.angularFrequency)); + return false; + }; + TransformSpringTween.prototype.setTweenedValue = function (value) { + switch (this._targetType) { + case es.TransformTargetType.position: + this._transform.position = value; + break; + case es.TransformTargetType.localPosition: + this._transform.localPosition = value; + break; + case es.TransformTargetType.scale: + this._transform.scale = value; + break; + case es.TransformTargetType.localScale: + this._transform.localScale = value; + break; + case es.TransformTargetType.rotationDegrees: + this._transform.rotationDegrees = value.x; + case es.TransformTargetType.localRotationDegrees: + this._transform.localRotationDegrees = value.x; + break; + } + }; + TransformSpringTween.prototype.getCurrentValueOfTweenedTargetType = function () { + switch (this._targetType) { + case es.TransformTargetType.position: + return this._transform.position; + case es.TransformTargetType.localPosition: + return this._transform.localPosition; + case es.TransformTargetType.scale: + return this._transform.scale; + case es.TransformTargetType.localScale: + return this._transform.localScale; + case es.TransformTargetType.rotationDegrees: + return new es.Vector2(this._transform.rotationDegrees); + case es.TransformTargetType.localRotationDegrees: + return new es.Vector2(this._transform.localRotationDegrees, 0); + default: + return es.Vector2.zero; + } + }; + return TransformSpringTween; + }(es.AbstractTweenable)); + es.TransformSpringTween = TransformSpringTween; +})(es || (es = {})); +/// +var es; +/// +(function (es) { + /** + * 对任何与Transform相关的属性tweens都是有用的枚举 + */ + var TransformTargetType; + (function (TransformTargetType) { + TransformTargetType[TransformTargetType["position"] = 0] = "position"; + TransformTargetType[TransformTargetType["localPosition"] = 1] = "localPosition"; + TransformTargetType[TransformTargetType["scale"] = 2] = "scale"; + TransformTargetType[TransformTargetType["localScale"] = 3] = "localScale"; + TransformTargetType[TransformTargetType["rotationDegrees"] = 4] = "rotationDegrees"; + TransformTargetType[TransformTargetType["localRotationDegrees"] = 5] = "localRotationDegrees"; + })(TransformTargetType = es.TransformTargetType || (es.TransformTargetType = {})); + /** + * 这是一个特殊的情况,因为Transform是迄今为止最被ween的对象。 + * 我们将Tween和ITweenTarget封装在一个单一的、可缓存的类中 + */ + var TransformVector2Tween = /** @class */ (function (_super) { + __extends(TransformVector2Tween, _super); + function TransformVector2Tween() { + return _super !== null && _super.apply(this, arguments) || this; + } + TransformVector2Tween.prototype.setTweenedValue = function (value) { + switch (this._targetType) { + case TransformTargetType.position: + this._transform.position = value; + break; + case TransformTargetType.localPosition: + this._transform.localPosition = value; + break; + case TransformTargetType.scale: + this._transform.scale = value; + break; + case TransformTargetType.localScale: + this._transform.localScale = value; + break; + case TransformTargetType.rotationDegrees: + this._transform.rotationDegrees = value.x; + case TransformTargetType.localRotationDegrees: + this._transform.localRotationDegrees = value.x; + break; + } + }; + TransformVector2Tween.prototype.getTweenedValue = function () { + switch (this._targetType) { + case TransformTargetType.position: + return this._transform.position; + case TransformTargetType.localPosition: + return this._transform.localPosition; + case TransformTargetType.scale: + return this._transform.scale; + case TransformTargetType.localScale: + return this._transform.localScale; + case TransformTargetType.rotationDegrees: + return new es.Vector2(this._transform.rotationDegrees, this._transform.rotationDegrees); + case TransformTargetType.localRotationDegrees: + return new es.Vector2(this._transform.localRotationDegrees, 0); + } + }; + TransformVector2Tween.prototype.getTargetObject = function () { + return this._transform; + }; + TransformVector2Tween.prototype.setTargetAndType = function (transform, targetType) { + this._transform = transform; + this._targetType = targetType; + }; + TransformVector2Tween.prototype.updateValue = function () { + // 非相对角勒普的特殊情况,使他们采取尽可能短的旋转 + if ((this._targetType == TransformTargetType.rotationDegrees || + this._targetType == TransformTargetType.localRotationDegrees) && !this._isRelative) { + this.setTweenedValue(es.Lerps.easeAngle(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } + else { + this.setTweenedValue(es.Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } + }; + TransformVector2Tween.prototype.recycleSelf = function () { + if (this._shouldRecycleTween) { + this._target = null; + this._nextTween = null; + this._transform = null; + es.Pool.free(this); + } + }; + return TransformVector2Tween; + }(es.Vector2Tween)); + es.TransformVector2Tween = TransformVector2Tween; +})(es || (es = {})); +var es; +(function (es) { + var EaseType; + (function (EaseType) { + EaseType[EaseType["linear"] = 0] = "linear"; + EaseType[EaseType["sineIn"] = 1] = "sineIn"; + EaseType[EaseType["sineOut"] = 2] = "sineOut"; + EaseType[EaseType["sineInOut"] = 3] = "sineInOut"; + EaseType[EaseType["quadIn"] = 4] = "quadIn"; + EaseType[EaseType["quadOut"] = 5] = "quadOut"; + EaseType[EaseType["quadInOut"] = 6] = "quadInOut"; + EaseType[EaseType["quintIn"] = 7] = "quintIn"; + EaseType[EaseType["quintOut"] = 8] = "quintOut"; + EaseType[EaseType["quintInOut"] = 9] = "quintInOut"; + EaseType[EaseType["cubicIn"] = 10] = "cubicIn"; + EaseType[EaseType["cubicOut"] = 11] = "cubicOut"; + EaseType[EaseType["cubicInOut"] = 12] = "cubicInOut"; + EaseType[EaseType["quartIn"] = 13] = "quartIn"; + EaseType[EaseType["quartOut"] = 14] = "quartOut"; + EaseType[EaseType["quartInOut"] = 15] = "quartInOut"; + EaseType[EaseType["expoIn"] = 16] = "expoIn"; + EaseType[EaseType["expoOut"] = 17] = "expoOut"; + EaseType[EaseType["expoInOut"] = 18] = "expoInOut"; + EaseType[EaseType["circleIn"] = 19] = "circleIn"; + EaseType[EaseType["circleOut"] = 20] = "circleOut"; + EaseType[EaseType["circleInOut"] = 21] = "circleInOut"; + EaseType[EaseType["elasticIn"] = 22] = "elasticIn"; + EaseType[EaseType["elasticOut"] = 23] = "elasticOut"; + EaseType[EaseType["elasticInOut"] = 24] = "elasticInOut"; + EaseType[EaseType["punch"] = 25] = "punch"; + EaseType[EaseType["backIn"] = 26] = "backIn"; + EaseType[EaseType["backOut"] = 27] = "backOut"; + EaseType[EaseType["backInOut"] = 28] = "backInOut"; + EaseType[EaseType["bounceIn"] = 29] = "bounceIn"; + EaseType[EaseType["bounceOut"] = 30] = "bounceOut"; + EaseType[EaseType["bounceInOut"] = 31] = "bounceInOut"; + })(EaseType = es.EaseType || (es.EaseType = {})); + /** + * 助手的一个方法,它接收一个EaseType,并通过给定的持续时间和时间参数来应用该Ease方程。 + * 我们这样做是为了避免传来传去的Funcs为垃圾收集器制造大量垃圾 + */ + var EaseHelper = /** @class */ (function () { + function EaseHelper() { + } + /** + * 返回 easeType 的相反 EaseType + * @param easeType + */ + EaseHelper.oppositeEaseType = function (easeType) { + switch (easeType) { + case EaseType.linear: + return easeType; + case EaseType.backIn: + return EaseType.backOut; + case EaseType.backOut: + return EaseType.backIn; + case EaseType.backInOut: + return easeType; + case EaseType.bounceIn: + return EaseType.bounceOut; + case EaseType.bounceOut: + return EaseType.bounceIn; + case EaseType.bounceInOut: + return easeType; + case EaseType.circleIn: + return EaseType.circleOut; + case EaseType.circleOut: + return EaseType.circleIn; + case EaseType.circleInOut: + return easeType; + case EaseType.cubicIn: + return EaseType.cubicOut; + case EaseType.cubicOut: + return EaseType.cubicIn; + case EaseType.circleInOut: + return easeType; + case EaseType.punch: + return easeType; + case EaseType.expoIn: + return EaseType.expoOut; + case EaseType.expoOut: + return EaseType.expoIn; + case EaseType.expoInOut: + return easeType; + case EaseType.quadIn: + return EaseType.quadOut; + case EaseType.quadOut: + return EaseType.quadIn; + case EaseType.quadInOut: + return easeType; + case EaseType.quartIn: + return EaseType.quadOut; + case EaseType.quartOut: + return EaseType.quartIn; + case EaseType.quadInOut: + return easeType; + case EaseType.sineIn: + return EaseType.sineOut; + case EaseType.sineOut: + return EaseType.sineIn; + case EaseType.sineInOut: + return easeType; + default: + return easeType; + } + }; + EaseHelper.ease = function (easeType, t, duration) { + switch (easeType) { + case EaseType.linear: + return es.Easing.Linear.easeNone(t, duration); + case EaseType.backIn: + return es.Easing.Back.easeIn(t, duration); + case EaseType.backOut: + return es.Easing.Back.easeOut(t, duration); + case EaseType.backInOut: + return es.Easing.Back.easeInOut(t, duration); + case EaseType.bounceIn: + return es.Easing.Bounce.easeIn(t, duration); + case EaseType.bounceOut: + return es.Easing.Bounce.easeOut(t, duration); + case EaseType.bounceInOut: + return es.Easing.Bounce.easeInOut(t, duration); + case EaseType.circleIn: + return es.Easing.Circular.easeIn(t, duration); + case EaseType.circleOut: + return es.Easing.Circular.easeOut(t, duration); + case EaseType.circleInOut: + return es.Easing.Circular.easeInOut(t, duration); + case EaseType.cubicIn: + return es.Easing.Cubic.easeIn(t, duration); + case EaseType.cubicOut: + return es.Easing.Cubic.easeOut(t, duration); + case EaseType.cubicInOut: + return es.Easing.Cubic.easeInOut(t, duration); + case EaseType.elasticIn: + return es.Easing.Elastic.easeIn(t, duration); + case EaseType.elasticOut: + return es.Easing.Elastic.easeOut(t, duration); + case EaseType.elasticInOut: + return es.Easing.Elastic.easeInOut(t, duration); + case EaseType.punch: + return es.Easing.Elastic.punch(t, duration); + case EaseType.expoIn: + return es.Easing.Exponential.easeIn(t, duration); + case EaseType.expoOut: + return es.Easing.Exponential.easeOut(t, duration); + case EaseType.expoInOut: + return es.Easing.Exponential.easeInOut(t, duration); + case EaseType.quadIn: + return es.Easing.Quadratic.easeIn(t, duration); + case EaseType.quadOut: + return es.Easing.Quadratic.easeOut(t, duration); + case EaseType.quadInOut: + return es.Easing.Quadratic.easeInOut(t, duration); + case EaseType.quadIn: + return es.Easing.Quadratic.easeIn(t, duration); + case EaseType.quadOut: + return es.Easing.Quadratic.easeOut(t, duration); + case EaseType.quadInOut: + return es.Easing.Quadratic.easeInOut(t, duration); + case EaseType.quintIn: + return es.Easing.Quintic.easeIn(t, duration); + case EaseType.quintOut: + return es.Easing.Quintic.easeOut(t, duration); + case EaseType.quintInOut: + return es.Easing.Quintic.easeInOut(t, duration); + case EaseType.sineIn: + return es.Easing.Sinusoidal.easeIn(t, duration); + case EaseType.sineOut: + return es.Easing.Sinusoidal.easeOut(t, duration); + case EaseType.sineInOut: + return es.Easing.Sinusoidal.easeInOut(t, duration); + default: + return es.Easing.Linear.easeNone(t, duration); + } + }; + return EaseHelper; + }()); + es.EaseHelper = EaseHelper; +})(es || (es = {})); +var es; +(function (es) { + var GlobalManager = /** @class */ (function () { + function GlobalManager() { + } + Object.defineProperty(GlobalManager.prototype, "enabled", { + /** + * 如果true则启用了GlobalManager。 + * 状态的改变会导致调用OnEnabled/OnDisable + */ + get: function () { + return this._enabled; + }, + /** + * 如果true则启用了GlobalManager。 + * 状态的改变会导致调用OnEnabled/OnDisable + * @param value + */ + set: function (value) { + this.setEnabled(value); + }, + enumerable: true, + configurable: true + }); + /** + * 启用/禁用这个GlobalManager + * @param isEnabled + */ + GlobalManager.prototype.setEnabled = function (isEnabled) { + if (this._enabled != isEnabled) { + this._enabled = isEnabled; + if (this._enabled) { + this.onEnabled(); + } + else { + this.onDisabled(); + } + } + }; + /** + * 此GlobalManager启用时调用 + */ + GlobalManager.prototype.onEnabled = function () { + }; + /** + * 此GlobalManager禁用时调用 + */ + GlobalManager.prototype.onDisabled = function () { + }; + /** + * 在frame .update之前调用每一帧 + */ + GlobalManager.prototype.update = function () { + }; + return GlobalManager; + }()); + es.GlobalManager = GlobalManager; +})(es || (es = {})); +/// +/// +var es; +/// +/// +(function (es) { + var TweenManager = /** @class */ (function (_super) { + __extends(TweenManager, _super); + function TweenManager() { + var _this = _super.call(this) || this; + /** + * 当前所有活跃用户的内部列表 + */ + _this._activeTweens = []; + _this._tempTweens = []; + TweenManager._instance = _this; + return _this; + } + TweenManager.prototype.update = function () { + this._isUpdating = true; + // 反向循环,这样我们就可以把完成的weens删除了 + for (var i = this._activeTweens.length - 1; i >= 0; --i) { + var tween = this._activeTweens[i]; + if (tween.tick()) + this._tempTweens.push(tween); + } + this._isUpdating = false; + for (var i = 0; i < this._tempTweens.length; i++) { + this._tempTweens[i].recycleSelf(); + new es.List(this._activeTweens).remove(this._tempTweens[i]); + } + this._tempTweens.length = 0; + }; + /** + * 将一个tween添加到活动tweens列表中 + * @param tween + */ + TweenManager.addTween = function (tween) { + TweenManager._instance._activeTweens.push(tween); + }; + /** + * 从当前的tweens列表中删除一个tween + * @param tween + */ + TweenManager.removeTween = function (tween) { + if (TweenManager._instance._isUpdating) { + TweenManager._instance._tempTweens.push(tween); + } + else { + tween.recycleSelf(); + new es.List(TweenManager._instance._activeTweens).remove(tween); + } + }; + /** + * 停止所有的tween并选择地把他们全部完成 + * @param bringToCompletion + */ + TweenManager.stopAllTweens = function (bringToCompletion) { + if (bringToCompletion === void 0) { bringToCompletion = false; } + for (var i = TweenManager._instance._activeTweens.length - 1; i >= 0; --i) + TweenManager._instance._activeTweens[i].stop(bringToCompletion); + }; + /** + * 返回具有特定上下文的所有tweens。 + * Tweens以ITweenable的形式返回,因为这就是TweenManager所知道的所有内容 + * @param context + */ + TweenManager.allTweensWithContext = function (context) { + var foundTweens = []; + for (var i = 0; i < TweenManager._instance._activeTweens.length; i++) { + if (TweenManager._instance._activeTweens[i].context == context) + foundTweens.push(TweenManager._instance._activeTweens[i]); + } + return foundTweens; + }; + /** + * 停止所有给定上下文的tweens + * @param context + * @param bringToCompletion + */ + TweenManager.stopAllTweensWithContext = function (context, bringToCompletion) { + if (bringToCompletion === void 0) { bringToCompletion = false; } + for (var i = TweenManager._instance._activeTweens.length - 1; i >= 0; --i) { + if (TweenManager._instance._activeTweens[i].context == context) + TweenManager._instance._activeTweens[i].stop(bringToCompletion); + } + }; + /** + * 返回具有特定目标的所有tweens。 + * Tweens以ITweenControl的形式返回,因为TweenManager只知道这些 + * @param target + */ + TweenManager.allTweenWithTarget = function (target) { + var foundTweens = []; + for (var i = 0; i < TweenManager._instance._activeTweens.length; i++) { + if (TweenManager._instance._activeTweens[i]) { + var tweenControl = TweenManager._instance._activeTweens[i]; + if (tweenControl.getTargetObject() == target) + foundTweens.push(TweenManager._instance._activeTweens[i]); + } + } + return foundTweens; + }; + /** + * 停止所有具有TweenManager知道的特定目标的tweens + * @param target + * @param bringToCompletion + */ + TweenManager.stopAllTweensWithTarget = function (target, bringToCompletion) { + if (bringToCompletion === void 0) { bringToCompletion = false; } + for (var i = TweenManager._instance._activeTweens.length - 1; i >= 0; --i) { + if (TweenManager._instance._activeTweens[i]) { + var tweenControl = TweenManager._instance._activeTweens[i]; + if (tweenControl.getTargetObject() == target) + tweenControl.stop(bringToCompletion); + } + } + }; + TweenManager.defaultEaseType = es.EaseType.quartIn; + /** + * 如果为真,当加载新关卡时,活动的tween列表将被清除 + */ + TweenManager.removeAllTweensOnLevelLoad = false; + /** + * 这里支持各种类型的自动缓存。请 + * 注意,只有在使用扩展方法启动tweens时,或者在做自定义tweens时从缓存中获取tween时,缓存才会起作用。 + * 关于如何获取缓存的tween,请参见扩展方法的实现 + */ + TweenManager.cacheNumberTweens = true; + TweenManager.cacheVector2Tweens = true; + TweenManager.cacheColorTweens = true; + TweenManager.cacheRectTweens = false; + return TweenManager; + }(es.GlobalManager)); + es.TweenManager = TweenManager; +})(es || (es = {})); +var es; +(function (es) { + /** + * 标准缓和方程通过将b和c参数(起始值和变化值)用0和1替换,然后进行简化。 + * 这样做的目的是为了让我们可以得到一个0 - 1之间的原始值(除了弹性/反弹故意超过界限),然后用这个值来lerp任何东西 + */ + var Easing; + (function (Easing) { + var Linear = /** @class */ (function () { + function Linear() { + } + Linear.easeNone = function (t, d) { + return t / d; + }; + return Linear; + }()); + Easing.Linear = Linear; + var Quadratic = /** @class */ (function () { + function Quadratic() { + } + Quadratic.easeIn = function (t, d) { + return (t /= d) * t; + }; + Quadratic.easeOut = function (t, d) { + return -1 * (t /= d) * (t - 2); + }; + Quadratic.easeInOut = function (t, d) { + if ((t /= d / 2) < 1) + return 0.5 * t * t; + return -0.5 * ((--t) * (t - 2) - 1); + }; + return Quadratic; + }()); + Easing.Quadratic = Quadratic; + var Back = /** @class */ (function () { + function Back() { + } + Back.easeIn = function (t, d) { + return (t /= d) * t * ((1.70158 + 1) * t - 1.70158); + }; + Back.easeOut = function (t, d) { + return ((t = t / d - 1) * t * ((1.70158 + 1) * t + 1.70158) + 1); + }; + Back.easeInOut = function (t, d) { + var s = 1.70158; + if ((t /= d / 2) < 1) { + return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)); + } + return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2); + }; + return Back; + }()); + Easing.Back = Back; + var Bounce = /** @class */ (function () { + function Bounce() { + } + Bounce.easeOut = function (t, d) { + if ((t /= d) < (1 / 2.75)) { + return (7.5625 * t * t); + } + else if (t < (2 / 2.75)) { + return (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75); + } + else if (t < (2.5 / 2.75)) { + return (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375); + } + else { + return (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375); + } + }; + Bounce.easeIn = function (t, d) { + return 1 - this.easeOut(d - t, d); + }; + Bounce.easeInOut = function (t, d) { + if (t < d / 2) + return this.easeIn(t * 2, d) * 0.5; + else + return this.easeOut(t * 2 - d, d) * 0.5 + 1 * 0.5; + }; + return Bounce; + }()); + Easing.Bounce = Bounce; + var Circular = /** @class */ (function () { + function Circular() { + } + Circular.easeIn = function (t, d) { + return -(Math.sqrt(1 - (t /= d) * t) - 1); + }; + Circular.easeOut = function (t, d) { + return Math.sqrt(1 - (t = t / d - 1) * t); + }; + Circular.easeInOut = function (t, d) { + if ((t /= d / 2) < 1) + return -0.5 * (Math.sqrt(1 - t * t) - 1); + return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1); + }; + return Circular; + }()); + Easing.Circular = Circular; + var Cubic = /** @class */ (function () { + function Cubic() { + } + Cubic.easeIn = function (t, d) { + return (t /= d) * t * t; + }; + Cubic.easeOut = function (t, d) { + return ((t = t / d - 1) * t * t + 1); + }; + Cubic.easeInOut = function (t, d) { + if ((t /= d / 2) < 1) + return 0.5 * t * t * t; + return 0.5 * ((t -= 2) * t * t + 2); + }; + return Cubic; + }()); + Easing.Cubic = Cubic; + var Elastic = /** @class */ (function () { + function Elastic() { + } + Elastic.easeIn = function (t, d) { + if (t == 0) + return 0; + if ((t /= d) == 1) + return 1; + var p = d * 0.3; + var s = p / 4; + return -(1 * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)); + }; + Elastic.easeOut = function (t, d) { + if (t == 0) + return 0; + if ((t /= d) == 1) + return 1; + var p = d * 0.3; + var s = p / 4; + return (1 * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + 1); + }; + Elastic.easeInOut = function (t, d) { + if (t == 0) + return 0; + if ((t /= d / 2) == 2) + return 1; + var p = d * (0.3 * 1.5); + var s = p / 4; + if (t < 1) + return -0.5 * (Math.pow(2, 10 * (t -= 1)) * Math.sin(t * d - s) * (2 * Math.PI) / p); + return (Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + 1); + }; + Elastic.punch = function (t, d) { + if (t == 0) + return 0; + if ((t /= d) == 1) + return 0; + var p = 0.3; + return (Math.pow(2, -10 * t) * Math.sin(t * (2 * Math.PI) / p)); + }; + return Elastic; + }()); + Easing.Elastic = Elastic; + var Exponential = /** @class */ (function () { + function Exponential() { + } + Exponential.easeIn = function (t, d) { + return (t == 0) ? 0 : Math.pow(2, 10 * (t / d - 1)); + }; + Exponential.easeOut = function (t, d) { + return t == d ? 1 : (-Math.pow(2, -10 * t / d) + 1); + }; + Exponential.easeInOut = function (t, d) { + if (t == 0) + return 0; + if (t == d) + return 1; + if ((t /= d / 2) < 1) { + return 0.5 * Math.pow(2, 10 * (t - 1)); + } + return 0.5 * (-Math.pow(2, -10 * --t) + 2); + }; + return Exponential; + }()); + Easing.Exponential = Exponential; + var Quartic = /** @class */ (function () { + function Quartic() { + } + Quartic.easeIn = function (t, d) { + return (t /= d) * t * t * t; + }; + Quartic.easeOut = function (t, d) { + return -1 * ((t = t / d - 1) * t * t * t - 1); + }; + Quartic.easeInOut = function (t, d) { + t /= d / 2; + if (t < 1) + return 0.5 * t * t * t * t; + t -= 2; + return -0.5 * (t * t * t * t - 2); + }; + return Quartic; + }()); + Easing.Quartic = Quartic; + var Quintic = /** @class */ (function () { + function Quintic() { + } + Quintic.easeIn = function (t, d) { + return (t /= d) * t * t * t * t; + }; + Quintic.easeOut = function (t, d) { + return ((t = t / d - 1) * t * t * t * t + 1); + }; + Quintic.easeInOut = function (t, d) { + if ((t /= d / 2) < 1) + return 0.5 * t * t * t * t * t; + return 0.5 * ((t -= 2) * t * t * t * t + 2); + }; + return Quintic; + }()); + Easing.Quintic = Quintic; + var Sinusoidal = /** @class */ (function () { + function Sinusoidal() { + } + Sinusoidal.easeIn = function (t, d) { + return -1 * Math.cos(t / d * (Math.PI / 2)) + 1; + }; + Sinusoidal.easeOut = function (t, d) { + return Math.sin(t / d * (Math.PI / 2)); + }; + Sinusoidal.easeInOut = function (t, d) { + return -0.5 * (Math.cos(Math.PI * t / d) - 1); + }; + return Sinusoidal; + }()); + Easing.Sinusoidal = Sinusoidal; + })(Easing = es.Easing || (es.Easing = {})); +})(es || (es = {})); +var es; +(function (es) { + /** + * 一系列静态方法来处理所有常见的tween类型结构,以及它们的unclamped lerps.unclamped lerps对于超过0-1范围的bounce、elastic或其他tweens是必需的 + */ + var Lerps = /** @class */ (function () { + function Lerps() { + } + Lerps.lerp = function (from, to, t) { + if (typeof (from) == "number" && typeof (to) == "number") { + return from + (to - from) * t; + } + if (from instanceof es.Color && to instanceof es.Color) { + var t255 = t * 255; + return new es.Color(from.r + (to.r - from.r) * t255 / 255, from.g + (to.g - from.g) * t255 / 255, from.b + (to.b - from.b) * t255 / 255, from.a + (to.a - from.a) * t255 / 255); + } + if (from instanceof es.Rectangle && to instanceof es.Rectangle) { + return new es.Rectangle((from.x + (to.x - from.x) * t), (from.y + (to.x - from.y) * t), (from.width + (to.width - from.width) * t), (from.height + (to.height - from.height) * t)); + } + if (from instanceof es.Vector2 && to instanceof es.Vector2) { + return new es.Vector2(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t); + } + }; + Lerps.angleLerp = function (from, to, t) { + // 我们计算这个lerp的最短角差 + var toMinusFrom = new es.Vector2(es.MathHelper.deltaAngle(from.x, to.x), es.MathHelper.deltaAngle(from.y, to.y)); + return new es.Vector2(from.x + toMinusFrom.x * t, from.y + toMinusFrom.y * t); + }; + Lerps.ease = function (easeType, from, to, t, duration) { + if (typeof (from) == 'number' && typeof (to) == "number") { + return this.lerp(from, to, es.EaseHelper.ease(easeType, t, duration)); + } + if (from instanceof es.Vector2 && to instanceof es.Vector2) { + return this.lerp(from, to, es.EaseHelper.ease(easeType, t, duration)); + } + if (from instanceof es.Rectangle && to instanceof es.Rectangle) { + return this.lerp(from, to, es.EaseHelper.ease(easeType, t, duration)); + } + if (from instanceof es.Color && to instanceof es.Color) { + return this.lerp(from, to, es.EaseHelper.ease(easeType, t, duration)); + } + }; + Lerps.easeAngle = function (easeType, from, to, t, duration) { + return this.angleLerp(from, to, es.EaseHelper.ease(easeType, t, duration)); + }; + /** + * 使用半隐式欧拉方法。速度较慢,但总是很稳定。见 + * http://allenchou.net/2015/04/game-math-more-on-numeric-springing/ + * @param currentValue + * @param targetValue + * @param velocity Velocity的引用。如果在两次调用之间改变targetValue,请务必将其重置为0 + * @param dampingRatio 值越低,阻尼越小,值越高,阻尼越大,导致弹簧度越小,应在0.01-1之间,以避免系统不稳定 + * @param angularFrequency 角频率为2pi(弧度/秒)意味着振荡在一秒钟内完成一个完整的周期,即1Hz.应小于35左右才能保持稳定 + */ + Lerps.fastSpring = function (currentValue, targetValue, velocity, dampingRatio, angularFrequency) { + velocity.add(velocity.scale(-2 * es.Time.deltaTime * dampingRatio * angularFrequency) + .add(targetValue.sub(currentValue).scale(es.Time.deltaTime * angularFrequency * angularFrequency))); + currentValue.add(velocity.scale(es.Time.deltaTime)); + return currentValue; + }; + return Lerps; + }()); + es.Lerps = Lerps; +})(es || (es = {})); +var es; (function (es) { var AnimCurve = /** @class */ (function () { function AnimCurve(points) { @@ -11053,64 +12454,6 @@ var es; es.EqualityComparer = EqualityComparer; })(es || (es = {})); var es; -(function (es) { - var GlobalManager = /** @class */ (function () { - function GlobalManager() { - } - Object.defineProperty(GlobalManager.prototype, "enabled", { - /** - * 如果true则启用了GlobalManager。 - * 状态的改变会导致调用OnEnabled/OnDisable - */ - get: function () { - return this._enabled; - }, - /** - * 如果true则启用了GlobalManager。 - * 状态的改变会导致调用OnEnabled/OnDisable - * @param value - */ - set: function (value) { - this.setEnabled(value); - }, - enumerable: true, - configurable: true - }); - /** - * 启用/禁用这个GlobalManager - * @param isEnabled - */ - GlobalManager.prototype.setEnabled = function (isEnabled) { - if (this._enabled != isEnabled) { - this._enabled = isEnabled; - if (this._enabled) { - this.onEnabled(); - } - else { - this.onDisabled(); - } - } - }; - /** - * 此GlobalManager启用时调用 - */ - GlobalManager.prototype.onEnabled = function () { - }; - /** - * 此GlobalManager禁用时调用 - */ - GlobalManager.prototype.onDisabled = function () { - }; - /** - * 在frame .update之前调用每一帧 - */ - GlobalManager.prototype.update = function () { - }; - return GlobalManager; - }()); - es.GlobalManager = GlobalManager; -})(es || (es = {})); -var es; (function (es) { var Hash = /** @class */ (function () { function Hash() { diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 58f951f5..f0d36fd1 100644 --- a/source/bin/framework.min.js +++ b/source/bin/framework.min.js @@ -1 +1 @@ -window.es={};var __awaiter=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))(function(r,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){t.done?r(t.value):new i(function(e){e(t.value)}).then(s,a)}h((n=n.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){r={error:t}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return s},__spread=this&&this.__spread||function(){for(var t=[],e=0;e=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}}},transform;!function(t){var e=function(){function e(i,n){void 0===i&&(i=!0),void 0===n&&(n=!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(this._timerManager),e.entitySystemsEnabled=n,this.debug=i,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 i=0,n=e._instance._globalManagers.length;i=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(){t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(i){return void 0===i&&(i=-1),__awaiter(this,void 0,void 0,function(){var n;return __generator(this,function(r){if(e.paused)return[2];if(t.Time.update(i),null!=this._scene){for(n=this._globalManagers.length-1;n>=0;n--)this._globalManagers[n].enabled&&this._globalManagers[n].update();this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}return this.startDebugDraw(),[2]})})},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 i=function(){function t(){}return t.warnIf=function(t,i){for(var n=[],r=2;r=0;t--){this.transform.getChild(t).entity.destroy()}},i.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.round=function(){return new e(Math.round(this.x),Math.round(this.y))},e.prototype.angleBetween=function(e,i){var n=e.sub(this),r=i.sub(this);return t.Vector2Ext.angle(n,r)},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,i){return new e(t.xi.x?t.x:i.x,t.y>i.y?t.y:i.y)},e.hermite=function(i,n,r,o,s){return new e(t.MathHelper.hermite(i.x,n.x,r.x,o.x,s),t.MathHelper.hermite(i.y,n.y,r.y,o.y,s))},e.unsignedAngle=function(e,i,n){void 0===n&&(n=!0),e.normalizeEqual(),i.normalizeEqual();var r=Math.acos(t.MathHelper.clamp(e.dot(i),-1,1))*t.MathHelper.Rad2Deg;return n?Math.round(r):r},e.prototype.clone=function(){return new e(this.x,this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this._renderers=[],this.entities=new t.EntityList(this),this.renderableComponents=new t.RenderableComponentList,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(){0==this._renderers.length&&this.addRenderer(new t.DefaultRenderer),t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1;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(),this.renderableComponents.updateLists(),this.render()},e.prototype.render=function(){for(var t=0;te.x?-1:1,n=this.position.sub(e).normalize();this.rotation=i*Math.acos(n.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(e.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},i.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},i.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},i.prototype.updateTransform=function(){this.hierarchyDirty!=e.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=e.clean)},i.prototype.setDirty=function(t){if(0==(this.hierarchyDirty&t)){switch(this.hierarchyDirty|=t,t){case e.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case e.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case e.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}for(var i=0;i1e-4?this._inverseMass=1/this._mass:this._inverseMass=0,this},i.prototype.setElasticity=function(e){return this._elasticity=t.MathHelper.clamp01(e),this},i.prototype.setFriction=function(e){return this._friction=t.MathHelper.clamp01(e),this},i.prototype.setGlue=function(e){return this._glue=t.MathHelper.clamp(e,0,10),this},i.prototype.setVelocity=function(t){return this.velocity=t,this},i.prototype.addImpulse=function(e){this.isImmovable||this.velocity.addEqual(e.scale(this._inverseMass*(t.Time.deltaTime*t.Time.deltaTime)*1e5))},i.prototype.onAddedToEntity=function(){this._collider=null;for(var e=0;e0&&(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 i=0;i0&&(this.ignoreOneWayPlatformsTime-=e)},n.prototype.warpToGrounded=function(e){void 0===e&&(e=1e3),this.ignoreOneWayPlatformsTime=0,this._isWarpingToGround=!0;var i=0;do{if(i+=1,this.move(new t.Vector2(0,1),.02),i>e)break}while(!this.isGrounded);this._isWarpingToGround=!1},n.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)},n.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)},n.prototype.moveHorizontally=function(e){for(var i=e.x>0,n=Math.abs(e.x)+this._skinWidth*this.rayOriginSkinMutiplier,r=i?t.Vector2.right:t.Vector2.left,o=this._raycastOrigins.bottomLeft.y,s=i?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 h=0;hthis.jumpingThreshold){var n=this.slopeSpeedMultiplier?this.slopeSpeedMultiplier.lerp(i):1;e.x*=n,e.y=Math.abs(Math.tan(i*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},n}();t.CharacterController=n}(es||(es={})),function(t){var e=function(){function e(){}return e.getITriggerListener=function(e,i){var n,r;try{for(var o=__values(e.components._components),s=o.next();!s.done;s=o.next()){var a=s.value;t.isITriggerListener(a)&&i.push(a)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}for(var h in e.components._componentsToAdd){a=e.components._componentsToAdd[h];t.isITriggerListener(a)&&i.push(a)}return i},e}();t.TriggerListenerHelper=e,t.isITriggerListener=function(t){return void 0!==t.onTriggerEnter}}(es||(es={})),function(t){var e=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return __extends(i,e),i.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},i.prototype.calculateMovement=function(e,i){for(var n,r,o=null,s=0;si;i++){var n=t[i];this.processDelta(n,this.acc);var r=this.getRemainingDelay(n);r<=0?this.processExpired(n):this.offerDelay(r)}this.acc=0}else this.stop()},i.prototype.checkProcessing=function(){return!!this.running&&(this.acc+=t.Time.deltaTime,this.acc>=this.delay)},i.prototype.offerDelay=function(t){this.running?this.delay=Math.min(this.delay,t):(this.running=!0,this.delay=t)},i.prototype.getInitialTimeDelay=function(){return this.delay},i.prototype.getRemainingTimeUntilProcessing=function(){return this.running?this.delay-this.acc:0},i.prototype.isRunning=function(){return this.running},i.prototype.stop=function(){this.running=!1,this.acc=0},i}(t.EntitySystem);t.DelayedIteratingSystem=e}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.lateProcessEntity=function(t){},e.prototype.process=function(t){if(0!=t.length)for(var e=0,i=t.length;e=this.interval&&(this.acc-=this.interval,this.intervalDelta=this.acc-this.intervalDelta,!0)},i.prototype.getIntervalDelta=function(){return this.interval+this.intervalDelta},i}(t.EntitySystem);t.IntervalSystem=e}(es||(es={})),function(t){var e=function(t){function e(e,i){return t.call(this,e,i)||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 i=_super.call(this,t)||this;i._threads=e,i._jobs=new Array(e);for(var n=0;nt.length&&(s=t.length);var a=o._jobs[i];if(a.set(t,r,s,o._executeStr,o),r!=s){var h=es.WorkerUtils.makeWorker(o.queueOnThread);es.WorkerUtils.workerMessage(h)(a).then(function(t){var i=t;e.resetJob(i),h.terminate()}).catch(function(t){a.err=t,h.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,i=this._components.length;e0)for(var e=0,i=this._components.length;e0){for(var e=function(t,e){var n=i._componentsToRemoveList[t];i.handleRemove(n);var r=i._components.findIndex(function(t){return t.id==n.id});-1!=r&&i._components.splice(r,1),i.removeComponentsByType(n)},i=this,n=0,r=this._componentsToRemoveList.length;n0){for(n=0,r=this._componentsToAddList.length;n0){for(n=0,r=this._tempBufferList.length;n0){var i=this._updatableComponents.findIndex(function(t){return t.id==e.id});-1!=i&&this._updatableComponents.splice(i,1)}this.decreaseBits(e),this._entity.scene.entityProcessors.onComponentRemoved(this._entity),e.onRemovedFromEntity(),e.entity=null},e.prototype.removeComponentsByType=function(e){var i=this.componentsByType.get(t.TypeUtils.getType(e)),n=i.findIndex(function(t){return t.id==e.id});-1!=n&&i.splice(n,1)},e.prototype.addComponentsByType=function(e){var i=this.componentsByType.get(t.TypeUtils.getType(e));i||(i=[]),i.push(e),this.componentsByType.set(t.TypeUtils.getType(e),i)},e.prototype.removeComponentsToAddByType=function(e){var i=this.componentsToAddByType.get(t.TypeUtils.getType(e)),n=i.findIndex(function(t){return t.id==e.id});-1!=n&&i.splice(n,1)},e.prototype.addComponentsToAddByType=function(e){var i=this.componentsToAddByType.get(t.TypeUtils.getType(e));i||(i=[]),i.push(e),this.componentsToAddByType.set(t.TypeUtils.getType(e),i)},e.prototype.getComponent=function(t,e){var i=this.componentsByType.get(t);if(i&&i.length>0)return i[0];if(!e){var n=this.componentsToAddByType.get(t);if(n&&n.length>0)return n[0]}return null},e.prototype.getComponents=function(t,e){e||(e=[]);var i=this.componentsByType.get(t);i&&(e=e.concat(i));var n=this.componentsToAddByType.get(t);return n&&(e=e.concat(n)),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,i=this._components.length;e0)for(e=0,i=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,i){var n=e._entitiesToRemoveList[t];e.removeFromTagList(n);var r=e._entities.findIndex(function(t){return t.id==n.id});-1!=r&&e._entities.splice(r,1),n.onRemovedFromScene(),n.scene=null,e.scene.entityProcessors.onEntityRemoved(n)},e=this,i=0,n=this._entitiesToRemoveList.length;i0){for(i=0,n=this._entitiesToAddedList.length;i0)for(var e=0,i=this._entities.length;e0)for(e=0,i=this._entitiesToAddedList.length;e0)for(var e=0,i=this._entities.length;e0)try{for(var s=__values(r),a=s.next();!a.done;a=s.next()){var h=a.value;o.push(h)}}catch(t){i={error:t}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(i)throw i.error}}return o},e.prototype.entityWithTag=function(t){var e,i,n=this.getTagList(t);if(n.size>0)try{for(var r=__values(n),o=r.next();!o.done;o=r.next()){return o.value}}catch(t){e={error:t}}finally{try{o&&!o.done&&(i=r.return)&&i.call(r)}finally{if(e)throw e.error}}return null},e.prototype.findComponentOfType=function(t){if(this._entities.length>0)for(var e=0,i=this._entities.length;e0)for(e=0;e0)for(var n=0,r=this._entities.length;n0)for(n=0,r=this._entitiesToAddedList.length;n0)for(var n=0,r=this._entities.length;n0)for(var s=0,a=t.length;s0)for(n=0,r=this._entitiesToAddedList.length;n0)for(s=0,a=t.length;s=t)return i}for(e=1|t;ethis.maxPrimeArrayLength&&this.maxPrimeArrayLength>t?this.maxPrimeArrayLength:this.getPrime(e)},t.getHashCode=function(t){var e,i=0;if(0==(e="object"==typeof t?JSON.stringify(t):t.toString()).length)return i;for(var n=0;n0?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 i=0,n=this.allSet.length;i0)for(var t=0,e=this._unsortedRenderLayers.length;t=e)return t;var n=!1;"-"==t.substr(0,1)&&(n=!0,t=t.substr(1));for(var r=e-i,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,i,n){void 0===n&&(n=!0),e=Math.floor(e),i=Math.floor(i);var r=t.length;e>r&&(e=r);var o,s=e,a=e+i;return n?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-i)+i,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var i=0,n=e.length;i",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){-1==t&&(t=Date.now()),-1==this._lastTime&&(this._lastTime=t);var e=0;(e=-1==t?(t-this._lastTime)/1e3:t)>this.maxDeltaTime&&(e=this.maxDeltaTime),this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.totalTime=0,t.unscaledDeltaTime=0,t.deltaTime=0,t.timeScale=1,t.maxDeltaTime=Number.MAX_VALUE,t.frameCount=0,t.timeSinceSceneLoad=0,t._lastTime=-1,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),i=t.getMonth()+1;return parseInt(e+(i<10?"0":"")+i)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,i=e<10?"0":"",n=t.getDate(),r=n<10?"0":"";return parseInt(t.getFullYear()+i+e+r+n)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var i=new Date;i.setTime(t.getTime()),i.setDate(1),i.setMonth(0);var n=i.getFullYear(),r=i.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,i.setDate(i.getDate()-(r-1))):i.setDate(i.getDate()+7-r+1);var s=this.diffDay(t,i,!1);if(s<0)return i.setDate(1),i.setMonth(0),i.setDate(i.getDate()-1),this.weekId(i,!1);var a=s/7,h=Math.floor(a)+1;if(53==h){i.setTime(t.getTime()),i.setDate(i.getDate()-1);var c=i.getDay();if(0==c&&(c=7),e&&(!o||c<4))return i.setFullYear(i.getFullYear()+1),i.setDate(1),i.setMonth(0),this.weekId(i,!1)}return parseInt(n+"00"+(h>9?"":"0")+h)},t.diffDay=function(t,e,i){void 0===i&&(i=!1);var n=(t.getTime()-e.getTime())/864e5;return i?Math.ceil(n):Math.floor(n)},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(),i=t.getMonth()+1;i=i<10?"0"+i:i;var n=t.getDate();return e+"-"+i+"-"+(n=n<10?"0"+n:n)},t.formatDateTime=function(t){var e=t.getFullYear(),i=t.getMonth()+1;i=i<10?"0"+i:i;var n=t.getDate();n=n<10?"0"+n:n;var r=t.getHours(),o=t.getMinutes();o=o<10?"0"+o:o;var s=t.getSeconds();return e+"-"+i+"-"+n+" "+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,i){void 0===t&&(t=0),void 0===e&&(e=":"),void 0===i&&(i=!0);var n=Math.floor(t/3600),r=Math.floor(t%3600/60),o=Math.floor(t%3600%60),s=n.toString(),a=r.toString(),h=o.toString();return n<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(h="0"+h),i?s+e+a+e+h:a+e+h},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var i=t.split(e),n=0,r=i.length,o=0;o1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t},t.fromRGBA=function(e,i,n,r){e/=255,i/=255,n/=255;var o=Math.max(e,i,n),s=Math.min(e,i,n),a=(o+s)/2,h=a,c=a;if(o===s)a=h=0;else{var l=o-s;switch(h=c>.5?l/(2-o-s):l/(o+s),o){case e:a=(i-n)/l+(i=1?(e=1,i.range=this._points.length-4):(e=t.MathHelper.clamp01(e)*this._curveCount,i.range=Math.floor(e),e-=i.range,i.range*=3),i.time=e,i},e.prototype.setControlPoint=function(t,e){if(t%3==0){var i=e.sub(this._points[t]);t>0&&this._points[t-1].addEqual(i),t+1-Math.PI&&t<=Math.PI?t:(t%=2*Math.PI)<=-Math.PI?t+2*Math.PI:t>Math.PI?t-2*Math.PI:t},e.isPowerOfTwo=function(t){return t>0&&t%(t-1)==0},e.lerp=function(t,e,i){return t+(e-t)*this.clamp01(i)},e.betterLerp=function(t,i,n,r){return Math.abs(t-i)180&&(n-=360),t+n*this.clamp01(i)},e.lerpAngleRadians=function(t,e,i){var n=this.repeat(e-t,2*Math.PI);return n>Math.PI&&(n-=2*Math.PI),t+n*this.clamp01(i)},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,i){if(te)return 1}else{if(it)return 0}return(i-t)/(e-t)},e.lerpPrecise=function(t,e,i){return(1-i)*t+e*i},e.clamp=function(t,e,i){return ti?i:t},e.snap=function(t,e){return Math.round(t/e)*e},e.pointOnCirlce=function(i,n,r){var o=e.toRadians(r);return new t.Vector2(Math.cos(o)*o+i.x,Math.sin(o)*o+i.y)},e.isEven=function(t){return t%2==0},e.isOdd=function(t){return t%2!=0},e.roundWithRoundedAmount=function(t,e){var i=Math.round(t);return e.value=t-i*Math.round(t/i),i},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,i){return new t.Vector2(Math.cos(e)*i,Math.sin(e)*i)},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&&(i-=360),i},e.between=function(t,e,i){return t>=e&&t<=i},e.deltaAngleRadians=function(t,e){var i=this.repeat(e-t,2*Math.PI);return i>Math.PI&&(i-=2*Math.PI),i},e.repeat=function(t,e){return t-Math.floor(t/e)*e},e.floorToInt=function(t){return Math.trunc(Math.floor(t))},e.rotateAround=function(e,i){var n=t.Time.totalTime*i,r=Math.cos(n),o=Math.sin(n);return new t.Vector2(e.x+r,e.y+o)},e.rotateAround2=function(e,i,n){n=this.toRadians(n);var r=Math.cos(n),o=Math.sin(n),s=r*(e.x-i.x)-o*(e.y-i.y)+i.x,a=o*(e.x-i.x)+r*(e.y-i.y)+i.y;return new t.Vector2(s,a)},e.pointOnCircle=function(e,i,n){var r=this.toRadians(n);return new t.Vector2(Math.cos(r)*i+e.x,Math.sin(r)*i+e.y)},e.pointOnCircleRadians=function(e,i,n){return new t.Vector2(Math.cos(n)*i+e.x,Math.sin(n)*i+e.y)},e.lissajou=function(e,i,n,r,o){void 0===e&&(e=2),void 0===i&&(i=3),void 0===n&&(n=1),void 0===r&&(r=1),void 0===o&&(o=0);var s=Math.sin(t.Time.totalTime*e+o)*n,a=Math.cos(t.Time.totalTime*i)*r;return new t.Vector2(s,a)},e.lissajouDamped=function(e,i,n,r,o,s,a){void 0===e&&(e=2),void 0===i&&(i=3),void 0===n&&(n=1),void 0===r&&(r=1),void 0===o&&(o=.5),void 0===s&&(s=0),void 0===a&&(a=5);var h=this.pingPong(t.Time.totalTime,a),c=Math.pow(Math.E,-s*h),l=c*Math.sin(t.Time.totalTime*e+o)*n,u=c*Math.cos(t.Time.totalTime*i)*r;return new t.Vector2(l,u)},e.hermite=function(t,e,i,n,r){return 0==r?t:1==r?i:(2*t-2*i+n+e)*(r*r*r)+(3*i-3*t-2*e-n)*(r*r)+e*r+t},e.isValid=function(t){return!Number.isNaN(t)&&t!==1/0},e.smoothDamp=function(t,e,i,n,r,o){var s=2/(n=Math.max(1e-4,n)),a=s*o,h=1/(1+(a+(a*a*.48+a*(a*a)*.235))),c=t-e,l=e,u=r*n,p=(i+s*(c=this.clamp(c,-1*u,u)))*o;i=(i-s*p)*h;var f=(e=t-c)+(c+p)*h;return l-t>0==f>l&&(i=((f=l)-l)/o),{value:f,currentVelocity:i}},e.smoothDampVector=function(e,i,n,r,o,s){var a=t.Vector2.zero,h=this.smoothDamp(e.x,i.x,n.x,r,o,s);a.x=h.value,n.x=h.currentVelocity;var c=this.smoothDamp(e.y,i.y,n.y,r,o,s);return a.y=c.value,n.y=c.currentVelocity,a},e.mapMinMax=function(t,i,n,r,o){return r+(e.clamp(t,i,n)-i)*(o-r)/(n-i)},e.fromAngle=function(e){return new t.Vector2(Math.cos(e),Math.sin(e)).normalizeEqual()},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,i,n,r,o,s,a,h,c,l,u,p,f,d,m){this.m11=t,this.m12=e,this.m13=i,this.m14=n,this.m21=r,this.m22=o,this.m23=s,this.m24=a,this.m31=h,this.m32=c,this.m33=l,this.m34=u,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,i,n,r,o,s,a){void 0===a&&(a=new t),a.m11=2/(i-e),a.m12=0,a.m13=0,a.m14=0,a.m21=0,a.m22=2/(r-n),a.m23=0,a.m24=0,a.m31=0,a.m32=0,a.m33=1/(o-s),a.m34=0,a.m41=(e+i)/(e-i),a.m42=(r+n)/(n-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,i){i=t.Identity;var n=Math.cos(e),r=Math.sin(e);i.m11=n,i.m12=r,i.m21=-r,i.m22=n},t.multiply=function(e,i,n){void 0===n&&(n=new t);var r=e.m11*i.m11+e.m12*i.m21+e.m13*i.m31+e.m14*i.m41,o=e.m11*i.m12+e.m12*i.m22+e.m13*i.m32+e.m14*i.m42,s=e.m11*i.m13+e.m12*i.m23+e.m13*i.m33+e.m14*i.m43,a=e.m11*i.m14+e.m12*i.m24+e.m13*i.m34+e.m14*i.m44,h=e.m21*i.m11+e.m22*i.m21+e.m23*i.m31+e.m24*i.m41,c=e.m21*i.m12+e.m22*i.m22+e.m23*i.m32+e.m24*i.m42,l=e.m21*i.m13+e.m22*i.m23+e.m23*i.m33+e.m24*i.m43,u=e.m21*i.m14+e.m22*i.m24+e.m23*i.m34+e.m24*i.m44,p=e.m31*i.m11+e.m32*i.m21+e.m33*i.m31+e.m34*i.m41,f=e.m31*i.m12+e.m32*i.m22+e.m33*i.m32+e.m34*i.m42,d=e.m31*i.m13+e.m32*i.m23+e.m33*i.m33+e.m34*i.m43,m=e.m31*i.m14+e.m32*i.m24+e.m33*i.m34+e.m34*i.m44,y=e.m41*i.m11+e.m42*i.m21+e.m43*i.m31+e.m44*i.m41,g=e.m41*i.m12+e.m42*i.m22+e.m43*i.m32+e.m44*i.m42,_=e.m41*i.m13+e.m42*i.m23+e.m43*i.m33+e.m44*i.m43,v=e.m41*i.m14+e.m42*i.m24+e.m43*i.m34+e.m44*i.m44;n.m11=r,n.m12=o,n.m13=s,n.m14=a,n.m21=h,n.m22=c,n.m23=l,n.m24=u,n.m31=p,n.m32=f,n.m33=d,n.m34=m,n.m41=y,n.m42=g,n.m43=_,n.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,i,n,r,o){return this.m11=t,this.m12=e,this.m21=i,this.m22=n,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),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,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 i=Math.cos(t),n=Math.sin(t);e.m11=i,e.m12=n,e.m21=-1*n,e.m22=i},e.createRotationOut=function(t,e){var i=Math.cos(t),n=Math.sin(t);e.m11=i,e.m12=n,e.m21=-n,e.m22=i},e.createScale=function(t,e,i){i.m11=t,i.m12=0,i.m21=0,i.m22=e,i.m31=0,i.m32=0},e.createScaleOut=function(t,e,i){i.m11=t,i.m12=0,i.m21=0,i.m22=e,i.m31=0,i.m32=0},e.createTranslation=function(t,e,i){return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=t,i.m32=e,i},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(),i=this.identity;return i.m11=t.m22*e,i.m12=-t.m12*e,i.m21=-t.m21*e,i.m22=t.m11*e,i.m31=(t.m32*t.m21-t.m31*t.m22)*e,i.m32=-(t.m32*t.m11-t.m31*t.m12)*e,i},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,i=this.m11*t.m12+this.m12*t.m22,n=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=i,this.m21=n,this.m22=r,this.m31=o,this.m32=s,this},e.multiply=function(t,e,i){var n=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,h=t.m31*e.m12+t.m32*e.m22+e.m32;i.m11=n,i.m12=r,i.m21=o,i.m22=s,i.m31=a,i.m32=h},e.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},e.lerp=function(t,e,i){return t.m11=t.m11+(e.m11-t.m11)*i,t.m12=t.m12+(e.m12-t.m12)*i,t.m21=t.m21+(e.m21-t.m21)*i,t.m22=t.m22+(e.m22-t.m22)*i,t.m31=t.m31+(e.m31-t.m31)*i,t.m32=t.m32+(e.m32-t.m32)*i,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(i,n){var r=new e;return e.createTranslation(i,n,r),t.MatrixHelper.mutiply(this,r)},e.prototype.equals=function(t){return this==t},e.toMatrix=function(e){var i=new t.Matrix;return i.m11=e.m11,i.m12=e.m12,i.m13=0,i.m14=0,i.m21=e.m21,i.m22=e.m22,i.m23=0,i.m24=0,i.m31=0,i.m32=0,i.m33=1,i.m34=0,i.m41=e.m31,i.m42=e.m32,i.m43=0,i.m44=1,i},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,i){var n=t.Matrix2D.identity;return n.m11=e.m11+i.m11,n.m12=e.m12+i.m12,n.m21=e.m21+i.m21,n.m22=e.m22+i.m22,n.m31=e.m31+i.m31,n.m32=e.m32+i.m32,n},e.divide=function(e,i){var n=t.Matrix2D.identity;return n.m11=e.m11/i.m11,n.m12=e.m12/i.m12,n.m21=e.m21/i.m21,n.m22=e.m22/i.m22,n.m31=e.m31/i.m31,n.m32=e.m32/i.m32,n},e.mutiply=function(e,i){var n=t.Matrix2D.identity;if(i instanceof t.Matrix2D){var r=e.m11*i.m11+e.m12*i.m21,o=i.m11*i.m12+e.m12*i.m22,s=e.m21*i.m11+e.m22*i.m21,a=e.m21*i.m12+e.m22*i.m22,h=e.m31*i.m11+e.m32*i.m21+i.m31,c=e.m31*i.m12+e.m32*i.m22+i.m32;n.m11=r,n.m12=o,n.m21=s,n.m22=a,n.m31=h,n.m32=c}else"number"==typeof i&&(n.m11=e.m11*i,n.m12=e.m12*i,n.m21=e.m21*i,n.m22=e.m22*i,n.m31=e.m31*i,n.m32=e.m32*i);return n},e.subtract=function(e,i){var n=t.Matrix2D.identity;return n.m11=e.m11-i.m11,n.m12=e.m12-i.m12,n.m21=e.m21-i.m21,n.m22=e.m22-i.m22,n.m31=e.m31-i.m31,n.m32=e.m32-i.m32,n},e}();t.MatrixHelper=e}(es||(es={})),function(t){var e=function(){function e(e,i,n,r){void 0===e&&(e=0),void 0===i&&(i=0),void 0===n&&(n=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=i,this.width=n,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,i,n,r){return new e(t,i,n-t,r-i)},e.rectEncompassingPoints=function(t){for(var e=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=0;on&&(n=s.x),s.yr&&(r=s.y)}return this.fromMinMax(e,i,n,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 n=1/t.direction.x,r=(this.x-t.start.x)*n,o=(this.x+this.width-t.start.x)*n;if(r>o){var s=r;r=o,o=s}if(e.distance=Math.max(r,e.distance),i=Math.min(o,i),e.distance>i)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,h=(this.y-t.start.y)*a,c=(this.y+this.height-t.start.y)*a;if(h>c){var l=h;h=c,c=l}if(e.distance=Math.max(h,e.distance),i=Math.max(c,i),e.distance>i)return e}return e.intersected=!0,e},e.prototype.containsRect=function(t){return this.x<=t.x&&t.x0?this.x:this.x+t,n.y=i>0?this.y:this.y+i,n.width=t>0?t+this.width:this.width-t,n.height=i>0?i+this.height:this.height-i,n},e.prototype.collisionCheck=function(t,e,i){e.value=i.value=0;var n=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!(n>0||r<0||o>0||s<0)&&(e.value=Math.abs(n)=u||Math.abs(l)>=p)return t.Vector2.zero;var f=c>0?u-c:-u-c,d=l>0?p-l:-p-l;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.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e,i,n=[],r=this._entity.getComponents(t.Collider),o=0;o=t.Collider.lateSortOrder?n.push(l):this.notifyTriggerListeners(l,!0)),this._activeTriggerIntersections.add(l)}}try{for(var u=__values(n),p=u.next();!p.done;p=u.next()){l=p.value;this.notifyTriggerListeners(l,!0)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(i=u.return)&&i.call(u)}finally{if(e)throw e.error}}this.checkForExitedColliders()},e.prototype.checkForExitedColliders=function(){this._previousTriggerIntersections.exceptWith(this._activeTriggerIntersections.toArray());for(var t=0;t1)return!1;var c=(a.x*r.y-a.y*r.x)/s;return!(c<0||c>1)},i.lineToLineIntersection=function(e,i,n,r,o){void 0===o&&(o=t.Vector2.zero),o.x=0,o.y=0;var s=i.sub(e),a=r.sub(n),h=s.x*a.y-s.y*a.x;if(0==h)return!1;var c=n.sub(e),l=(c.x*a.y-c.y*a.x)/h;if(l<0||l>1)return!1;var u=(c.x*s.y-c.y*s.x)/h;if(u<0||u>1)return!1;var p=e.add(s.scale(l));return o.x=p.x,o.y=p.y,!0},i.closestPointOnLine=function(e,i,n){var r=i.sub(e),o=n.sub(e).dot(r)/r.dot(r);return o=t.MathHelper.clamp(o,0,1),e.add(r.scale(o))},i.circleToCircle=function(e,i,n,r){return t.Vector2.sqrDistance(e,n)<(i+r)*(i+r)},i.circleToLine=function(e,i,n,r){return t.Vector2.sqrDistance(e,this.closestPointOnLine(n,r,e))=t&&r.y>=e&&r.x=t+n&&(s|=e.right),o.y=i+r&&(s|=e.bottom),s},i}();t.Collisions=i}(es||(es={})),function(t){var e=function(){function e(e,i,n,r,o){this.fraction=0,this.distance=0,this.point=t.Vector2.zero,this.normal=t.Vector2.zero,this.collider=e,this.fraction=i,this.distance=n,this.point=r,this.centroid=t.Vector2.zero}return e.prototype.setAllValues=function(t,e,i,n,r){this.collider=t,this.fraction=e,this.distance=i,this.point=n,this.normal=r},e.prototype.setValues=function(t,e,i,n){this.fraction=t,this.distance=e,this.point=i,this.normal=n},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.debugDraw=function(t){this.debugRender&&this._spatialHash.debugDraw(t)},e.overlapCircle=function(t,i,n){return void 0===n&&(n=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapCircle(t,i,this._colliderArray,n),this._colliderArray[0]},e.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=this.allLayers),this._spatialHash.overlapCircle(t,e,i,n)},e.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},e.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},e.boxcastBroadphaseExcludingSelfNonRect=function(t,e){void 0===e&&(e=this.allLayers);var i=t.bounds;return this._spatialHash.aabbBroadphase(i,t,e)},e.boxcastBroadphaseExcludingSelfDelta=function(t,i,n,r){void 0===r&&(r=e.allLayers);var o=t.bounds.getSweptBroadphaseBounds(i,n);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,i,n,r){return void 0===n&&(n=this.allLayers),void 0===r&&(r=null),this._hitArray[0].reset(),this.linecastAll(t,i,this._hitArray,n),this._hitArray[0].reset(),e.linecastAll(t,i,this._hitArray,n,r),this._hitArray[0].clone()},e.linecastAll=function(t,e,i,n,r){return void 0===n&&(n=this.allLayers),void 0===r&&(r=null),this._spatialHash.linecast(t,e,i,n,r)},e.overlapRectangle=function(t,i){return void 0===i&&(i=e.allLayers),this._colliderArray[0]=null,this._spatialHash.overlapRectangle(t,this._colliderArray,i),this._colliderArray[0]},e.overlapRectangleAll=function(t,i,n){return void 0===n&&(n=e.allLayers),0==i.length?(console.warn("传入了一个空的结果数组。不会返回任何结果"),0):this._spatialHash.overlapRectangle(t,i,n)},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 i,this._tempHashSet=new Set,this._cellSize=e,this._inverseCellSize=1/this._cellSize,this._raycastParser=new n}return e.prototype.register=function(e){var i=e.bounds.clone();e.registeredPhysicsBounds=i;var n=this.cellCoords(i.x,i.y),r=this.cellCoords(i.right,i.bottom);this.gridBounds.contains(n.x,n.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,n)),this.gridBounds.contains(r.x,r.y)||(this.gridBounds=t.RectangleExt.union(this.gridBounds,r));for(var o=n.x;o<=r.x;o++)for(var s=n.y;s<=r.y;s++){this.cellAtPosition(o,s,!0).push(e)}},e.prototype.remove=function(e){for(var i=e.registeredPhysicsBounds.clone(),n=this.cellCoords(i.x,i.y),r=this.cellCoords(i.right,i.bottom),o=n.x;o<=r.x;o++)for(var s=n.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.debugDraw=function(t){for(var e=this.gridBounds.x;e<=this.gridBounds.right;e++)for(var i=this.gridBounds.y;i<=this.gridBounds.bottom;i++){var n=this.cellAtPosition(e,i);null!=n&&n.length>0&&this.debugDrawCellDetails(e,i,t)}},e.prototype.debugDrawCellDetails=function(e,i,n){void 0===n&&(n=.5),t.Graphics.instance.batcher.drawHollowRect(e*this._cellSize,i*this._cellSize,this._cellSize,this._cellSize,new t.Color(255,0,0),n),t.Graphics.instance.batcher.end()},e.prototype.aabbBroadphase=function(e,i,n){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 h=this.cellAtPosition(s,a);if(h)for(var c=0;c=this.points.length?this.points[0]:this.points[n+1];var o=t.Vector2Ext.perpendicular(r,e);t.Vector2Ext.normalize(o),this._edgeNormals[n]=o}},i.buildSymmetricalPolygon=function(e,i){for(var n=new Array(e),r=0;rn&&(n=o,i=r)}return t[i]},i.getClosestPointOnPolygonToPoint=function(e,i){for(var n={distanceSquared:Number.MAX_VALUE,edgeNormal:t.Vector2.zero,closestPoint:t.Vector2.zero},r=0,o=0;ot.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},i.prototype.pointCollidesWithShape=function(e,i){return t.ShapeCollisionsPoint.pointToPoly(e,this,i)},i}(t.Shape);t.Polygon=e}(es||(es={})),function(t){var e=function(e){function i(t,n){var r=e.call(this,i.buildBox(t,n),!0)||this;return r.width=t,r.height=n,r}return __extends(i,e),i.buildBox=function(e,i){var n=e/2,r=i/2,o=new Array(4);return o[0]=new t.Vector2(-n,-r),o[1]=new t.Vector2(n,-r),o[2]=new t.Vector2(n,r),o[3]=new t.Vector2(-n,r),o},i.prototype.updateBox=function(e,i){this.width=e,this.height=i;var n=e/2,r=i/2;this.points[0]=new t.Vector2(-n,-r),this.points[1]=new t.Vector2(n,-r),this.points[2]=new t.Vector2(n,r),this.points[3]=new t.Vector2(-n,r);for(var o=0;o1)return!1;var h,c=s.start.add(s.direction.scale(r)),l=0;c.xi.bounds.right&&(l|=1),c.yi.bounds.bottom&&(l|=2);var u=h+l;return 3==u&&console.log("m == 3. corner "+t.Time.frameCount),!0},e.corner=function(e,i){var n=t.Vector2.zero;return n.x=0==(1&i)?e.right:e.left,n.y=0==(1&i)?e.bottom:e.top,n},e.testCircleBox=function(t,e,i){var n=e.bounds.getClosestPointOnRectangleToPoint(t.position).sub(t.position);return n.dot(n)<=t.radius*t.radius},e}();t.RealtimeCollisions=e}(es||(es={})),function(t){var e=function(){function e(){}return e.boxToBox=function(e,i,n){var r=this.minkowskiDifference(e,i);return!!r.contains(0,0)&&(n.minimumTranslationVector=r.getClosestPointOnBoundsToOrigin(),!n.minimumTranslationVector.equals(t.Vector2.zero)&&(n.normal=n.minimumTranslationVector.scale(-1),n.normal=n.normal.normalize(),!0))},e.boxToBoxCast=function(e,i,n,r){var o=this.minkowskiDifference(e,i);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x,-s.y),r.normal=r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,n.scale(-1)),h=o.rayIntersects(a);return!!(h.intersected&&h.distance<=1)&&(r.fraction=h.distance,r.distance=n.magnitude()*h.distance,r.normal=n.scale(-1),r.normal=r.normal.normalize(),r.centroid=e.bounds.center.add(n.scale(h.distance)),!0)},e.minkowskiDifference=function(e,i){var n=e.position.sub(e.bounds.center),r=e.bounds.location.add(n.sub(i.bounds.max)),o=e.bounds.size.add(i.bounds.size);return new t.Rectangle(r.x,r.y,o.x,o.y)},e}();t.ShapeCollisionsBox=e}(es||(es={})),function(t){var e=function(){function e(){}return e.circleToCircleCast=function(e,i,n,r){var o=e.position.add(n),s=this.closestPointOnLine(e.position,o,i.position),a=t.Vector2.sqrDistance(i.position,s),h=(e.radius+i.radius)*(e.radius+i.radius);if(a<=h){var c=n.normalize();s===o&&(o=e.position.add(n.add(c.scale(i.radius))),s=this.closestPointOnLine(e.position,o,i.position),a=t.Vector2.sqrDistance(i.position,s));var l=Math.sqrt(h-a);return r.centroid=s.sub(c.scale(l)),r.normal=r.centroid.sub(i.position).normalize(),r.fraction=(r.centroid.x-e.position.x)/n.x,r.distance=t.Vector2.distance(e.position,r.centroid),r.point=i.position.add(r.normal.scale(i.radius)),!0}return!1},e.circleToCircle=function(e,i,n){void 0===n&&(n=new t.CollisionResult);var r=t.Vector2.sqrDistance(e.position,i.position),o=e.radius+i.radius;if(re.radius*e.radius&&!a)return!1;if(a)s=n.normal.scale(Math.sqrt(o.distanceSquared)-e.radius);else if(0===o.distanceSquared)s=n.normal.scale(e.radius);else{var h=Math.sqrt(o.distanceSquared);s=r.sub(o.closestPoint).scale((e.radius-h)/h*-1)}return n.minimumTranslationVector=s,n.point=o.closestPoint.add(i.position),!0},e.closestPointOnLine=function(e,i,n){var r=i.sub(e),o=n.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(i,n,r,o){void 0===o&&(o=new t.RaycastHit);for(var s=t.Vector2.zero,a=t.Vector2.zero,h=Number.MAX_VALUE,c=!1,l=r.points.length-1,u=0;u1)return!1;var l=(h.x*o.y-h.y*o.x)/a;if(l<0||l>1)return!1;var u=t.add(o.scale(c));return r.x=u.x,r.y=u.y,!0},e.lineToCircle=function(e,i,n,r){var o=t.Vector2.distance(e,i),s=t.Vector2.divideScaler(i.sub(e),o),a=e.sub(n.position),h=a.dot(s),c=a.dot(a)-n.radius*n.radius;if(c>0&&h>0)return!1;var l=h*h-c;return!(l<0)&&(r.fraction=-h-Math.sqrt(l),r.fraction<0&&(r.fraction=0),r.point=e.add(s.scale(r.fraction)),r.distance=t.Vector2.distance(e,r.point),r.normal=r.point.sub(n.position).normalize(),r.fraction=r.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,i,n){var r=t.Vector2.sqrDistance(e,i.position),o=1+i.radius;if(r0&&(o=!1),!o)return!1;(p=Math.abs(p))n.max&&(n.max=i);return n},e.intervalDistance=function(t,e,i,n){return t=0;e--){for(var i=this._composites[e],n=0;ni.height?e.y=i.height:e.yi.width&&(e.x=i.width)):(e.yi.height-t.radius&&(e.y=2*(i.height-t.radius)-e.y),e.x>i.width-t.radius&&(e.x=2*(i.width-t.radius)-e.x),e.x=0;t--)this._constraints[t].solve()},e.prototype.updateParticles=function(t,e){for(var i=0;i=0;t--)this._constraints[t].collidesWithColliders&&this._constraints[t].handleCollisions(this.collidesWithLayers)},e.prototype.debugRender=function(e){if(this.drawConstraints)for(var i=0;i0&&r.addConstraint(new t.DistanceConstraint(r.particles[o],r.particles[o-1],n))}return r}return __extends(i,e),i.prototype.pinParticleAtIndex=function(t){return this.particles[t].pin(),this},i}(t.Composite);t.LineSegments=e}(es||(es={})),function(t){var e=function(){function t(){this.collidesWithColliders=!0}return t.prototype.handleCollisions=function(t){},t.prototype.debugRender=function(t){},t}();t.Constraint=e}(es||(es={})),function(t){var e=function(e){function i(t,i,n,r){var o=e.call(this)||this;return o.stiffness=0,o.angleInRadius=0,o._particleA=t,o._centerParticle=i,o._particleC=n,o.stiffness=r,o.collidesWithColliders=!1,o.angleInRadius=o.angleBetweenParticles(),o}return __extends(i,e),i.prototype.angleBetweenParticles=function(){var t=this._particleA.position.sub(this._centerParticle.position),e=this._particleC.position.sub(this._centerParticle.position);return Math.atan2(t.x*e.y-t.y*e.x,t.x*e.x+t.y*e.y)},i.prototype.solve=function(){var e=this.angleBetweenParticles()-this.angleInRadius;e<=-Math.PI?e+=2*Math.PI:e>=Math.PI&&(e-=2*Math.PI),e*=this.stiffness,this._particleA.position=t.MathHelper.rotateAround2(this._particleA.position,this._centerParticle.position,e),this._particleC.position=t.MathHelper.rotateAround2(this._particleC.position,this._centerParticle.position,-e),this._centerParticle.position=t.MathHelper.rotateAround2(this._centerParticle.position,this._particleA.position,e),this._centerParticle.position=t.MathHelper.rotateAround2(this._centerParticle.position,this._particleC.position,-e)},i}(t.Constraint);t.AngleConstraint=e}(es||(es={})),function(t){var e=function(e){function i(t,n,r,o){void 0===o&&(o=-1);var s=e.call(this)||this;return s.stiffness=0,s.restingDistance=0,s.tearSensitivity=Number.POSITIVE_INFINITY,s.shouldApproximateCollisionsWithPoints=!1,s.totalPointsToApproximateCollisionsWith=5,i._polygon.create(2,1),s._particleOne=t,s._particleTwo=n,s.stiffness=r,s.restingDistance=o>-1?o:t.position.distance(n.position),s}return __extends(i,e),i.create=function(e,n,r,o,s){var a=e.position.distance(n.position),h=r.position.distance(n.position);return new i(e,r,o,Math.sqrt(a*a+h*h-2*a*h*Math.cos(s*t.MathHelper.Deg2Rad)))},i.prototype.setTearSensitivity=function(t){return this.tearSensitivity=t,this},i.prototype.setCollidesWithColliders=function(t){return this.collidesWithColliders=t,this},i.prototype.setShouldApproximateCollisionsWithPoints=function(t){return this.shouldApproximateCollisionsWithPoints=t,this},i.prototype.solve=function(){var t=this._particleOne.position.sub(this._particleTwo.position),e=t.distance(),i=(this.restingDistance-e)/e;if(e/this.restingDistance>this.tearSensitivity)this.composite.removeConstraint(this);else{var n=1/this._particleOne.mass,r=n/(n+1/this._particleTwo.mass)*this.stiffness,o=this.stiffness-r;this._particleOne.position=this._particleOne.position.add(t.scale(r*i)),this._particleTwo.position=this._particleTwo.position.sub(t.scale(o*i))}},i.prototype.handleCollisions=function(e){if(this.shouldApproximateCollisionsWithPoints)this.approximateCollisionsWithPoints(e);else{var n=Math.min(this._particleOne.position.x,this._particleTwo.position.x),r=Math.max(this._particleOne.position.x,this._particleTwo.position.x),o=Math.min(this._particleOne.position.y,this._particleTwo.position.y),s=Math.max(this._particleOne.position.y,this._particleTwo.position.y);i._polygon.bounds=t.Rectangle.fromMinMax(n,o,r,s);var a=t.Vector2.zero;this.preparePolygonForCollisionChecks(a);for(var h=t.Physics.boxcastBroadphase(i._polygon.bounds,e),c=0;c= 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 i=1;i=0;o--)(e=r[o].func).call.apply(e,__spread([r[o].context],i))},i}();t.Emitter=i}(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 i=385229220;return this.forOwn(t,function(t){"number"==typeof t?i+=e._getHashCodeForNumber(t):"string"==typeof t?i+=e._getHashCodeForString(t):"object"==typeof t&&e.forOwn(t,function(){i+=e.getHashCode(t)})}),i},t.prototype._getHashCodeForNumber=function(t){return t},t.prototype._getHashCodeForString=function(t){for(var e=385229220,i=0;i>7,i+=i<<3,i^=i>>17,i+=i<<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(i){return i.callback===e&&i.caller===t})&&this._listeners.push({caller:t,callback:e})},t.prototype.removeListener=function(t,e){var i=this._listeners.findIndex(function(i){return i.callback===e&&i.caller===t});i>=0&&this._listeners.splice(i,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=[],i=0;i=0;n--){var r=this._listeners[n];r.caller?(t=r.callback).call.apply(t,__spread([r.caller],e)):r.callback.apply(r,__spread(e))}},t}();t.Observable=e;var i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,i){t.prototype.addListener.call(this,e,i)},e.prototype.removeListener=function(e,i){t.prototype.removeListener.call(this,e,i)},e.prototype.notify=function(e){t.prototype.notify.call(this,e)},e}(e);t.ObservableT=i;var n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.addListener=function(e,i){t.prototype.addListener.call(this,e,i)},e.prototype.removeListener=function(e,i){t.prototype.removeListener.call(this,e,i)},e.prototype.notify=function(e,i){t.prototype.notify.call(this,e,i)},e}(e);t.ObservableTT=n;var r=function(){function t(t,i){this.bindAction(t,i),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=[],i=0;i3&&o<500;){o++;var a=!0,h=i[this._triPrev[s]],c=i[s],l=i[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(h,c,l)){var u=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(i[u],h,c,l)){a=!1;break}u=this._triNext[u]}while(u!=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]),n||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&i]+e[i>>8&255]+"-"+e[i>>16&15|64]+e[i>>24&255]+"-"+e[63&n|128]+e[n>>8&255]+"-"+e[n>>16&255]+e[n>>24&255]+e[255&r]+e[r>>8&255]+e[r>>16&255]+e[r>>24&255]},t}();t.UUID=i}(es||(es={})),function(t){t.getClassName=function(t){return t.className||t.name}}(es||(es={})),function(t){var e,i=function(){function t(t){void 0===t&&(t=n),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=(i=this.getSystemTime())-this._stopSystemTime;this._stopDuration+=e,this._stopSystemTime=void 0}else if(void 0===this._startSystemTime){var i=this.getSystemTime();this._startSystemTime=i,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=i,function(t){t.IDLE="IDLE",t.RUNNING="RUNNING",t.STOPPED="STOPPED"}(e||(e={})),t.setDefaultSystemTimeGetter=function(t){void 0===t&&(t=Date.now),n=t};var n=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,i=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,i;for(e=0,i=this.size_;i>e;e++)if(t===this.array[e])return!0;return!1},t.prototype.removeAll=function(t){var e,i,n,r,o=!1;for(e=0,n=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(n,r,o){var s=t.HashHelpers.getHashCode(n),a=e.reduce(s,this._buckets.length);if(this._freeValueCellIndex==this._values.length){var h=t.HashHelpers.expandPrime(this._freeValueCellIndex);this._values.length=h,this._valuesInfo.length=h}var c=t.NumberExtension.toNumber(this._buckets[a])-1;if(-1==c)this._valuesInfo[this._freeValueCellIndex]=new i(n,s);else{var l=c;do{if(this._valuesInfo[l].hashcode==s&&this._valuesInfo[l].key==n)return this._values[l]=r,o.value=l,!1;l=this._valuesInfo[l].previous}while(-1!=l);this._collisions++,this._valuesInfo[this._freeValueCellIndex]=new i(n,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 u=0;u=e?t%e:t},e}();t.FasterDictionary=e;var i=function(){return function(t,e,i){void 0===i&&(i=-1),this.key=t,this.hashcode=e,this.previous=i,this.next=-1}}();t.FastNode=i}(es||(es={})),function(t){var e=function(){return function(t,e){this.element=t,this.next=e}}();function i(t,e){return t===e}t.Node=e,t.defaultEquals=i;var n=function(){function t(t){void 0===t&&(t=i),this.count=0,this.next=void 0,this.equalsFn=t,this.head=null}return t.prototype.push=function(t){var i,n=new e(t);if(null==this.head)this.head=n;else{for(i=this.head;null!=i.next;)i=i.next;i.next=n}this.count++},t.prototype.removeAt=function(t){if(t>=0&&t=0&&t<=this.count){for(var e=this.head,i=0;i=0&&i<=this.count){var n=new e(t);if(0===i)n.next=this.head,this.head=n;else{var r=this.getElementAt(i-1);n.next=r.next,r.next=n}return this.count++,!0}return!1},t.prototype.indexOf=function(t){for(var e=this.head,i=0;i0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var i=0;ithis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,i=this.getHashCode(t),n=this.buckets[i];if(void 0===n){var r=new Array;return r.push(t),this.buckets[i]=r,this.count=this.count+1,!0}return!n.some(function(i){return e.areEqual(i,t)})&&(n.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,i=this.getHashCode(t),n=this.buckets[i];if(void 0===n)return!1;var r=!1,o=new Array;return n.forEach(function(i){e.areEqual(i,t)?r=!0:o.push(t)}),this.buckets[i]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var i=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(i.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,i=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(i.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,i=new Array,n=0;return t.forEach(function(t){var r=e.getHashCode(t),o=i[r];if(void 0===o){var s=new Array;s.push(t),i[r]=s,n+=1}else o.some(function(i){return e.areEqual(i,t)})||(o.push(t),n+=1)}),{Buckets:i,Count:n}},t.prototype.bucketsContains=function(t,e){var i=this,n=t[this.getHashCode(e)];return void 0!==n&&n.some(function(t){return i.areEqual(t,e)})},t}());t.HashSet=e}(es||(es={})),function(t){var e=function(){function t(){}return t.waitForSeconds=function(t){return i.waiter.wait(t)},t}();t.Coroutine=e;var i=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=i}(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 i=function(i){function n(){var t=null!==i&&i.apply(this,arguments)||this;return t._unblockedCoroutines=[],t._shouldRunNextFrame=[],t}return __extends(n,i),n.prototype.startCoroutine=function(i){var n=t.Pool.obtain(e);return n.prepareForUse(),n.enumerator=i,this.tickCoroutine(n)?(this._isInUpdate?this._shouldRunNextFrame.push(n):this._unblockedCoroutines.push(n),n):null},n.prototype.update=function(){this._isInUpdate=!0;for(var e=0;e0?(i.waitTimer-=i.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(i)):this.tickCoroutine(i)&&this._shouldRunNextFrame.push(i)}}var n=new t.List(this._unblockedCoroutines);n.clear(),n.addRange(this._shouldRunNextFrame),this._shouldRunNextFrame.length=0,this._isInUpdate=!1},n.prototype.tickCoroutine=function(i){var n=i.enumerator.next();return n.done||i.isDone?(t.Pool.free(i),!1):null==n.value||(n.value instanceof t.WaitForSeconds?(i.waitTimer=n.value.waitTime,!0):"number"==typeof n.value?(i.waitTimer=n.value,!0):"string"==typeof n.value?"break"!=n.value||(t.Pool.free(i),!1):!(n.value instanceof e)||(i.waitForCoroutine=n.value,!0))},n}(t.GlobalManager);t.CoroutineManager=i}(es||(es={})),function(t){var e=function(){function e(t,e,i){void 0===i&&(i=!0),this.binWidth=0,this.binHeight=0,this.usedRectangles=[],this.freeRectangles=[],this.init(t,e,i)}return e.prototype.init=function(e,i,n){void 0===n&&(n=!0),this.binWidth=e,this.binHeight=i,this.allowRotations=n;var r=new t.Rectangle;r.x=0,r.y=0,r.width=e,r.height=i,this.usedRectangles.length=0,this.freeRectangles.length=0,this.freeRectangles.push(r)},e.prototype.insert=function(e,i){var n=new t.Rectangle,r=new t.Ref(0),o=new t.Ref(0);if(0==(n=this.findPositionForNewNodeBestAreaFit(e,i,r,o)).height)return n;for(var s=this.freeRectangles.length,a=0;a=e&&this.freeRectangles[s].height>=i){var h=Math.abs(this.freeRectangles[s].width-e),c=Math.abs(this.freeRectangles[s].height-i),l=Math.min(h,c);(a=i&&this.freeRectangles[s].height>=e){h=Math.abs(this.freeRectangles[s].width-i),c=Math.abs(this.freeRectangles[s].height-e),l=Math.min(h,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 i;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,i=0;ii;n--)if(t[n]0&&t[r-1]>n;r--)t[r]=t[r-1];t[r]=n}},e.binarySearch=function(t,e){for(var i=0,n=t.length,r=i+n>>1;i=t[r]&&(i=r+1),r=i+n>>1;return t[i]==e?i:-1},e.findElementIndex=function(t,e){for(var i=t.length,n=0;nt[e]&&(e=n);return e},e.getMinElementIndex=function(t){for(var e=0,i=t.length,n=1;n=0;--r)i.unshift(e[r]);return i},e.getDifferAry=function(t,e){t=this.getUniqueAry(t),e=this.getUniqueAry(e);for(var i=t.concat(e),n={},r=[],o=i.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 i=t.length;if(i!=e.length)return!1;for(;i--;)if(t[i]!=e[i])return!1;return!0},e.insert=function(t,e,i){if(!t)return null;var n=t.length;if(e>n&&(e=n),e<0&&(e=0),e==n)t.push(i);else if(0==e)t.unshift(i);else{for(var r=n-1;r>=e;r-=1)t[r+1]=t[r];t[e]=i}return i},e.shuffle=function(e){for(var i=e.length;i>1;){i--;var n=t.RandomUtils.randint(0,i+1),r=e[n];e[n]=e[i],e[i]=r}},e.addIfNotPresent=function(e,i){return!new t.List(e).contains(i)&&(e.push(i),!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,i){for(var n=new Set;n.size!=i;){var r=this.randomItem(e);n.has(r)||n.add(r)}var o=t.ListPool.obtain();return n.forEach(function(t){return o.push(t)}),o},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,i,n,r,o,s,a=[],h=0;h>4,i=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(h++)))>>2,n=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(h++))),a.push(String.fromCharCode(e)),64!==o&&a.push(String.fromCharCode(i)),64!==s&&a.push(String.fromCharCode(n));return a=a.join("")},t.encode=function(t){if(t=t.replace(/\r\n/g,"\n"),!this.nativeBase64){for(var e,i,n,r,o,s,a,h=[],c=0;c>2,o=(3&e)<<4|(i=t.charCodeAt(c++))>>4,s=(15&i)<<2|(n=t.charCodeAt(c++))>>6,a=63&n,isNaN(i)?s=a=64:isNaN(n)&&(a=64),h.push(this._keyStr.charAt(r)),h.push(this._keyStr.charAt(o)),h.push(this._keyStr.charAt(s)),h.push(this._keyStr.charAt(a));return h=h.join("")}window.btoa(t)},t.decodeBase64AsArray=function(e,i){i=i||1;var n,r,o,s=t.decode(e),a=new Uint32Array(s.length/i);for(n=0,o=s.length/i;n=0;--r)a[n]+=s.charCodeAt(n*i+r)<<(r<<3);return a},t.decompress=function(t,e,i){throw new Error("GZIP/ZLIB compressed TMX Tile Map not supported!")},t.decodeCSV=function(t){for(var e=t.replace("\n","").trim().split(","),i=[],n=0;n(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 i=t.length;if(e<=0||i=0;)s=Math.floor(this.random()*i);n.push(t[s]),r.push(s)}return n},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,i){switch(i){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,i){var n=new t.Rectangle(i.x,i.y,0,0),r=new t.Rectangle;return r.x=Math.min(e.x,n.x),r.y=Math.min(e.y,n.y),r.width=Math.max(e.right,n.right)-r.x,r.height=Math.max(e.bottom,n.bottom)-r.y,r},e.getHalfRect=function(e,i){switch(i){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,i,n){switch(void 0===n&&(n=1),i){case t.Edge.top:return new t.Rectangle(e.x,e.y,e.width,n);case t.Edge.bottom:return new t.Rectangle(e.x,e.y+e.height-n,e.width,n);case t.Edge.left:return new t.Rectangle(e.x,e.y,n,e.height);case t.Edge.right:return new t.Rectangle(e.x+e.width-n,e.y,n,e.height)}},e.expandSide=function(e,i,n){switch(n=Math.abs(n),i){case t.Edge.top:e.y-=n,e.height+=n;break;case t.Edge.bottom:e.height+=n;break;case t.Edge.left:e.x-=n,e.width+=n;break;case t.Edge.right:e.width+=n}},e.contract=function(t,e,i){t.x+=e,t.y+=i,t.width-=2*e,t.height-=2*i},e.boundsFromPolygonVector=function(e){for(var i=Number.POSITIVE_INFINITY,n=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(i,n),new t.Vector2(r,o))},e.fromMinMaxVector=function(e,i){return new t.Rectangle(e.x,e.y,i.x-e.x,i.y-e.y)},e.getSweptBroadphaseBounds=function(e,i,n){var r=t.Rectangle.empty;return r.x=i>0?e.x:e.x+i,r.y=n>0?e.y:e.y+n,r.width=i>0?i+e.width:e.width-i,r.height=n>0?n+e.height:e.height-n,r},e.prototype.collisionCheck=function(t,e,i,n){i.value=n.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)&&(i.value=Math.abs(r)=u||Math.abs(l)>=p)return t.Vector2.zero;var f=c>0?u-c:-u-c,d=l>0?p-l:-p-l;return new t.Vector2(f,d)},e.getClosestPointOnBoundsToOrigin=function(e){var i=this.getMax(e),n=Math.abs(e.location.x),r=new t.Vector2(e.location.x,0);return Math.abs(i.x)r&&(r=a.x),a.yo&&(o=a.y)}return this.fromMinMaxVector(new t.Vector2(Math.trunc(i),Math.trunc(n)),new t.Vector2(Math.trunc(r),Math.trunc(o)))},e.calculateBounds=function(e,i,n,r,o,s,a,h){if(0==s)e.x=Math.trunc(i.x+n.x-r.x*o.x),e.y=Math.trunc(i.y+n.y-r.y*o.y),e.width=Math.trunc(a*o.x),e.height=Math.trunc(h*o.y);else{var c=i.x+n.x,l=i.y+n.y,u=new t.Matrix2D;t.Matrix2D.createTranslation(-c-r.x,-l-r.y,u),t.Matrix2D.createScale(o.x,o.y,void 0),u=u.multiply(void 0),t.Matrix2D.createRotation(s,void 0),u=u.multiply(void 0),t.Matrix2D.createTranslation(c,l,void 0),u=u.multiply(void 0);var p=new t.Vector2(c,l),f=new t.Vector2(c+a,l),d=new t.Vector2(c,l+h),m=new t.Vector2(c+a,l+h);t.Vector2Ext.transformR(p,u,p),t.Vector2Ext.transformR(f,u,f),t.Vector2Ext.transformR(d,u,d),t.Vector2Ext.transformR(m,u,m);var y=Math.trunc(Math.min(p.x,m.x,f.x,d.x)),g=Math.trunc(Math.max(p.x,m.x,f.x,d.x)),_=Math.trunc(Math.min(p.y,m.y,f.y,d.y)),v=Math.trunc(Math.max(p.y,m.y,f.y,d.y));e.location=new t.Vector2(y,_),e.width=Math.trunc(g-y),e.height=Math.trunc(v-_)}},e.scale=function(t,e){t.x=Math.trunc(t.x*e.x),t.y=Math.trunc(t.y*e.y),t.width=Math.trunc(t.width*e.x),t.height=Math.trunc(t.height*e.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],i=0;it.MathHelper.Epsilon?e.divideScaler(i):e.x=e.y=0},e.transformA=function(t,e,i,n,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 i=this.groupBy(t);return Object.keys(i).reduce(function(t,e){return t.add(i[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(i,n){var r=t(n),o=i[r],s=e(n);return o?o.push(s):i[r]=[s],i},{})},e.prototype.groupJoin=function(t,e,i,n){return this.select(function(r){return n(r,t.where(function(t){return e(r)===i(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,i,n){return this.selectMany(function(r){return t.where(function(t){return i(t)===e(r)}).select(function(t){return n(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,n){return void 0===n&&(n=t.keyComparer(e,!1)),new i(this._elements,n)},e.prototype.orderByDescending=function(e,n){return void 0===n&&(n=t.keyComparer(e,!0)),new i(this._elements,n)},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 i=this;return this.aggregate(function(e,n,r){return e.addRange(i.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(i){return t(e.elementAt(i))?++i:i},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(i){return t(e.elementAt(i))?++i:i},0))},e.prototype.toArray=function(){return this._elements},e.prototype.toDictionary=function(t,i){var n=this;return this.aggregate(function(e,r,o){return e[n.select(t).elementAt(o).toString()]=i?n.select(i).elementAt(o):r,e.add({Key:n.select(t).elementAt(o),Value:i?n.select(i).elementAt(o):r}),e},new e)},e.prototype.toSet=function(){var t,e,i=new Set;try{for(var n=__values(this._elements),r=n.next();!r.done;r=n.next()){var o=r.value;i.add(o)}}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}return i},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 i=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{n&&!n.done&&(e=i.return)&&e.call(i)}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,i,n){this._timeInSeconds=t,this._repeats=e,this.context=i,this._onTime=n},e.prototype.unload=function(){this.context=null,this._onTime=null},e}();t.Timer=e}(es||(es={})),function(t){var e=function(e){function i(){var t=null!==e&&e.apply(this,arguments)||this;return t._timers=[],t}return __extends(i,e),i.prototype.update=function(){for(var e=this._timers.length-1;e>=0;e--)this._timers[e].tick()&&(this._timers[e].unload(),new t.List(this._timers).removeAt(e))},i.prototype.schedule=function(e,i,n,r){var o=new t.Timer;return o.initialize(e,i,n,r),this._timers.push(o),o},i}(t.GlobalManager);t.TimerManager=e}(es||(es={})); \ No newline at end of file +window.es={};var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function s(t){try{h(i.next(t))}catch(t){o(t)}}function a(t){try{h(i.throw(t))}catch(t){o(t)}}function h(t){t.done?r(t.value):new n(function(e){e(t.value)}).then(s,a)}h((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(r=2&o[0]?i.return:o[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,o[1])).done)return r;switch(i=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,i=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]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;e=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}},transform;!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(){t.Time.sceneChanged()},e.prototype.initialize=function(){},e.prototype.update=function(n){return void 0===n&&(n=-1),__awaiter(this,void 0,void 0,function(){var i;return __generator(this,function(r){if(e.paused)return[2];if(t.Time.update(n),null!=this._scene){for(i=this._globalManagers.length-1;i>=0;i--)this._globalManagers[i].enabled&&this._globalManagers[i].update();this._scene.update(),null!=this._nextScene&&(this._scene.end(),this._scene=this._nextScene,this._nextScene=null,this.onSceneChanged(),this._scene.begin())}return this.startDebugDraw(),[2]})})},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 t(){}return t.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.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.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.prototype.clone=function(){return new e(this.x,this.y)},e}();t.Vector2=e}(es||(es={})),function(t){var e=function(){function e(){this._sceneComponents=[],this._renderers=[],this.entities=new t.EntityList(this),this.renderableComponents=new t.RenderableComponentList,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(){0==this._renderers.length&&this.addRenderer(new t.DefaultRenderer),t.Physics.reset(),null!=this.entityProcessors&&this.entityProcessors.begin(),this._didSceneBegin=!0,this.onStart()},e.prototype.end=function(){this._didSceneBegin=!1;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(),this.renderableComponents.updateLists(),this.render()},e.prototype.render=function(){for(var t=0;te.x?-1:1,i=this.position.sub(e).normalize();this.rotation=n*Math.acos(i.dot(t.Vector2.unitY))},n.prototype.setLocalRotation=function(t){return this._localRotation=t,this._localDirty=this._positionDirty=this._localPositionDirty=this._localRotationDirty=this._localScaleDirty=!0,this.setDirty(e.rotationDirty),this},n.prototype.setLocalRotationDegrees=function(e){return this.setLocalRotation(t.MathHelper.toRadians(e))},n.prototype.setScale=function(e){return this._scale=e,null!=this.parent?this.localScale=t.Vector2.divide(e,this.parent._scale):this.localScale=e,this},n.prototype.setLocalScale=function(t){return this._localScale=t,this._localDirty=this._positionDirty=this._localScaleDirty=!0,this.setDirty(e.scaleDirty),this},n.prototype.roundPosition=function(){this.position=t.Vector2Ext.round(this._position)},n.prototype.updateTransform=function(){this.hierarchyDirty!=e.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=e.clean)},n.prototype.setDirty=function(t){if(0==(this.hierarchyDirty&t)){switch(this.hierarchyDirty|=t,t){case e.positionDirty:this.entity.onTransformChanged(transform.Component.position);break;case e.rotationDirty:this.entity.onTransformChanged(transform.Component.rotation);break;case e.scaleDirty:this.entity.onTransformChanged(transform.Component.scale)}for(var n=0;n1e-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&&(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 h=0;hthis.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){var i,r;try{for(var o=__values(e.components._components),s=o.next();!s.done;s=o.next()){var a=s.value;t.isITriggerListener(a)&&n.push(a)}}catch(t){i={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}for(var h in e.components._componentsToAdd){a=e.components._componentsToAdd[h];t.isITriggerListener(a)&&n.push(a)}return n},e}();t.TriggerListenerHelper=e,t.isITriggerListener=function(t){return void 0!==t.onTriggerEnter}}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.onAddedToEntity=function(){this._triggerHelper=new t.ColliderTriggerHelper(this.entity)},n.prototype.calculateMovement=function(e,n){for(var i,r,o=null,s=0;sn;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){return t.call(this,e)||this}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 h=es.WorkerUtils.makeWorker(o.queueOnThread);es.WorkerUtils.workerMessage(h)(a).then(function(t){var n=t;e.resetJob(n),h.terminate()}).catch(function(t){a.err=t,h.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 h=a.value;o.push(h)}}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;n0)for(var t=0,e=this._unsortedRenderLayers.length;t=e)return t;var i=!1;"-"==t.substr(0,1)&&(i=!0,t=t.substr(1));for(var r=e-n,o=0;o1?this.reverse(t.substring(1))+t.substring(0,1):t},t.cutOff=function(t,e,n,i){void 0===i&&(i=!0),e=Math.floor(e),n=Math.floor(n);var r=t.length;e>r&&(e=r);var o,s=e,a=e+n;return i?o=t.substring(0,s)+t.substr(a,r):(a=(s=r-1-e-n)+n,o=t.substring(0,s+1)+t.substr(a+1,r)),o},t.strReplace=function(t,e){for(var n=0,i=e.length;n",">",'"',""","'","'","®","®","©","©","™","™"],t}();!function(t){var e=function(){function t(){}return t.update=function(t){-1==t&&(t=Date.now()),-1==this._lastTime&&(this._lastTime=t);var e=0;(e=-1==t?(t-this._lastTime)/1e3:t)>this.maxDeltaTime&&(e=this.maxDeltaTime),this.totalTime+=e,this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.timeSinceSceneLoad+=e,this.frameCount++,this._lastTime=t},t.sceneChanged=function(){this.timeSinceSceneLoad=0},t.checkEvery=function(t){return this.timeSinceSceneLoad/t>(this.timeSinceSceneLoad-this.deltaTime)/t},t.totalTime=0,t.unscaledDeltaTime=0,t.deltaTime=0,t.timeScale=1,t.maxDeltaTime=Number.MAX_VALUE,t.frameCount=0,t.timeSinceSceneLoad=0,t._lastTime=-1,t}();t.Time=e}(es||(es={}));var TimeUtils=function(){function t(){}return t.monthId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getFullYear(),n=t.getMonth()+1;return parseInt(e+(n<10?"0":"")+n)},t.dateId=function(t){void 0===t&&(t=null);var e=(t=t||new Date).getMonth()+1,n=e<10?"0":"",i=t.getDate(),r=i<10?"0":"";return parseInt(t.getFullYear()+n+e+r+i)},t.weekId=function(t,e){void 0===t&&(t=null),void 0===e&&(e=!0),t=t||new Date;var n=new Date;n.setTime(t.getTime()),n.setDate(1),n.setMonth(0);var i=n.getFullYear(),r=n.getDay();0==r&&(r=7);var o=!1;r<=4?(o=r>1,n.setDate(n.getDate()-(r-1))):n.setDate(n.getDate()+7-r+1);var s=this.diffDay(t,n,!1);if(s<0)return n.setDate(1),n.setMonth(0),n.setDate(n.getDate()-1),this.weekId(n,!1);var a=s/7,h=Math.floor(a)+1;if(53==h){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"+(h>9?"":"0")+h)},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(),h=o.toString();return i<10&&(s="0"+s),r<10&&(a="0"+a),o<10&&(h="0"+h),n?s+e+a+e+h:a+e+h},t.timeToMillisecond=function(t,e){void 0===e&&(e=":");for(var n=t.split(e),i=0,r=n.length,o=0;o1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t},t.fromRGBA=function(e,n,i,r){e/=255,n/=255,i/=255;var o=Math.max(e,n,i),s=Math.min(e,n,i),a=(o+s)/2,h=a,c=a;if(o===s)a=h=0;else{var u=o-s;switch(h=c>.5?u/(2-o-s):u/(o+s),o){case e:a=(n-i)/u+(n=1?(e=1,n.range=this._points.length-4):(e=t.MathHelper.clamp01(e)*this._curveCount,n.range=Math.floor(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+1-Math.PI&&t<=Math.PI?t:(t%=2*Math.PI)<=-Math.PI?t+2*Math.PI:t>Math.PI?t-2*Math.PI:t},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){if(te)return 1}else{if(nt)return 0}return(n-t)/(e-t)},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 Math.trunc(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 h=this.pingPong(t.Time.totalTime,a),c=Math.pow(Math.E,-s*h),u=c*Math.sin(t.Time.totalTime*e+o)*i,l=c*Math.cos(t.Time.totalTime*n)*r;return new t.Vector2(u,l)},e.hermite=function(t,e,n,i,r){return 0==r?t:1==r?n:(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,h=1/(1+(a+(a*a*.48+a*(a*a)*.235))),c=t-e,u=e,l=r*i,p=(n+s*(c=this.clamp(c,-1*l,l)))*o;n=(n-s*p)*h;var f=(e=t-c)+(c+p)*h;return u-t>0==f>u&&(n=((f=u)-u)/o),{value:f,currentVelocity:n}},e.smoothDampVector=function(e,n,i,r,o,s){var a=t.Vector2.zero,h=this.smoothDamp(e.x,n.x,i.x,r,o,s);a.x=h.value,i.x=h.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.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,h,c,u,l,p,f,d,y){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=h,this.m32=c,this.m33=u,this.m34=l,this.m41=p,this.m42=f,this.m43=d,this.m44=y}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,h=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,u=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,y=e.m31*n.m14+e.m32*n.m24+e.m33*n.m34+e.m34*n.m44,m=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=h,i.m22=c,i.m23=u,i.m24=l,i.m31=p,i.m32=f,i.m33=d,i.m34=y,i.m41=m,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,h=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=h},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,h=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=h,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,h=(this.y-t.start.y)*a,c=(this.y+this.height-t.start.y)*a;if(h>c){var u=h;h=c,c=u}if(e.distance=Math.max(h,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(u)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=u>0?p-u:-p-u;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.HashSet,this._previousTriggerIntersections=new t.HashSet,this._tempTriggerList=[],this._entity=e}return e.prototype.update=function(){for(var e,n,i=[],r=this._entity.getComponents(t.Collider),o=0;o=t.Collider.lateSortOrder?i.push(u):this.notifyTriggerListeners(u,!0)),this._activeTriggerIntersections.add(u)}}try{for(var l=__values(i),p=l.next();!p.done;p=l.next()){u=p.value;this.notifyTriggerListeners(u,!0)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(n=l.return)&&n.call(l)}finally{if(e)throw e.error}}this.checkForExitedColliders()},e.prototype.checkForExitedColliders=function(){this._previousTriggerIntersections.exceptWith(this._activeTriggerIntersections.toArray());for(var t=0;t1)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),h=s.x*a.y-s.y*a.x;if(0==h)return!1;var c=i.sub(e),u=(c.x*a.y-c.y*a.x)/h;if(u<0||u>1)return!1;var l=(c.x*s.y-c.y*s.x)/h;if(l<0||l>1)return!1;var p=e.add(s.scale(u));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.debugDraw=function(t){this.debugRender&&this._spatialHash.debugDraw(t)},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(),this.linecastAll(t,n,this._hitArray,i),this._hitArray[0].reset(),e.linecastAll(t,n,this._hitArray,i,r),this._hitArray[0].clone()},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.debugDraw=function(t){for(var e=this.gridBounds.x;e<=this.gridBounds.right;e++)for(var n=this.gridBounds.y;n<=this.gridBounds.bottom;n++){var i=this.cellAtPosition(e,n);null!=i&&i.length>0&&this.debugDrawCellDetails(e,n,t)}},e.prototype.debugDrawCellDetails=function(e,n,i){void 0===i&&(i=.5),t.Graphics.instance.batcher.drawHollowRect(e*this._cellSize,n*this._cellSize,this._cellSize,this._cellSize,new t.Color(255,0,0),i),t.Graphics.instance.batcher.end()},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 h=this.cellAtPosition(s,a);if(h)for(var c=0;c=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;o1)return!1;var h,c=s.start.add(s.direction.scale(r)),u=0;c.xn.bounds.right&&(u|=1),c.yn.bounds.bottom&&(u|=2);var l=h+u;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(){function e(){}return e.boxToBox=function(e,n,i){var r=this.minkowskiDifference(e,n);return!!r.contains(0,0)&&(i.minimumTranslationVector=r.getClosestPointOnBoundsToOrigin(),!i.minimumTranslationVector.equals(t.Vector2.zero)&&(i.normal=i.minimumTranslationVector.scale(-1),i.normal=i.normal.normalize(),!0))},e.boxToBoxCast=function(e,n,i,r){var o=this.minkowskiDifference(e,n);if(o.contains(0,0)){var s=o.getClosestPointOnBoundsToOrigin();return!s.equals(t.Vector2.zero)&&(r.normal=new t.Vector2(-s.x,-s.y),r.normal=r.normal.normalize(),r.distance=0,r.fraction=0,!0)}var a=new t.Ray2D(t.Vector2.zero,i.scale(-1)),h=o.rayIntersects(a);return!!(h.intersected&&h.distance<=1)&&(r.fraction=h.distance,r.distance=i.magnitude()*h.distance,r.normal=i.scale(-1),r.normal=r.normal.normalize(),r.centroid=e.bounds.center.add(i.scale(h.distance)),!0)},e.minkowskiDifference=function(e,n){var i=e.position.sub(e.bounds.center),r=e.bounds.location.add(i.sub(n.bounds.max)),o=e.bounds.size.add(n.bounds.size);return new t.Rectangle(r.x,r.y,o.x,o.y)},e}();t.ShapeCollisionsBox=e}(es||(es={})),function(t){var e=function(){function e(){}return e.circleToCircleCast=function(e,n,i,r){var o=e.position.add(i),s=this.closestPointOnLine(e.position,o,n.position),a=t.Vector2.sqrDistance(n.position,s),h=(e.radius+n.radius)*(e.radius+n.radius);if(a<=h){var c=i.normalize();s===o&&(o=e.position.add(i.add(c.scale(n.radius))),s=this.closestPointOnLine(e.position,o,n.position),a=t.Vector2.sqrDistance(n.position,s));var u=Math.sqrt(h-a);return r.centroid=s.sub(c.scale(u)),r.normal=r.centroid.sub(n.position).normalize(),r.fraction=(r.centroid.x-e.position.x)/i.x,r.distance=t.Vector2.distance(e.position,r.centroid),r.point=n.position.add(r.normal.scale(n.radius)),!0}return!1},e.circleToCircle=function(e,n,i){void 0===i&&(i=new t.CollisionResult);var r=t.Vector2.sqrDistance(e.position,n.position),o=e.radius+n.radius;if(re.radius*e.radius&&!a)return!1;if(a)s=i.normal.scale(Math.sqrt(o.distanceSquared)-e.radius);else if(0===o.distanceSquared)s=i.normal.scale(e.radius);else{var h=Math.sqrt(o.distanceSquared);s=r.sub(o.closestPoint).scale((e.radius-h)/h*-1)}return i.minimumTranslationVector=s,i.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){void 0===o&&(o=new t.RaycastHit);for(var s=t.Vector2.zero,a=t.Vector2.zero,h=Number.MAX_VALUE,c=!1,u=r.points.length-1,l=0;l1)return!1;var u=(h.x*o.y-h.y*o.x)/a;if(u<0||u>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){var o=t.Vector2.distance(e,n),s=t.Vector2.divideScaler(n.sub(e),o),a=e.sub(i.position),h=a.dot(s),c=a.dot(a)-i.radius*i.radius;if(c>0&&h>0)return!1;var u=h*h-c;return!(u<0)&&(r.fraction=-h-Math.sqrt(u),r.fraction<0&&(r.fraction=0),r.point=e.add(s.scale(r.fraction)),r.distance=t.Vector2.distance(e,r.point),r.normal=r.point.sub(i.position).normalize(),r.fraction=r.distance/o,!0)},e}();t.ShapeCollisionsLine=e}(es||(es={})),function(t){var e=function(){function e(){}return e.pointToCircle=function(e,n,i){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=0;e--){for(var n=this._composites[e],i=0;in.height?e.y=n.height:e.yn.width&&(e.x=n.width)):(e.yn.height-t.radius&&(e.y=2*(n.height-t.radius)-e.y),e.x>n.width-t.radius&&(e.x=2*(n.width-t.radius)-e.x),e.x=0;t--)this._constraints[t].solve()},e.prototype.updateParticles=function(t,e){for(var n=0;n=0;t--)this._constraints[t].collidesWithColliders&&this._constraints[t].handleCollisions(this.collidesWithLayers)},e.prototype.debugRender=function(e){if(this.drawConstraints)for(var n=0;n0&&r.addConstraint(new t.DistanceConstraint(r.particles[o],r.particles[o-1],i))}return r}return __extends(n,e),n.prototype.pinParticleAtIndex=function(t){return this.particles[t].pin(),this},n}(t.Composite);t.LineSegments=e}(es||(es={})),function(t){var e=function(){function t(){this.collidesWithColliders=!0}return t.prototype.handleCollisions=function(t){},t.prototype.debugRender=function(t){},t}();t.Constraint=e}(es||(es={})),function(t){var e=function(e){function n(t,n,i,r){var o=e.call(this)||this;return o.stiffness=0,o.angleInRadius=0,o._particleA=t,o._centerParticle=n,o._particleC=i,o.stiffness=r,o.collidesWithColliders=!1,o.angleInRadius=o.angleBetweenParticles(),o}return __extends(n,e),n.prototype.angleBetweenParticles=function(){var t=this._particleA.position.sub(this._centerParticle.position),e=this._particleC.position.sub(this._centerParticle.position);return Math.atan2(t.x*e.y-t.y*e.x,t.x*e.x+t.y*e.y)},n.prototype.solve=function(){var e=this.angleBetweenParticles()-this.angleInRadius;e<=-Math.PI?e+=2*Math.PI:e>=Math.PI&&(e-=2*Math.PI),e*=this.stiffness,this._particleA.position=t.MathHelper.rotateAround2(this._particleA.position,this._centerParticle.position,e),this._particleC.position=t.MathHelper.rotateAround2(this._particleC.position,this._centerParticle.position,-e),this._centerParticle.position=t.MathHelper.rotateAround2(this._centerParticle.position,this._particleA.position,e),this._centerParticle.position=t.MathHelper.rotateAround2(this._centerParticle.position,this._particleC.position,-e)},n}(t.Constraint);t.AngleConstraint=e}(es||(es={})),function(t){var e=function(e){function n(t,i,r,o){void 0===o&&(o=-1);var s=e.call(this)||this;return s.stiffness=0,s.restingDistance=0,s.tearSensitivity=Number.POSITIVE_INFINITY,s.shouldApproximateCollisionsWithPoints=!1,s.totalPointsToApproximateCollisionsWith=5,n._polygon.create(2,1),s._particleOne=t,s._particleTwo=i,s.stiffness=r,s.restingDistance=o>-1?o:t.position.distance(i.position),s}return __extends(n,e),n.create=function(e,i,r,o,s){var a=e.position.distance(i.position),h=r.position.distance(i.position);return new n(e,r,o,Math.sqrt(a*a+h*h-2*a*h*Math.cos(s*t.MathHelper.Deg2Rad)))},n.prototype.setTearSensitivity=function(t){return this.tearSensitivity=t,this},n.prototype.setCollidesWithColliders=function(t){return this.collidesWithColliders=t,this},n.prototype.setShouldApproximateCollisionsWithPoints=function(t){return this.shouldApproximateCollisionsWithPoints=t,this},n.prototype.solve=function(){var t=this._particleOne.position.sub(this._particleTwo.position),e=t.distance(),n=(this.restingDistance-e)/e;if(e/this.restingDistance>this.tearSensitivity)this.composite.removeConstraint(this);else{var i=1/this._particleOne.mass,r=i/(i+1/this._particleTwo.mass)*this.stiffness,o=this.stiffness-r;this._particleOne.position=this._particleOne.position.add(t.scale(r*n)),this._particleTwo.position=this._particleTwo.position.sub(t.scale(o*n))}},n.prototype.handleCollisions=function(e){if(this.shouldApproximateCollisionsWithPoints)this.approximateCollisionsWithPoints(e);else{var i=Math.min(this._particleOne.position.x,this._particleTwo.position.x),r=Math.max(this._particleOne.position.x,this._particleTwo.position.x),o=Math.min(this._particleOne.position.y,this._particleTwo.position.y),s=Math.max(this._particleOne.position.y,this._particleTwo.position.y);n._polygon.bounds=t.Rectangle.fromMinMax(i,o,r,s);var a=t.Vector2.zero;this.preparePolygonForCollisionChecks(a);for(var h=t.Physics.boxcastBroadphase(n._polygon.bounds,e),c=0;c=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.getTargetObject()),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(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(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(this)},n}(t.Tween);t.RectangleTween=i;var r=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.cacheColorTweens?t.Pool.obtain(n):new n},n.prototype.setIsRelative=function(){return this._isRelative=!0,this._toValue.r+=this._fromValue.r,this._toValue.g+=this._fromValue.g,this._toValue.b+=this._fromValue.b,this._toValue.a+=this._fromValue.a,this},n.prototype.updateValue=function(){this._target.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n}(t.Tween);t.ColorTween=r}(es||(es={})),function(t){var e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return __extends(n,e),n.prototype.setTweenedValue=function(t){this._renderable.color=t},n.prototype.getTweenedValue=function(){return this._renderable.color},n.prototype.getTargetObject=function(){return this._renderable},n.prototype.updateValue=function(){this.setTweenedValue(t.Lerps.ease(this._easeType,this._fromValue,this._toValue,this._elapsedTime,this._duration))},n.prototype.setTarget=function(t){this._renderable=t},n.prototype.recycleSelf=function(){this._shouldRecycleTween&&(this._renderable=null,this._target=null,this._nextTween=null),this._shouldRecycleTween&&t.TweenManager.cacheColorTweens&&t.Pool.free(this)},n}(t.ColorTween);t.RenderableColorTween=e}(es||(es={})),function(t){var e=function(e){function n(t,n,i){var r=e.call(this)||this;return r.dampingRatio=.23,r.angularFrequency=25,r._transform=t,r._targetType=n,r.setTargetValue(i),r}return __extends(n,e),Object.defineProperty(n.prototype,"targetType",{get:function(){return this._targetType},enumerable:!0,configurable:!0}),n.prototype.setTargetValue=function(e){this._velocity=t.Vector2.zero,this._targetValue=e,this._isCurrentlyManagedByTweenManager||this.start()},n.prototype.updateDampingRatioWithHalfLife=function(t){this.dampingRatio=-t/this.angularFrequency*Math.log(.5)},n.prototype.tick=function(){return this._isPaused||this.setTweenedValue(t.Lerps.fastSpring(this.getCurrentValueOfTweenedTargetType(),this._targetValue,this._velocity,this.dampingRatio,this.angularFrequency)),!1},n.prototype.setTweenedValue=function(e){switch(this._targetType){case t.TransformTargetType.position:this._transform.position=e;break;case t.TransformTargetType.localPosition:this._transform.localPosition=e;break;case t.TransformTargetType.scale:this._transform.scale=e;break;case t.TransformTargetType.localScale:this._transform.localScale=e;break;case t.TransformTargetType.rotationDegrees:this._transform.rotationDegrees=e.x;case t.TransformTargetType.localRotationDegrees:this._transform.localRotationDegrees=e.x}},n.prototype.getCurrentValueOfTweenedTargetType=function(){switch(this._targetType){case t.TransformTargetType.position:return this._transform.position;case t.TransformTargetType.localPosition:return this._transform.localPosition;case t.TransformTargetType.scale:return this._transform.scale;case t.TransformTargetType.localScale:return this._transform.localScale;case t.TransformTargetType.rotationDegrees:return new t.Vector2(this._transform.rotationDegrees);case t.TransformTargetType.localRotationDegrees:return new t.Vector2(this._transform.localRotationDegrees,0);default:return t.Vector2.zero}},n}(t.AbstractTweenable);t.TransformSpringTween=e}(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(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.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),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,h=n[this._triPrev[s]],c=n[s],u=n[this._triNext[s]];if(t.Vector2Ext.isTriangleCCW(h,c,u)){var l=this._triNext[this._triNext[s]];do{if(e.testPointTriangle(n[l],h,c,u)){a=!1;break}l=this._triNext[l]}while(l!=this._triPrev[s])}else a=!1;a?(this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),this._triNext[this._triPrev[s]]=this._triNext[s],this._triPrev[this._triNext[s]]=this._triPrev[s],r--,s=this._triPrev[s]):s=this._triNext[s]}this.triangleIndices.push(this._triPrev[s]),this.triangleIndices.push(s),this.triangleIndices.push(this._triNext[s]),i||this.triangleIndices.reverse()},e.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.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 h=t.HashHelpers.expandPrime(this._freeValueCellIndex);this._values.length=h,this._valuesInfo.length=h}var c=t.NumberExtension.toNumber(this._buckets[a])-1;if(-1==c)this._valuesInfo[this._freeValueCellIndex]=new n(i,s);else{var u=c;do{if(this._valuesInfo[u].hashcode==s&&this._valuesInfo[u].key==i)return this._values[u]=r,o.value=u,!1;u=this._valuesInfo[u].previous}while(-1!=u);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 e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}();t.ListPool=e}(es||(es={})),function(t){var e=function(){function e(t,e){this.first=t,this.second=e}return e.prototype.clear=function(){this.first=this.second=null},e.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},e.prototype.getHashCode=function(){return 37*t.EqualityComparer.default().getHashCode(this.first)+t.EqualityComparer.default().getHashCode(this.second)},e}();t.Pair=e}(es||(es={})),function(t){var e=function(){function e(){}return e.warmCache=function(t,e){if((e-=this._objectQueue.length)>0)for(var n=0;nthis._objectQueue.length;)this._objectQueue.shift()},e.clearCache=function(){this._objectQueue.length=0},e.obtain=function(t){return this._objectQueue.length>0?this._objectQueue.shift():new t},e.free=function(e){this._objectQueue.unshift(e),t.isIPoolable(e)&&e.reset()},e._objectQueue=[],e}();t.Pool=e,t.isIPoolable=function(t){return void 0!==t.reset}}(es||(es={})),function(t){var e=function(t){function e(e){return t.call(this,e)||this}return __extends(e,t),e.prototype.getHashCode=function(t){return t.getHashCode()},e.prototype.areEqual=function(t,e){return t.equals(e)},e}(function(){function t(t){var e=this;this.clear(),t&&t.forEach(function(t){e.add(t)})}return t.prototype.add=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i){var r=new Array;return r.push(t),this.buckets[n]=r,this.count=this.count+1,!0}return!i.some(function(n){return e.areEqual(n,t)})&&(i.push(t),this.count=this.count+1,!0)},t.prototype.remove=function(t){var e=this,n=this.getHashCode(t),i=this.buckets[n];if(void 0===i)return!1;var r=!1,o=new Array;return i.forEach(function(n){e.areEqual(n,t)?r=!0:o.push(t)}),this.buckets[n]=o,r&&(this.count=this.count-1),r},t.prototype.contains=function(t){return this.bucketsContains(this.buckets,t)},t.prototype.getCount=function(){return this.count},t.prototype.clear=function(){this.buckets=new Array,this.count=0},t.prototype.toArray=function(){var t=new Array;return this.buckets.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},t.prototype.exceptWith=function(t){var e=this;t&&t.forEach(function(t){e.remove(t)})},t.prototype.intersectWith=function(t){var e=this;if(t){var n=this.buildInternalBuckets(t);this.toArray().forEach(function(t){e.bucketsContains(n.Buckets,t)||e.remove(t)})}else this.clear()},t.prototype.unionWith=function(t){var e=this;t.forEach(function(t){e.add(t)})},t.prototype.isSubsetOf=function(t){var e=this,n=this.buildInternalBuckets(t);return this.toArray().every(function(t){return e.bucketsContains(n.Buckets,t)})},t.prototype.isSupersetOf=function(t){var e=this;return t.every(function(t){return e.contains(t)})},t.prototype.overlaps=function(t){var e=this;return t.some(function(t){return e.contains(t)})},t.prototype.setEquals=function(t){var e=this;return this.buildInternalBuckets(t).Count===this.count&&t.every(function(t){return e.contains(t)})},t.prototype.buildInternalBuckets=function(t){var e=this,n=new Array,i=0;return t.forEach(function(t){var r=e.getHashCode(t),o=n[r];if(void 0===o){var s=new Array;s.push(t),n[r]=s,i+=1}else o.some(function(n){return e.areEqual(n,t)})||(o.push(t),i+=1)}),{Buckets:n,Count:i}},t.prototype.bucketsContains=function(t,e){var n=this,i=t[this.getHashCode(e)];return void 0!==i&&i.some(function(t){return n.areEqual(t,e)})},t}());t.HashSet=e}(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.startCoroutine=function(n){var i=t.Pool.obtain(e);return i.prepareForUse(),i.enumerator=n,this.tickCoroutine(i)?(this._isInUpdate?this._shouldRunNextFrame.push(i):this._unblockedCoroutines.push(i),i):null},i.prototype.update=function(){this._isInUpdate=!0;for(var e=0;e0?(n.waitTimer-=n.useUnscaledDeltaTime?t.Time.unscaledDeltaTime:t.Time.deltaTime,this._shouldRunNextFrame.push(n)):this.tickCoroutine(n)&&this._shouldRunNextFrame.push(n)}}var i=new t.List(this._unblockedCoroutines);i.clear(),i.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(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(n),!1):!(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 h=Math.abs(this.freeRectangles[s].width-e),c=Math.abs(this.freeRectangles[s].height-n),u=Math.min(h,c);(a=n&&this.freeRectangles[s].height>=e){h=Math.abs(this.freeRectangles[s].width-n),c=Math.abs(this.freeRectangles[s].height-e),u=Math.min(h,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){for(var i=new Set;i.size!=n;){var r=this.randomItem(e);i.has(r)||i.add(r)}var o=t.ListPool.obtain();return i.forEach(function(t){return o.push(t)}),o},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=[],h=0;h>4,n=(15&r)<<4|(o=this._keyStr.indexOf(t.charAt(h++)))>>2,i=(3&o)<<6|(s=this._keyStr.indexOf(t.charAt(h++))),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,h=[],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),h.push(this._keyStr.charAt(r)),h.push(this._keyStr.charAt(o)),h.push(this._keyStr.charAt(s)),h.push(this._keyStr.charAt(a));return h=h.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(u)>=p)return t.Vector2.zero;var f=c>0?l-c:-l-c,d=u>0?p-u:-p-u;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(Math.trunc(n),Math.trunc(i)),new t.Vector2(Math.trunc(r),Math.trunc(o)))},e.calculateBounds=function(e,n,i,r,o,s,a,h){if(0==s)e.x=Math.trunc(n.x+i.x-r.x*o.x),e.y=Math.trunc(n.y+i.y-r.y*o.y),e.width=Math.trunc(a*o.x),e.height=Math.trunc(h*o.y);else{var c=n.x+i.x,u=n.y+i.y,l=new t.Matrix2D;t.Matrix2D.createTranslation(-c-r.x,-u-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,u,void 0),l=l.multiply(void 0);var p=new t.Vector2(c,u),f=new t.Vector2(c+a,u),d=new t.Vector2(c,u+h),y=new t.Vector2(c+a,u+h);t.Vector2Ext.transformR(p,l,p),t.Vector2Ext.transformR(f,l,f),t.Vector2Ext.transformR(d,l,d),t.Vector2Ext.transformR(y,l,y);var m=Math.trunc(Math.min(p.x,y.x,f.x,d.x)),g=Math.trunc(Math.max(p.x,y.x,f.x,d.x)),_=Math.trunc(Math.min(p.y,y.y,f.y,d.y)),v=Math.trunc(Math.max(p.y,y.y,f.y,d.y));e.location=new t.Vector2(m,_),e.width=Math.trunc(g-m),e.height=Math.trunc(v-_)}},e.scale=function(t,e){t.x=Math.trunc(t.x*e.x),t.y=Math.trunc(t.y*e.y),t.width=Math.trunc(t.width*e.x),t.height=Math.trunc(t.height*e.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},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 e=this._timers.length-1;e>=0;e--)this._timers[e].tick()&&(this._timers[e].unload(),new t.List(this._timers).removeAt(e))},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/Core.ts b/source/src/Core.ts index 676aeb10..175efb3d 100644 --- a/source/src/Core.ts +++ b/source/src/Core.ts @@ -43,6 +43,7 @@ module es { Core.emitter.addObserver(CoreEvents.frameUpdated, this.update, this); Core.registerGlobalManager(this._coroutineManager); + Core.registerGlobalManager(new TweenManager()); Core.registerGlobalManager(this._timerManager); Core.entitySystemsEnabled = enableEntitySystems; diff --git a/source/src/ECS/Components/Renderables/RenderableComponent.ts b/source/src/ECS/Components/Renderables/RenderableComponent.ts index 4703c1e3..fd8eb9aa 100644 --- a/source/src/ECS/Components/Renderables/RenderableComponent.ts +++ b/source/src/ECS/Components/Renderables/RenderableComponent.ts @@ -3,11 +3,11 @@ module es { public getwidth() { return this.bounds.width; } - + public getheight() { return this.bounds.height; } - + protected _bounds: es.Rectangle = new es.Rectangle(); public getbounds(): es.Rectangle { if (this._areBoundsDirty) { @@ -21,44 +21,45 @@ module es { return this.getbounds(); } protected _areBoundsDirty: boolean = true; - + public color: Color = Color.White; + public get renderLayer() { return this._renderLayer; } public set renderLayer(value: number) { this.setRenderLayer(value); } - + protected _renderLayer: number = 0; - + public onEntityTransformChanged(comp: transform.Component) { this._areBoundsDirty = true; } - + public get localOffset() { return this._localOffset; } public set localOffset(value: es.Vector2) { this.setLocalOffset(value); } - + public setLocalOffset(offset: es.Vector2) { if (!this._localOffset.equals(offset)) { this._localOffset = offset; this._areBoundsDirty = true; } - + return this; } - + public get isVisible() { return this._isVisible; } - + public set isVisible(value: boolean) { if (this._isVisible != value) { this._isVisible = value; - + if (this._isVisible) { this.onBecameVisible(); } else { @@ -66,44 +67,44 @@ module es { } } } - + public debugRenderEnabled: boolean = true; - + protected _isVisible: boolean = false; protected _localOffset: es.Vector2 = new es.Vector2(); - + public abstract render(batcher: IBatcher, camera: ICamera): void; - + protected onBecameVisible() { - + } - + protected onBecameInvisible() { - + } - + public setRenderLayer(renderLayer: number): RenderableComponent { if (renderLayer != this._renderLayer) { let oldRenderLayer = this._renderLayer; this._renderLayer = renderLayer; - + if (this.entity != null && this.entity.scene != null) es.Core.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer); } - + return this; } - + public isVisibleFromCamera(cam: ICamera): boolean { this.isVisible = cam.bounds.intersects(this.bounds); - + return this.isVisible; } - + public debugRender(batcher: IBatcher) { if (!this.debugRenderEnabled) return; - + let collider = null; for (let i = 0; i < this.entity.components.buffer.length; i++) { let component = this.entity.components.buffer[i]; @@ -112,14 +113,21 @@ module es { break; } } - + if (collider == null) { batcher.drawHollowRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height, new Color(255, 255, 0)); batcher.end(); } - + batcher.drawPixel(es.Vector2.add(this.entity.transform.position, this._localOffset), new Color(153, 50, 204), 4); batcher.end(); } + + public tweenColorTo(to: Color, duration: number) { + const tween = Pool.obtain(RenderableColorTween); + tween.setTarget(this); + tween.initialize(tween, to, duration); + return tween; + } } } \ No newline at end of file diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts index 07adaba1..ea1dcd2f 100644 --- a/source/src/ECS/Entity.ts +++ b/source/src/ECS/Entity.ts @@ -491,6 +491,66 @@ module es { } } + public tweenPositionTo(to: Vector2, duration: number = 0.3): ITween { + const tween = Pool.obtain(TransformVector2Tween); + tween.setTargetAndType(this.transform, TransformTargetType.position); + tween.initialize(tween, to, duration); + + return tween; + } + + public tweenLocalPositionTo(to: Vector2, duration = 0.3): ITween { + const tween = Pool.obtain(TransformVector2Tween); + tween.setTargetAndType(this.transform, TransformTargetType.localPosition); + tween.initialize(tween, to, duration); + + return tween; + } + + public tweenScaleTo(to: Vector2, duration?: number); + public tweenScaleTo(to: number, duration?: number); + public tweenScaleTo(to: Vector2 | number, duration: number = 0.3) { + if (typeof (to) == 'number') { + return this.tweenScaleTo(new Vector2(to, to), duration); + } + + const tween = Pool.obtain(TransformVector2Tween); + tween.setTargetAndType(this.transform, TransformTargetType.scale); + tween.initialize(tween, to, duration); + + return tween; + } + + public tweenLocalScaleTo(to: Vector2, duration?); + public tweenLocalScaleTo(to: number, duration?); + public tweenLocalScaleTo(to: Vector2 | number, duration = 0.3) { + if (typeof (to) == 'number') { + return this.tweenLocalScaleTo(new Vector2(to, to), duration); + } + + const tween = Pool.obtain(TransformVector2Tween); + tween.setTargetAndType(this.transform, TransformTargetType.localScale); + tween.initialize(tween, to, duration); + + return tween; + } + + public tweenRotationDegreesTo(to: number, duration = 0.3) { + const tween = Pool.obtain(TransformVector2Tween); + tween.setTargetAndType(this.transform, TransformTargetType.rotationDegrees); + tween.initialize(tween, new Vector2(to, to), duration); + + return tween; + } + + public tweenLocalRotationDegreesTo(to: number, duration = 0.3) { + const tween = Pool.obtain(TransformVector2Tween); + tween.setTargetAndType(this.transform, TransformTargetType.localRotationDegrees); + tween.initialize(tween, new Vector2(to, to), duration); + + return tween; + } + public compareTo(other: Entity): number { let compare = this._updateOrder - other._updateOrder; if (compare == 0) diff --git a/source/src/Math/Bezier.ts b/source/src/Math/Bezier.ts index 0906e922..2a6c65e6 100644 --- a/source/src/Math/Bezier.ts +++ b/source/src/Math/Bezier.ts @@ -13,9 +13,9 @@ module es { public static getPoint(p0: Vector2, p1: Vector2, p2: Vector2, t: number): Vector2 { t = MathHelper.clamp01(t); let oneMinusT = 1 - t; - return new Vector2(oneMinusT * oneMinusT).multiply(p0) - .addEqual(new Vector2(2 * oneMinusT * t).multiply(p1)) - .addEqual(new Vector2(t * t).multiply(p2)); + return p0.scale(oneMinusT * oneMinusT) + .addEqual(p1.scale(2 * oneMinusT * t)) + .addEqual(p2.scale(t * t)); } /** @@ -29,11 +29,11 @@ module es { public static getPointThree(start: Vector2, firstControlPoint: Vector2, secondControlPoint: Vector2, end: Vector2, t: number): Vector2 { t = MathHelper.clamp01(t); - let oneMinusT = 1 - t; - return new Vector2(oneMinusT * oneMinusT * oneMinusT).multiply(start) - .addEqual(new Vector2(3 * oneMinusT * oneMinusT * t).multiply(firstControlPoint)) - .addEqual(new Vector2(3 * oneMinusT * t * t).multiply(secondControlPoint)) - .addEqual(new Vector2(t * t * t).multiply(end)); + const oneMinusT = 1 - t; + return start.scale(oneMinusT * oneMinusT * oneMinusT) + .addEqual(firstControlPoint.scale(3 * oneMinusT * oneMinusT * t)) + .addEqual(secondControlPoint.scale(3 * oneMinusT * t * t)) + .addEqual(end.scale(t * t * t)); } /** diff --git a/source/src/Physics/Verlet/Constraints/AngleConstraint.ts b/source/src/Physics/Verlet/Constraints/AngleConstraint.ts index b7f00229..87d8bfd5 100644 --- a/source/src/Physics/Verlet/Constraints/AngleConstraint.ts +++ b/source/src/Physics/Verlet/Constraints/AngleConstraint.ts @@ -3,7 +3,7 @@ module es { export class AngleConstraint extends Constraint { public stiffness: number = 0; public angleInRadius: number = 0; - + _particleA: Particle; _centerParticle: Particle; _particleC: Particle; diff --git a/source/src/Tween/AbstractTweenable.ts b/source/src/Tween/AbstractTweenable.ts new file mode 100644 index 00000000..1389dfea --- /dev/null +++ b/source/src/Tween/AbstractTweenable.ts @@ -0,0 +1,51 @@ +module es { + /** + * AbstractTweenable作为你可能想做的任何可以执行的自定义类的基础。 + * 这些类不同于ITweens,因为他们没有实现ITweenT接口。 + * 它只是说一个AbstractTweenable不仅仅是将一个值从开始移动到结束。 + * 它可以做任何需要每帧执行的事情。 + */ + export abstract class AbstractTweenable implements ITweenable { + protected _isPaused: boolean; + + /** + * abstractTweenable在完成后往往会被保留下来。 + * 这个标志可以让它们在内部知道自己当前是否被TweenManager盯上了,以便在必要时可以重新添加自己。 + */ + protected _isCurrentlyManagedByTweenManager: boolean; + + public abstract tick(): boolean; + + public recycleSelf() { + } + + public isRunning(): boolean { + return this._isCurrentlyManagedByTweenManager && !this._isPaused; + } + + public start() { + if (this._isCurrentlyManagedByTweenManager) { + this._isPaused = false; + return; + } + + TweenManager.addTween(this); + this._isCurrentlyManagedByTweenManager = true; + this._isPaused = false; + } + + public pause() { + this._isPaused = true; + } + + public resume() { + this._isPaused = false; + } + + public stop(bringToCompletion: boolean = false) { + TweenManager.removeTween(this); + this._isCurrentlyManagedByTweenManager = false; + this._isPaused = true; + } + } +} \ No newline at end of file diff --git a/source/src/Tween/Easing/EaseType.ts b/source/src/Tween/Easing/EaseType.ts new file mode 100644 index 00000000..f43ee2be --- /dev/null +++ b/source/src/Tween/Easing/EaseType.ts @@ -0,0 +1,207 @@ +module es { + export enum EaseType { + linear, + + sineIn, + sineOut, + sineInOut, + + quadIn, + quadOut, + quadInOut, + + quintIn, + quintOut, + quintInOut, + + cubicIn, + cubicOut, + cubicInOut, + + quartIn, + quartOut, + quartInOut, + + expoIn, + expoOut, + expoInOut, + + circleIn, + circleOut, + circleInOut, + + elasticIn, + elasticOut, + elasticInOut, + punch, + + backIn, + backOut, + backInOut, + + bounceIn, + bounceOut, + bounceInOut + } + + /** + * 助手的一个方法,它接收一个EaseType,并通过给定的持续时间和时间参数来应用该Ease方程。 + * 我们这样做是为了避免传来传去的Funcs为垃圾收集器制造大量垃圾 + */ + export class EaseHelper { + /** + * 返回 easeType 的相反 EaseType + * @param easeType + */ + public static oppositeEaseType(easeType: EaseType) { + switch (easeType) { + case EaseType.linear: + return easeType; + + case EaseType.backIn: + return EaseType.backOut; + case EaseType.backOut: + return EaseType.backIn; + case EaseType.backInOut: + return easeType; + + case EaseType.bounceIn: + return EaseType.bounceOut; + case EaseType.bounceOut: + return EaseType.bounceIn; + case EaseType.bounceInOut: + return easeType; + + case EaseType.circleIn: + return EaseType.circleOut; + case EaseType.circleOut: + return EaseType.circleIn; + case EaseType.circleInOut: + return easeType; + + case EaseType.cubicIn: + return EaseType.cubicOut; + case EaseType.cubicOut: + return EaseType.cubicIn; + case EaseType.circleInOut: + return easeType; + + case EaseType.punch: + return easeType; + + case EaseType.expoIn: + return EaseType.expoOut; + case EaseType.expoOut: + return EaseType.expoIn; + case EaseType.expoInOut: + return easeType; + + case EaseType.quadIn: + return EaseType.quadOut; + case EaseType.quadOut: + return EaseType.quadIn; + case EaseType.quadInOut: + return easeType; + + case EaseType.quartIn: + return EaseType.quadOut; + case EaseType.quartOut: + return EaseType.quartIn; + case EaseType.quadInOut: + return easeType; + + case EaseType.sineIn: + return EaseType.sineOut; + case EaseType.sineOut: + return EaseType.sineIn; + case EaseType.sineInOut: + return easeType; + + default: + return easeType; + } + } + + public static ease(easeType: EaseType, t: number, duration: number) { + switch (easeType) { + case EaseType.linear: + return Easing.Linear.easeNone(t, duration); + + case EaseType.backIn: + return Easing.Back.easeIn(t, duration); + case EaseType.backOut: + return Easing.Back.easeOut(t, duration); + case EaseType.backInOut: + return Easing.Back.easeInOut(t, duration); + + case EaseType.bounceIn: + return Easing.Bounce.easeIn(t, duration); + case EaseType.bounceOut: + return Easing.Bounce.easeOut(t, duration); + case EaseType.bounceInOut: + return Easing.Bounce.easeInOut(t, duration); + + case EaseType.circleIn: + return Easing.Circular.easeIn(t, duration); + case EaseType.circleOut: + return Easing.Circular.easeOut(t, duration); + case EaseType.circleInOut: + return Easing.Circular.easeInOut(t, duration); + + case EaseType.cubicIn: + return Easing.Cubic.easeIn(t, duration); + case EaseType.cubicOut: + return Easing.Cubic.easeOut(t, duration); + case EaseType.cubicInOut: + return Easing.Cubic.easeInOut(t, duration); + + case EaseType.elasticIn: + return Easing.Elastic.easeIn(t, duration); + case EaseType.elasticOut: + return Easing.Elastic.easeOut(t, duration); + case EaseType.elasticInOut: + return Easing.Elastic.easeInOut(t, duration); + case EaseType.punch: + return Easing.Elastic.punch(t, duration); + + case EaseType.expoIn: + return Easing.Exponential.easeIn(t, duration); + case EaseType.expoOut: + return Easing.Exponential.easeOut(t, duration); + case EaseType.expoInOut: + return Easing.Exponential.easeInOut(t, duration); + + case EaseType.quadIn: + return Easing.Quadratic.easeIn(t, duration); + case EaseType.quadOut: + return Easing.Quadratic.easeOut(t, duration); + case EaseType.quadInOut: + return Easing.Quadratic.easeInOut(t, duration); + + case EaseType.quadIn: + return Easing.Quadratic.easeIn(t, duration); + case EaseType.quadOut: + return Easing.Quadratic.easeOut(t, duration); + case EaseType.quadInOut: + return Easing.Quadratic.easeInOut(t, duration); + + case EaseType.quintIn: + return Easing.Quintic.easeIn(t, duration); + case EaseType.quintOut: + return Easing.Quintic.easeOut(t, duration); + case EaseType.quintInOut: + return Easing.Quintic.easeInOut(t, duration); + + case EaseType.sineIn: + return Easing.Sinusoidal.easeIn(t, duration); + case EaseType.sineOut: + return Easing.Sinusoidal.easeOut(t, duration); + case EaseType.sineInOut: + return Easing.Sinusoidal.easeInOut(t, duration); + + default: + return Easing.Linear.easeNone(t, duration); + } + } + } +} \ No newline at end of file diff --git a/source/src/Tween/Easing/Easing.ts b/source/src/Tween/Easing/Easing.ts new file mode 100644 index 00000000..2ebd6f9f --- /dev/null +++ b/source/src/Tween/Easing/Easing.ts @@ -0,0 +1,230 @@ +module es { + /** + * 标准缓和方程通过将b和c参数(起始值和变化值)用0和1替换,然后进行简化。 + * 这样做的目的是为了让我们可以得到一个0 - 1之间的原始值(除了弹性/反弹故意超过界限),然后用这个值来lerp任何东西 + */ + export module Easing { + export class Linear { + public static easeNone(t: number, d: number) { + return t / d; + } + } + + export class Quadratic { + public static easeIn(t: number, d: number) { + return (t /= d) * t; + } + + public static easeOut(t: number, d: number) { + return -1 * (t /= d) * (t - 2); + } + + public static easeInOut(t: number, d: number) { + if ((t /= d / 2) < 1) + return 0.5 * t * t; + return -0.5 * ((--t) * (t - 2) - 1); + } + } + + export class Back { + public static easeIn(t: number, d: number) { + return (t /= d) * t * ((1.70158 + 1) * t - 1.70158); + } + + public static easeOut(t: number, d: number) { + return ((t = t / d - 1) * t * ((1.70158 + 1) * t + 1.70158) + 1); + } + + public static easeInOut(t: number, d: number) { + let s = 1.70158; + if ((t /= d / 2) < 1) { + return 0.5 * (t * t * (((s *= (1.525)) + 1) * t - s)); + } + + return 0.5 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2); + } + } + + export class Bounce { + public static easeOut(t: number, d: number) { + if ((t /= d) < (1 / 2.75)) { + return (7.5625 * t * t); + } else if (t < (2 / 2.75)) { + return (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75); + } else if (t < (2.5 / 2.75)) { + return (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375); + } else { + return (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375); + } + } + + public static easeIn(t: number, d: number) { + return 1 - this.easeOut(d - t, d); + } + + public static easeInOut(t: number, d: number) { + if (t < d / 2) + return this.easeIn(t * 2, d) * 0.5; + else + return this.easeOut(t * 2 - d, d) * 0.5 + 1 * 0.5; + } + } + + export class Circular { + public static easeIn(t: number, d: number) { + return -(Math.sqrt(1 - (t /= d) * t) - 1); + } + + public static easeOut(t: number, d: number) { + return Math.sqrt(1 - (t = t / d - 1) * t); + } + + public static easeInOut(t: number, d: number) { + if ((t /= d / 2) < 1) + return -0.5 * (Math.sqrt(1 - t * t) - 1); + return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1); + } + } + + export class Cubic { + public static easeIn(t: number, d: number) { + return (t /= d) * t * t; + } + + public static easeOut(t: number, d: number) { + return ((t = t / d - 1) * t * t + 1); + } + + public static easeInOut(t: number, d: number) { + if ((t /= d / 2) < 1) + return 0.5 * t * t * t; + return 0.5 * ((t -= 2) * t * t + 2); + } + } + + export class Elastic { + public static easeIn(t: number, d: number) { + if (t == 0) + return 0; + + if ((t /= d) == 1) + return 1; + + let p = d * 0.3; + let s = p / 4; + return -(1 * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)); + } + + public static easeOut(t: number, d: number) { + if (t == 0) + return 0; + + if ((t /= d) == 1) + return 1; + + let p = d * 0.3; + let s = p / 4; + return (1 * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + 1); + } + + public static easeInOut(t: number, d: number) { + if (t == 0) + return 0; + + if ((t /= d / 2) == 2) + return 1; + + let p = d * (0.3 * 1.5); + let s = p / 4; + if (t < 1) + return -0.5 * (Math.pow(2, 10 * (t -= 1)) * Math.sin(t * d - s) * (2 * Math.PI) / p); + + return (Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * 0.5 + 1); + } + + public static punch(t: number, d: number) { + if (t == 0) + return 0; + + if ((t /= d) == 1) + return 0; + + const p = 0.3; + return (Math.pow(2, -10 * t) * Math.sin(t * (2 * Math.PI) / p)); + } + } + + export class Exponential { + public static easeIn(t: number, d: number) { + return (t == 0) ? 0 : Math.pow(2, 10 * (t / d - 1)); + } + + public static easeOut(t: number, d: number) { + return t == d ? 1 : (-Math.pow(2, -10 * t / d) + 1); + } + + public static easeInOut(t: number, d: number) { + if (t == 0) + return 0; + + if (t == d) + return 1; + + if ((t /= d / 2) < 1) { + return 0.5 * Math.pow(2, 10 * (t - 1)); + } + return 0.5 * (-Math.pow(2, -10 * --t) + 2); + } + } + + export class Quartic { + public static easeIn(t: number, d: number) { + return (t /= d) * t * t * t; + } + + public static easeOut(t: number, d: number) { + return -1 * ((t = t / d - 1) * t * t * t - 1); + } + + public static easeInOut(t: number, d: number) { + t /= d / 2; + if (t < 1) + return 0.5 * t * t * t * t; + + t -= 2; + return -0.5 * (t * t * t * t - 2); + } + } + + export class Quintic { + public static easeIn(t: number, d: number) { + return (t /= d) * t * t * t * t; + } + + public static easeOut(t: number, d: number) { + return ((t = t / d - 1) * t * t * t * t + 1); + } + + public static easeInOut(t: number, d: number) { + if ((t /= d / 2) < 1) + return 0.5 * t * t * t * t * t; + + return 0.5 * ((t -= 2) * t * t * t * t + 2); + } + } + + export class Sinusoidal { + public static easeIn(t: number, d: number) { + return -1 * Math.cos(t / d * (Math.PI / 2)) + 1; + } + + public static easeOut(t: number, d: number) { + return Math.sin(t / d * (Math.PI / 2)); + } + + public static easeInOut(t: number, d: number) { + return -0.5 * (Math.cos(Math.PI * t / d) - 1); + } + } + } +} \ No newline at end of file diff --git a/source/src/Tween/Easing/Lerps.ts b/source/src/Tween/Easing/Lerps.ts new file mode 100644 index 00000000..53957bda --- /dev/null +++ b/source/src/Tween/Easing/Lerps.ts @@ -0,0 +1,84 @@ +module es { + /** + * 一系列静态方法来处理所有常见的tween类型结构,以及它们的unclamped lerps.unclamped lerps对于超过0-1范围的bounce、elastic或其他tweens是必需的 + */ + export class Lerps { + public static lerp(from: Color, to: Color, t: number); + public static lerp(from: number, to: number, t: number); + public static lerp(from: Rectangle, to: Rectangle, t: number); + public static lerp(from: Vector2, to: Vector2, t: number); + public static lerp(from: any, to: any, t: number) { + if (typeof(from) == "number" && typeof(to) == "number") { + return from + (to - from) * t; + } + + if (from instanceof Color && to instanceof Color) { + const t255 = t * 255; + return new Color(from.r + (to.r - from.r) * t255 / 255, from.g + (to.g - from.g) * t255 / 255, + from.b + (to.b - from.b) * t255 / 255, from.a + (to.a - from.a) * t255 / 255) + } + + if (from instanceof Rectangle && to instanceof Rectangle) { + return new Rectangle( + (from.x + (to.x - from.x) * t), + (from.y + (to.x - from.y) * t), + (from.width + (to.width - from.width) * t), + (from.height + (to.height - from.height) * t) + ); + } + + if (from instanceof Vector2 && to instanceof Vector2) { + return new Vector2(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t); + } + } + + public static angleLerp(from: Vector2, to: Vector2, t: number) { + // 我们计算这个lerp的最短角差 + let toMinusFrom = new Vector2(MathHelper.deltaAngle(from.x, to.x), MathHelper.deltaAngle(from.y, to.y)); + return new Vector2(from.x + toMinusFrom.x * t, from.y + toMinusFrom.y * t); + } + + public static ease(easeType: EaseType, from: Rectangle, to: Rectangle, t: number, duration: number); + public static ease(easeType: EaseType, from: Vector2, to: Vector2, t: number, duration: number); + public static ease(easeType: EaseType, from: number, to: number, t: number, duration: number); + public static ease(easeType: EaseType, from: Color, to: Color, t: number, duration: number); + public static ease(easeType: EaseType, from: any, to: any, t: number, duration: number) { + if (typeof(from) == 'number' && typeof(to) == "number") { + return this.lerp(from, to, EaseHelper.ease(easeType, t, duration)); + } + + if (from instanceof Vector2 && to instanceof Vector2) { + return this.lerp(from, to, EaseHelper.ease(easeType, t, duration)); + } + + if (from instanceof Rectangle && to instanceof Rectangle) { + return this.lerp(from, to, EaseHelper.ease(easeType, t, duration)); + } + + if (from instanceof Color && to instanceof Color) { + return this.lerp(from, to, EaseHelper.ease(easeType, t, duration)); + } + } + + public static easeAngle(easeType: EaseType, from: Vector2, to: Vector2, t: number, duration: number) { + return this.angleLerp(from, to, EaseHelper.ease(easeType, t, duration)); + } + + /** + * 使用半隐式欧拉方法。速度较慢,但总是很稳定。见 + * http://allenchou.net/2015/04/game-math-more-on-numeric-springing/ + * @param currentValue + * @param targetValue + * @param velocity Velocity的引用。如果在两次调用之间改变targetValue,请务必将其重置为0 + * @param dampingRatio 值越低,阻尼越小,值越高,阻尼越大,导致弹簧度越小,应在0.01-1之间,以避免系统不稳定 + * @param angularFrequency 角频率为2pi(弧度/秒)意味着振荡在一秒钟内完成一个完整的周期,即1Hz.应小于35左右才能保持稳定 + */ + public static fastSpring(currentValue: Vector2, targetValue: Vector2, velocity: Vector2, + dampingRatio: number, angularFrequency: number) { + velocity.add(velocity.scale(-2 * Time.deltaTime * dampingRatio * angularFrequency) + .add(targetValue.sub(currentValue).scale(Time.deltaTime * angularFrequency * angularFrequency))); + currentValue.add(velocity.scale(Time.deltaTime)); + return currentValue; + } + } +} \ No newline at end of file diff --git a/source/src/Tween/Interfaces/ITween.ts b/source/src/Tween/Interfaces/ITween.ts new file mode 100644 index 00000000..98fa1c0f --- /dev/null +++ b/source/src/Tween/Interfaces/ITween.ts @@ -0,0 +1,79 @@ +module es { + /** + * 一系列强类型、可链式的方法来设置各种tween属性 + */ + export interface ITween extends ITweenControl { + /** + * 设置该tween的易用性类型 + * @param easeType + */ + setEaseType(easeType: EaseType): ITween; + /** + * 设置启动tween前的延迟 + * @param delay + */ + setDelay(delay: number): ITween; + /** + * 设置tween的持续时间 + * @param duration + */ + setDuration(duration: number): ITween; + /** + * 设置这个tween使用的timeScale。 + * TimeScale将与Time.deltaTime/Time.unscaledDeltaTime相乘,从而得到tween实际使用的delta时间 + * @param timeScale + */ + setTimeScale(timeScale: number): ITween; + /** + * 设置tween使用Time.unscaledDeltaTime代替Time.deltaTime + */ + setIsTimeScaleIndependent(): ITween; + /** + * 设置当tween完成时应该调用的动作 + * @param completionHandler + */ + setCompletionHandler(completionHandler: (tween: ITween) => void): ITween; + /** + * 设置tween的循环类型。一个pingpong循环意味着从开始-结束-开始 + * @param loopType + * @param loops + * @param delayBetweenLoops + */ + setLoops(loopType: LoopType, loops: number, delayBetweenLoops: number): ITween; + /** + * 设置tween的起始位置 + * @param from + */ + setFrom(from: T): ITween; + /** + * 通过重置tween的from/to值和持续时间,为重复使用tween做准备。 + * @param from + * @param to + * @param duration + */ + prepareForReuse(from: T, to: T, duration: number): ITween; + /** + * 如果为true(默认值),tween将在使用后被回收。 + * 如果在TweenManager类中进行了配置,所有的Tween子类都有自己相关的自动缓存 + * @param shouldRecycleTween + */ + setRecycleTween(shouldRecycleTween: boolean): ITween; + /** + * 帮助程序,只是将tween的to值设置为相对于其当前值的+从使tween + */ + setIsRelative(): ITween; + /** + * 允许你通过tween.context.context来设置任何可检索的对象引用。 + * 这对于避免完成处理程序方法的闭包分配是很方便的。 + * 你也可以在TweenManager中搜索具有特定上下文的所有tweens + * @param context + */ + setContext(context): ITween; + /** + * 允许你添加一个tween,这个tween完成后会被运行。 + * 注意 nextTween 必须是一个 ITweenable! 同时注意,所有的ITweenT都是ITweenable + * @param nextTween + */ + setNextTween(nextTween: ITweenable): ITween; + } +} \ No newline at end of file diff --git a/source/src/Tween/Interfaces/ITweenControl.ts b/source/src/Tween/Interfaces/ITweenControl.ts new file mode 100644 index 00000000..8c08870b --- /dev/null +++ b/source/src/Tween/Interfaces/ITweenControl.ts @@ -0,0 +1,24 @@ +module es { + /** + * 更多具体的Tween播放控制在这里 + */ + export interface ITweenControl extends ITweenable { + /** + * 当使用匿名方法时,您可以在任何回调(如完成处理程序)中使用该属性来避免分配 + */ + context; + /** + * 将tween扭曲为elapsedTime,并将其限制在0和duration之间,无论tween对象是暂停、完成还是运行,都会立即更新 + * @param elapsedTime 所用时间 + */ + jumpToElapsedTime(elapsedTime: number); + /** + * 当从StartCoroutine调用时,它将直到tween完成 + */ + waitForCompletion(): any; + /** + * 获取tween的目标,如果TweenTargets不一定都是一个对象,则为null,它的唯一真正用途是让TweenManager按目标查找tweens的列表 + */ + getTargetObject(): any; + } +} \ No newline at end of file diff --git a/source/src/Tween/Interfaces/ITweenTarget.ts b/source/src/Tween/Interfaces/ITweenTarget.ts new file mode 100644 index 00000000..0495efeb --- /dev/null +++ b/source/src/Tween/Interfaces/ITweenTarget.ts @@ -0,0 +1,19 @@ +module es { + /** + * 任何想要被weened的对象都需要实现这个功能。 + * TweenManager内部喜欢做一个简单的对象来实现这个接口,并存储一个对被tweened对象的引用 + */ + export interface ITweenTarget { + /** + * 在你选择的对象上设置最终的tweened值 + * @param value + */ + setTweenedValue(value: T); + + getTweenedValue(): T; + /** + * 获取tween的目标,如果TweenTargets不一定都是一个对象,则为null,它的唯一真正用途是让TweenManager按目标查找tweens的列表 + */ + getTargetObject(): any; + } +} \ No newline at end of file diff --git a/source/src/Tween/Interfaces/ITweenable.ts b/source/src/Tween/Interfaces/ITweenable.ts new file mode 100644 index 00000000..b1f3eae1 --- /dev/null +++ b/source/src/Tween/Interfaces/ITweenable.ts @@ -0,0 +1,34 @@ +module es { + export interface ITweenable { + /** + * 就像内部的Update一样,每一帧都被TweenManager调用 + */ + tick(): boolean; + /** + * 当一个tween被移除时,由TweenManager调用。子 + * 类可以选择自己回收。子类应该首先在其实现中检查_shouldRecycleTween bool! + */ + recycleSelf(); + /** + * 检查是否有tween在运行 + */ + isRunning(): boolean; + /** + * 启动tween + */ + start(); + /** + * 暂停 + */ + pause(); + /** + * 暂停后恢复tween + */ + resume(); + /** + * 停止tween,并可选择将其完成 + * @param bringToCompletion + */ + stop(bringToCompletion: boolean); + } +} \ No newline at end of file diff --git a/source/src/Tween/PropertyTweens.ts b/source/src/Tween/PropertyTweens.ts new file mode 100644 index 00000000..ad27bb89 --- /dev/null +++ b/source/src/Tween/PropertyTweens.ts @@ -0,0 +1,44 @@ +module es { + /** + * 通用ITweenTarget用于所有属性tweens。 + */ + class PropertyTarget implements ITweenTarget { + protected _target; + protected _propertyName; + + constructor(target, propertyName: string) { + this._target = target; + this._propertyName = propertyName; + } + + public getTargetObject() { + return this._target; + } + + public setTweenedValue(value: T) { + this._target[this._propertyName] = value; + } + + public getTweenedValue(): T { + return this._target[this._propertyName]; + } + } + + export class PropertyTweens { + public static NumberPropertyTo(self, memberName: string, to: number, duration: number): ITween { + let tweenTarget = new PropertyTarget(self, memberName); + let tween = TweenManager.cacheNumberTweens ? Pool.obtain(NumberTween) : new NumberTween(); + tween.initialize(tweenTarget, to, duration); + + return tween; + } + + public static Vector2PropertyTo(self, memeberName: string, to: Vector2, duration: number): ITween { + let tweenTarget = new PropertyTarget(self, memeberName); + let tween = TweenManager.cacheVector2Tweens ? Pool.obtain(Vector2Tween) : new Vector2Tween(); + tween.initialize(tweenTarget, to, duration); + + return tween; + } + } +} \ No newline at end of file diff --git a/source/src/Tween/RenderableColorTween.ts b/source/src/Tween/RenderableColorTween.ts new file mode 100644 index 00000000..eea8271f --- /dev/null +++ b/source/src/Tween/RenderableColorTween.ts @@ -0,0 +1,38 @@ +/// +module es { + export class RenderableColorTween extends ColorTween implements ITweenTarget { + _renderable: RenderableComponent; + + setTweenedValue(value: Color) { + this._renderable.color = value; + } + + getTweenedValue(): Color { + return this._renderable.color; + } + + public getTargetObject() { + return this._renderable; + } + + public updateValue() { + this.setTweenedValue(Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } + + public setTarget(renderable: RenderableComponent) { + this._renderable = renderable; + } + + public recycleSelf() { + if (this._shouldRecycleTween) { + this._renderable = null; + this._target = null; + this._nextTween = null; + } + + if (this._shouldRecycleTween && TweenManager.cacheColorTweens) { + Pool.free(this); + } + } + } +} \ No newline at end of file diff --git a/source/src/Tween/TransformSpringTween.ts b/source/src/Tween/TransformSpringTween.ts new file mode 100644 index 00000000..f9d8765f --- /dev/null +++ b/source/src/Tween/TransformSpringTween.ts @@ -0,0 +1,100 @@ +module es { + export class TransformSpringTween extends AbstractTweenable { + public get targetType() { + return this._targetType; + } + + private _transform: Transform; + private _targetType: TransformTargetType; + private _targetValue: Vector2; + private _velocity: Vector2; + + // 阻尼比(dampingRatio)和角频率(angularFrequency)的配置是公开的,以便于在设计时进行调整 + + /** + * 值越低,阻尼越小,值越高,阻尼越大,导致弹簧度越小,应在0.01-1之间,以避免系统不稳定 + */ + public dampingRatio: number = 0.23; + /** + * 角频率为2pi(弧度/秒)意味着振荡在一秒钟内完成一个完整的周期,即1Hz.应小于35左右才能保持稳定角频率 + */ + public angularFrequency: number = 25; + + constructor(transform: Transform, targetType: TransformTargetType, targetValue: Vector2) { + super(); + this._transform = transform; + this._targetType = targetType; + this.setTargetValue(targetValue); + } + + /** + * 你可以在任何时候调用setTargetValue来重置目标值到一个新的Vector2。 + * 如果你没有调用start来添加spring tween,它会为你调用 + * @param targetValue + */ + public setTargetValue(targetValue: Vector2) { + this._velocity = Vector2.zero; + this._targetValue = targetValue; + + if (!this._isCurrentlyManagedByTweenManager) + this.start(); + } + + /** + * lambda应该是振荡幅度减少50%时的理想持续时间 + * @param lambda + */ + public updateDampingRatioWithHalfLife(lambda: number) { + this.dampingRatio = (-lambda / this.angularFrequency) * Math.log(0.5); + } + + public tick() { + if (!this._isPaused) + this.setTweenedValue(Lerps.fastSpring(this.getCurrentValueOfTweenedTargetType(), this._targetValue, this._velocity, + this.dampingRatio, this.angularFrequency)); + + return false; + } + + private setTweenedValue(value: Vector2) { + switch (this._targetType) { + case TransformTargetType.position: + this._transform.position = value; + break; + case TransformTargetType.localPosition: + this._transform.localPosition = value; + break; + case TransformTargetType.scale: + this._transform.scale = value; + break; + case TransformTargetType.localScale: + this._transform.localScale = value; + break; + case TransformTargetType.rotationDegrees: + this._transform.rotationDegrees = value.x; + case TransformTargetType.localRotationDegrees: + this._transform.localRotationDegrees = value.x; + break; + } + } + + private getCurrentValueOfTweenedTargetType() { + switch (this._targetType) { + case TransformTargetType.position: + return this._transform.position; + case TransformTargetType.localPosition: + return this._transform.localPosition; + case TransformTargetType.scale: + return this._transform.scale; + case TransformTargetType.localScale: + return this._transform.localScale; + case TransformTargetType.rotationDegrees: + return new Vector2(this._transform.rotationDegrees); + case TransformTargetType.localRotationDegrees: + return new Vector2(this._transform.localRotationDegrees, 0); + default: + return Vector2.zero; + } + } + } +} \ No newline at end of file diff --git a/source/src/Tween/TransformVector2Tween.ts b/source/src/Tween/TransformVector2Tween.ts new file mode 100644 index 00000000..8f367954 --- /dev/null +++ b/source/src/Tween/TransformVector2Tween.ts @@ -0,0 +1,90 @@ +/// +module es { + /** + * 对任何与Transform相关的属性tweens都是有用的枚举 + */ + export enum TransformTargetType { + position, + localPosition, + scale, + localScale, + rotationDegrees, + localRotationDegrees, + } + + /** + * 这是一个特殊的情况,因为Transform是迄今为止最被ween的对象。 + * 我们将Tween和ITweenTarget封装在一个单一的、可缓存的类中 + */ + export class TransformVector2Tween extends Vector2Tween implements ITweenTarget { + private _transform: Transform; + private _targetType: TransformTargetType; + + public setTweenedValue(value: Vector2) { + switch (this._targetType) { + case TransformTargetType.position: + this._transform.position = value; + break; + case TransformTargetType.localPosition: + this._transform.localPosition = value; + break; + case TransformTargetType.scale: + this._transform.scale = value; + break; + case TransformTargetType.localScale: + this._transform.localScale = value; + break; + case TransformTargetType.rotationDegrees: + this._transform.rotationDegrees = value.x; + case TransformTargetType.localRotationDegrees: + this._transform.localRotationDegrees = value.x; + break; + } + } + + public getTweenedValue(): Vector2 { + switch (this._targetType) { + case TransformTargetType.position: + return this._transform.position; + case TransformTargetType.localPosition: + return this._transform.localPosition; + case TransformTargetType.scale: + return this._transform.scale; + case TransformTargetType.localScale: + return this._transform.localScale; + case TransformTargetType.rotationDegrees: + return new Vector2(this._transform.rotationDegrees, this._transform.rotationDegrees); + case TransformTargetType.localRotationDegrees: + return new Vector2(this._transform.localRotationDegrees, 0); + } + } + + public getTargetObject() { + return this._transform; + } + + public setTargetAndType(transform: Transform, targetType: TransformTargetType) { + this._transform = transform; + this._targetType = targetType; + } + + protected updateValue() { + // 非相对角勒普的特殊情况,使他们采取尽可能短的旋转 + if ((this._targetType == TransformTargetType.rotationDegrees || + this._targetType == TransformTargetType.localRotationDegrees) && !this._isRelative) { + this.setTweenedValue(Lerps.easeAngle(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } else { + this.setTweenedValue(Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } + } + + public recycleSelf() { + if (this._shouldRecycleTween) { + this._target = null; + this._nextTween = null; + this._transform = null; + Pool.free(this); + } + } + } +} \ No newline at end of file diff --git a/source/src/Tween/Tween.ts b/source/src/Tween/Tween.ts new file mode 100644 index 00000000..f594d99c --- /dev/null +++ b/source/src/Tween/Tween.ts @@ -0,0 +1,319 @@ +module es { + export enum LoopType { + none, + restartFromBeginning, + pingpong + } + + export enum TweenState { + running, + paused, + complete + } + + export abstract class Tween implements ITweenable, ITween { + protected _target: ITweenTarget; + protected _isFromValueOverridden: boolean; + protected _fromValue: T; + protected _toValue: T; + protected _easeType: EaseType; + protected _shouldRecycleTween: boolean = true; + protected _isRelative: boolean; + protected _completionHandler: (tween: ITween) => void; + protected _loopCompleteHandler: (tween: ITween) => void; + protected _nextTween: ITweenable; + + protected _tweenState: TweenState = TweenState.complete; + private _isTimeScaleIndependent: boolean; + protected _delay: number; + protected _duration: number; + protected _timeScale: number = 1; + protected _elapsedTime: number; + + protected _loopType: LoopType; + protected _loops: number; + protected _delayBetweenLoops: number; + private _isRunningInReverse: boolean; + + public context: any; + + public setEaseType(easeType: EaseType): ITween { + this._easeType = easeType; + return this; + } + + public setDelay(delay: number): ITween { + this._delay = delay; + this._elapsedTime = -this._delay; + return this; + } + + public setDuration(duration: number): ITween { + this._duration = duration; + return this; + } + + public setTimeScale(timeSclae: number): ITween { + this._timeScale = timeSclae; + return this; + } + + public setIsTimeScaleIndependent(): ITween { + this._isTimeScaleIndependent = true; + return this; + } + + public setCompletionHandler(completeHandler: (tween: ITween) => void): ITween { + this._completionHandler = completeHandler; + return this; + } + + public setLoops(loopType: LoopType, loops: number = 1, delayBetweenLoops: number = 0): ITween { + this._loopType = loopType; + this._delayBetweenLoops = delayBetweenLoops; + + if (loops < 0) + loops = -1; + + if (loopType == LoopType.pingpong) + loops = loops * 2; + + this._loops = loops; + return this; + } + + public setLoopCompletionHanlder(loopCompleteHandler: (tween: ITween) => void): ITween { + this._loopCompleteHandler = loopCompleteHandler; + return this; + } + + public setFrom(from: T): ITween { + this._isFromValueOverridden = true; + this._fromValue = from; + return this; + } + + public prepareForReuse(from: T, to: T, duration: number): ITween { + this.initialize(this._target, to, duration); + return this; + } + + public setRecycleTween(shouldRecycleTween: boolean): ITween { + this._shouldRecycleTween = shouldRecycleTween; + return this; + } + + public abstract setIsRelative(): ITween; + + public setContext(context): ITween { + this.context = context; + return this; + } + + public setNextTween(nextTween: ITweenable): ITween { + this._nextTween = nextTween; + return this; + } + + public tick(): boolean { + if (this._tweenState == TweenState.paused) + return false; + + // 当我们进行循环时,我们会在0和持续时间之间限制数值 + let elapsedTimeExcess = 0; + if (!this._isRunningInReverse && this._elapsedTime >= this._duration) { + elapsedTimeExcess = this._elapsedTime - this._duration; + this._elapsedTime = this._duration; + this._tweenState = TweenState.complete; + } else if (this._isRunningInReverse && this._elapsedTime <= 0) { + elapsedTimeExcess = 0 - this._elapsedTime; + this._elapsedTime = 0; + this._tweenState = TweenState.complete; + } + + // 当我们延迟开始tween的时候,经过的时间会是负数,所以不要更新这个值。 + if (this._elapsedTime >= 0 && this._elapsedTime <= this._duration) { + this.updateValue(); + } + + + // 如果我们有一个loopType,并且我们是Complete(意味着我们达到了0或持续时间)处理循环。 + // handleLooping将采取任何多余的elapsedTime,并将其因子化,并在必要时调用udpateValue来保持tween的完美准确性 + if (this._loopType != LoopType.none && this._tweenState == TweenState.complete && this._loops != 0) { + this.handleLooping(elapsedTimeExcess); + } + + let deltaTime = this._isTimeScaleIndependent ? Time.unscaledDeltaTime : Time.deltaTime; + deltaTime *= this._timeScale; + + // 我们需要减去deltaTime + if (this._isRunningInReverse) + this._elapsedTime -= deltaTime; + else + this._elapsedTime += deltaTime; + + if (this._tweenState == TweenState.complete) { + this._completionHandler && this._completionHandler(this); + + // 如果我们有一个nextTween,把它添加到TweenManager中,这样它就可以开始运行了 + if (this._nextTween != null) { + this._nextTween.start(); + this._nextTween = null; + } + + return true; + } + + return false; + } + + public recycleSelf() { + if (this._shouldRecycleTween) { + this._target = null; + this._nextTween = null; + } + } + + public isRunning(): boolean { + return this._tweenState == TweenState.running; + } + + public start() { + if (!this._isFromValueOverridden) + this._fromValue = this._target.getTargetObject(); + + if (this._tweenState == TweenState.complete) { + this._tweenState = TweenState.running; + TweenManager.addTween(this); + } + } + + public pause() { + this._tweenState = TweenState.paused; + } + + public resume() { + this._tweenState = TweenState.running; + } + + public stop(bringToCompletion: boolean = false) { + this._tweenState = TweenState.complete; + + if (bringToCompletion) { + // 如果我们逆向运行,我们在0处结束,否则我们进入持续时间 + this._elapsedTime = this._isRunningInReverse ? 0 : this._duration; + this._loopType = LoopType.none; + this._loops = 0; + + // TweenManager将在下一个tick上进行删除处理 + } else { + TweenManager.removeTween(this); + } + } + + public jumpToElapsedTime(elapsedTime) { + this._elapsedTime = MathHelper.clamp(elapsedTime, 0, this._duration); + this.updateValue(); + } + + /** + * 反转当前的tween,如果是向前走,就会向后走,反之亦然 + */ + public reverseTween() { + this._isRunningInReverse = !this._isRunningInReverse; + } + + /** + * 当通过StartCoroutine调用时,这将一直持续到tween完成 + */ + public * waitForCompletion() { + while (this._tweenState != TweenState.complete) + yield null; + } + + public getTargetObject() { + return this._target.getTargetObject(); + } + + private resetState() { + this.context = null; + this._completionHandler = this._loopCompleteHandler = null; + this._isFromValueOverridden = false; + this._isTimeScaleIndependent = false; + this._tweenState = TweenState.complete; + + // TODO: 我认为在没有得到用户同意的情况下,我们绝对不应该从_shouldRecycleTween=false。需要研究和思考 + // this._shouldRecycleTween = true; + this._isRelative = false; + this._easeType = TweenManager.defaultEaseType; + + if (this._nextTween != null) { + this._nextTween.recycleSelf(); + this._nextTween = null; + } + + this._delay = 0; + this._duration = 0; + this._timeScale = 1; + this._elapsedTime = 0; + this._loopType = LoopType.none; + this._delayBetweenLoops = 0; + this._loops = 0; + this._isRunningInReverse = false; + } + + /** + * 将所有状态重置为默认值,并根据传入的参数设置初始状态。 + * 这个方法作为一个切入点,这样Tween子类就可以调用它,这样tweens就可以被回收。 + * 当回收时,构造函数不会再被调用,所以这个方法封装了构造函数要做的事情 + * @param target + * @param to + * @param duration + */ + public initialize(target: ITweenTarget, to: T, duration: number) { + // 重置状态,以防我们被回收 + this.resetState(); + + this._target = target; + this._toValue = to; + this._duration = duration; + } + + /** + * 处理循环逻辑 + * @param elapsedTimeExcess + */ + private handleLooping(elapsedTimeExcess: number) { + this._loops--; + if (this._loopType == LoopType.pingpong) { + this.reverseTween(); + } + + if (this._loopType == LoopType.restartFromBeginning || this._loops % 2 == 0) { + this._loopCompleteHandler && this._completionHandler(this); + } + + // 如果我们还有循环要处理,就把我们的状态重置为Running,这样我们就可以继续处理它们了 + if (this._loops != 0) { + this._tweenState = TweenState.running; + + // 现在,我们需要设置我们的经过时间,并考虑到我们的elapsedTimeExcess + if (this._loopType == LoopType.restartFromBeginning) { + this._elapsedTime = elapsedTimeExcess - this._delayBetweenLoops; + } else { + if (this._isRunningInReverse) + this._elapsedTime += this._delayBetweenLoops - elapsedTimeExcess; + else + this._elapsedTime = elapsedTimeExcess - this._delayBetweenLoops; + } + + // 如果我们有一个elapsedTimeExcess,并且没有delayBetweenLoops,则更新该值 + if (this._delayBetweenLoops == 0 && elapsedTimeExcess > 0) { + this.updateValue(); + } + } + } + + protected abstract updateValue(); + } +} \ No newline at end of file diff --git a/source/src/Tween/TweenManager.ts b/source/src/Tween/TweenManager.ts new file mode 100644 index 00000000..653b2d00 --- /dev/null +++ b/source/src/Tween/TweenManager.ts @@ -0,0 +1,152 @@ +/// +/// +module es { + export class TweenManager extends GlobalManager { + public static defaultEaseType: EaseType = EaseType.quartIn; + + /** + * 如果为真,当加载新关卡时,活动的tween列表将被清除 + */ + public static removeAllTweensOnLevelLoad: boolean = false; + + /** + * 这里支持各种类型的自动缓存。请 + * 注意,只有在使用扩展方法启动tweens时,或者在做自定义tweens时从缓存中获取tween时,缓存才会起作用。 + * 关于如何获取缓存的tween,请参见扩展方法的实现 + */ + public static cacheNumberTweens = true; + public static cacheVector2Tweens = true; + public static cacheColorTweens = true; + public static cacheRectTweens = false; + + /** + * 当前所有活跃用户的内部列表 + */ + private _activeTweens: ITweenable[] = []; + private _tempTweens: ITweenable[] = []; + /** + * 标志表示tween更新循环正在运行 + */ + private _isUpdating: boolean; + /** + * 便于暴露一个静态的API以方便访问 + */ + private static _instance: TweenManager; + + constructor() { + super(); + TweenManager._instance = this; + } + + public update() { + this._isUpdating = true; + + // 反向循环,这样我们就可以把完成的weens删除了 + for (let i = this._activeTweens.length - 1; i >= 0; --i) { + let tween = this._activeTweens[i]; + if (tween.tick()) + this._tempTweens.push(tween); + } + + this._isUpdating = false; + + for (let i = 0; i < this._tempTweens.length; i++) { + this._tempTweens[i].recycleSelf(); + new List(this._activeTweens).remove(this._tempTweens[i]); + } + + this._tempTweens.length = 0; + } + + /** + * 将一个tween添加到活动tweens列表中 + * @param tween + */ + public static addTween(tween: ITweenable) { + TweenManager._instance._activeTweens.push(tween); + } + + /** + * 从当前的tweens列表中删除一个tween + * @param tween + */ + public static removeTween(tween: ITweenable) { + if (TweenManager._instance._isUpdating) { + TweenManager._instance._tempTweens.push(tween); + } else { + tween.recycleSelf(); + new List(TweenManager._instance._activeTweens).remove(tween); + } + } + + /** + * 停止所有的tween并选择地把他们全部完成 + * @param bringToCompletion + */ + public static stopAllTweens(bringToCompletion: boolean = false) { + for (let i = TweenManager._instance._activeTweens.length - 1; i >= 0; --i) + TweenManager._instance._activeTweens[i].stop(bringToCompletion); + } + + /** + * 返回具有特定上下文的所有tweens。 + * Tweens以ITweenable的形式返回,因为这就是TweenManager所知道的所有内容 + * @param context + */ + public static allTweensWithContext(context): ITweenable[] { + let foundTweens = []; + for (let i = 0; i < TweenManager._instance._activeTweens.length; i++) { + if ((TweenManager._instance._activeTweens[i] as ITweenControl).context == context) + foundTweens.push(TweenManager._instance._activeTweens[i]); + } + + return foundTweens; + } + + /** + * 停止所有给定上下文的tweens + * @param context + * @param bringToCompletion + */ + public static stopAllTweensWithContext(context, bringToCompletion: boolean = false) { + for (let i = TweenManager._instance._activeTweens.length - 1; i >= 0; --i) { + if ((TweenManager._instance._activeTweens[i] as ITweenControl).context == context) + TweenManager._instance._activeTweens[i].stop(bringToCompletion); + } + } + + /** + * 返回具有特定目标的所有tweens。 + * Tweens以ITweenControl的形式返回,因为TweenManager只知道这些 + * @param target + */ + public static allTweenWithTarget(target): ITweenable[] { + let foundTweens = []; + + for (let i = 0; i < TweenManager._instance._activeTweens.length; i++) { + if (TweenManager._instance._activeTweens[i]) { + let tweenControl = TweenManager._instance._activeTweens[i] as ITweenControl; + if (tweenControl.getTargetObject() == target) + foundTweens.push(TweenManager._instance._activeTweens[i]); + } + } + + return foundTweens; + } + + /** + * 停止所有具有TweenManager知道的特定目标的tweens + * @param target + * @param bringToCompletion + */ + public static stopAllTweensWithTarget(target, bringToCompletion: boolean = false) { + for (let i = TweenManager._instance._activeTweens.length - 1; i >= 0; --i) { + if (TweenManager._instance._activeTweens[i]) { + let tweenControl = TweenManager._instance._activeTweens[i] as ITweenControl; + if (tweenControl.getTargetObject() == target) + tweenControl.stop(bringToCompletion); + } + } + } + } +} \ No newline at end of file diff --git a/source/src/Tween/Tweens.ts b/source/src/Tween/Tweens.ts new file mode 100644 index 00000000..aac1eb75 --- /dev/null +++ b/source/src/Tween/Tweens.ts @@ -0,0 +1,117 @@ +/// +module es { + export class NumberTween extends Tween { + public static create(): NumberTween { + return TweenManager.cacheNumberTweens ? Pool.obtain(NumberTween) : new NumberTween(); + } + + constructor(target?: ITweenTarget, to?: number, duration?: number) { + super(); + this.initialize(target, to, duration); + } + + public setIsRelative(): ITween { + this._isRelative = true; + this._toValue += this._fromValue; + return this; + } + + protected updateValue() { + this._target.setTweenedValue(Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } + + public recycleSelf() { + super.recycleSelf(); + + if (this._shouldRecycleTween && TweenManager.cacheNumberTweens) + Pool.free(this); + } + } + + export class Vector2Tween extends Tween { + public static create(): Vector2Tween { + return TweenManager.cacheVector2Tweens ? Pool.obtain(Vector2Tween) : new Vector2Tween(); + } + + constructor(target?: ITweenTarget, to?: Vector2, duration?: number) { + super(); + this.initialize(target, to, duration); + } + + public setIsRelative(): ITween { + this._isRelative = true; + this._toValue.add(this._fromValue); + return this; + } + + protected updateValue() { + this._target.setTweenedValue(Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } + + public recycleSelf() { + super.recycleSelf(); + + if (this._shouldRecycleTween && TweenManager.cacheVector2Tweens) + Pool.free(this); + } + } + + export class RectangleTween extends Tween { + public static create(): RectangleTween { + return TweenManager.cacheRectTweens ? Pool.obtain(RectangleTween) : new RectangleTween(); + } + + constructor(target?: ITweenTarget, to?: Rectangle, duration?: number) { + super(); + this.initialize(target, to, duration); + } + + public setIsRelative(): ITween { + this._isRelative = true; + this._toValue = new 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); + + return this; + } + + protected updateValue() { + this._target.setTweenedValue(Lerps.ease(this._easeType, this._fromValue, this._toValue, this._elapsedTime, this._duration)); + } + + public recycleSelf() { + super.recycleSelf(); + + if (this._shouldRecycleTween && TweenManager.cacheRectTweens) + Pool.free(this); + } + } + + export class ColorTween extends Tween { + public static create() : ColorTween { + return TweenManager.cacheColorTweens ? Pool.obtain(ColorTween) : new ColorTween(); + + } + + constructor(target?: ITweenTarget, to?: Color, duration?: number) { + super(); + + this.initialize(target, to, duration); + } + + public setIsRelative() { + this._isRelative = true; + this._toValue.r += this._fromValue.r; + this._toValue.g += this._fromValue.g; + this._toValue.b += this._fromValue.b; + this._toValue.a += this._fromValue.a; + return this; + } + + protected updateValue() { + this._target.setTweenedValue(Lerps.ease(this._easeType, this._fromValue as any, this._toValue as any, this._elapsedTime, this._duration)); + } + } +} \ No newline at end of file